]> granicus.if.org Git - python/commitdiff
Consistently raise a TypeError when a non str is passed to hashlib.new
authorGregory P. Smith <greg@krypto.org>
Sun, 22 Jul 2012 04:22:16 +0000 (21:22 -0700)
committerGregory P. Smith <greg@krypto.org>
Sun, 22 Jul 2012 04:22:16 +0000 (21:22 -0700)
regardless of which of the two implementations of new is used.

Lib/hashlib.py
Lib/test/test_hashlib.py

index 2732d184aaf2c5db6a3ba5b554fe84d1f3d9c6eb..d20e1f95a2afc8407ad6ea7b3602163f598e0896 100644 (file)
@@ -88,7 +88,7 @@ def __get_builtin_constructor(name):
     except ImportError:
         pass  # no extension module, this hash is unsupported.
 
-    raise ValueError('unsupported hash type %s' % name)
+    raise ValueError('unsupported hash type ' + name)
 
 
 def __get_openssl_constructor(name):
index 95bf0b347c59deb1b90aff5070b0bc33466f3d43..f5c242e6c9da6f2461a01df31b74b0f3f4bda461 100644 (file)
@@ -128,6 +128,7 @@ class HashLibTestCase(unittest.TestCase):
                 sys.modules['_md5'] = _md5
             else:
                 del sys.modules['_md5']
+        self.assertRaises(TypeError, get_builtin_constructor, 3)
 
     def test_hexdigest(self):
         for name in self.supported_hash_names: