# Path: vcstool/clients/vcs_base.py
# def load_url(url, retry=2, retry_period=1, timeout=10):
#     try:
#         fh = urlopen(url, timeout=timeout)
#     except HTTPError as e:
#         if e.code == 503 and retry:
#             time.sleep(retry_period)
#             return load_url(
#                 url, retry=retry - 1, retry_period=retry_period,
#                 timeout=timeout)
#         e.msg += ' (%s)' % url
#         raise
#     except URLError as e:
#         if isinstance(e.reason, socket.timeout) and retry:
#             time.sleep(retry_period)
#             return load_url(
#                 url, retry=retry - 1, retry_period=retry_period,
#                 timeout=timeout)
#         raise URLError(str(e) + ' (%s)' % url)
#     return fh.read()
# 
# Path: vcstool/clients/vcs_base.py
# def test_url(url, retry=2, retry_period=1, timeout=10):
#     request = Request(url)
#     request.get_method = lambda: 'HEAD'
# 
#     try:
#         response = urlopen(request)
#     except HTTPError as e:
#         if e.code == 503 and retry:
#             time.sleep(retry_period)
#             return test_url(
#                 url, retry=retry - 1, retry_period=retry_period,
#                 timeout=timeout)
#         e.msg += ' (%s)' % url
#         raise
#     except URLError as e:
#         if isinstance(e.reason, socket.timeout) and retry:
#             time.sleep(retry_period)
#             return test_url(
#                 url, retry=retry - 1, retry_period=retry_period,
#                 timeout=timeout)
#         raise URLError(str(e) + ' (%s)' % url)
#     return response
# 
# Path: vcstool/clients/vcs_base.py
# class VcsClientBase(object):
# 
#     type = None
# 
#     def __init__(self, path):
#         self.path = path
# 
#     def __getattribute__(self, name):
#         if name == 'import':
#             try:
#                 return self.import_
#             except AttributeError:
#                 pass
#         return super(VcsClientBase, self).__getattribute__(name)
# 
#     def _not_applicable(self, command, message=None):
#         return {
#             'cmd': '%s.%s(%s)' % (
#                 self.__class__.type, 'push', command.__class__.command),
#             'output': "Command '%s' not applicable for client '%s'%s" % (
#                 command.__class__.command, self.__class__.type,
#                 ': ' + message if message else ''),
#             'returncode': NotImplemented
#         }
# 
#     def _run_command(self, cmd, env=None, retry=0):
#         for i in range(retry + 1):
#             result = run_command(cmd, os.path.abspath(self.path), env=env)
#             if not result['returncode']:
#                 # return successful result
#                 break
#             if i >= retry:
#                 # return the failure after retries
#                 break
#             # increasing sleep before each retry
#             time.sleep(i + 1)
#         return result
# 
#     def _create_path(self):
#         if not os.path.exists(self.path):
#             try:
#                 os.makedirs(self.path)
#             except os.error as e:
#                 return {
#                     'cmd': 'os.makedirs(%s)' % self.path,
#                     'cwd': self.path,
#                     'output':
#                         "Could not create directory '%s': %s" % (self.path, e),
#                     'returncode': 1
#                 }
#         return None
# 
# Path: vcstool/util.py
# def rmtree(path):
#     kwargs = {}
#     if sys.platform == 'win32':
#         kwargs['onerror'] = _onerror_windows
#     return shutil_rmtree(path, **kwargs)


