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