comparison mercurial/httprepo.py @ 2556:f1ebc4311f47

Allow http://user@example.com URLs (i.e. without passwords)
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Mon, 03 Jul 2006 00:23:56 -0300
parents b73552a00b20
children 1727ff712a4e
comparison
equal deleted inserted replaced
2555:d6605381c6df 2556:f1ebc4311f47
18 self.ui = ui 18 self.ui = ui
19 19
20 def find_user_password(self, realm, authuri): 20 def find_user_password(self, realm, authuri):
21 authinfo = urllib2.HTTPPasswordMgrWithDefaultRealm.find_user_password( 21 authinfo = urllib2.HTTPPasswordMgrWithDefaultRealm.find_user_password(
22 self, realm, authuri) 22 self, realm, authuri)
23 if authinfo != (None, None): 23 user, passwd = authinfo
24 return authinfo 24 if user and passwd:
25 return (user, passwd)
25 26
26 if not self.ui.interactive: 27 if not self.ui.interactive:
27 raise util.Abort(_('http authorization required')) 28 raise util.Abort(_('http authorization required'))
28 29
29 self.ui.write(_("http authorization required\n")) 30 self.ui.write(_("http authorization required\n"))
30 self.ui.status(_("realm: %s\n") % realm) 31 self.ui.status(_("realm: %s\n") % realm)
31 user = self.ui.prompt(_("user:"), default=None) 32 if user:
32 passwd = self.ui.getpass() 33 self.ui.status(_("user: %s\n") % user)
34 else:
35 user = self.ui.prompt(_("user:"), default=None)
36
37 if not passwd:
38 passwd = self.ui.getpass()
33 39
34 self.add_password(realm, authuri, user, passwd) 40 self.add_password(realm, authuri, user, passwd)
35 return (user, passwd) 41 return (user, passwd)
36 42
37 def netlocsplit(netloc): 43 def netlocsplit(netloc):
146 except OSError: 152 except OSError:
147 pass 153 pass
148 154
149 passmgr = passwordmgr(ui) 155 passmgr = passwordmgr(ui)
150 if user: 156 if user:
151 ui.debug(_('will use user %s, password %s for http auth\n') % 157 ui.debug(_('http auth: user %s, password %s\n') %
152 (user, '*' * len(passwd))) 158 (user, passwd and '*' * len(passwd) or 'not set'))
153 passmgr.add_password(None, host, user, passwd or '') 159 passmgr.add_password(None, host, user, passwd or '')
154 160
155 opener = urllib2.build_opener( 161 opener = urllib2.build_opener(
156 handler, 162 handler,
157 urllib2.HTTPBasicAuthHandler(passmgr), 163 urllib2.HTTPBasicAuthHandler(passmgr),