diff options
author | Gregory P. Smith <greg@mad-scientist.com> | 2010-09-06 08:30:23 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@mad-scientist.com> | 2010-09-06 08:30:23 (GMT) |
commit | 13b55291ac84d2fb74f93c286a0bd5673f439e38 (patch) | |
tree | 3be269bb34eb782e9ec28a92b3f07d1b95b32c4f /Lib/hashlib.py | |
parent | c86adb4c5c616e6aa7dcf9e59c71ba66ab5ea553 (diff) | |
download | cpython-13b55291ac84d2fb74f93c286a0bd5673f439e38.zip cpython-13b55291ac84d2fb74f93c286a0bd5673f439e38.tar.gz cpython-13b55291ac84d2fb74f93c286a0bd5673f439e38.tar.bz2 |
hashlib has two new constant attributes: algorithms_guaranteed and
algorithms_avaiable that respectively list the names of hash algorithms
guaranteed to exist in all Python implementations and the names of hash
algorithms available in the current process.
Renames the attribute new in 3.2a0 'algorithms' to 'algorithms_guaranteed'.
Diffstat (limited to 'Lib/hashlib.py')
-rw-r--r-- | Lib/hashlib.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/Lib/hashlib.py b/Lib/hashlib.py index aacb268..9d860c4 100644 --- a/Lib/hashlib.py +++ b/Lib/hashlib.py @@ -1,6 +1,4 @@ -# $Id$ -# -# Copyright (C) 2005-2007 Gregory P. Smith (greg@krypto.org) +# Copyright (C) 2005-2010 Gregory P. Smith (greg@krypto.org) # Licensed to PSF under a Contributor Agreement. # @@ -15,8 +13,9 @@ than using new(name): md5(), sha1(), sha224(), sha256(), sha384(), and sha512() -More algorithms may be available on your platform but the above are -guaranteed to exist. +More algorithms may be available on your platform but the above are guaranteed +to exist. See the algorithms_guaranteed and algorithms_available attributes +to find out what algorithm names can be passed to new(). NOTE: If you want the adler32 or crc32 hash functions they are available in the zlib module. @@ -57,9 +56,11 @@ More condensed: # always available algorithm is added. __always_supported = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512') -algorithms = __always_supported +algorithms_guaranteed = __always_supported +algorithms_available = frozenset(__always_supported) -__all__ = __always_supported + ('new', 'algorithms') +__all__ = __always_supported + ('new', 'algorithms_guaranteed', + 'algorithms_available') def __get_builtin_constructor(name): @@ -124,6 +125,8 @@ try: import _hashlib new = __hash_new __get_hash = __get_openssl_constructor + algorithms_available = algorithms_available.union( + _hashlib.openssl_md_meth_names) except ImportError: new = __py_new __get_hash = __get_builtin_constructor |