Index: Doc/library/hashlib.rst =================================================================== --- Doc/library/hashlib.rst (révision 76622) +++ Doc/library/hashlib.rst (copie de travail) @@ -82,6 +82,13 @@ >>> 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. + The following values are provided as constant attributes of the hash objects returned by the constructors: Index: Lib/hashlib.py =================================================================== --- Lib/hashlib.py (révision 76622) +++ Lib/hashlib.py (copie de travail) @@ -57,9 +57,11 @@ # 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): if name in ('SHA1', 'sha1'): import _sha1 Index: Lib/test/test_hashlib.py =================================================================== --- Lib/test/test_hashlib.py (révision 76622) +++ Lib/test/test_hashlib.py (copie de travail) @@ -30,6 +30,11 @@ 'sha224', 'SHA224', 'sha256', 'SHA256', 'sha384', 'SHA384', 'sha512', 'SHA512' ) + 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')