~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/http.py

[merge] bzr.robey, small fixes (--lsprof-file, log, status, http parsing, parmiko)

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
from bzrlib.errors import BzrError, BzrCheckError
30
30
from bzrlib.branch import Branch
31
31
from bzrlib.trace import mutter
 
32
from bzrlib.ui import ui_factory
32
33
 
33
34
 
34
35
def extract_auth(url, password_manager):
37
38
    password manager.  Return the url, minus those auth parameters (which
38
39
    confuse urllib2).
39
40
    """
40
 
    assert url.startswith('http://') or url.startswith('https://')
41
 
    scheme, host = url.split('//', 1)
42
 
    if '/' in host:
43
 
        host, path = host.split('/', 1)
44
 
        path = '/' + path
45
 
    else:
46
 
        path = ''
47
 
    port = ''
48
 
    if '@' in host:
49
 
        auth, host = host.split('@', 1)
 
41
    scheme, netloc, path, query, fragment = urlparse.urlsplit(url)
 
42
    assert (scheme == 'http') or (scheme == 'https')
 
43
    
 
44
    if '@' in netloc:
 
45
        auth, netloc = netloc.split('@', 1)
50
46
        if ':' in auth:
51
47
            username, password = auth.split(':', 1)
52
48
        else:
53
49
            username, password = auth, None
54
 
        if ':' in host:
55
 
            host, port = host.split(':', 1)
56
 
            port = ':' + port
57
 
        # FIXME: if password isn't given, should we ask for it?
 
50
        if ':' in netloc:
 
51
            host = netloc.split(':', 1)[0]
 
52
        else:
 
53
            host = netloc
 
54
        username = urllib.unquote(username)
58
55
        if password is not None:
59
 
            username = urllib.unquote(username)
60
56
            password = urllib.unquote(password)
61
 
            password_manager.add_password(None, host, username, password)
62
 
    url = scheme + '//' + host + port + path
 
57
        else:
 
58
            password = ui_factory.get_password(prompt='HTTP %(user)@%(host) password',
 
59
                                               user=username, host=host)
 
60
        password_manager.add_password(None, host, username, password)
 
61
    url = urlparse.urlunsplit((scheme, netloc, path, query, fragment))
63
62
    return url
 
63
 
64
64
    
65
65
def get_url(url):
66
66
    import urllib2
67
 
    mutter("get_url %s" % url)
 
67
    mutter("get_url %s", url)
68
68
    manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
69
69
    url = extract_auth(url, manager)
70
70
    auth_handler = urllib2.HTTPBasicAuthHandler(manager)