# Copyright (c) 2001-2004 Twisted Matrix Laboratories
__doc__ = """
-Compatibility idioms for __builtin__ names
+Compatibility idioms for builtins names
-This module adds names to the __builtin__ module for things that we want
+This module adds names to the builtins module for things that we want
to use in SCons but which don't show up until later Python versions than
the earliest ones we support.
-This module checks for the following __builtin__ names:
+This module checks for the following builtins names:
all()
any()
bool()
dict()
sorted()
+ memoryview()
True
False
zip()
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-import __builtin__
+import builtins
try:
all
if not element:
return False
return True
- __builtin__.all = all
+ builtins.all = all
all = all
try:
if element:
return True
return False
- __builtin__.any = any
+ builtins.any = any
any = any
try:
worth the trouble.
"""
return not not value
- __builtin__.bool = bool
+ builtins.bool = bool
bool = bool
try:
d[k] = v
d.update(kwargs)
return d
- __builtin__.dict = dict
+ builtins.dict = dict
try:
False
except NameError:
# Pre-2.2 Python has no False keyword.
- __builtin__.False = not 1
+ builtins.False = not 1
# Assign to False in this module namespace so it shows up in pydoc output.
False = False
True
except NameError:
# Pre-2.2 Python has no True keyword.
- __builtin__.True = not 0
+ builtins.True = not 0
# Assign to True in this module namespace so it shows up in pydoc output.
True = True
file
except NameError:
# Pre-2.2 Python has no file() function.
- __builtin__.file = open
+ builtins.file = open
+
+try:
+ memoryview
+except NameError:
+ # Pre-2.7 doesn't have the memoryview() built-in.
+ class memoryview:
+ from types import SliceType
+ def __init__(self, obj):
+ # wrapping buffer in () keeps the fixer from changing it
+ self.obj = (buffer)(obj)
+ def __getitem__(self, indx):
+ if isinstance(indx, self.SliceType):
+ return self.obj[indx.start:indx.stop]
+ else:
+ return self.obj[indx]
+ builtins.memoryview = memoryview
try:
sorted
if reverse:
result.reverse()
return result
- __builtin__.sorted = sorted
+ builtins.sorted = sorted
#
try:
for i in range(min(list(map(len, lists)))):
result.append(tuple([l[i] for l in lists]))
return result
- __builtin__.zip = zip
+ builtins.zip = zip
#if sys.version_info[:3] in ((2, 2, 0), (2, 2, 1)):
# def lstrip(s, c=string.whitespace):