[Python-checkins] cpython (2.7): Issue #2202: Fix UnboundLocalError in
berker.peksag
python-checkins at python.org
Sun Mar 6 09:27:15 EST 2016
https://hg.python.org/cpython/rev/d135799e952b
changeset: 100432:d135799e952b
branch: 2.7
parent: 100428:8554423dd392
user: Berker Peksag <berker.peksag at gmail.com>
date: Sun Mar 06 16:27:23 2016 +0200
summary:
Issue #2202: Fix UnboundLocalError in AbstractDigestAuthHandler.get_algorithm_impls
Raise ValueError if algorithm is not MD5 or SHA.
Initial patch by Mathieu Dupuy.
files:
Lib/test/test_urllib2.py | 12 +++++++++++-
Lib/urllib2.py | 3 +++
Misc/NEWS | 3 +++
3 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -6,7 +6,7 @@
import StringIO
import urllib2
-from urllib2 import Request, OpenerDirector
+from urllib2 import Request, OpenerDirector, AbstractDigestAuthHandler
try:
import ssl
@@ -1290,6 +1290,16 @@
else:
self.assertTrue(False)
+ def test_unsupported_algorithm(self):
+ handler = AbstractDigestAuthHandler()
+ with self.assertRaises(ValueError) as exc:
+ handler.get_algorithm_impls('invalid')
+ self.assertEqual(
+ str(exc.exception),
+ "Unsupported digest authentication algorithm 'invalid'"
+ )
+
+
class RequestTests(unittest.TestCase):
def setUp(self):
diff --git a/Lib/urllib2.py b/Lib/urllib2.py
--- a/Lib/urllib2.py
+++ b/Lib/urllib2.py
@@ -1071,6 +1071,9 @@
elif algorithm == 'SHA':
H = lambda x: hashlib.sha1(x).hexdigest()
# XXX MD5-sess
+ else:
+ raise ValueError("Unsupported digest authentication "
+ "algorithm %r" % algorithm.lower())
KD = lambda s, d: H("%s:%s" % (s, d))
return H, KD
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -55,6 +55,9 @@
Library
-------
+- Issue #2202: Fix UnboundLocalError in
+ AbstractDigestAuthHandler.get_algorithm_impls. Initial patch by Mathieu Dupuy.
+
- Issue #26475: Fixed debugging output for regular expressions with the (?x)
flag.
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list