diff options
author | Robin H. Johnson <robbat2@gentoo.org> | 2011-10-01 07:40:51 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2011-10-01 22:24:58 -0700 |
commit | f27473d04e6dee44983d1e5ac32ea9d4d375b5a2 (patch) | |
tree | 858b30fa97c0b2e38755ff09077e104019b6c751 | |
parent | 1ae379c59a5cdc2d729f2b33807e70548afcbfb4 (diff) | |
download | portage-f27473d04e6dee44983d1e5ac32ea9d4d375b5a2.tar.gz portage-f27473d04e6dee44983d1e5ac32ea9d4d375b5a2.tar.bz2 portage-f27473d04e6dee44983d1e5ac32ea9d4d375b5a2.zip |
Refactor RMD160 hashlib code for less-hardcoding
To be used shortly for WHIRLPOOL as well as RMD160.
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
-rw-r--r-- | pym/portage/checksum.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py index 52e45d388..8daefbcb9 100644 --- a/pym/portage/checksum.py +++ b/pym/portage/checksum.py @@ -87,19 +87,22 @@ except ImportError as e: # Use hashlib from python-2.5 if available and prefer it over pycrypto and internal fallbacks. # Need special handling for RMD160 as it may not always be provided by hashlib. try: - import hashlib + import hashlib, functools md5hash = _generate_hash_function("MD5", hashlib.md5, origin="hashlib") sha1hash = _generate_hash_function("SHA1", hashlib.sha1, origin="hashlib") sha256hash = _generate_hash_function("SHA256", hashlib.sha256, origin="hashlib") - try: - hashlib.new('ripemd160') - except ValueError: - pass - else: - def rmd160(): - return hashlib.new('ripemd160') - rmd160hash = _generate_hash_function("RMD160", rmd160, origin="hashlib") + for local_name, hash_name in (("rmd160", "ripemd160"), ): + try: + hashlib.new(hash_name) + except ValueError: + pass + else: + globals()['%shash' % local_name] = \ + _generate_hash_function(local_name.upper(), \ + functools.partial(hashlib.new, hash_name), \ + origin='hashlib') + except ImportError as e: pass |