]> granicus.if.org Git - python/commitdiff
Adds the hashlib.algorithms attribute. See issue7418.
authorGregory P. Smith <greg@mad-scientist.com>
Mon, 1 Mar 2010 02:01:47 +0000 (02:01 +0000)
committerGregory P. Smith <greg@mad-scientist.com>
Mon, 1 Mar 2010 02:01:47 +0000 (02:01 +0000)
Doc/library/hashlib.rst
Lib/hashlib.py
Lib/test/test_hashlib.py

index 4e279dea0eb34960633134e25ed4337124507d16..a7f24d258b416f5e830adc3c69860161b769cdb7 100644 (file)
@@ -74,6 +74,15 @@ Using :func:`new` with an algorithm provided by OpenSSL:
    >>> h.hexdigest()
    'cc4a5ce1b3df48aec5d22d1f16b894a0b894eccc'
 
+This module provides the following constant attribute:
+
+.. data:: hashlib.algorithms
+
+   A tuple providing the names of the hash algorithms guaranteed to be
+   supported by this module.
+
+   .. versionadded:: 2.7
+
 The following values are provided as constant attributes of the hash objects
 returned by the constructors:
 
index 5ecca2bf63bc02d07e4ad9727996a93ca4862be7..48f2cfddbd76f09406c101d9f25051e13696b35c 100644 (file)
@@ -58,7 +58,9 @@ More condensed:
 # always available algorithm is added.
 __always_supported = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512')
 
-__all__ = __always_supported + ('new',)
+algorithms = __always_supported
+
+__all__ = __always_supported + ('new', 'algorithms')
 
 
 def __get_builtin_constructor(name):
index 6ef55577f71af71494001648724500819e7ea054..8710dd6121ae288e6a7402917525433eefca41d2 100644 (file)
@@ -102,6 +102,11 @@ class HashLibTestCase(unittest.TestCase):
             c = cons(a)
             c.hexdigest()
 
+    def test_algorithms_attribute(self):
+        self.assertEqual(hashlib.algorithms,
+            tuple([_algo for _algo in self.supported_hash_names if
+                                                _algo.islower()]))
+
     def test_unknown_hash(self):
         try:
             hashlib.new('spam spam spam spam spam')