summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Deegan <bill@baddogconsulting.com>2017-05-09 13:28:36 (GMT)
committerWilliam Deegan <bill@baddogconsulting.com>2017-05-09 13:28:36 (GMT)
commit2a2f26cd83da8e63ead93999e7a08502f222ffd8 (patch)
tree70b3ee667a0602c7bcbc3bdd5f3a3f5eeb04f89f
parentfa879a1ea3230176d3bfa64212883dd29d6358b3 (diff)
parent9bac6ca4c581925ed96f8b0d7881607f6bc03883 (diff)
downloadSCons-2a2f26cd83da8e63ead93999e7a08502f222ffd8.zip
SCons-2a2f26cd83da8e63ead93999e7a08502f222ffd8.tar.gz
SCons-2a2f26cd83da8e63ead93999e7a08502f222ffd8.tar.bz2
Merged in bdbaddog/scons (pull request #460)
PY2/3 changes.
-rw-r--r--src/engine/SCons/Util.py17
-rw-r--r--test/SConsignFile/use-dbm.py12
-rw-r--r--test/Win32/bad-drive.py2
3 files changed, 23 insertions, 8 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:
diff --git a/test/SConsignFile/use-dbm.py b/test/SConsignFile/use-dbm.py
index 90983b3..129d5b6 100644
--- a/test/SConsignFile/use-dbm.py
+++ b/test/SConsignFile/use-dbm.py
@@ -34,10 +34,16 @@ _python_ = TestSCons._python_
test = TestSCons.TestSCons()
+
try:
import dbm.ndbm
+ use_db = 'dbm.ndbm'
except ImportError:
- test.skip_test('No dbm in this version of Python; skipping test.\n')
+ try:
+ import dbm
+ use_db = 'dbm'
+ except ImportError:
+ test.skip_test('No dbm.ndbm in this version of Python; skipping test.\n')
test.subdir('subdir')
@@ -53,8 +59,8 @@ sys.exit(0)
#
test.write('SConstruct', """
import sys
-import dbm
-SConsignFile('.sconsign', dbm)
+import %(use_db)s
+SConsignFile('.sconsign', %(use_db)s)
B = Builder(action = '%(_python_)s build.py $TARGETS $SOURCES')
env = Environment(BUILDERS = { 'B' : B })
env.B(target = 'f1.out', source = 'f1.in')
diff --git a/test/Win32/bad-drive.py b/test/Win32/bad-drive.py
index 5e8e66a..80a36c8 100644
--- a/test/Win32/bad-drive.py
+++ b/test/Win32/bad-drive.py
@@ -84,7 +84,7 @@ test.write("no_source", "no_source\n")
test.run(arguments = 'aaa.out')
-test.fail_test(test.read('aaa.out') != "aaa.in\n")
+test.must_match('aaa.out', "aaa.in\n", mode='r')
# This next test used to provide a slightly different error message:
# "scons: *** Do not know how to make File target `%snot_mentioned'. Stop.\n"