1 |
From: "Robin H. Johnson" <robbat2@g.o> |
2 |
|
3 |
To be used shortly for WHIRLPOOL as well as RMD160. |
4 |
|
5 |
Signed-off-by: Robin H. Johnson <robbat2@g.o> |
6 |
--- |
7 |
pym/portage/checksum.py | 21 ++++++++++++--------- |
8 |
1 files changed, 12 insertions(+), 9 deletions(-) |
9 |
|
10 |
diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py |
11 |
index 9e7e455..e5455fa 100644 |
12 |
--- a/pym/portage/checksum.py |
13 |
+++ b/pym/portage/checksum.py |
14 |
@@ -82,19 +82,22 @@ except ImportError as e: |
15 |
# Use hashlib from python-2.5 if available and prefer it over pycrypto and internal fallbacks. |
16 |
# Need special handling for RMD160 as it may not always be provided by hashlib. |
17 |
try: |
18 |
- import hashlib |
19 |
+ import hashlib, functools |
20 |
|
21 |
md5hash = _generate_hash_function("MD5", hashlib.md5, origin="hashlib") |
22 |
sha1hash = _generate_hash_function("SHA1", hashlib.sha1, origin="hashlib") |
23 |
sha256hash = _generate_hash_function("SHA256", hashlib.sha256, origin="hashlib") |
24 |
- try: |
25 |
- hashlib.new('ripemd160') |
26 |
- except ValueError: |
27 |
- pass |
28 |
- else: |
29 |
- def rmd160(): |
30 |
- return hashlib.new('ripemd160') |
31 |
- rmd160hash = _generate_hash_function("RMD160", rmd160, origin="hashlib") |
32 |
+ for local_name, hash_name in (("rmd160", "ripemd160"), ): |
33 |
+ try: |
34 |
+ hashlib.new(hash_name) |
35 |
+ except ValueError: |
36 |
+ pass |
37 |
+ else: |
38 |
+ globals()['%shash' % local_name] = \ |
39 |
+ _generate_hash_function(local_name.upper(), \ |
40 |
+ functools.partial(hashlib.new, hash_name), \ |
41 |
+ origin='hashlib') |
42 |
+ |
43 |
except ImportError as e: |
44 |
pass |
45 |
|
46 |
-- |
47 |
1.7.7 |