From 9ced8fe7b4e2f878df32ab3f606f851ac4cb6efc Mon Sep 17 00:00:00 2001 From: Gaurav Juvekar Date: Sun, 16 Apr 2017 19:46:47 +0530 Subject: Try to fix some more py2/3 tests becuase of str vs bytearray --- src/engine/SCons/Node/Python.py | 8 +++++++- src/engine/SCons/Tool/textfile.py | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/engine/SCons/Node/Python.py b/src/engine/SCons/Node/Python.py index 2a3ce98..8c47c97 100644 --- a/src/engine/SCons/Node/Python.py +++ b/src/engine/SCons/Node/Python.py @@ -137,7 +137,13 @@ class Value(SCons.Node.Node): return contents def get_contents(self): - return self.get_text_contents().encode() + text_contents = self.get_text_contents() + try: + return text_contents.encode() + except UnicodeDecodeError: + # Already encoded as python2 str are bytes + return text_contents + def changed_since_last_build(self, target, prev_ni): cur_csig = self.get_csig() diff --git a/src/engine/SCons/Tool/textfile.py b/src/engine/SCons/Tool/textfile.py index 0e4d943..42a79cd 100644 --- a/src/engine/SCons/Tool/textfile.py +++ b/src/engine/SCons/Tool/textfile.py @@ -71,7 +71,11 @@ def _do_subst(node, subs): contents = re.sub(k, v, contents) if 'b' in TEXTFILE_FILE_WRITE_MODE: - contents = bytearray(contents, 'utf-8') + try: + contents = bytearray(contents, 'utf-8') + except UnicodeDecodeError: + # contents is already utf-8 encoded python 2 str i.e. a byte array + contents = bytearray(contents) return contents -- cgit v0.12