aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2010-09-06 08:30:23 +0000
committerGregory P. Smith <greg@mad-scientist.com>2010-09-06 08:30:23 +0000
commit13b55291ac84d2fb74f93c286a0bd5673f439e38 (patch)
tree3be269bb34eb782e9ec28a92b3f07d1b95b32c4f /Lib/hashlib.py
parent#9780: both { and } are not valid fill characters. (diff)
downloadcpython-13b55291ac84d2fb74f93c286a0bd5673f439e38.tar.gz
cpython-13b55291ac84d2fb74f93c286a0bd5673f439e38.tar.bz2
cpython-13b55291ac84d2fb74f93c286a0bd5673f439e38.zip
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.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/Lib/hashlib.py b/Lib/hashlib.py
index aacb268bfd4..9d860c481b1 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