Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/url.py @ 36681:8381126bf43c
url: more bytes/unicodes fussing in url.py around auth handling
Once again, these methods are a little annoying to handle because they
can get unicodes or bytes depending on who's calling. I think we can
probably clean this up a TON once we can run something like pytype and
do typechecking of our Python, but until then this is going to be the
easy way out. This fixes test-http-bundle1.t.
Differential Revision: https://phab.mercurial-scm.org/D2599
author | Augie Fackler <augie@google.com> |
---|---|
date | Sat, 03 Mar 2018 14:28:51 -0500 |
parents | 698fe0f6eb5c |
children | 02221d6fb041 |
comparison
equal
deleted
inserted
replaced
36680:6b1eb4c610b4 | 36681:8381126bf43c |
---|---|
65 if res: | 65 if res: |
66 group, auth = res | 66 group, auth = res |
67 user, passwd = auth.get('username'), auth.get('password') | 67 user, passwd = auth.get('username'), auth.get('password') |
68 self.ui.debug("using auth.%s.* for authentication\n" % group) | 68 self.ui.debug("using auth.%s.* for authentication\n" % group) |
69 if not user or not passwd: | 69 if not user or not passwd: |
70 u = util.url(authuri) | 70 u = util.url(pycompat.bytesurl(authuri)) |
71 u.query = None | 71 u.query = None |
72 if not self.ui.interactive(): | 72 if not self.ui.interactive(): |
73 raise error.Abort(_('http authorization required for %s') % | 73 raise error.Abort(_('http authorization required for %s') % |
74 util.hidepassword(bytes(u))) | 74 util.hidepassword(bytes(u))) |
75 | 75 |
76 self.ui.write(_("http authorization required for %s\n") % | 76 self.ui.write(_("http authorization required for %s\n") % |
77 util.hidepassword(bytes(u))) | 77 util.hidepassword(bytes(u))) |
78 self.ui.write(_("realm: %s\n") % realm) | 78 self.ui.write(_("realm: %s\n") % pycompat.bytesurl(realm)) |
79 if user: | 79 if user: |
80 self.ui.write(_("user: %s\n") % user) | 80 self.ui.write(_("user: %s\n") % user) |
81 else: | 81 else: |
82 user = self.ui.prompt(_("user:"), default=None) | 82 user = self.ui.prompt(_("user:"), default=None) |
83 | 83 |
422 | 422 |
423 def retry_http_basic_auth(self, host, req, realm): | 423 def retry_http_basic_auth(self, host, req, realm): |
424 user, pw = self.passwd.find_user_password( | 424 user, pw = self.passwd.find_user_password( |
425 realm, urllibcompat.getfullurl(req)) | 425 realm, urllibcompat.getfullurl(req)) |
426 if pw is not None: | 426 if pw is not None: |
427 raw = "%s:%s" % (user, pw) | 427 raw = "%s:%s" % (pycompat.bytesurl(user), pycompat.bytesurl(pw)) |
428 auth = 'Basic %s' % base64.b64encode(raw).strip() | 428 auth = r'Basic %s' % pycompat.strurl(base64.b64encode(raw).strip()) |
429 if req.get_header(self.auth_header, None) == auth: | 429 if req.get_header(self.auth_header, None) == auth: |
430 return None | 430 return None |
431 self.auth = auth | 431 self.auth = auth |
432 req.add_unredirected_header(self.auth_header, auth) | 432 req.add_unredirected_header(self.auth_header, auth) |
433 return self.parent.open(req) | 433 return self.parent.open(req) |