Package SCons :: Package compat :: Module _scons_builtins
[hide private]
[frames] | no frames]

Source Code for Module SCons.compat._scons_builtins

  1  # 
  2  # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 The SCons 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          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      # Pre-2.5 Python has no all() function. 
62 - def all(iterable):
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 # Pre-2.5 Python has no any() function.
77 - def any(iterable):
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 # Pre-2.7 doesn't have the memoryview() built-in.
92 - class memoryview(object):
93 - def __init__(self, obj):
94 # wrapping buffer in () keeps the fixer from changing it 95 self.obj = (buffer)(obj)
96 - def __getitem__(self, indx):
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 # Local Variables: 104 # tab-width:4 105 # indent-tabs-mode:nil 106 # End: 107 # vim: set expandtab tabstop=4 shiftwidth=4: 108