Mercurial > cpython-lru_cache-weakref
annotate Lib/hashlib.py @ 58765:2ba7677bfa95 legacy-trunk
testCopysign was defined twice in test_math; combine the definitions
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Sat, 06 Feb 2010 23:11:25 +0000 |
| parents | 746f10e0624e |
| children | e1b70c6df9e7 |
| rev | line source |
|---|---|
|
35375
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
1 # $Id$ |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
2 # |
|
43298
a11b4885b445
email address update
Gregory P. Smith <greg@mad-scientist.com>
parents:
40254
diff
changeset
|
3 # Copyright (C) 2005 Gregory P. Smith (greg@krypto.org) |
|
35375
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
4 # Licensed to PSF under a Contributor Agreement. |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
5 # |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
6 |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
7 __doc__ = """hashlib module - A common interface to many hash functions. |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
8 |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
9 new(name, string='') - returns a new hash object implementing the |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
10 given hash function; initializing the hash |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
11 using the given string data. |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
12 |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
13 Named constructor functions are also available, these are much faster |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
14 than using new(): |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
15 |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
16 md5(), sha1(), sha224(), sha256(), sha384(), and sha512() |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
17 |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
18 More algorithms may be available on your platform but the above are |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
19 guaranteed to exist. |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
20 |
|
45895
19d4b697fbf9
Mention that crc32 and adler32 are available in a different module (zlib).
Gregory P. Smith <greg@mad-scientist.com>
parents:
43298
diff
changeset
|
21 NOTE: If you want the adler32 or crc32 hash functions they are available in |
|
19d4b697fbf9
Mention that crc32 and adler32 are available in a different module (zlib).
Gregory P. Smith <greg@mad-scientist.com>
parents:
43298
diff
changeset
|
22 the zlib module. |
|
19d4b697fbf9
Mention that crc32 and adler32 are available in a different module (zlib).
Gregory P. Smith <greg@mad-scientist.com>
parents:
43298
diff
changeset
|
23 |
|
40254
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
24 Choose your hash function wisely. Some have known collision weaknesses. |
|
35375
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
25 sha384 and sha512 will be slow on 32 bit platforms. |
|
40254
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
26 |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
27 Hash objects have these methods: |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
28 - update(arg): Update the hash object with the string arg. Repeated calls |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
29 are equivalent to a single call with the concatenation of all |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
30 the arguments. |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
31 - digest(): Return the digest of the strings passed to the update() method |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
32 so far. This may contain non-ASCII characters, including |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
33 NUL bytes. |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
34 - hexdigest(): Like digest() except the digest is returned as a string of |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
35 double length, containing only hexadecimal digits. |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
36 - copy(): Return a copy (clone) of the hash object. This can be used to |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
37 efficiently compute the digests of strings that share a common |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
38 initial substring. |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
39 |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
40 For example, to obtain the digest of the string 'Nobody inspects the |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
41 spammish repetition': |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
42 |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
43 >>> import hashlib |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
44 >>> m = hashlib.md5() |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
45 >>> m.update("Nobody inspects") |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
46 >>> m.update(" the spammish repetition") |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
47 >>> m.digest() |
|
48915
be63ec748ee0
issue3715: docstring representation of hex escaped string needs to be double
Gregory P. Smith <greg@mad-scientist.com>
parents:
45895
diff
changeset
|
48 '\\xbbd\\x9c\\x83\\xdd\\x1e\\xa5\\xc9\\xd9\\xde\\xc9\\xa1\\x8d\\xf0\\xff\\xe9' |
|
40254
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
49 |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
50 More condensed: |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
51 |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
52 >>> hashlib.sha224("Nobody inspects the spammish repetition").hexdigest() |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
53 'a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2' |
|
da79c4e9a5bb
Bug #1586773: extend hashlib docstring.
Georg Brandl <georg@python.org>
parents:
35465
diff
changeset
|
54 |
|
35375
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
55 """ |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
56 |
|
55666
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
57 # This tuple and __get_builtin_constructor() must be modified if a new |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
58 # always available algorithm is added. |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
59 __always_supported = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512') |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
60 |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
61 __all__ = __always_supported + ('new',) |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
62 |
|
35375
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
63 |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
64 def __get_builtin_constructor(name): |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
65 if name in ('SHA1', 'sha1'): |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
66 import _sha |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
67 return _sha.new |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
68 elif name in ('MD5', 'md5'): |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
69 import _md5 |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
70 return _md5.new |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
71 elif name in ('SHA256', 'sha256', 'SHA224', 'sha224'): |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
72 import _sha256 |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
73 bs = name[3:] |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
74 if bs == '256': |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
75 return _sha256.sha256 |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
76 elif bs == '224': |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
77 return _sha256.sha224 |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
78 elif name in ('SHA512', 'sha512', 'SHA384', 'sha384'): |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
79 import _sha512 |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
80 bs = name[3:] |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
81 if bs == '512': |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
82 return _sha512.sha512 |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
83 elif bs == '384': |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
84 return _sha512.sha384 |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
85 |
|
55666
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
86 raise ValueError('unsupported hash type %s' % name) |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
87 |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
88 |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
89 def __get_openssl_constructor(name): |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
90 try: |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
91 f = getattr(_hashlib, 'openssl_' + name) |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
92 # Allow the C module to raise ValueError. The function will be |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
93 # defined but the hash not actually available thanks to OpenSSL. |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
94 f() |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
95 # Use the C function directly (very fast) |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
96 return f |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
97 except (AttributeError, ValueError): |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
98 return __get_builtin_constructor(name) |
|
35375
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
99 |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
100 |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
101 def __py_new(name, string=''): |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
102 """new(name, string='') - Return a new hashing object using the named algorithm; |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
103 optionally initialized with a string. |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
104 """ |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
105 return __get_builtin_constructor(name)(string) |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
106 |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
107 |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
108 def __hash_new(name, string=''): |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
109 """new(name, string='') - Return a new hashing object using the named algorithm; |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
110 optionally initialized with a string. |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
111 """ |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
112 try: |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
113 return _hashlib.new(name, string) |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
114 except ValueError: |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
115 # If the _hashlib module (OpenSSL) doesn't support the named |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
116 # hash, try using our builtin implementations. |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
117 # This allows for SHA224/256 and SHA384/512 support even though |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
118 # the OpenSSL library prior to 0.9.8 doesn't provide them. |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
119 return __get_builtin_constructor(name)(string) |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
120 |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
121 |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
122 try: |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
123 import _hashlib |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
124 new = __hash_new |
|
55666
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
125 __get_hash = __get_openssl_constructor |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
126 except ImportError: |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
127 new = __py_new |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
128 __get_hash = __get_builtin_constructor |
|
35375
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
129 |
|
55666
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
130 for __func_name in __always_supported: |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
131 # try them all, some may not work due to the OpenSSL |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
132 # version not supporting that algorithm. |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
133 try: |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
134 globals()[__func_name] = __get_hash(__func_name) |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
135 except ValueError: |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
136 import logging |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
137 logging.exception('code for hash %s was not found.', __func_name) |
|
35375
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
138 |
|
55666
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
139 # Cleanup locals() |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
140 del __always_supported, __func_name, __get_hash |
|
746f10e0624e
Clean up the C library import code (based on suggestions in issue6281).
Gregory P. Smith <greg@mad-scientist.com>
parents:
48915
diff
changeset
|
141 del __py_new, __hash_new, __get_openssl_constructor |
