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 builtins names
31
32 This module adds names to the builtins 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 builtins names:
37
38 all()
39 any()
40 memoryview()
41
42 Implementations of functions are *NOT* guaranteed to be fully compliant
43 with these functions in later versions of Python. We are only concerned
44 with adding functionality that we actually use in SCons, so be wary
45 if you lift this code for other uses. (That said, making these more
46 nearly the same as later, official versions is still a desirable goal,
47 we just don't need to be obsessive about it.)
48
49 If you're looking at this with pydoc and various names don't show up in
50 the FUNCTIONS or DATA output, that means those names are already built in
51 to this version of Python and we don't need to add them from this module.
52 """
53
54 __revision__ = "src/engine/SCons/compat/_scons_builtins.py 2013/03/03 09:48:35 garyo"
55
56 import builtins
57
58 try:
59 all
60 except NameError:
61
63 """
64 Returns True if all elements of the iterable are true.
65 """
66 for element in iterable:
67 if not element:
68 return False
69 return True
70 builtins.all = all
71 all = all
72
73 try:
74 any
75 except NameError:
76
78 """
79 Returns True if any element of the iterable is true.
80 """
81 for element in iterable:
82 if element:
83 return True
84 return False
85 builtins.any = any
86 any = any
87
88 try:
89 memoryview
90 except NameError:
91
94
95 self.obj = (buffer)(obj)
97 if isinstance(indx, slice):
98 return self.obj[indx.start:indx.stop]
99 else:
100 return self.obj[indx]
101 builtins.memoryview = memoryview
102
103
104
105
106
107
108