1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 __doc__ = """
30 Compatibility idioms for __builtin__ names
31
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.
35
36 This module checks for the following __builtin__ names:
37
38 all()
39 any()
40 bool()
41 dict()
42 True
43 False
44 zip()
45
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.)
52
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.
56 """
57
58 __revision__ = "src/engine/SCons/compat/builtins.py 5110 2010/07/25 16:14:38 bdeegan"
59
60 import __builtin__
61
62 try:
63 all
64 except NameError:
65
67 """
68 Returns True if all elements of the iterable are true.
69 """
70 for element in iterable:
71 if not element:
72 return False
73 return True
74 __builtin__.all = all
75 all = all
76
77 try:
78 any
79 except NameError:
80
82 """
83 Returns True if any element of the iterable is true.
84 """
85 for element in iterable:
86 if element:
87 return True
88 return False
89 __builtin__.any = any
90 any = any
91
92 try:
93 bool
94 except NameError:
95
97 """Demote a value to 0 or 1, depending on its truth value.
98
99 This is not to be confused with types.BooleanType, which is
100 way too hard to duplicate in early Python versions to be
101 worth the trouble.
102 """
103 return not not value
104 __builtin__.bool = bool
105 bool = bool
106
107 try:
108 dict
109 except NameError:
110
111 - def dict(seq=[], **kwargs):
112 """
113 New dictionary initialization.
114 """
115 d = {}
116 for k, v in seq:
117 d[k] = v
118 d.update(kwargs)
119 return d
120 __builtin__.dict = dict
121
122 try:
123 False
124 except NameError:
125
126 __builtin__.False = not 1
127
128 False = False
129
130 try:
131 True
132 except NameError:
133
134 __builtin__.True = not 0
135
136 True = True
137
138 try:
139 file
140 except NameError:
141
142 __builtin__.file = open
143
144
145 try:
146 zip
147 except NameError:
148
150 """
151 Emulates the behavior we need from the built-in zip() function
152 added in Python 2.2.
153
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
157 argument sequence.
158 """
159 result = []
160 for i in xrange(min(map(len, lists))):
161 result.append(tuple(map(lambda l, i=i: l[i], lists)))
162 return result
163 __builtin__.zip = zip
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188