From 9a4b31a59d24cd5aca28d326e44bce66683c9048 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 30 Jun 2008 03:18:07 +0000 Subject: [PATCH] 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 --- pym/portage/checksum.py | 16 +++++++++++++--- 1 file 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: -- 2.26.2