summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Deegan <bill@baddogconsulting.com>2017-05-09 12:26:07 (GMT)
committerWilliam Deegan <bill@baddogconsulting.com>2017-05-09 12:26:07 (GMT)
commit9bac6ca4c581925ed96f8b0d7881607f6bc03883 (patch)
tree85000d11f49ef5c2854ed5aabc7fa0375ba95f62
parent1976be7b15db2b89bf7c6361ea28806824c9c399 (diff)
downloadSCons-9bac6ca4c581925ed96f8b0d7881607f6bc03883.zip
SCons-9bac6ca4c581925ed96f8b0d7881607f6bc03883.tar.gz
SCons-9bac6ca4c581925ed96f8b0d7881607f6bc03883.tar.bz2
PY2/3 Change logic to check if the node has an issue with ascii encoding and only then encode
-rw-r--r--src/engine/SCons/Util.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py
index 2d8e75a..a927c6d 100644
--- a/src/engine/SCons/Util.py
+++ b/src/engine/SCons/Util.py
@@ -293,14 +293,23 @@ def print_tree(root, child_func, prune=0, showtags=0, margin=[0], visited=None):
if sys.version_info.major < 3:
# Python 2 UTF-8 encoded str are str. escape_encode is a str to str
# encoding
- rname = codecs.escape_encode(rname)[0]
+ try:
+ rname.decode('ascii')
+ except UnicodeDecodeError:
+ # If we can't decode into ascii, then escape it
+ rname = codecs.escape_encode(rname)[0]
else:
# Python 3 UTF-8 encoded str are bytes. escape_encode is a byte to byte
# encoding here.
rname = rname.encode('utf-8')
- rname = codecs.escape_encode(rname)[0]
- # Finally, we need a string again.
- rname = rname.decode('ascii')
+ try:
+ # Finally, we need a string again.
+ rname = rname.decode('ascii')
+ except UnicodeDecodeError:
+ # If we can't decode into ascii, then escape it
+ rname = codecs.escape_encode(rname)[0]
+ rname = rname.decode('ascii')
+
# Initialize 'visited' dict, if required
if visited is None: