]> granicus.if.org Git - python/commitdiff
Merged revisions 78528 via svnmerge from
authorGregory P. Smith <greg@mad-scientist.com>
Mon, 1 Mar 2010 02:05:26 +0000 (02:05 +0000)
committerGregory P. Smith <greg@mad-scientist.com>
Mon, 1 Mar 2010 02:05:26 +0000 (02:05 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r78528 | gregory.p.smith | 2010-02-28 18:01:47 -0800 (Sun, 28 Feb 2010) | 2 lines

  Adds the hashlib.algorithms attribute.  See issue7418.
........

Doc/library/hashlib.rst
Lib/hashlib.py
Lib/test/test_hashlib.py

index a776df1ed4d2a1ff07ecbe1ef65ceb4bcf27e570..3c98af76274a696aaf5e3ea4fd99c173c0c4a7bc 100644 (file)
@@ -82,6 +82,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:: 3.2
+
 The following values are provided as constant attributes of the hash objects
 returned by the constructors:
 
index 9709cde3f7c9a93fcd1f10ac4907fd2357eb21f0..aacb268bfd4a2a4bc3de04021573275432d58ecc 100644 (file)
@@ -57,7 +57,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 7d58da9f844cfee332ef587930b3fce060456b03..e1a1bd30bd479d69c4d05dd21bc3ab1d50e22ab1 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')