summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2008-06-30 03:18:07 +0000
committerZac Medico <zmedico@gentoo.org>2008-06-30 03:18:07 +0000
commit9a4b31a59d24cd5aca28d326e44bce66683c9048 (patch)
tree34a7585a97c8ee8b8f2f568e09487cd16a6e207c
parentd7b88e3f8f60b30b54b5033f1391d1739175e6e3 (diff)
downloadportage-9a4b31a59d24cd5aca28d326e44bce66683c9048.tar.gz
portage-9a4b31a59d24cd5aca28d326e44bce66683c9048.tar.bz2
portage-9a4b31a59d24cd5aca28d326e44bce66683c9048.zip
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
-rw-r--r--pym/portage/checksum.py16
1 files changed, 13 insertions, 3 deletions
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: