4 # Permission is hereby granted, free of charge, to any person obtaining
5 # a copy of this software and associated documentation files (the
6 # "Software"), to deal in the Software without restriction, including
7 # without limitation the rights to use, copy, modify, merge, publish,
8 # distribute, sublicense, and/or sell copies of the Software, and to
9 # permit persons to whom the Software is furnished to do so, subject to
10 # the following conditions:
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
16 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
17 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 # Portions of the following are derived from the compat.py file in
25 # Twisted, under the following copyright:
27 # Copyright (c) 2001-2004 Twisted Matrix Laboratories
30 Compatibility idioms for __builtin__ names
32 This module adds names to the __builtin__ module for things that we want
33 to use in SCons but which don't show up until later Python versions than
34 the earliest ones we support.
36 This module checks for the following __builtin__ names:
44 Implementations of functions are *NOT* guaranteed to be fully compliant
45 with these functions in later versions of Python. We are only concerned
46 with adding functionality that we actually use in SCons, so be wary
47 if you lift this code for other uses. (That said, making these more
48 nearly the same as later, official versions is still a desirable goal,
49 we just don't need to be obsessive about it.)
51 If you're looking at this with pydoc and various names don't show up in
52 the FUNCTIONS or DATA output, that means those names are already built in
53 to this version of Python and we don't need to add them from this module.
56 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
63 # Pre-2.2 Python has no bool() function.
65 """Demote a value to 0 or 1, depending on its truth value.
67 This is not to be confused with types.BooleanType, which is
68 way too hard to duplicate in early Python versions to be
72 __builtin__.bool = bool
78 # Pre-2.2 Python has no dict() keyword.
79 def dict(seq=[], **kwargs):
81 New dictionary initialization.
88 __builtin__.dict = dict
93 # Pre-2.2 Python has no False keyword.
94 __builtin__.False = not 1
95 # Assign to False in this module namespace so it shows up in pydoc output.
101 # Pre-2.2 Python has no True keyword.
102 __builtin__.True = not 0
103 # Assign to True in this module namespace so it shows up in pydoc output.
110 # Pre-2.2 Python has no zip() function.
113 Emulates the behavior we need from the built-in zip() function
116 Returns a list of tuples, where each tuple contains the i-th
117 element rom each of the argument sequences. The returned
118 list is truncated in length to the length of the shortest
122 for i in xrange(min(map(len, lists))):
123 result.append(tuple(map(lambda l, i=i: l[i], lists)))
125 __builtin__.zip = zip
129 #if sys.version_info[:3] in ((2, 2, 0), (2, 2, 1)):
130 # def lstrip(s, c=string.whitespace):
131 # while s and s[0] in c:
134 # def rstrip(s, c=string.whitespace):
135 # while s and s[-1] in c:
138 # def strip(s, c=string.whitespace, l=lstrip, r=rstrip):
139 # return l(r(s, c), c)
141 # object.__setattr__(str, 'lstrip', lstrip)
142 # object.__setattr__(str, 'rstrip', rstrip)
143 # object.__setattr__(str, 'strip', strip)