mirror of
https://github.com/python/cpython.git
synced 2025-10-06 15:11:58 +00:00
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'.
This commit is contained in:
parent
c86adb4c5c
commit
13b55291ac
5 changed files with 111 additions and 18 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue