Encode string before hash it
Otherwise, in python3.4, it will throw error: b'TypeError: Unicode-objects must be encoded before hashing' Partially-Implements: blueprint magnum-python3 Change-Id: Ia8aff8f4b5634fd8abda0ec185e8d9dc58c11fcd
This commit is contained in:
parent
ef6f6674bd
commit
0c9d1762d1
@ -354,7 +354,7 @@ def file_open(*args, **kwargs):
|
||||
def hash_file(file_like_object):
|
||||
"""Generate a hash for the contents of a file."""
|
||||
checksum = hashlib.sha1()
|
||||
for chunk in iter(lambda: file_like_object.read(32768), b''):
|
||||
for chunk in iter(lambda: six.b(file_like_object.read(32768)), b''):
|
||||
checksum.update(chunk)
|
||||
return checksum.hexdigest()
|
||||
|
||||
|
@ -336,7 +336,7 @@ class GenericUtilsTestCase(base.TestCase):
|
||||
data = 'Mary had a little lamb, its fleece as white as snow'
|
||||
flo = six.StringIO(data)
|
||||
h1 = utils.hash_file(flo)
|
||||
h2 = hashlib.sha1(data).hexdigest()
|
||||
h2 = hashlib.sha1(six.b(data)).hexdigest()
|
||||
self.assertEqual(h1, h2)
|
||||
|
||||
def test_is_valid_boolstr(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user