diff options
author | Greg Noel <GregNoel@tigris.org> | 2010-06-07 01:03:58 (GMT) |
---|---|---|
committer | Greg Noel <GregNoel@tigris.org> | 2010-06-07 01:03:58 (GMT) |
commit | 4342bb15a6592e9a29716523902d717aaa841ccc (patch) | |
tree | 18ab3ca340a61eae1a313c1f6c6ab91ecde56412 /src/engine/SCons | |
parent | a50e413e5dd97a4bb014fcdfdec6050f03de699c (diff) | |
download | SCons-4342bb15a6592e9a29716523902d717aaa841ccc.zip SCons-4342bb15a6592e9a29716523902d717aaa841ccc.tar.gz SCons-4342bb15a6592e9a29716523902d717aaa841ccc.tar.bz2 |
For some reason, using the `imp` module to do imports doesn't do quite the
same thing as using the 'import' statement, even though the documentation
clearly says that the 'import' statement uses the 'imp' module under the
covers. I have no clue why, but there were some cases where it made a
difference. The code was changed to using 'imp' to prevent the fixers
from trying to convert the old names to the new names, so this changeset
uses a different technique to hide the old names.
Diffstat (limited to 'src/engine/SCons')
-rw-r--r-- | src/engine/SCons/Util.py | 27 | ||||
-rw-r--r-- | src/engine/SCons/UtilTests.py | 1 | ||||
-rw-r--r-- | src/engine/SCons/compat/__init__.py | 13 | ||||
-rw-r--r-- | src/engine/SCons/compat/_scons_collections.py | 19 |
4 files changed, 22 insertions, 38 deletions
diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index 738f2b5..cc6c95e 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -1,9 +1,7 @@ """SCons.Util Various utility functions go here. - """ - # # __COPYRIGHT__ # @@ -25,27 +23,22 @@ Various utility functions go here. # 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__" -import SCons.compat - -import copy import os -import re import sys +import copy +import re import types 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. -DictType = dict InstanceType = types.InstanceType -ListType = list -StringType = str -TupleType = tuple +MethodType = types.MethodType +FunctionType = types.FunctionType try: unicode except NameError: UnicodeType = None else: UnicodeType = unicode @@ -1377,20 +1370,20 @@ def AddMethod(obj, function, name=None): if hasattr(obj, '__class__') and obj.__class__ is not type: # "obj" is an instance, so it gets a bound method. - setattr(obj, name, types.MethodType(function, obj, obj.__class__)) + setattr(obj, name, MethodType(function, obj, obj.__class__)) else: # "obj" is a class, so it gets an unbound method. - setattr(obj, name, types.MethodType(function, None, obj)) + setattr(obj, name, MethodType(function, None, obj)) def RenameFunction(function, name): """ Returns a function identical to the specified function, but with the specified name. """ - return types.FunctionType(function.func_code, - function.func_globals, - name, - function.func_defaults) + return FunctionType(function.func_code, + function.func_globals, + name, + function.func_defaults) md5 = False diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py index 2a89509..3f65456 100644 --- a/src/engine/SCons/UtilTests.py +++ b/src/engine/SCons/UtilTests.py @@ -207,6 +207,7 @@ class UtilTestCase(unittest.TestCase): def test_is_Dict(self): assert is_Dict({}) assert is_Dict(UserDict()) + assert is_Dict(os.environ) try: class mydict(dict): pass diff --git a/src/engine/SCons/compat/__init__.py b/src/engine/SCons/compat/__init__.py index bfa8384..c870fbc 100644 --- a/src/engine/SCons/compat/__init__.py +++ b/src/engine/SCons/compat/__init__.py @@ -121,21 +121,20 @@ else: try: collections.UserDict except AttributeError: - _UserDict = imp.load_module('UserDict', *imp.find_module('UserDict')) - collections.UserDict = _UserDict.UserDict + exec('from UserDict import UserDict as _UserDict') + collections.UserDict = _UserDict del _UserDict try: collections.UserList except AttributeError: - _UserList = imp.load_module('UserList', *imp.find_module('UserList')) - collections.UserList = _UserList.UserList + exec('from UserList import UserList as _UserList') + collections.UserList = _UserList del _UserList try: collections.UserString except AttributeError: - _UserString = imp.load_module('UserString', - *imp.find_module('UserString')) - collections.UserString = _UserString.UserString + exec('from UserString import UserString as _UserString') + collections.UserString = _UserString del _UserString diff --git a/src/engine/SCons/compat/_scons_collections.py b/src/engine/SCons/compat/_scons_collections.py index 089f0aa..1591b2e 100644 --- a/src/engine/SCons/compat/_scons_collections.py +++ b/src/engine/SCons/compat/_scons_collections.py @@ -32,20 +32,11 @@ our purposes. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" -# Use the "imp" module to protect the imports below from fixers. -import imp - -_UserDict = imp.load_module('UserDict', *imp.find_module('UserDict')) -_UserList = imp.load_module('UserList', *imp.find_module('UserList')) -_UserString = imp.load_module('UserString', *imp.find_module('UserString')) - -UserDict = _UserDict.UserDict -UserList = _UserList.UserList -UserString = _UserString.UserString - -del _UserDict -del _UserList -del _UserString +# Use exec to hide old names from fixers. +exec("""if True: + from UserDict import UserDict + from UserList import UserList + from UserString import UserString""") # Local Variables: # tab-width:4 |