From 85630852a80bc54a47b5ed06664414fad8711898 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Sun, 11 Apr 2010 14:09:56 +0000 Subject: [PATCH] Add compat "collections" module for pre-2.4 Python verseions. For now. git-svn-id: http://scons.tigris.org/svn/scons/trunk@4779 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/engine/MANIFEST.in | 1 + src/engine/SCons/Node/NodeTests.py | 2 + src/engine/SCons/Platform/PlatformTests.py | 2 + src/engine/SCons/Scanner/CTests.py | 2 + src/engine/SCons/Scanner/LaTeXTests.py | 2 + src/engine/SCons/Scanner/ScannerTests.py | 2 + src/engine/SCons/compat/__init__.py | 41 ++++++++++-------- src/engine/SCons/compat/_scons_collections.py | 43 +++++++++++++++++++ 8 files changed, 77 insertions(+), 18 deletions(-) create mode 100644 src/engine/SCons/compat/_scons_collections.py diff --git a/src/engine/MANIFEST.in b/src/engine/MANIFEST.in index ec5e32c0..576c82cd 100644 --- a/src/engine/MANIFEST.in +++ b/src/engine/MANIFEST.in @@ -2,6 +2,7 @@ SCons/__init__.py SCons/Action.py SCons/Builder.py SCons/compat/__init__.py +SCons/compat/_scons_collections.py SCons/compat/_scons_hashlib.py SCons/compat/_scons_io.py SCons/compat/_scons_itertools.py diff --git a/src/engine/SCons/Node/NodeTests.py b/src/engine/SCons/Node/NodeTests.py index 8c3dbe85..5f1b4b09 100644 --- a/src/engine/SCons/Node/NodeTests.py +++ b/src/engine/SCons/Node/NodeTests.py @@ -24,6 +24,8 @@ from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" +import SCons.compat + import collections import os import re diff --git a/src/engine/SCons/Platform/PlatformTests.py b/src/engine/SCons/Platform/PlatformTests.py index 464dd023..6841272d 100644 --- a/src/engine/SCons/Platform/PlatformTests.py +++ b/src/engine/SCons/Platform/PlatformTests.py @@ -23,6 +23,8 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" +import SCons.compat + import collections import sys import unittest diff --git a/src/engine/SCons/Scanner/CTests.py b/src/engine/SCons/Scanner/CTests.py index acbfe503..34e3163d 100644 --- a/src/engine/SCons/Scanner/CTests.py +++ b/src/engine/SCons/Scanner/CTests.py @@ -23,6 +23,8 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" +import SCons.compat + import collections import os import sys diff --git a/src/engine/SCons/Scanner/LaTeXTests.py b/src/engine/SCons/Scanner/LaTeXTests.py index afc17cff..8cea63fa 100644 --- a/src/engine/SCons/Scanner/LaTeXTests.py +++ b/src/engine/SCons/Scanner/LaTeXTests.py @@ -23,6 +23,8 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" +import SCons.compat + import collections import os import sys diff --git a/src/engine/SCons/Scanner/ScannerTests.py b/src/engine/SCons/Scanner/ScannerTests.py index cec89f48..922c2213 100644 --- a/src/engine/SCons/Scanner/ScannerTests.py +++ b/src/engine/SCons/Scanner/ScannerTests.py @@ -24,6 +24,8 @@ from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" +import SCons.compat + import collections import sys import unittest diff --git a/src/engine/SCons/compat/__init__.py b/src/engine/SCons/compat/__init__.py index f220c324..cc14b92a 100644 --- a/src/engine/SCons/compat/__init__.py +++ b/src/engine/SCons/compat/__init__.py @@ -97,25 +97,30 @@ except NameError: __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 collections +except ImportError: + # Pre-2.4 Python has no collections module. + import_as('_scons_collections', 'collections') +else: + 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 diff --git a/src/engine/SCons/compat/_scons_collections.py b/src/engine/SCons/compat/_scons_collections.py new file mode 100644 index 00000000..80832b7d --- /dev/null +++ b/src/engine/SCons/compat/_scons_collections.py @@ -0,0 +1,43 @@ +# +# __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. +# + +__doc__ = """ +collections compatibility module for older (pre-2.4) Python versions + +This does not not NOT (repeat, *NOT*) provide complete collections +functionality. It only wraps the portions of collections functionality +used by SCons, in an interface that looks enough like collections for +our purposes. +""" + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +from UserDict import UserDict +from UserList import UserList +from UserString import UserString + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: -- 2.26.2