示例#1
0
def extract_auth(url, password_manager):
    """Extract auth parameters from am HTTP/HTTPS url and add them to the given
    password manager.  Return the url, minus those auth parameters (which
    confuse urllib2).
    """
    if not re.match(r'^(https?)(\+\w+)?://', url):
        raise ValueError(
            'invalid absolute url %r' % (url,))
    scheme, netloc, path, query, fragment = urlparse.urlsplit(url)

    if '@' in netloc:
        auth, netloc = netloc.split('@', 1)
        if ':' in auth:
            username, password = auth.split(':', 1)
        else:
            username, password = auth, None
        if ':' in netloc:
            host = netloc.split(':', 1)[0]
        else:
            host = netloc
        username = urlutils.unquote(username)
        if password is not None:
            password = urlutils.unquote(password)
        else:
            password = ui.ui_factory.get_password(
                prompt=u'HTTP %(user)s@%(host)s password',
                user=username, host=host)
        password_manager.add_password(None, host, username, password)
    url = urlparse.urlunsplit((scheme, netloc, path, query, fragment))
    return url
    def _translate_path(self, path):
        """Translate a /-separated PATH to the local filename syntax.

        Note that we're translating http URLs here, not file URLs.
        The URL root location is the server's startup directory.
        Components that mean special things to the local file system
        (e.g. drive or directory names) are ignored.  (XXX They should
        probably be diagnosed.)

        Override from python standard library to stop it calling os.getcwd()
        """
        # abandon query parameters
        path = urlparse.urlparse(path)[2]
        path = posixpath.normpath(urlutils.unquote(path))
        path = path.decode('utf-8')
        words = path.split('/')
        words = filter(None, words)
        path = self._cwd
        for num, word in enumerate(words):
            if num == 0:
                drive, word = os.path.splitdrive(word)
            head, word = os.path.split(word)
            if word in (os.curdir, os.pardir): continue
            path = os.path.join(path, word)
        return path
示例#3
0
 def remote_path_from_transport(self, transport):
     # Strip the optional 'bzr+' prefix from transport so it will have the
     # same scheme as self.
     transport_base = transport.base
     if transport_base.startswith('bzr+'):
         transport_base = transport_base[4:]
     rel_url = urlutils.relative_url(self.base, transport_base)
     return urlutils.unquote(rel_url)
示例#4
0
 def remote_path_from_transport(self, transport):
     # Strip the optional 'bzr+' prefix from transport so it will have the
     # same scheme as self.
     transport_base = transport.base
     if transport_base.startswith('bzr+'):
         transport_base = transport_base[4:]
     rel_url = urlutils.relative_url(self.base, transport_base)
     return urlutils.unquote(rel_url)
示例#5
0
 def keys(self):
     if not self._is_locked():
         raise errors.ObjectNotLocked(self)
     relpaths = set()
     for quoted_relpath in self._transport.iter_files_recursive():
         relpath = urlutils.unquote(quoted_relpath)
         path, ext = os.path.splitext(relpath)
         if ext == '.gz':
             relpath = path
         if not relpath.endswith('.sig'):
             relpaths.add(relpath)
     paths = list(relpaths)
     return set([self._mapper.unmap(path) for path in paths])
示例#6
0
 def keys(self):
     if not self._is_locked():
         raise errors.ObjectNotLocked(self)
     relpaths = set()
     for quoted_relpath in self._transport.iter_files_recursive():
         relpath = urlutils.unquote(quoted_relpath)
         path, ext = os.path.splitext(relpath)
         if ext == '.gz':
             relpath = path
         if not relpath.endswith('.sig'):
             relpaths.add(relpath)
     paths = list(relpaths)
     return set([self._mapper.unmap(path) for path in paths])
示例#7
0
 def test_unquote(self):
     self.assertEqual('%', urlutils.unquote('%25'))
     self.assertEqual('\xc3\xa5', urlutils.unquote('%C3%A5'))
     self.assertEqual(u"\xe5", urlutils.unquote(u'\xe5'))
示例#8
0
 def test_unquote(self):
     self.assertEqual('%', urlutils.unquote('%25'))
     self.assertEqual('\xc3\xa5', urlutils.unquote('%C3%A5'))
     self.assertEqual(u"\xe5", urlutils.unquote(u'\xe5'))