from io import BytesIO
from urllib.error import URLError
from .vcs_base import load_url
from .vcs_base import test_url
from .vcs_base import VcsClientBase
from ..util import rmtree
import os
import zipfile
        return {
            'cmd': '',
            'cwd': self.path,
            'output':
                "Downloaded zipfile from '%s' and unpacked it" % command.url,
            'returncode': 0
        }

    def validate(self, command):
        if not command.url:
            return {
                'cmd': '',
                'cwd': self.path,
                'output': "Repository data lacks the 'url' value",
                'returncode': 1
            }

        # test url
        try:
            test_url(command.url, retry=command.retry)
        except URLError as e:
            return {
                'cmd': '',
                'cwd': self.path,
                'output':
                    "Failed to contact zip url '%s': %s" % (command.url, e),
                'returncode': 1
            }
        return {
            'cmd': 'http HEAD',

# Path: vcstool/clients/vcs_base.py
# def load_url(url, retry=2, retry_period=1, timeout=10):
#     try:
#         fh = urlopen(url, timeout=timeout)
#     except HTTPError as e:
#         if e.code == 503 and retry:
#             time.sleep(retry_period)
#             return load_url(
#                 url, retry=retry - 1, retry_period=retry_period,
#                 timeout=timeout)
#         e.msg += ' (%s)' % url
#         raise
#     except URLError as e:
#         if isinstance(e.reason, socket.timeout) and retry:
#             time.sleep(retry_period)
#             return load_url(
#                 url, retry=retry - 1, retry_period=retry_period,
#                 timeout=timeout)
#         raise URLError(str(e) + ' (%s)' % url)
#     return fh.read()
# 
# Path: vcstool/clients/vcs_base.py
# def test_url(url, retry=2, retry_period=1, timeout=10):
#     request = Request(url)
#     request.get_method = lambda: 'HEAD'
# 
#     try:
#         response = urlopen(request)
#     except HTTPError as e:
#         if e.code == 503 and retry:
#             time.sleep(retry_period)
#             return test_url(
#                 url, retry=retry - 1, retry_period=retry_period,
#                 timeout=timeout)
#         e.msg += ' (%s)' % url
#         raise
#     except URLError as e:
#         if isinstance(e.reason, socket.timeout) and retry:
#             time.sleep(retry_period)
#             return test_url(
#                 url, retry=retry - 1, retry_period=retry_period,
#                 timeout=timeout)
#         raise URLError(str(e) + ' (%s)' % url)
#     return response
# 
# Path: vcstool/clients/vcs_base.py
# class VcsClientBase(object):
# 
#     type = None
# 
#     def __init__(self, path):
#         self.path = path
# 
#     def __getattribute__(self, name):
#         if name == 'import':
#             try:
#                 return self.import_
#             except AttributeError:
#                 pass
#         return super(VcsClientBase, self).__getattribute__(name)
# 
#     def _not_applicable(self, command, message=None):
#         return {
#             'cmd': '%s.%s(%s)' % (
#                 self.__class__.type, 'push', command.__class__.command),
#             'output': "Command '%s' not applicable for client '%s'%s" % (
#                 command.__class__.command, self.__class__.type,
#                 ': ' + message if message else ''),
#             'returncode': NotImplemented
#         }
# 
#     def _run_command(self, cmd, env=None, retry=0):
#         for i in range(retry + 1):
#             result = run_command(cmd, os.path.abspath(self.path), env=env)
#             if not result['returncode']:
#                 # return successful result
#                 break
#             if i >= retry:
#                 # return the failure after retries
#                 break
#             # increasing sleep before each retry
#             time.sleep(i + 1)
#         return result
# 
#     def _create_path(self):
#         if not os.path.exists(self.path):
#             try:
#                 os.makedirs(self.path)
#             except os.error as e:
#                 return {
#                     'cmd': 'os.makedirs(%s)' % self.path,
#                     'cwd': self.path,
#                     'output':
#                         "Could not create directory '%s': %s" % (self.path, e),
#                     'returncode': 1
#                 }
#         return None
# 
# Path: vcstool/util.py
# def rmtree(path):
#     kwargs = {}
#     if sys.platform == 'win32':
#         kwargs['onerror'] = _onerror_windows
#     return shutil_rmtree(path, **kwargs)


# Path: vcstool/clients/zip.py
from io import BytesIO
from urllib.error import URLError
from .vcs_base import load_url
from .vcs_base import test_url
from .vcs_base import VcsClientBase
from ..util import rmtree
import os
import zipfile

        return {
            'cmd': '',
            'cwd': self.path,
            'output':
                "Downloaded zipfile from '%s' and unpacked it" % command.url,
            'returncode': 0
        }

    def validate(self, command):
        if not command.url:
            return {
                'cmd': '',
                'cwd': self.path,
                'output': "Repository data lacks the 'url' value",
                'returncode': 1
            }

        # test url
        try:
            test_url(command.url, retry=command.retry)
        except URLError as e:
            return {
                'cmd': '',
                'cwd': self.path,
                'output':
                    "Failed to contact zip url '%s': %s" % (command.url, e),
                'returncode': 1
            }
        return {
            'cmd': 'http HEAD',

            'cwd': self.path,