changeset 27357:7f5a0bd4c9aa

util: make hashlib import unconditional hashlib was added in Python 2.5. As far as I can tell, SHA-512 is always available in 2.6+. So move the hashlib import to the top of the file and remove the one-off handling of SHA-512.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 12 Dec 2015 23:30:37 -0500
parents c2effd1ecebf
children ac839ee45b6a
files mercurial/util.py
diffstat 1 files changed, 7 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/util.py	Sat Dec 12 23:26:12 2015 -0800
+++ b/mercurial/util.py	Sat Dec 12 23:30:37 2015 -0500
@@ -23,12 +23,17 @@
 import gc
 import bz2
 import zlib
+import hashlib
 
 if os.name == 'nt':
     import windows as platform
 else:
     import posix as platform
 
+md5 = hashlib.md5
+sha1 = hashlib.sha1
+sha512 = hashlib.sha512
+
 cachestat = platform.cachestat
 checkexec = platform.checkexec
 checklink = platform.checklink
@@ -95,23 +100,13 @@
 def safehasattr(thing, attr):
     return getattr(thing, attr, _notset) is not _notset
 
-from hashlib import md5, sha1
-
 DIGESTS = {
     'md5': md5,
     'sha1': sha1,
+    'sha512': sha512,
 }
 # List of digest types from strongest to weakest
-DIGESTS_BY_STRENGTH = ['sha1', 'md5']
-
-try:
-    import hashlib
-    DIGESTS.update({
-        'sha512': hashlib.sha512,
-    })
-    DIGESTS_BY_STRENGTH.insert(0, 'sha512')
-except ImportError:
-    pass
+DIGESTS_BY_STRENGTH = ['sha512', 'sha1', 'md5']
 
 for k in DIGESTS_BY_STRENGTH:
     assert k in DIGESTS