Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: scons-2.0.1/engine/SCons/compat/_scons_builtins.py

Issue 6711079: Added an unmodified copy of SCons to third_party. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/third_party/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 #
2 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The S Cons Foundation
3 #
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:
11 #
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
14 #
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.
22 #
23
24 # Portions of the following are derived from the compat.py file in
25 # Twisted, under the following copyright:
26 #
27 # Copyright (c) 2001-2004 Twisted Matrix Laboratories
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 sorted()
41 memoryview()
42
43 Implementations of functions are *NOT* guaranteed to be fully compliant
44 with these functions in later versions of Python. We are only concerned
45 with adding functionality that we actually use in SCons, so be wary
46 if you lift this code for other uses. (That said, making these more
47 nearly the same as later, official versions is still a desirable goal,
48 we just don't need to be obsessive about it.)
49
50 If you're looking at this with pydoc and various names don't show up in
51 the FUNCTIONS or DATA output, that means those names are already built in
52 to this version of Python and we don't need to add them from this module.
53 """
54
55 __revision__ = "src/engine/SCons/compat/_scons_builtins.py 5134 2010/08/16 23:02 :40 bdeegan"
56
57 import builtins
58
59 try:
60 all
61 except NameError:
62 # Pre-2.5 Python has no all() function.
63 def all(iterable):
64 """
65 Returns True if all elements of the iterable are true.
66 """
67 for element in iterable:
68 if not element:
69 return False
70 return True
71 builtins.all = all
72 all = all
73
74 try:
75 any
76 except NameError:
77 # Pre-2.5 Python has no any() function.
78 def any(iterable):
79 """
80 Returns True if any element of the iterable is true.
81 """
82 for element in iterable:
83 if element:
84 return True
85 return False
86 builtins.any = any
87 any = any
88
89 try:
90 memoryview
91 except NameError:
92 # Pre-2.7 doesn't have the memoryview() built-in.
93 class memoryview(object):
94 def __init__(self, obj):
95 # wrapping buffer in () keeps the fixer from changing it
96 self.obj = (buffer)(obj)
97 def __getitem__(self, indx):
98 if isinstance(indx, slice):
99 return self.obj[indx.start:indx.stop]
100 else:
101 return self.obj[indx]
102 builtins.memoryview = memoryview
103
104 try:
105 sorted
106 except NameError:
107 # Pre-2.4 Python has no sorted() function.
108 #
109 # The pre-2.4 Python list.sort() method does not support
110 # list.sort(key=) nor list.sort(reverse=) keyword arguments, so
111 # we must implement the functionality of those keyword arguments
112 # by hand instead of passing them to list.sort().
113 def sorted(iterable, cmp=None, key=None, reverse=False):
114 if key is not None:
115 result = [(key(x), x) for x in iterable]
116 else:
117 result = iterable[:]
118 if cmp is None:
119 # Pre-2.3 Python does not support list.sort(None).
120 result.sort()
121 else:
122 result.sort(cmp)
123 if key is not None:
124 result = [t1 for t0,t1 in result]
125 if reverse:
126 result.reverse()
127 return result
128 builtins.sorted = sorted
129
130 #if sys.version_info[:3] in ((2, 2, 0), (2, 2, 1)):
131 # def lstrip(s, c=string.whitespace):
132 # while s and s[0] in c:
133 # s = s[1:]
134 # return s
135 # def rstrip(s, c=string.whitespace):
136 # while s and s[-1] in c:
137 # s = s[:-1]
138 # return s
139 # def strip(s, c=string.whitespace, l=lstrip, r=rstrip):
140 # return l(r(s, c), c)
141 #
142 # object.__setattr__(str, 'lstrip', lstrip)
143 # object.__setattr__(str, 'rstrip', rstrip)
144 # object.__setattr__(str, 'strip', strip)
145
146 # Local Variables:
147 # tab-width:4
148 # indent-tabs-mode:nil
149 # End:
150 # vim: set expandtab tabstop=4 shiftwidth=4:
OLDNEW
« no previous file with comments | « scons-2.0.1/engine/SCons/compat/__init__.py ('k') | scons-2.0.1/engine/SCons/compat/_scons_collections.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698