2 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundation
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:
46 Implementations of functions are *NOT* guaranteed to be fully compliant
47 with these functions in later versions of Python. We are only concerned
48 with adding functionality that we actually use in SCons, so be wary
49 if you lift this code for other uses. (That said, making these more
50 nearly the same as later, official versions is still a desirable goal,
51 we just don't need to be obsessive about it.)
53 If you're looking at this with pydoc and various names don't show up in
54 the FUNCTIONS or DATA output, that means those names are already built in
55 to this version of Python and we don't need to add them from this module.
58 __revision__ = "src/engine/SCons/compat/builtins.py 3842 2008/12/20 22:59:52 scons"
65 # Pre-2.5 Python has no all() function.
68 Returns True if all elements of the iterable are true.
70 for element in iterable:
80 # Pre-2.5 Python has no any() function.
83 Returns True if any element of the iterable is true.
85 for element in iterable:
95 # Pre-2.2 Python has no bool() function.
97 """Demote a value to 0 or 1, depending on its truth value.
99 This is not to be confused with types.BooleanType, which is
100 way too hard to duplicate in early Python versions to be
104 __builtin__.bool = bool
110 # Pre-2.2 Python has no dict() keyword.
111 def dict(seq=[], **kwargs):
113 New dictionary initialization.
120 __builtin__.dict = dict
125 # Pre-2.2 Python has no False keyword.
126 __builtin__.False = not 1
127 # Assign to False in this module namespace so it shows up in pydoc output.
133 # Pre-2.2 Python has no True keyword.
134 __builtin__.True = not 0
135 # Assign to True in this module namespace so it shows up in pydoc output.
141 # Pre-2.2 Python has no file() function.
142 __builtin__.file = open
148 # Pre-2.2 Python has no zip() function.
151 Emulates the behavior we need from the built-in zip() function
154 Returns a list of tuples, where each tuple contains the i-th
155 element rom each of the argument sequences. The returned
156 list is truncated in length to the length of the shortest
160 for i in xrange(min(map(len, lists))):
161 result.append(tuple(map(lambda l, i=i: l[i], lists)))
163 __builtin__.zip = zip
167 #if sys.version_info[:3] in ((2, 2, 0), (2, 2, 1)):
168 # def lstrip(s, c=string.whitespace):
169 # while s and s[0] in c:
172 # def rstrip(s, c=string.whitespace):
173 # while s and s[-1] in c:
176 # def strip(s, c=string.whitespace, l=lstrip, r=rstrip):
177 # return l(r(s, c), c)
179 # object.__setattr__(str, 'lstrip', lstrip)
180 # object.__setattr__(str, 'rstrip', rstrip)
181 # object.__setattr__(str, 'strip', strip)