[Python-checkins] r78528 - in python/trunk: Doc/library/hashlib.rst Lib/hashlib.py Lib/test/test_hashlib.py

gregory.p.smith python-checkins at python.org
Mon Mar 1 03:01:47 CET 2010


Author: gregory.p.smith
Date: Mon Mar  1 03:01:47 2010
New Revision: 78528

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


Modified:
   python/trunk/Doc/library/hashlib.rst
   python/trunk/Lib/hashlib.py
   python/trunk/Lib/test/test_hashlib.py

Modified: python/trunk/Doc/library/hashlib.rst
==============================================================================
--- python/trunk/Doc/library/hashlib.rst	(original)
+++ python/trunk/Doc/library/hashlib.rst	Mon Mar  1 03:01:47 2010
@@ -74,6 +74,15 @@
    >>> 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:
 

Modified: python/trunk/Lib/hashlib.py
==============================================================================
--- python/trunk/Lib/hashlib.py	(original)
+++ python/trunk/Lib/hashlib.py	Mon Mar  1 03:01:47 2010
@@ -58,7 +58,9 @@
 # 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):

Modified: python/trunk/Lib/test/test_hashlib.py
==============================================================================
--- python/trunk/Lib/test/test_hashlib.py	(original)
+++ python/trunk/Lib/test/test_hashlib.py	Mon Mar  1 03:01:47 2010
@@ -102,6 +102,11 @@
             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')


More information about the Python-checkins mailing list