X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=tools%2Fscons-1.2.0%2Fengine%2FSCons%2Fcompat%2F_scons_UserString.py;fp=tools%2Fscons-1.2.0%2Fengine%2FSCons%2Fcompat%2F_scons_UserString.py;h=cde813d9d3e85772a016437a3d9c09ff8c7ce1b1;hb=84bd150c667e693c7ba6c31819b3f155f53e514a;hp=0000000000000000000000000000000000000000;hpb=4b94735961fc9474411a1ca200c3a00f744ec3f1;p=senf.git diff --git a/tools/scons-1.2.0/engine/SCons/compat/_scons_UserString.py b/tools/scons-1.2.0/engine/SCons/compat/_scons_UserString.py new file mode 100644 index 0000000..cde813d --- /dev/null +++ b/tools/scons-1.2.0/engine/SCons/compat/_scons_UserString.py @@ -0,0 +1,92 @@ +# +# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundation +# +# 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__ = "src/engine/SCons/compat/_scons_UserString.py 3842 2008/12/20 22:59:52 scons" + +__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. +""" + +import types + +StringType = types.StringType + +if hasattr(types, 'UnicodeType'): + UnicodeType = types.UnicodeType + def is_String(obj): + return type(obj) in (StringType, UnicodeType) +else: + def is_String(obj): + return type(obj) is StringType + +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, string): + if isinstance(string, UserString): + return cmp(self.data, string.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__