summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2010-04-07 15:29:39 (GMT)
committerSteven Knight <knight@baldmt.com>2010-04-07 15:29:39 (GMT)
commitca29ee5e30d4d4ad60d51f95e4ac61eee7e5cd42 (patch)
treeeb60dd8251a7fd064aa255309df2056dbf49a258
parent32d7c315d62846ea8febadcbb2c60cf9e3382cbf (diff)
downloadSCons-ca29ee5e30d4d4ad60d51f95e4ac61eee7e5cd42.zip
SCons-ca29ee5e30d4d4ad60d51f95e4ac61eee7e5cd42.tar.gz
SCons-ca29ee5e30d4d4ad60d51f95e4ac61eee7e5cd42.tar.bz2
Issue 2334: Use compatibility versions of collections.User{Dict,List,String}
instead of the deprecated User{Dict,List,String} modules. The two test scripts that use User{List,String} fall back on ImportError by hand.
-rw-r--r--src/engine/SCons/ActionTests.py2
-rw-r--r--src/engine/SCons/Builder.py9
-rw-r--r--src/engine/SCons/BuilderTests.py6
-rw-r--r--src/engine/SCons/DefaultsTests.py4
-rw-r--r--src/engine/SCons/Environment.py2
-rw-r--r--src/engine/SCons/EnvironmentTests.py18
-rw-r--r--src/engine/SCons/Executor.py8
-rw-r--r--src/engine/SCons/Node/Alias.py4
-rw-r--r--src/engine/SCons/Node/FSTests.py4
-rw-r--r--src/engine/SCons/Node/NodeTests.py4
-rw-r--r--src/engine/SCons/Node/__init__.py6
-rw-r--r--src/engine/SCons/Platform/PlatformTests.py4
-rw-r--r--src/engine/SCons/Scanner/CTests.py7
-rw-r--r--src/engine/SCons/Scanner/LaTeXTests.py8
-rw-r--r--src/engine/SCons/Scanner/RCTests.py7
-rw-r--r--src/engine/SCons/Scanner/ScannerTests.py6
-rw-r--r--src/engine/SCons/Script/SConscript.py2
-rw-r--r--src/engine/SCons/Script/__init__.py4
-rw-r--r--src/engine/SCons/Subst.py19
-rw-r--r--src/engine/SCons/SubstTests.py22
-rw-r--r--src/engine/SCons/Util.py4
-rw-r--r--src/engine/SCons/UtilTests.py17
-rw-r--r--src/engine/SCons/Variables/ListVariable.py6
-rw-r--r--src/engine/SCons/compat/__init__.py27
-rw-r--r--src/engine/SCons/compat/_scons_UserString.py94
-rw-r--r--test/SConscript/SConscript.py7
-rw-r--r--test/subclassing.py5
27 files changed, 115 insertions, 191 deletions
diff --git a/src/engine/SCons/ActionTests.py b/src/engine/SCons/ActionTests.py
index 6b8b465..4cb5a0a 100644
--- a/src/engine/SCons/ActionTests.py
+++ b/src/engine/SCons/ActionTests.py
@@ -36,13 +36,13 @@ class GlobalActFunc:
def __call__(self):
pass
+import collections
import io
import os
import re
import sys
import types
import unittest
-import UserDict
import SCons.Action
import SCons.Environment
diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py
index c999afd..4cce92f 100644
--- a/src/engine/SCons/Builder.py
+++ b/src/engine/SCons/Builder.py
@@ -101,8 +101,7 @@ from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-import UserDict
-import UserList
+import collections
import SCons.Action
from SCons.Debug import logInstanceCreation
@@ -200,7 +199,7 @@ class DictEmitter(SCons.Util.Selector):
target, source = emitter(target, source, env)
return (target, source)
-class ListEmitter(UserList.UserList):
+class ListEmitter(collections.UserList):
"""A callable list of emitters that calls each in sequence,
returning the result.
"""
@@ -218,7 +217,7 @@ misleading_keywords = {
'sources' : 'source',
}
-class OverrideWarner(UserDict.UserDict):
+class OverrideWarner(collections.UserDict):
"""A class for warning about keyword arguments that we use as
overrides in a Builder call.
@@ -227,7 +226,7 @@ class OverrideWarner(UserDict.UserDict):
warnings once, no matter how many Builders are invoked.
"""
def __init__(self, dict):
- UserDict.UserDict.__init__(self, dict)
+ collections.UserDict.__init__(self, dict)
if __debug__: logInstanceCreation(self, 'Builder.OverrideWarner')
self.already_warned = None
def warn(self):
diff --git a/src/engine/SCons/BuilderTests.py b/src/engine/SCons/BuilderTests.py
index de6d2be..38eb0ca 100644
--- a/src/engine/SCons/BuilderTests.py
+++ b/src/engine/SCons/BuilderTests.py
@@ -32,12 +32,12 @@ import SCons.compat
def Func():
pass
+import collections
import io
import os.path
import re
import sys
import unittest
-import UserList
import TestCmd
@@ -253,7 +253,7 @@ class BuilderTestCase(unittest.TestCase):
assert not hasattr(n2, 'env')
l = [1]
- ul = UserList.UserList([2])
+ ul = collections.UserList([2])
try:
l.extend(ul)
except TypeError:
@@ -707,7 +707,7 @@ class BuilderTestCase(unittest.TestCase):
assert env['CNT'][0] == 2
tgts = builder(env, None, infiles[2:4])
try:
- [].extend(UserList.UserList())
+ [].extend(collections.UserList())
except TypeError:
# Old Python version (1.5.2) that can't handle extending
# a list with list-like objects. That means the return
diff --git a/src/engine/SCons/DefaultsTests.py b/src/engine/SCons/DefaultsTests.py
index 99cb120..96d5de7 100644
--- a/src/engine/SCons/DefaultsTests.py
+++ b/src/engine/SCons/DefaultsTests.py
@@ -23,13 +23,15 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import SCons.compat
+
import os
import os.path
import StringIO
import sys
import unittest
-from UserDict import UserDict
+from collections import UserDict
import TestCmd
diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py
index 1fd763d..5449669 100644
--- a/src/engine/SCons/Environment.py
+++ b/src/engine/SCons/Environment.py
@@ -41,7 +41,7 @@ import os
import sys
import re
import shlex
-from UserDict import UserDict
+from collections import UserDict
import SCons.Action
import SCons.Builder
diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py
index 3a2cd8a..0719853 100644
--- a/src/engine/SCons/EnvironmentTests.py
+++ b/src/engine/SCons/EnvironmentTests.py
@@ -25,13 +25,13 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import SCons.compat
+import collections
import copy
import io
import os
import sys
import TestCmd
import unittest
-import UserList
from SCons.Environment import *
import SCons.Warnings
@@ -126,15 +126,15 @@ class Scanner:
-class CLVar(UserList.UserList):
+class CLVar(collections.UserList):
def __init__(self, seq):
if isinstance(seq, str):
seq = seq.split()
- UserList.UserList.__init__(self, seq)
+ collections.UserList.__init__(self, seq)
def __add__(self, other):
- return UserList.UserList.__add__(self, CLVar(other))
+ return collections.UserList.__add__(self, CLVar(other))
def __radd__(self, other):
- return UserList.UserList.__radd__(self, CLVar(other))
+ return collections.UserList.__radd__(self, CLVar(other))
def __coerce__(self, other):
return (self, CLVar(other))
@@ -1480,9 +1480,9 @@ def exists(env):
assert b1 == b2, diff_dict(b1, b2)
import UserDict
- UD = UserDict.UserDict
+ UD = collections.UserDict
import UserList
- UL = UserList.UserList
+ UL = collections.UserList
cases = [
'a1', 'A1', 'a1A1',
@@ -2152,9 +2152,9 @@ f5: \
"""Test prepending to construction variables in an Environment
"""
import UserDict
- UD = UserDict.UserDict
+ UD = collections.UserDict
import UserList
- UL = UserList.UserList
+ UL = collections.UserList
cases = [
'a1', 'A1', 'A1a1',
diff --git a/src/engine/SCons/Executor.py b/src/engine/SCons/Executor.py
index aaf71b8..8f9b917 100644
--- a/src/engine/SCons/Executor.py
+++ b/src/engine/SCons/Executor.py
@@ -31,7 +31,7 @@ from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-import UserList
+import collections
from SCons.Debug import logInstanceCreation
import SCons.Errors
@@ -47,15 +47,15 @@ class Batch:
-class TSList(UserList.UserList):
+class TSList(collections.UserList):
"""A class that implements $TARGETS or $SOURCES expansions by wrapping
an executor Method. This class is used in the Executor.lvars()
to delay creation of NodeList objects until they're needed.
- Note that we subclass UserList.UserList purely so that the
+ Note that we subclass collections.UserList purely so that the
is_Sequence() function will identify an object of this class as
a list during variable expansion. We're not really using any
- UserList.UserList methods in practice.
+ collections.UserList methods in practice.
"""
def __init__(self, func):
self.func = func
diff --git a/src/engine/SCons/Node/Alias.py b/src/engine/SCons/Node/Alias.py
index 521488e..f817356 100644
--- a/src/engine/SCons/Node/Alias.py
+++ b/src/engine/SCons/Node/Alias.py
@@ -32,13 +32,13 @@ This creates a hash of global Aliases (dummy targets).
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-import UserDict
+import collections
import SCons.Errors
import SCons.Node
import SCons.Util
-class AliasNameSpace(UserDict.UserDict):
+class AliasNameSpace(collections.UserDict):
def Alias(self, name, **kw):
if isinstance(name, SCons.Node.Alias.Alias):
return name
diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py
index 8e581f1..01ceb51 100644
--- a/src/engine/SCons/Node/FSTests.py
+++ b/src/engine/SCons/Node/FSTests.py
@@ -2820,8 +2820,8 @@ class RepositoryTestCase(_tempdirTestCase):
try:
eval('test_string = u"Con\x1aTents\n"')
except SyntaxError:
- import UserString
- class FakeUnicodeString(UserString.UserString):
+ import collections
+ class FakeUnicodeString(collections.UserString):
def encode(self, encoding):
return str(self)
test_string = FakeUnicodeString("Con\x1aTents\n")
diff --git a/src/engine/SCons/Node/NodeTests.py b/src/engine/SCons/Node/NodeTests.py
index 9c5973c..8c3dbe8 100644
--- a/src/engine/SCons/Node/NodeTests.py
+++ b/src/engine/SCons/Node/NodeTests.py
@@ -24,11 +24,11 @@ from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import collections
import os
import re
import sys
import unittest
-import UserList
import SCons.Errors
import SCons.Node
@@ -1274,7 +1274,7 @@ class NodeListTestCase(unittest.TestCase):
nl = SCons.Node.NodeList([n3, n2, n1])
l = [1]
- ul = UserList.UserList([2])
+ ul = collections.UserList([2])
try:
l.extend(ul)
except TypeError:
diff --git a/src/engine/SCons/Node/__init__.py b/src/engine/SCons/Node/__init__.py
index d7846c5..472f99f 100644
--- a/src/engine/SCons/Node/__init__.py
+++ b/src/engine/SCons/Node/__init__.py
@@ -45,9 +45,9 @@ from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import collections
import copy
from itertools import chain, izip
-import UserList
from SCons.Debug import logInstanceCreation
import SCons.Executor
@@ -1255,7 +1255,7 @@ class Node:
return ( ' '*11).join(lines)
try:
- [].extend(UserList.UserList([]))
+ [].extend(collections.UserList([]))
except TypeError:
# Python 1.5.2 doesn't allow a list to be extended by list-like
# objects (such as UserList instances), so just punt and use
@@ -1263,7 +1263,7 @@ except TypeError:
def NodeList(l):
return l
else:
- class NodeList(UserList.UserList):
+ class NodeList(collections.UserList):
def __str__(self):
return str(list(map(str, self.data)))
diff --git a/src/engine/SCons/Platform/PlatformTests.py b/src/engine/SCons/Platform/PlatformTests.py
index 59d7e71..464dd02 100644
--- a/src/engine/SCons/Platform/PlatformTests.py
+++ b/src/engine/SCons/Platform/PlatformTests.py
@@ -23,14 +23,14 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import collections
import sys
import unittest
import SCons.Errors
import SCons.Platform
-import UserDict
-class Environment(UserDict.UserDict):
+class Environment(collections.UserDict):
def Detect(self, cmd):
return cmd
def AppendENVPath(self, key, value):
diff --git a/src/engine/SCons/Scanner/CTests.py b/src/engine/SCons/Scanner/CTests.py
index 2869d3b..acbfe50 100644
--- a/src/engine/SCons/Scanner/CTests.py
+++ b/src/engine/SCons/Scanner/CTests.py
@@ -23,12 +23,11 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import collections
import os
-import os.path
import sys
import TestCmd
import unittest
-import UserDict
import SCons.Node.FS
import SCons.Warnings
@@ -170,9 +169,9 @@ test.write("f5b.h", "\n")
# define some helpers:
-class DummyEnvironment(UserDict.UserDict):
+class DummyEnvironment(collections.UserDict):
def __init__(self, **kw):
- UserDict.UserDict.__init__(self)
+ collections.UserDict.__init__(self)
self.data.update(kw)
self.fs = SCons.Node.FS.FS(test.workpath(''))
diff --git a/src/engine/SCons/Scanner/LaTeXTests.py b/src/engine/SCons/Scanner/LaTeXTests.py
index 4ded0b8..afc17cf 100644
--- a/src/engine/SCons/Scanner/LaTeXTests.py
+++ b/src/engine/SCons/Scanner/LaTeXTests.py
@@ -23,10 +23,10 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-import os.path
+import collections
+import os
import sys
import unittest
-import UserDict
import TestCmd
import SCons.Node.FS
@@ -64,9 +64,9 @@ test.write('incNO.tex', "\n")
# define some helpers:
# copied from CTest.py
-class DummyEnvironment(UserDict.UserDict):
+class DummyEnvironment(collections.UserDict):
def __init__(self, **kw):
- UserDict.UserDict.__init__(self)
+ collections.UserDict.__init__(self)
self.data.update(kw)
self.fs = SCons.Node.FS.FS(test.workpath(''))
diff --git a/src/engine/SCons/Scanner/RCTests.py b/src/engine/SCons/Scanner/RCTests.py
index 60af3b4..2d97df5 100644
--- a/src/engine/SCons/Scanner/RCTests.py
+++ b/src/engine/SCons/Scanner/RCTests.py
@@ -27,11 +27,10 @@ import TestCmd
import SCons.Scanner.RC
import unittest
import sys
+import collections
import os
-import os.path
import SCons.Node.FS
import SCons.Warnings
-import UserDict
test = TestCmd.TestCmd(workdir = '')
@@ -71,9 +70,9 @@ for h in headers:
# define some helpers:
-class DummyEnvironment(UserDict.UserDict):
+class DummyEnvironment(collections.UserDict):
def __init__(self,**kw):
- UserDict.UserDict.__init__(self)
+ collections.UserDict.__init__(self)
self.data.update(kw)
self.fs = SCons.Node.FS.FS(test.workpath(''))
diff --git a/src/engine/SCons/Scanner/ScannerTests.py b/src/engine/SCons/Scanner/ScannerTests.py
index 500ce1a..cec89f4 100644
--- a/src/engine/SCons/Scanner/ScannerTests.py
+++ b/src/engine/SCons/Scanner/ScannerTests.py
@@ -24,9 +24,9 @@ from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import collections
import sys
import unittest
-import UserDict
import SCons.Scanner
@@ -34,9 +34,9 @@ class DummyFS:
def File(self, name):
return DummyNode(name)
-class DummyEnvironment(UserDict.UserDict):
+class DummyEnvironment(collections.UserDict):
def __init__(self, dict=None, **kw):
- UserDict.UserDict.__init__(self, dict)
+ collections.UserDict.__init__(self, dict)
self.data.update(kw)
self.fs = DummyFS()
def subst(self, strSubst, target=None, source=None, conv=None):
diff --git a/src/engine/SCons/Script/SConscript.py b/src/engine/SCons/Script/SConscript.py
index c55d220..4e43382 100644
--- a/src/engine/SCons/Script/SConscript.py
+++ b/src/engine/SCons/Script/SConscript.py
@@ -46,12 +46,12 @@ import SCons.Script.Main
import SCons.Tool
import SCons.Util
+import collections
import os
import os.path
import re
import sys
import traceback
-import UserList
# The following variables used to live in this module. Some
# SConscript files out there may have referred to them directly as
diff --git a/src/engine/SCons/Script/__init__.py b/src/engine/SCons/Script/__init__.py
index 7763210..465508c 100644
--- a/src/engine/SCons/Script/__init__.py
+++ b/src/engine/SCons/Script/__init__.py
@@ -39,9 +39,9 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import time
start_time = time.time()
+import collections
import os
import sys
-import UserList
# Special chicken-and-egg handling of the "--debug=memoizer" flag:
#
@@ -183,7 +183,7 @@ CScan = SCons.Defaults.CScan
DefaultEnvironment = SCons.Defaults.DefaultEnvironment
# Other variables we provide.
-class TargetList(UserList.UserList):
+class TargetList(collections.UserList):
def _do_nothing(self, *args, **kw):
pass
def _add_Default(self, list):
diff --git a/src/engine/SCons/Subst.py b/src/engine/SCons/Subst.py
index 9888e8d..a0a4859 100644
--- a/src/engine/SCons/Subst.py
+++ b/src/engine/SCons/Subst.py
@@ -30,9 +30,8 @@ from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import collections
import re
-import UserList
-import UserString
import SCons.Errors
@@ -120,7 +119,7 @@ def quote_spaces(arg):
else:
return str(arg)
-class CmdStringHolder(UserString.UserString):
+class CmdStringHolder(collections.UserString):
"""This is a special class used to hold strings generated by
scons_subst() and scons_subst_list(). It defines a special method
escape(). When passed a function with an escape algorithm for a
@@ -128,7 +127,7 @@ class CmdStringHolder(UserString.UserString):
proper escape sequences inserted.
"""
def __init__(self, cmd, literal=None):
- UserString.UserString.__init__(self, cmd)
+ collections.UserString.__init__(self, cmd)
self.literal = literal
def is_literal(self):
@@ -195,15 +194,15 @@ class NLWrapper:
_create_nodelist = _gen_nodelist
-class Targets_or_Sources(UserList.UserList):
+class Targets_or_Sources(collections.UserList):
"""A class that implements $TARGETS or $SOURCES expansions by in turn
wrapping a NLWrapper. This class handles the different methods used
to access the list, calling the NLWrapper to create proxies on demand.
- Note that we subclass UserList.UserList purely so that the
+ Note that we subclass collections.UserList purely so that the
is_Sequence() function will identify an object of this class as
a list during variable expansion. We're not really using any
- UserList.UserList methods in practice.
+ collections.UserList methods in practice.
"""
def __init__(self, nl):
self.nl = nl
@@ -594,7 +593,7 @@ def scons_subst_list(strSubst, env, mode=SUBST_RAW, target=None, source=None, gv
# Subst_List_Strings[strSubst] = 1
# import SCons.Debug
# SCons.Debug.caller_trace(1)
- class ListSubber(UserList.UserList):
+ class ListSubber(collections.UserList):
"""A class to construct the results of a scons_subst_list() call.
Like StringSubber, this class binds a specific construction
@@ -611,7 +610,7 @@ def scons_subst_list(strSubst, env, mode=SUBST_RAW, target=None, source=None, gv
internally.
"""
def __init__(self, env, mode, conv, gvars):
- UserList.UserList.__init__(self, [])
+ collections.UserList.__init__(self, [])
self.env = env
self.mode = mode
self.conv = conv
@@ -734,7 +733,7 @@ def scons_subst_list(strSubst, env, mode=SUBST_RAW, target=None, source=None, gv
"""Arrange for the next word to start a new line. This
is like starting a new word, except that we have to append
another line to the result."""
- UserList.UserList.append(self, [])
+ collections.UserList.append(self, [])
self.next_word()
def this_word(self):
diff --git a/src/engine/SCons/SubstTests.py b/src/engine/SCons/SubstTests.py
index 2eb91ca..b423fa4 100644
--- a/src/engine/SCons/SubstTests.py
+++ b/src/engine/SCons/SubstTests.py
@@ -31,7 +31,7 @@ import StringIO
import sys
import unittest
-from UserDict import UserDict
+from collections import UserDict
import SCons.Errors
@@ -208,7 +208,7 @@ class SubstTestCase(unittest.TestCase):
'T' : ('x', 'y'),
'CS' : cs,
'CL' : cl,
- 'US' : UserString.UserString('us'),
+ 'US' : collections.UserString('us'),
# Test function calls within ${}.
'FUNCCALL' : '${FUNC1("$AAA $FUNC2 $BBB")}',
@@ -366,9 +366,9 @@ class scons_subst_TestCase(SubstTestCase):
'$CL', 'cl',
# Various uses of UserString.
- UserString.UserString('x'), 'x',
- UserString.UserString('$X'), 'x',
- UserString.UserString('$US'), 'us',
+ collections.UserString('x'), 'x',
+ collections.UserString('$X'), 'x',
+ collections.UserString('$US'), 'us',
'$US', 'us',
# Test function calls within ${}.
@@ -758,12 +758,12 @@ class scons_subst_list_TestCase(SubstTestCase):
['$CL'], [['cl']],
# Various uses of UserString.
- UserString.UserString('x'), [['x']],
- [UserString.UserString('x')], [['x']],
- UserString.UserString('$X'), [['x']],
- [UserString.UserString('$X')], [['x']],
- UserString.UserString('$US'), [['us']],
- [UserString.UserString('$US')], [['us']],
+ collections.UserString('x'), [['x']],
+ [collections.UserString('x')], [['x']],
+ collections.UserString('$X'), [['x']],
+ [collections.UserString('$X')], [['x']],
+ collections.UserString('$US'), [['us']],
+ [collections.UserString('$US')], [['us']],
'$US', [['us']],
['$US'], [['us']],
diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py
index 4ada273..e88a90b 100644
--- a/src/engine/SCons/Util.py
+++ b/src/engine/SCons/Util.py
@@ -36,9 +36,7 @@ import re
import sys
import types
-from UserDict import UserDict
-from UserList import UserList
-from UserString import UserString
+from collections import UserDict, UserList, UserString
# Don't "from types import ..." these because we need to get at the
# types module later to look for UnicodeType.
diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py
index fd7862c..e044065 100644
--- a/src/engine/SCons/UtilTests.py
+++ b/src/engine/SCons/UtilTests.py
@@ -25,13 +25,12 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import SCons.compat
+import collections
import io
import os
-import os.path
import sys
import unittest
-from UserDict import UserDict
import TestCmd
@@ -208,7 +207,7 @@ class UtilTestCase(unittest.TestCase):
def test_is_Dict(self):
assert is_Dict({})
- assert is_Dict(UserDict())
+ assert is_Dict(collections.UserDict())
try:
class mydict(dict):
pass
@@ -225,7 +224,7 @@ class UtilTestCase(unittest.TestCase):
def test_is_List(self):
assert is_List([])
import UserList
- assert is_List(UserList.UserList())
+ assert is_List(collections.UserList())
try:
class mylist(list):
pass
@@ -248,7 +247,7 @@ class UtilTestCase(unittest.TestCase):
except:
pass
else:
- assert is_String(UserString.UserString(''))
+ assert is_String(collections.UserString(''))
try:
class mystr(str):
pass
@@ -284,18 +283,18 @@ class UtilTestCase(unittest.TestCase):
try:
import UserString
- s1=UserString.UserString('blah')
+ s1=collections.UserString('blah')
assert to_String(s1) == s1, s1
assert to_String(s1) == 'blah', s1
- class Derived(UserString.UserString):
+ class Derived(collections.UserString):
pass
s2 = Derived('foo')
assert to_String(s2) == s2, s2
assert to_String(s2) == 'foo', s2
if HasUnicode:
- s3=UserString.UserString(unicode('bar'))
+ s3=collections.UserString(unicode('bar'))
assert to_String(s3) == s3, s3
assert to_String(s3) == unicode('bar'), s3
assert isinstance(to_String(s3), unicode), \
@@ -619,7 +618,7 @@ class UtilTestCase(unittest.TestCase):
s['c'] = 'CCC'
assert s['c'] == 'CCC', s['c']
- class DummyEnv(UserDict):
+ class DummyEnv(collections.UserDict):
def subst(self, key):
if key[0] == '$':
return self[key[1:]]
diff --git a/src/engine/SCons/Variables/ListVariable.py b/src/engine/SCons/Variables/ListVariable.py
index 5980f33..6cab091 100644
--- a/src/engine/SCons/Variables/ListVariable.py
+++ b/src/engine/SCons/Variables/ListVariable.py
@@ -55,14 +55,14 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
__all__ = ['ListVariable',]
-import UserList
+import collections
import SCons.Util
-class _ListVariable(UserList.UserList):
+class _ListVariable(collections.UserList):
def __init__(self, initlist=[], allowedElems=[]):
- UserList.UserList.__init__(self, [_f for _f in initlist if _f])
+ collections.UserList.__init__(self, [_f for _f in initlist if _f])
self.allowedElems = sorted(allowedElems)
def __cmp__(self, other):
diff --git a/src/engine/SCons/compat/__init__.py b/src/engine/SCons/compat/__init__.py
index 0b70c5d..7e93a71 100644
--- a/src/engine/SCons/compat/__init__.py
+++ b/src/engine/SCons/compat/__init__.py
@@ -96,6 +96,28 @@ except NameError:
import __builtin__, sets
__builtin__.set = sets.Set
+
+import collections
+try:
+ collections.UserDict
+except AttributeError:
+ import UserDict
+ collections.UserDict = UserDict.UserDict
+ del UserDict
+try:
+ collections.UserList
+except AttributeError:
+ import UserList
+ collections.UserList = UserList.UserList
+ del UserList
+try:
+ collections.UserString
+except AttributeError:
+ import UserString
+ collections.UserString = UserString.UserString
+ del UserString
+
+
import fnmatch
try:
fnmatch.filter
@@ -267,11 +289,6 @@ except AttributeError:
# Wrapping sys in () is silly, but protects it from 2to3 renames fixer
sys.maxsize = (sys).maxint
-try:
- import UserString
-except ImportError:
- # Pre-1.6 Python has no UserString module.
- import_as('_scons_UserString', 'UserString')
import tempfile
try:
diff --git a/src/engine/SCons/compat/_scons_UserString.py b/src/engine/SCons/compat/_scons_UserString.py
deleted file mode 100644
index 59be10b..0000000
--- a/src/engine/SCons/compat/_scons_UserString.py
+++ /dev/null
@@ -1,94 +0,0 @@
-#
-# __COPYRIGHT__
-#
-# Permission is hereby granted, free of charge, to any person obtaining
-# a copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sublicense, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice shall be included
-# in all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
-# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
-# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-
-__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-
-__doc__ = """
-A user-defined wrapper around string objects
-
-This class is "borrowed" from the Python 2.2 UserString and modified
-slightly for use with SCons. It is *NOT* guaranteed to be fully compliant
-with the standard UserString class from all later versions of Python.
-In particular, it does not necessarily contain all of the methods found
-in later versions.
-"""
-
-try: unicode
-except NameError:
- def is_String(obj):
- return isinstance(obj, str)
-else:
- def is_String(obj):
- return type(obj) in (str, unicode)
-
-class UserString:
- def __init__(self, seq):
- if is_String(seq):
- self.data = seq
- elif isinstance(seq, UserString):
- self.data = seq.data[:]
- else:
- self.data = str(seq)
- def __str__(self): return str(self.data)
- def __repr__(self): return repr(self.data)
- def __int__(self): return int(self.data)
- def __long__(self): return long(self.data)
- def __float__(self): return float(self.data)
- def __complex__(self): return complex(self.data)
- def __hash__(self): return hash(self.data)
-
- def __cmp__(self, str):
- if isinstance(string, UserString):
- return cmp(self.data, str.data)
- else:
- return cmp(self.data, string)
- def __contains__(self, char):
- return char in self.data
-
- def __len__(self): return len(self.data)
- def __getitem__(self, index): return self.__class__(self.data[index])
- def __getslice__(self, start, end):
- start = max(start, 0); end = max(end, 0)
- return self.__class__(self.data[start:end])
-
- def __add__(self, other):
- if isinstance(other, UserString):
- return self.__class__(self.data + other.data)
- elif is_String(other):
- return self.__class__(self.data + other)
- else:
- return self.__class__(self.data + str(other))
- def __radd__(self, other):
- if is_String(other):
- return self.__class__(other + self.data)
- else:
- return self.__class__(str(other) + self.data)
- def __mul__(self, n):
- return self.__class__(self.data*n)
- __rmul__ = __mul__
-
-# Local Variables:
-# tab-width:4
-# indent-tabs-mode:nil
-# End:
-# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/test/SConscript/SConscript.py b/test/SConscript/SConscript.py
index 5bd49f3..177b5df 100644
--- a/test/SConscript/SConscript.py
+++ b/test/SConscript/SConscript.py
@@ -71,10 +71,13 @@ assert foo == "subdir/SConscript foo"
SConscript('SConscript5')
-import UserList
+try:
+ from io import UserList
+except ImportError:
+ from UserList import UserList
x7 = "SConstruct x7"
x8 = "SConstruct x8"
-x9 = SConscript('SConscript6', UserList.UserList(["x7", "x8"]))
+x9 = SConscript('SConscript6', UserList(["x7", "x8"]))
assert x9 == "SConscript6 x9", x9
SConscript('SConscript7')
diff --git a/test/subclassing.py b/test/subclassing.py
index 655de51..fc00349 100644
--- a/test/subclassing.py
+++ b/test/subclassing.py
@@ -51,7 +51,10 @@ class my_Environment(Environment):
env = my_Environment()
env.Command('f0.out', 'f0.in', copy_action)
-from UserString import UserString
+try:
+ from io import UserString
+except ImportError:
+ from UserString import UserString
try:
class mystr(str):
pass