Mercurial > hg-stable
changeset 4678:a814a5b11fff
Work around urllib2 digest auth bug with Python < 2.5
This should fix issue570.
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Fri, 22 Jun 2007 14:32:54 -0300 |
parents | de8ec7e1753a |
children | 826659bd8053 |
files | mercurial/httprepo.py |
diffstat | 1 files changed, 15 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/httprepo.py Thu Jun 21 23:42:06 2007 -0300 +++ b/mercurial/httprepo.py Fri Jun 22 14:32:54 2007 -0300 @@ -121,6 +121,20 @@ class httphandler(basehttphandler): pass +# In python < 2.5 AbstractDigestAuthHandler raises a ValueError if +# it doesn't know about the auth type requested. This can happen if +# somebody is using BasicAuth and types a bad password. +class httpdigestauthhandler(urllib2.HTTPDigestAuthHandler): + def http_error_auth_reqed(self, auth_header, host, req, headers): + try: + return urllib2.HTTPDigestAuthHandler.http_error_auth_reqed( + self, auth_header, host, req, headers) + except ValueError, inst: + arg = inst.args[0] + if arg.startswith("AbstractDigestAuthHandler doesn't know "): + return + raise + def zgenerator(f): zd = zlib.decompressobj() try: @@ -202,7 +216,7 @@ passmgr.add_password(None, host, user, passwd or '') handlers.extend((urllib2.HTTPBasicAuthHandler(passmgr), - urllib2.HTTPDigestAuthHandler(passmgr))) + httpdigestauthhandler(passmgr))) opener = urllib2.build_opener(*handlers) # 1.0 here is the _protocol_ version