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
34
35
def extract_auth(url, password_manager):
37
38
password manager. Return the url, minus those auth parameters (which
40
assert url.startswith('http://') or url.startswith('https://')
41
scheme, host = url.split('//', 1)
43
host, path = host.split('/', 1)
49
auth, host = host.split('@', 1)
41
scheme, netloc, path, query, fragment = urlparse.urlsplit(url)
42
assert (scheme == 'http') or (scheme == 'https')
45
auth, netloc = netloc.split('@', 1)
51
47
username, password = auth.split(':', 1)
53
49
username, password = auth, None
55
host, port = host.split(':', 1)
57
# FIXME: if password isn't given, should we ask for it?
51
host = netloc.split(':', 1)[0]
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
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))
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)