From 916e4fa90ee512fedeba05665fb357ffd208319c Mon Sep 17 00:00:00 2001 From: Gaurav Juvekar Date: Sun, 26 Mar 2017 15:59:59 +0530 Subject: string-escape unicode characters while printing --tree Fixes #2910 --- src/engine/SCons/Util.py | 8 ++++---- test/option--tree.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index a8a6990..ecdd77f 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -148,7 +148,7 @@ class NodeList(UserList): # else: # self.data = [ initlist,] - + def __nonzero__(self): return len(self.data) != 0 @@ -170,10 +170,10 @@ class NodeList(UserList): return self.__class__(result) def __getitem__(self, index): - """ + """ This comes for free on py2, but py3 slices of NodeList are returning a list - breaking slicing nodelist and refering to + breaking slicing nodelist and refering to properties and methods on contained object """ # return self.__class__(self.data[index]) @@ -288,7 +288,7 @@ def print_tree(root, child_func, prune=0, showtags=0, margin=[0], visited=None): or in the whole tree if prune. """ - rname = str(root) + rname = str(root).encode('string-escape') # Initialize 'visited' dict, if required if visited is None: diff --git a/test/option--tree.py b/test/option--tree.py index a50433c..a8c360e 100644 --- a/test/option--tree.py +++ b/test/option--tree.py @@ -51,6 +51,23 @@ scons: warning: The --debug=tree option is deprecated; please use --tree=all ins """, status = 0, match=TestSCons.match_re_dotall) + +# Test that unicode characters can be printed with the --tree option +test.write('SConstruct', +""" +env = Environment() +env.Tool("textfile") +env.Textfile("Foo", unichr(0xe7).encode('utf-8')) +""") + +test.run(arguments = '-Q --tree=all', + stdout = """Creating 'Foo.txt' ++-. + +-Foo.txt + | +-\\xc3\\xa7 + +-SConstruct +""", + status = 0) test.pass_test() # Local Variables: -- cgit v0.12 From b34164950ee97eb57f28ed665137e95de70effb9 Mon Sep 17 00:00:00 2001 From: Gaurav Juvekar Date: Sun, 26 Mar 2017 16:06:01 +0530 Subject: Reword comment in test case to highlight that unicode is printed escaped --- test/option--tree.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/option--tree.py b/test/option--tree.py index a8c360e..1c1832b 100644 --- a/test/option--tree.py +++ b/test/option--tree.py @@ -52,7 +52,7 @@ scons: warning: The --debug=tree option is deprecated; please use --tree=all ins status = 0, match=TestSCons.match_re_dotall) -# Test that unicode characters can be printed with the --tree option +# Test that unicode characters can be printed (escaped) with the --tree option test.write('SConstruct', """ env = Environment() -- cgit v0.12 From 52f4d73e7b8577660ccf9d8c0a9f6fb5837c2e28 Mon Sep 17 00:00:00 2001 From: Gaurav Juvekar Date: Mon, 27 Mar 2017 12:32:29 +0530 Subject: Make --tree=all work with Python 3 The codecs module is used which is distributed in the python standard library. --- src/engine/SCons/Util.py | 14 +++++++++++++- test/option--tree.py | 9 ++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index ecdd77f..2d8e75a 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -31,6 +31,7 @@ import sys import copy import re import types +import codecs try: from UserDict import UserDict @@ -288,7 +289,18 @@ def print_tree(root, child_func, prune=0, showtags=0, margin=[0], visited=None): or in the whole tree if prune. """ - rname = str(root).encode('string-escape') + 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 + 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') # Initialize 'visited' dict, if required if visited is None: diff --git a/test/option--tree.py b/test/option--tree.py index 1c1832b..a9618d8 100644 --- a/test/option--tree.py +++ b/test/option--tree.py @@ -57,7 +57,14 @@ test.write('SConstruct', """ env = Environment() env.Tool("textfile") -env.Textfile("Foo", unichr(0xe7).encode('utf-8')) +try: + # Python 2 + write = unichr(0xe7).encode('utf-8') +except NameError: + # Python 3 + # str is utf-8 by default + write = chr(0xe7) +env.Textfile("Foo", write) """) test.run(arguments = '-Q --tree=all', -- cgit v0.12 From 4e4854aabb4f3283972737440aa64dd221e7aeee Mon Sep 17 00:00:00 2001 From: Gaurav Juvekar Date: Mon, 27 Mar 2017 12:40:17 +0530 Subject: Add contribution to src/CHANGES.txt --- src/CHANGES.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index cb6ab21..5127c51 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -13,6 +13,10 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER RELEASE VERSION/DATE TO BE FILLED IN LATER + From Gaurav Juvekar: + - Fix issue #2910: Make --tree=all handle Unicode. (PR #427) + - Fix issue #2788: Fix typo in documentation example for sconf. (PR #388) + From Manish Vachharajani: - Update debian rules, compat, and control to not use features deprecated or obsolete in later versions of debhelpers -- cgit v0.12