From 166cd52fd4c2f8ca32966b7669e9caf0ede05a5d Mon Sep 17 00:00:00 2001 From: Gaurav Juvekar Date: Wed, 10 May 2017 00:44:08 +0530 Subject: Directly print unicode in --tree --- src/engine/SCons/Util.py | 23 ++--------------------- test/option--tree.py | 8 +++++++- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index a927c6d..dcfe823 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -290,25 +290,6 @@ def print_tree(root, child_func, prune=0, showtags=0, margin=[0], visited=None): """ rname = str(root) - if sys.version_info.major < 3: - # Python 2 UTF-8 encoded str are str. escape_encode is a str to str - # encoding - 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') - 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 @@ -354,10 +335,10 @@ def print_tree(root, child_func, prune=0, showtags=0, margin=[0], visited=None): children = child_func(root) if prune and rname in visited and children: - sys.stdout.write(''.join(tags + margins + ['+-[', rname, ']']) + u'\n') + sys.stdout.write(''.join(tags + margins + ['+-[', rname, ']']) + '\n') return - sys.stdout.write(''.join(tags + margins + ['+-', rname]) + u'\n') + sys.stdout.write(''.join(tags + margins + ['+-', rname]) + '\n') visited[rname] = 1 diff --git a/test/option--tree.py b/test/option--tree.py index a9618d8..2918c85 100644 --- a/test/option--tree.py +++ b/test/option--tree.py @@ -24,6 +24,7 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" +import sys import TestSCons test = TestSCons.TestSCons() @@ -67,11 +68,16 @@ except NameError: env.Textfile("Foo", write) """) +if sys.version_info.major < 3: + py23_char = unichr(0xe7).encode('utf-8') +else: + py23_char = chr(0xe7) + test.run(arguments = '-Q --tree=all', stdout = """Creating 'Foo.txt' +-. +-Foo.txt - | +-\\xc3\\xa7 + | +-""" + py23_char + """ +-SConstruct """, status = 0) -- cgit v0.12