def download(self, source, dest):
     # propogate all exceptions
     # URLError, OSError, etc
     proto, netloc, path, params, query, fragment = urlparse.urlparse(
         source)
     if proto in ('http', 'https'):
         auth, barehost = urllib2.splituser(netloc)
         if auth is not None:
             source = urlparse.urlunparse(
                 (proto, barehost, path, params, query, fragment))
             username, password = urllib2.splitpasswd(auth)
             passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
             # Realm is set to None in add_password to force the username and password
             # to be used whatever the realm
             passman.add_password(None, source, username, password)
             authhandler = urllib2.HTTPBasicAuthHandler(passman)
             opener = urllib2.build_opener(authhandler)
             urllib2.install_opener(opener)
     response = urllib2.urlopen(source)
     try:
         with open(dest, 'w') as dest_file:
             dest_file.write(response.read())
     except Exception as e:
         if os.path.isfile(dest):
             os.unlink(dest)
         raise e
    def download(self, source, dest):
        """
        Download an archive file.

        :param str source: URL pointing to an archive file.
        :param str dest: Local path location to download archive file to.
        """
        # propogate all exceptions
        # URLError, OSError, etc
        proto, netloc, path, params, query, fragment = urlparse.urlparse(source)
        if proto in ('http', 'https'):
            auth, barehost = urllib2.splituser(netloc)
            if auth is not None:
                source = urlparse.urlunparse((proto, barehost, path, params, query, fragment))
                username, password = urllib2.splitpasswd(auth)
                passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
                # Realm is set to None in add_password to force the username and password
                # to be used whatever the realm
                passman.add_password(None, source, username, password)
                authhandler = urllib2.HTTPBasicAuthHandler(passman)
                opener = urllib2.build_opener(authhandler)
                urllib2.install_opener(opener)
        response = urllib2.urlopen(source)
        try:
            with open(dest, 'w') as dest_file:
                dest_file.write(response.read())
        except Exception as e:
            if os.path.isfile(dest):
                os.unlink(dest)
            raise e
 def set_site(cls, value):
     if value is not None:
         host = urlparse.urlsplit(value)[1]
         auth_info, host = urllib2.splituser(host)
         if auth_info:
             user, password = urllib2.splitpasswd(auth_info)
             if user:
                 cls._user = urllib.unquote(user)
             if password:
                 cls._password = urllib.unquote(password)
     cls._connection = None
     cls._site = value
 def set_site(cls, value):
     if value is not None:
         host = urlparse.urlsplit(value)[1]
         auth_info, host = urllib2.splituser(host)
         if auth_info:
             user, password = urllib2.splitpasswd(auth_info)
             if user:
                 cls._user = urllib.unquote(user)
             if password:
                 cls._password = urllib.unquote(password)
     cls._connection = None
     cls._site = value
 def set_site(cls, value):
     cls._threadlocal.connection = None
     ShopifyResource._site = cls._threadlocal.site = value
     if value is not None:
         host = urlparse.urlsplit(value)[1]
         auth_info, host = urllib2.splituser(host)
         if auth_info:
             user, password = urllib2.splitpasswd(auth_info)
             if user:
                 cls.user = urllib.unquote(user)
             if password:
                 cls.password = urllib.unquote(password)
Example #6
0
 def set_site(cls, value):
     cls._threadlocal.connection = None
     ShopifyResource._site = cls._threadlocal.site = value
     if value is not None:
         host = urlparse.urlsplit(value)[1]
         auth_info, host = urllib2.splituser(host)
         if auth_info:
             user, password = urllib2.splitpasswd(auth_info)
             if user:
                 cls.user = urllib.unquote(user)
             if password:
                 cls.password = urllib.unquote(password)
Example #7
0
 def __init__(self, url):
     self.url = url
     self.schema, url = urllib2.splittype(url)
     host, path = urllib2.splithost(url)
     userpass, host = urllib2.splituser(host)
     if userpass:
         self.user, self.password = urllib2.splitpasswd(userpass)
     path, self.querystring = urllib.splitquery(path)
     self.query = self.querystring and self.querystring.split('&') or []
     #urllib.splitquery(url)
     self.host, self.port = urllib2.splitport(host)
     path, self.tag = urllib2.splittag(path)
     self.path = path.strip('/')
    def _parse_site(self, site):
        """Retrieve the auth information and base url for a site.

        Args:
            site: The URL to parse.
        Returns:
            A tuple containing (site, username, password).
        """
        proto, host, path, query, fragment = urlparse.urlsplit(site)
        auth_info, host = urllib2.splituser(host)
        if not auth_info:
            user, password = None, None
        else:
            user, password = urllib2.splitpasswd(auth_info)

        new_site = urlparse.urlunparse((proto, host, '', '', '', ''))
        return (new_site, user, password)
Example #9
0
    def _parse_site(self, site):
        """Retrieve the auth information and base url for a site.

        Args:
            site: The URL to parse.
        Returns:
            A tuple containing (site, username, password).
        """
        proto, host, path, query, fragment = urlparse.urlsplit(site)
        auth_info, host = urllib2.splituser(host)
        if not auth_info:
            user, password = None, None
        else:
            user, password = urllib2.splitpasswd(auth_info)

        new_site = urlparse.urlunparse((proto, host, '', '', '', ''))
        return (new_site, user, password)