23
23
from warnings import warn
25
26
from bzrlib.transport import Transport, Server
26
27
from bzrlib.errors import (TransportNotPossible, NoSuchFile,
27
28
TransportError, ConnectionError)
28
29
from bzrlib.errors import BzrError, BzrCheckError
29
30
from bzrlib.branch import Branch
30
31
from bzrlib.trace import mutter
32
from bzrlib.ui import ui_factory
33
35
def extract_auth(url, password_manager):
36
38
password manager. Return the url, minus those auth parameters (which
39
assert url.startswith('http://') or url.startswith('https://')
40
scheme, host = url.split('//', 1)
42
host, path = host.split('/', 1)
48
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)
50
47
username, password = auth.split(':', 1)
52
49
username, password = auth, None
54
host, port = host.split(':', 1)
56
# FIXME: if password isn't given, should we ask for it?
51
host = netloc.split(':', 1)[0]
54
username = urllib.unquote(username)
57
55
if password is not None:
58
username = urllib.unquote(username)
59
56
password = urllib.unquote(password)
60
password_manager.add_password(None, host, username, password)
61
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))
66
mutter("get_url %s" % url)
67
mutter("get_url %s", url)
67
68
manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
68
69
url = extract_auth(url, manager)
69
70
auth_handler = urllib2.HTTPBasicAuthHandler(manager)
70
71
opener = urllib2.build_opener(auth_handler)
71
url_f = opener.open(url)
73
request = urllib2.Request(url)
74
request.add_header('User-Agent', 'bzr/%s' % bzrlib.__version__)
75
response = opener.open(request)
74
78
class HttpTransport(Transport):
75
79
"""This is the transport agent for http:// access.