Mercurial > public > mercurial-scm > hg
comparison mercurial/url.py @ 11844:6c51a5056020 stable
http basic auth: reset redirect counter on new requests (issue2255)
On Python 2.6.6 (and patched 2.6.5 on certain Linux distros),
the change that caused issue2255 was also applied to non-digest
authentication; this change extends the 2ec346160783 fix
accordingly.
author | Wagner Bruna <wbruna@softwareexpress.com.br> |
---|---|
date | Fri, 13 Aug 2010 13:32:05 -0300 |
parents | 2ec346160783 |
children | 1fe94103c6ee 11035185b619 |
comparison
equal
deleted
inserted
replaced
11843:00f8e7837668 | 11844:6c51a5056020 |
---|---|
568 arg = inst.args[0] | 568 arg = inst.args[0] |
569 if arg.startswith("AbstractDigestAuthHandler doesn't know "): | 569 if arg.startswith("AbstractDigestAuthHandler doesn't know "): |
570 return | 570 return |
571 raise | 571 raise |
572 | 572 |
573 class httpbasicauthhandler(urllib2.HTTPBasicAuthHandler): | |
574 def __init__(self, *args, **kwargs): | |
575 urllib2.HTTPBasicAuthHandler.__init__(self, *args, **kwargs) | |
576 self.retried_req = None | |
577 | |
578 def reset_retry_count(self): | |
579 # Python 2.6.5 will call this on 401 or 407 errors and thus loop | |
580 # forever. We disable reset_retry_count completely and reset in | |
581 # http_error_auth_reqed instead. | |
582 pass | |
583 | |
584 def http_error_auth_reqed(self, auth_header, host, req, headers): | |
585 # Reset the retry counter once for each request. | |
586 if req is not self.retried_req: | |
587 self.retried_req = req | |
588 self.retried = 0 | |
589 return urllib2.HTTPBasicAuthHandler.http_error_auth_reqed( | |
590 self, auth_header, host, req, headers) | |
591 | |
573 def getauthinfo(path): | 592 def getauthinfo(path): |
574 scheme, netloc, urlpath, query, frag = urlparse.urlsplit(path) | 593 scheme, netloc, urlpath, query, frag = urlparse.urlsplit(path) |
575 if not urlpath: | 594 if not urlpath: |
576 urlpath = '/' | 595 urlpath = '/' |
577 if scheme != 'file': | 596 if scheme != 'file': |
613 passmgr.add_password(*authinfo) | 632 passmgr.add_password(*authinfo) |
614 user, passwd = authinfo[2:4] | 633 user, passwd = authinfo[2:4] |
615 ui.debug('http auth: user %s, password %s\n' % | 634 ui.debug('http auth: user %s, password %s\n' % |
616 (user, passwd and '*' * len(passwd) or 'not set')) | 635 (user, passwd and '*' * len(passwd) or 'not set')) |
617 | 636 |
618 handlers.extend((urllib2.HTTPBasicAuthHandler(passmgr), | 637 handlers.extend((httpbasicauthhandler(passmgr), |
619 httpdigestauthhandler(passmgr))) | 638 httpdigestauthhandler(passmgr))) |
620 handlers.extend([h(ui, passmgr) for h in handlerfuncs]) | 639 handlers.extend([h(ui, passmgr) for h in handlerfuncs]) |
621 opener = urllib2.build_opener(*handlers) | 640 opener = urllib2.build_opener(*handlers) |
622 | 641 |
623 # 1.0 here is the _protocol_ version | 642 # 1.0 here is the _protocol_ version |