From: Zac Medico Date: Mon, 30 Jun 2008 03:18:07 +0000 (-0000) Subject: Avoid python-2.6 deprecation warnings for md5 and sha modules by trying X-Git-Tag: v2.2_rc2~271 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=9a4b31a59d24cd5aca28d326e44bce66683c9048;p=portage.git Avoid python-2.6 deprecation warnings for md5 and sha modules by trying to import hashlib first and then falling back to the deprecated modules if necessary. Thanks to ColdWind for reporting. svn path=/main/trunk/; revision=10854 --- diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py index 77716aefc..52ce59148 100644 --- a/pym/portage/checksum.py +++ b/pym/portage/checksum.py @@ -11,7 +11,6 @@ import tempfile import portage.exception import portage.process import commands -import md5, sha #dict of all available hash functions hashfunc_map = {} @@ -46,8 +45,19 @@ def _generate_hash_function(hashtype, hashobject, origin="unknown"): # override earlier ones # Use the internal modules as last fallback -md5hash = _generate_hash_function("MD5", md5.new, origin="internal") -sha1hash = _generate_hash_function("SHA1", sha.new, origin="internal") +try: + from hashlib import md5 as _new_md5 +except ImportError: + from md5 import new as _new_md5 + +md5hash = _generate_hash_function("MD5", _new_md5, origin="internal") + +try: + from hashlib import sha1 as _new_sha1 +except ImportError: + from sha import new as _new_sha1 + +sha1hash = _generate_hash_function("SHA1", _new_sha1, origin="internal") # Use pycrypto when available, prefer it over the internal fallbacks try: