diff options
| author | Steven Knight <knight@baldmt.com> | 2010-04-07 15:29:39 (GMT) |
|---|---|---|
| committer | Steven Knight <knight@baldmt.com> | 2010-04-07 15:29:39 (GMT) |
| commit | ca29ee5e30d4d4ad60d51f95e4ac61eee7e5cd42 (patch) | |
| tree | eb60dd8251a7fd064aa255309df2056dbf49a258 /src/engine/SCons/compat | |
| parent | 32d7c315d62846ea8febadcbb2c60cf9e3382cbf (diff) | |
| download | SCons-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.
Diffstat (limited to 'src/engine/SCons/compat')
| -rw-r--r-- | src/engine/SCons/compat/__init__.py | 27 | ||||
| -rw-r--r-- | src/engine/SCons/compat/_scons_UserString.py | 94 |
2 files changed, 22 insertions, 99 deletions
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: |
