##// END OF EJS Templates
util: make hashlib import unconditional...
Gregory Szorc -
r27357:7f5a0bd4 default
parent child Browse files
Show More
@@ -23,12 +23,17 b' import imp, socket, urllib'
23 import gc
23 import gc
24 import bz2
24 import bz2
25 import zlib
25 import zlib
26 import hashlib
26
27
27 if os.name == 'nt':
28 if os.name == 'nt':
28 import windows as platform
29 import windows as platform
29 else:
30 else:
30 import posix as platform
31 import posix as platform
31
32
33 md5 = hashlib.md5
34 sha1 = hashlib.sha1
35 sha512 = hashlib.sha512
36
32 cachestat = platform.cachestat
37 cachestat = platform.cachestat
33 checkexec = platform.checkexec
38 checkexec = platform.checkexec
34 checklink = platform.checklink
39 checklink = platform.checklink
@@ -95,23 +100,13 b' os.stat_float_times(False)'
95 def safehasattr(thing, attr):
100 def safehasattr(thing, attr):
96 return getattr(thing, attr, _notset) is not _notset
101 return getattr(thing, attr, _notset) is not _notset
97
102
98 from hashlib import md5, sha1
99
100 DIGESTS = {
103 DIGESTS = {
101 'md5': md5,
104 'md5': md5,
102 'sha1': sha1,
105 'sha1': sha1,
106 'sha512': sha512,
103 }
107 }
104 # List of digest types from strongest to weakest
108 # List of digest types from strongest to weakest
105 DIGESTS_BY_STRENGTH = ['sha1', 'md5']
109 DIGESTS_BY_STRENGTH = ['sha512', 'sha1', 'md5']
106
107 try:
108 import hashlib
109 DIGESTS.update({
110 'sha512': hashlib.sha512,
111 })
112 DIGESTS_BY_STRENGTH.insert(0, 'sha512')
113 except ImportError:
114 pass
115
110
116 for k in DIGESTS_BY_STRENGTH:
111 for k in DIGESTS_BY_STRENGTH:
117 assert k in DIGESTS
112 assert k in DIGESTS
General Comments 0
You need to be logged in to leave comments. Login now