diff options
-rw-r--r-- | src/engine/SCons/Util.py | 17 |
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: |