summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--QMTest/TestCmd.py24
-rw-r--r--QMTest/TestCommon.py10
-rw-r--r--bench/is_types.py20
-rw-r--r--bin/scons-proc.py12
-rw-r--r--src/engine/SCons/DefaultsTests.py2
-rw-r--r--src/engine/SCons/SubstTests.py2
-rw-r--r--src/engine/SCons/UtilTests.py52
-rw-r--r--test/option/profile.py19
8 files changed, 71 insertions, 70 deletions
diff --git a/QMTest/TestCmd.py b/QMTest/TestCmd.py
index 1ee5d4e4..1c71907a 100644
--- a/QMTest/TestCmd.py
+++ b/QMTest/TestCmd.py
@@ -228,7 +228,12 @@ import sys
import tempfile
import time
import traceback
-import UserList
+try:
+ from collections import UserList, UserString
+except ImportError:
+ # no 'collections' module or no UserFoo in collections
+ exec('from UserList import UserList')
+ exec('from UserString import UserString')
try:
# pre-2.7 doesn't have the memoryview() built-in
@@ -264,24 +269,15 @@ except ImportError:
__all__.append('simple_diff')
def is_List(e):
- return isinstance(e, list) \
- or isinstance(e, UserList.UserList)
-
-try:
- from UserString import UserString
-except ImportError:
- class UserString:
- pass
+ return isinstance(e, (list,UserList))
-try: unicode
+try: eval('unicode')
except NameError:
def is_String(e):
- return isinstance(e, str) or isinstance(e, UserString)
+ return isinstance(e, (str,UserString))
else:
def is_String(e):
- return isinstance(e, str) \
- or isinstance(e, unicode) \
- or isinstance(e, UserString)
+ return isinstance(e, (str,unicode,UserString))
tempfile.template = 'testcmd.'
if os.name in ('posix', 'nt'):
diff --git a/QMTest/TestCommon.py b/QMTest/TestCommon.py
index fce0fc82..fcd3e70c 100644
--- a/QMTest/TestCommon.py
+++ b/QMTest/TestCommon.py
@@ -95,10 +95,13 @@ __version__ = "0.37"
import copy
import os
-import os.path
import stat
import sys
-import UserList
+try:
+ from collections import UserList
+except ImportError:
+ # no 'collections' module or no UserList in collections
+ exec('from UserList import UserList')
from TestCmd import *
from TestCmd import __all__
@@ -171,8 +174,7 @@ else:
dll_suffix = '.so'
def is_List(e):
- return isinstance(e, list) \
- or isinstance(e, UserList.UserList)
+ return isinstance(e, (list,UserList))
def is_writable(f):
mode = os.stat(f)[stat.ST_MODE]
diff --git a/bench/is_types.py b/bench/is_types.py
index 0353dc8a..b47c3812 100644
--- a/bench/is_types.py
+++ b/bench/is_types.py
@@ -5,9 +5,13 @@
# src/engine/SCons/Util.py.
import types
-from UserDict import UserDict
-from UserList import UserList
-from UserString import UserString
+try:
+ from collections import UserDict, UserList, UserString
+except ImportError:
+ # No 'collections' module or no UserFoo in collections
+ exec('from UserDict import UserDict')
+ exec('from UserList import UserList')
+ exec('from UserString import UserString')
InstanceType = types.InstanceType
DictType = dict
@@ -25,19 +29,17 @@ else:
# User* type.
def original_is_Dict(e):
- return isinstance(e, dict) or isinstance(e, UserDict)
+ return isinstance(e, (dict,UserDict))
def original_is_List(e):
- return isinstance(e, list) or isinstance(e, UserList)
+ return isinstance(e, (list,UserList))
if UnicodeType is not None:
def original_is_String(e):
- return isinstance(e, str) \
- or isinstance(e, unicode) \
- or isinstance(e, UserString)
+ return isinstance(e, (str,unicode,UserString))
else:
def original_is_String(e):
- return isinstance(e, str) or isinstance(e, UserString)
+ return isinstance(e, (str,UserString))
diff --git a/bin/scons-proc.py b/bin/scons-proc.py
index 922ddd65..b8b12385 100644
--- a/bin/scons-proc.py
+++ b/bin/scons-proc.py
@@ -10,12 +10,16 @@
# and/or .mod files contining the ENTITY definitions for each item,
# or in man-page-formatted output.
#
+import os
+import sys
import getopt
-import os.path
import re
-import StringIO
-import sys
import xml.sax
+try:
+ from io import StringIO
+except ImportError:
+ # No 'io' module or no StringIO in io
+ exec('from cStringIO import StringIO')
import SConsDoc
@@ -100,7 +104,7 @@ for f in args:
content = content.replace('-->\n', '-->')
input = xml_preamble + content + xml_postamble
try:
- saxparser.parse(StringIO.StringIO(input))
+ saxparser.parse(StringIO(input))
except:
sys.stderr.write("error in %s\n" % f)
raise
diff --git a/src/engine/SCons/DefaultsTests.py b/src/engine/SCons/DefaultsTests.py
index 96d5de7a..fd10c129 100644
--- a/src/engine/SCons/DefaultsTests.py
+++ b/src/engine/SCons/DefaultsTests.py
@@ -26,8 +26,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import SCons.compat
import os
-import os.path
-import StringIO
import sys
import unittest
diff --git a/src/engine/SCons/SubstTests.py b/src/engine/SCons/SubstTests.py
index fbd50378..1c8412c7 100644
--- a/src/engine/SCons/SubstTests.py
+++ b/src/engine/SCons/SubstTests.py
@@ -26,8 +26,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import SCons.compat
import os
-import os.path
-import StringIO
import sys
import unittest
diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py
index a4d69d72..2d7f3fae 100644
--- a/src/engine/SCons/UtilTests.py
+++ b/src/engine/SCons/UtilTests.py
@@ -25,12 +25,11 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import SCons.compat
-import collections
import io
import os
import sys
import unittest
-
+from collections import UserDict, UserList, UserString
import TestCmd
@@ -38,7 +37,7 @@ import SCons.Errors
from SCons.Util import *
-try: unicode
+try: eval('unicode')
except NameError: HasUnicode = False
else: HasUnicode = True
@@ -207,7 +206,7 @@ class UtilTestCase(unittest.TestCase):
def test_is_Dict(self):
assert is_Dict({})
- assert is_Dict(collections.UserDict())
+ assert is_Dict(UserDict())
try:
class mydict(dict):
pass
@@ -223,8 +222,7 @@ class UtilTestCase(unittest.TestCase):
def test_is_List(self):
assert is_List([])
- import UserList
- assert is_List(collections.UserList())
+ assert is_List(UserList())
try:
class mylist(list):
pass
@@ -242,12 +240,7 @@ class UtilTestCase(unittest.TestCase):
assert is_String("")
if HasUnicode:
exec "assert is_String(u'')"
- try:
- import UserString
- except:
- pass
- else:
- assert is_String(collections.UserString(''))
+ assert is_String(UserString(''))
try:
class mystr(str):
pass
@@ -280,27 +273,22 @@ class UtilTestCase(unittest.TestCase):
assert to_String([ 1, 2, 3]) == str([1, 2, 3]), to_String([1,2,3])
assert to_String("foo") == "foo", to_String("foo")
- try:
- import UserString
+ s1=UserString('blah')
+ assert to_String(s1) == s1, s1
+ assert to_String(s1) == 'blah', s1
- s1=collections.UserString('blah')
- assert to_String(s1) == s1, s1
- assert to_String(s1) == 'blah', s1
-
- class Derived(collections.UserString):
- pass
- s2 = Derived('foo')
- assert to_String(s2) == s2, s2
- assert to_String(s2) == 'foo', s2
-
- if HasUnicode:
- s3=collections.UserString(unicode('bar'))
- assert to_String(s3) == s3, s3
- assert to_String(s3) == unicode('bar'), s3
- assert isinstance(to_String(s3), unicode), \
- type(to_String(s3))
- except ImportError:
+ class Derived(UserString):
pass
+ s2 = Derived('foo')
+ assert to_String(s2) == s2, s2
+ assert to_String(s2) == 'foo', s2
+
+ if HasUnicode:
+ s3=UserString(unicode('bar'))
+ assert to_String(s3) == s3, s3
+ assert to_String(s3) == unicode('bar'), s3
+ assert isinstance(to_String(s3), unicode), \
+ type(to_String(s3))
if HasUnicode:
s4 = unicode('baz')
@@ -618,7 +606,7 @@ class UtilTestCase(unittest.TestCase):
s['c'] = 'CCC'
assert s['c'] == 'CCC', s['c']
- class DummyEnv(collections.UserDict):
+ class DummyEnv(UserDict):
def subst(self, key):
if key[0] == '$':
return self[key[1:]]
diff --git a/test/option/profile.py b/test/option/profile.py
index 16032fbc..fef4b7a8 100644
--- a/test/option/profile.py
+++ b/test/option/profile.py
@@ -23,8 +23,21 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-import StringIO
import sys
+try:
+ # In Python 2.5 and before, there was no 'io' module. The 'io' module
+ # in 2.6 provides a StringIO, but it only works with Unicode strings,
+ # while virtually all the strings we use are normal eight-bit strings,
+ # including all the strings generated by the 'profile' module. This
+ # is a horrible hack that just papers over the problem without fixing
+ # it, but I don't see any other way to do it. We'll keep using the old
+ # StringIO module until it no longer exists, and hope that if it's not
+ # there, it means that we've converted to Python 3.x where all strings
+ # are Unicode.
+ exec('from cStringIO import StringIO')
+except ImportError:
+ # No 'cStringIO' assume new 3.x structure
+ from io import StringIO
import TestSCons
@@ -48,7 +61,7 @@ test.must_contain_all_lines(test.stdout(), ['usage: scons [OPTION]'])
try:
save_stdout = sys.stdout
- sys.stdout = StringIO.StringIO()
+ sys.stdout = StringIO()
stats = pstats.Stats(scons_prof)
stats.sort_stats('time')
@@ -69,7 +82,7 @@ test.run(arguments = "--profile %s" % scons_prof)
try:
save_stdout = sys.stdout
- sys.stdout = StringIO.StringIO()
+ sys.stdout = StringIO()
stats = pstats.Stats(scons_prof)
stats.sort_stats('time')