[Python-checkins] r45939 - in python/trunk/Lib: test/test_urllib2.py urllib2.py
georg.brandl
python-checkins at python.org
Mon May 8 19:36:09 CEST 2006
Author: georg.brandl
Date: Mon May 8 19:36:08 2006
New Revision: 45939
Modified:
python/trunk/Lib/test/test_urllib2.py
python/trunk/Lib/urllib2.py
Log:
Patch #1479302: Make urllib2 digest auth and basic auth play together.
Modified: python/trunk/Lib/test/test_urllib2.py
==============================================================================
--- python/trunk/Lib/test/test_urllib2.py (original)
+++ python/trunk/Lib/test/test_urllib2.py Mon May 8 19:36:08 2006
@@ -779,6 +779,27 @@
"proxy.example.com:3128",
)
+ def test_basic_and_digest_auth_handlers(self):
+ # HTTPDigestAuthHandler threw an exception if it couldn't handle a 40*
+ # response (http://python.org/sf/1479302), where it should instead
+ # return None to allow another handler (especially
+ # HTTPBasicAuthHandler) to handle the response.
+ class TestDigestAuthHandler(urllib2.HTTPDigestAuthHandler):
+ handler_order = 400 # strictly before HTTPBasicAuthHandler
+ opener = OpenerDirector()
+ password_manager = MockPasswordManager()
+ digest_handler = TestDigestAuthHandler(password_manager)
+ basic_handler = urllib2.HTTPBasicAuthHandler(password_manager)
+ opener.add_handler(digest_handler)
+ realm = "ACME Networks"
+ http_handler = MockHTTPHandler(
+ 401, 'WWW-Authenticate: Basic realm="%s"\r\n\r\n' % realm)
+ self._test_basic_auth(opener, basic_handler, "Authorization",
+ realm, http_handler, password_manager,
+ "http://acme.example.com/protected",
+ "http://acme.example.com/protected",
+ )
+
def _test_basic_auth(self, opener, auth_handler, auth_header,
realm, http_handler, password_manager,
request_url, protected_url):
Modified: python/trunk/Lib/urllib2.py
==============================================================================
--- python/trunk/Lib/urllib2.py (original)
+++ python/trunk/Lib/urllib2.py Mon May 8 19:36:08 2006
@@ -846,9 +846,6 @@
scheme = authreq.split()[0]
if scheme.lower() == 'digest':
return self.retry_http_digest_auth(req, authreq)
- else:
- raise ValueError("AbstractDigestAuthHandler doesn't know "
- "about %s"%(scheme))
def retry_http_digest_auth(self, req, auth):
token, challenge = auth.split(' ', 1)
More information about the Python-checkins
mailing list