From 13b55291ac84d2fb74f93c286a0bd5673f439e38 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Mon, 6 Sep 2010 08:30:23 +0000 Subject: 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'. --- Lib/hashlib.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'Lib/hashlib.py') diff --git a/Lib/hashlib.py b/Lib/hashlib.py index aacb268bfd..9d860c481b 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 -- cgit v1.2.1