Skip to content

Commit e3c8c61

Browse files
authored
Fix python3 issues with hashing (#379)
1 parent b2a2d1d commit e3c8c61

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

aliBuild

+3-2
Original file line numberDiff line numberDiff line change
@@ -778,8 +778,9 @@ def doMain():
778778
h(str(time.time()))
779779
if spec["package"] in develPkgs and "incremental_recipe" in spec:
780780
h(spec["incremental_recipe"])
781-
incremental_hash = hashlib.sha1(spec["incremental_recipe"]).hexdigest()
782-
spec["incremental_hash"] = incremental_hash
781+
ih = Hasher()
782+
ih(spec["incremental_recipe"])
783+
spec["incremental_hash"] = ih.hexdigest()
783784
elif p in develPkgs:
784785
h(spec.get("devel_hash"))
785786
spec["hash"] = h.hexdigest()

alibuild_helpers/utilities.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ class Hasher:
284284
def __init__(self):
285285
self.h = hashlib.sha1()
286286
def __call__(self, txt):
287-
self.h.update(txt.encode('utf-8', 'ignore'))
287+
if not type(txt) == bytes:
288+
txt = txt.encode('utf-8', 'ignore')
289+
self.h.update(txt)
288290
def hexdigest(self):
289291
return self.h.hexdigest()

tests/test_utilities.py

+3
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,13 @@ def test_Hasher(self):
120120
def test_UTF8_Hasher(self):
121121
h1 = Hasher()
122122
h2 = Hasher()
123+
h3 = Hasher()
123124
h1(u'\ua000')
124125
h2(u'\ua001')
126+
h3(b'foo')
125127
self.assertEqual(h1.hexdigest(), "2af8e41129115eb231a0af76ec5465d3a9184fc4")
126128
self.assertEqual(h2.hexdigest(), "1619bcdbeff6828138ad9b6e43cc17e856457603")
129+
self.assertEqual(h3.hexdigest(), "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33")
127130
self.assertNotEqual(h1.hexdigest(), h2.hexdigest())
128131

129132
if __name__ == '__main__':

0 commit comments

Comments
 (0)