# HG changeset patch # User Gregory Szorc # Date 1449981037 18000 # Node ID 7f5a0bd4c9aa6892f78997ad00aea4477a58b995 # Parent c2effd1ecebff8c3f154edfed7f1c90ce044283a 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. diff -r c2effd1ecebf -r 7f5a0bd4c9aa mercurial/util.py --- 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