Show More
@@ -11,6 +11,25 b' from i18n import gettext as _' | |||||
11 | from demandload import * |
|
11 | from demandload import * | |
12 | demandload(globals(), "hg os urllib urllib2 urlparse zlib util httplib") |
|
12 | demandload(globals(), "hg os urllib urllib2 urlparse zlib util httplib") | |
13 |
|
13 | |||
|
14 | class passwordmgr(urllib2.HTTPPasswordMgr): | |||
|
15 | def __init__(self, ui): | |||
|
16 | urllib2.HTTPPasswordMgr.__init__(self) | |||
|
17 | self.ui = ui | |||
|
18 | ||||
|
19 | def find_user_password(self, realm, authuri): | |||
|
20 | authinfo = urllib2.HTTPPasswordMgr.find_user_password( | |||
|
21 | self, realm, authuri) | |||
|
22 | if authinfo != (None, None): | |||
|
23 | return authinfo | |||
|
24 | ||||
|
25 | self.ui.write(_("http authorization required\n")) | |||
|
26 | self.ui.status(_("realm: %s\n") % realm) | |||
|
27 | user = self.ui.prompt(_("user:"), default=None) | |||
|
28 | passwd = self.ui.getpass() | |||
|
29 | ||||
|
30 | self.add_password(realm, authuri, user, passwd) | |||
|
31 | return (user, passwd) | |||
|
32 | ||||
14 | class httprepository(remoterepository): |
|
33 | class httprepository(remoterepository): | |
15 | def __init__(self, ui, path): |
|
34 | def __init__(self, ui, path): | |
16 | # fix missing / after hostname |
|
35 | # fix missing / after hostname | |
@@ -53,13 +72,21 b' class httprepository(remoterepository):' | |||||
53 | if host and not no_proxy: |
|
72 | if host and not no_proxy: | |
54 | proxy_handler = urllib2.ProxyHandler({"http" : "http://" + host}) |
|
73 | proxy_handler = urllib2.ProxyHandler({"http" : "http://" + host}) | |
55 |
|
74 | |||
56 | authinfo = None |
|
75 | proxyauthinfo = None | |
57 | if user and passwd: |
|
76 | if user and passwd: | |
58 | passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm() |
|
77 | passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm() | |
59 | passmgr.add_password(None, host, user, passwd) |
|
78 | passmgr.add_password(None, host, user, passwd) | |
60 | authinfo = urllib2.ProxyBasicAuthHandler(passmgr) |
|
79 | proxyauthinfo = urllib2.ProxyBasicAuthHandler(passmgr) | |
61 |
|
80 | |||
62 | opener = urllib2.build_opener(proxy_handler, authinfo) |
|
81 | if ui.interactive: | |
|
82 | passmgr = passwordmgr(ui) | |||
|
83 | opener = urllib2.build_opener( | |||
|
84 | proxy_handler, proxyauthinfo, | |||
|
85 | urllib2.HTTPBasicAuthHandler(passmgr), | |||
|
86 | urllib2.HTTPDigestAuthHandler(passmgr)) | |||
|
87 | else: | |||
|
88 | opener = urllib2.build_opener(proxy_handler, proxyauthinfo) | |||
|
89 | ||||
63 | # 1.0 here is the _protocol_ version |
|
90 | # 1.0 here is the _protocol_ version | |
64 | opener.addheaders = [('User-agent', 'mercurial/proto-1.0')] |
|
91 | opener.addheaders = [('User-agent', 'mercurial/proto-1.0')] | |
65 | urllib2.install_opener(opener) |
|
92 | urllib2.install_opener(opener) |
@@ -8,7 +8,7 b'' | |||||
8 | import ConfigParser |
|
8 | import ConfigParser | |
9 | from i18n import gettext as _ |
|
9 | from i18n import gettext as _ | |
10 | from demandload import * |
|
10 | from demandload import * | |
11 | demandload(globals(), "errno os re smtplib socket sys tempfile util") |
|
11 | demandload(globals(), "errno getpass os re smtplib socket sys tempfile util") | |
12 |
|
12 | |||
13 | class ui(object): |
|
13 | class ui(object): | |
14 | def __init__(self, verbose=False, debug=False, quiet=False, |
|
14 | def __init__(self, verbose=False, debug=False, quiet=False, | |
@@ -224,15 +224,18 b' class ui(object):' | |||||
224 |
|
224 | |||
225 | def readline(self): |
|
225 | def readline(self): | |
226 | return sys.stdin.readline()[:-1] |
|
226 | return sys.stdin.readline()[:-1] | |
227 | def prompt(self, msg, pat, default="y"): |
|
227 | def prompt(self, msg, pat=None, default="y"): | |
228 | if not self.interactive: return default |
|
228 | if not self.interactive: return default | |
229 | while 1: |
|
229 | while 1: | |
230 | self.write(msg, " ") |
|
230 | self.write(msg, " ") | |
231 | r = self.readline() |
|
231 | r = self.readline() | |
232 | if re.match(pat, r): |
|
232 | if not pat or re.match(pat, r): | |
233 | return r |
|
233 | return r | |
234 | else: |
|
234 | else: | |
235 | self.write(_("unrecognized response\n")) |
|
235 | self.write(_("unrecognized response\n")) | |
|
236 | def getpass(self, prompt=None, default=None): | |||
|
237 | if not self.interactive: return default | |||
|
238 | return getpass.getpass(prompt or _('password: ')) | |||
236 | def status(self, *msg): |
|
239 | def status(self, *msg): | |
237 | if not self.quiet: self.write(*msg) |
|
240 | if not self.quiet: self.write(*msg) | |
238 | def warn(self, *msg): |
|
241 | def warn(self, *msg): |
General Comments 0
You need to be logged in to leave comments.
Login now