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:
47 Implementations of functions are *NOT* guaranteed to be fully compliant
48 with these functions in later versions of Python. We are only concerned
49 with adding functionality that we actually use in SCons, so be wary
50 if you lift this code for other uses. (That said, making these more
51 nearly the same as later, official versions is still a desirable goal,
52 we just don't need to be obsessive about it.)
54 If you're looking at this with pydoc and various names don't show up in
55 the FUNCTIONS or DATA output, that means those names are already built in
56 to this version of Python and we don't need to add them from this module.
59 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
66 # Pre-2.5 Python has no all() function.
69 Returns True if all elements of the iterable are true.
71 for element in iterable:
81 # Pre-2.5 Python has no any() function.
84 Returns True if any element of the iterable is true.
86 for element in iterable:
96 # Pre-2.2 Python has no bool() function.
98 """Demote a value to 0 or 1, depending on its truth value.
100 This is not to be confused with types.BooleanType, which is
101 way too hard to duplicate in early Python versions to be
105 __builtin__.bool = bool
111 # Pre-2.2 Python has no dict() keyword.
112 def dict(seq=[], **kwargs):
114 New dictionary initialization.
121 __builtin__.dict = dict
126 # Pre-2.2 Python has no False keyword.
127 __builtin__.False = not 1
128 # Assign to False in this module namespace so it shows up in pydoc output.
134 # Pre-2.2 Python has no True keyword.
135 __builtin__.True = not 0
136 # Assign to True in this module namespace so it shows up in pydoc output.
142 # Pre-2.2 Python has no file() function.
143 __builtin__.file = open
148 # Pre-2.4 Python has no sorted() function.
150 # The pre-2.4 Python list.sort() method does not support
151 # list.sort(key=) nor list.sort(reverse=) keyword arguments, so
152 # we must implement the functionality of those keyword arguments
153 # by hand instead of passing them to list.sort().
154 def sorted(iterable, cmp=None, key=None, reverse=False):
156 result = [(key(x), x) for x in iterable]
160 # Pre-2.3 Python does not support list.sort(None).
165 result = [t1 for t0,t1 in result]
169 __builtin__.sorted = sorted
175 # Pre-2.2 Python has no zip() function.
178 Emulates the behavior we need from the built-in zip() function
181 Returns a list of tuples, where each tuple contains the i-th
182 element rom each of the argument sequences. The returned
183 list is truncated in length to the length of the shortest
187 for i in xrange(min(map(len, lists))):
188 result.append(tuple(map(lambda l: l[i], lists)))
190 __builtin__.zip = zip
194 #if sys.version_info[:3] in ((2, 2, 0), (2, 2, 1)):
195 # def lstrip(s, c=string.whitespace):
196 # while s and s[0] in c:
199 # def rstrip(s, c=string.whitespace):
200 # while s and s[-1] in c:
203 # def strip(s, c=string.whitespace, l=lstrip, r=rstrip):
204 # return l(r(s, c), c)
206 # object.__setattr__(str, 'lstrip', lstrip)
207 # object.__setattr__(str, 'rstrip', rstrip)
208 # object.__setattr__(str, 'strip', strip)
212 # indent-tabs-mode:nil
214 # vim: set expandtab tabstop=4 shiftwidth=4: