From 948f492fc307bc974885388ecfdde126143ca6c0 Mon Sep 17 00:00:00 2001 From: Jane Doe Date: Sat, 27 May 2017 23:38:53 -0700 Subject: py2/3 fix to_bytes to not stringify bytearrays. Fix MD5signiture to not stringify if not needed contents --- src/engine/SCons/Util.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index 3ce7fe4..31213e1 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -32,6 +32,7 @@ import copy import re import types import codecs +import pprint PY3 = sys.version[0] == 3 @@ -497,7 +498,13 @@ def to_String_for_signature(obj, to_String_for_subst=to_String_for_subst, try: f = obj.for_signature except AttributeError: - return to_String_for_subst(obj) + if isinstance(obj, dict): + # pprint will output dictionary in key sorted order + # with py3.5 the order was randomized. In general depending on dictionary order + # which was undefined until py3.6 (where it's by insertion order) was not wise. + return pprint.pformat(obj, width=1000000) + else: + return to_String_for_subst(obj) else: return f() @@ -1515,7 +1522,12 @@ else: def MD5signature(s): m = hashlib.md5() - m.update(to_bytes(str(s))) + + try: + m.update(to_bytes(s)) + except TypeError as e: + m.update(to_bytes(str(s))) + return m.hexdigest() def MD5filesignature(fname, chunksize=65536): @@ -1525,7 +1537,7 @@ else: blck = f.read(chunksize) if not blck: break - m.update(to_bytes (str(blck))) + m.update(to_bytes(blck)) f.close() return m.hexdigest() @@ -1602,7 +1614,7 @@ class NullSeq(Null): del __revision__ def to_bytes (s): - if isinstance (s, bytes) or bytes is str: + if isinstance (s, (bytes, bytearray)) or bytes is str: return s return bytes (s, 'utf-8') -- cgit v0.12