remove unnecessary builtin directory in favour of a single file
--HG-- branch : trunk
This commit is contained in:
parent
58e1693af0
commit
690ccaedc1
|
@ -1,6 +1,92 @@
|
|||
import py
|
||||
import sys
|
||||
|
||||
try:
|
||||
reversed = reversed
|
||||
except NameError:
|
||||
def reversed(sequence):
|
||||
"""reversed(sequence) -> reverse iterator over values of the sequence
|
||||
|
||||
Return a reverse iterator
|
||||
"""
|
||||
if hasattr(sequence, '__reversed__'):
|
||||
return sequence.__reversed__()
|
||||
if not hasattr(sequence, '__getitem__'):
|
||||
raise TypeError("argument to reversed() must be a sequence")
|
||||
return reversed_iterator(sequence)
|
||||
|
||||
class reversed_iterator(object):
|
||||
|
||||
def __init__(self, seq):
|
||||
self.seq = seq
|
||||
self.remaining = len(seq)
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def next(self):
|
||||
i = self.remaining
|
||||
if i > 0:
|
||||
i -= 1
|
||||
item = self.seq[i]
|
||||
self.remaining = i
|
||||
return item
|
||||
raise StopIteration
|
||||
|
||||
def __length_hint__(self):
|
||||
return self.remaining
|
||||
|
||||
try:
|
||||
sorted = sorted
|
||||
except NameError:
|
||||
builtin_cmp = cmp # need to use cmp as keyword arg
|
||||
|
||||
def sorted(iterable, cmp=None, key=None, reverse=0):
|
||||
use_cmp = None
|
||||
if key is not None:
|
||||
if cmp is None:
|
||||
def use_cmp(x, y):
|
||||
return builtin_cmp(x[0], y[0])
|
||||
else:
|
||||
def use_cmp(x, y):
|
||||
return cmp(x[0], y[0])
|
||||
l = [(key(element), element) for element in iterable]
|
||||
else:
|
||||
if cmp is not None:
|
||||
use_cmp = cmp
|
||||
l = list(iterable)
|
||||
if use_cmp is not None:
|
||||
l.sort(use_cmp)
|
||||
else:
|
||||
l.sort()
|
||||
if reverse:
|
||||
l.reverse()
|
||||
if key is not None:
|
||||
return [element for (_, element) in l]
|
||||
return l
|
||||
|
||||
try:
|
||||
set, frozenset = set, frozenset
|
||||
except NameError:
|
||||
from sets import set, frozenset
|
||||
|
||||
# pass through
|
||||
enumerate = enumerate
|
||||
|
||||
try:
|
||||
BaseException = BaseException
|
||||
except NameError:
|
||||
BaseException = Exception
|
||||
|
||||
try:
|
||||
GeneratorExit = GeneratorExit
|
||||
except NameError:
|
||||
class GeneratorExit(Exception):
|
||||
""" This exception is never raised, it is there to make it possible to
|
||||
write code compatible with CPython 2.5 even in lower CPython
|
||||
versions."""
|
||||
pass
|
||||
GeneratorExit.__module__ = 'exceptions'
|
||||
|
||||
if sys.version_info >= (3, 0):
|
||||
exec ("print_ = print ; exec_=exec")
|
||||
import builtins
|
||||
|
@ -114,4 +200,4 @@ def _tryimport(*names):
|
|||
return __import__(name, None, None, '__doc__')
|
||||
except ImportError:
|
||||
excinfo = sys.exc_info()
|
||||
py.builtin._reraise(*excinfo)
|
||||
_reraise(*excinfo)
|
|
@ -1,2 +0,0 @@
|
|||
""" backports and additions of builtins """
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
try:
|
||||
reversed = reversed
|
||||
except NameError:
|
||||
def reversed(sequence):
|
||||
"""reversed(sequence) -> reverse iterator over values of the sequence
|
||||
|
||||
Return a reverse iterator
|
||||
"""
|
||||
if hasattr(sequence, '__reversed__'):
|
||||
return sequence.__reversed__()
|
||||
if not hasattr(sequence, '__getitem__'):
|
||||
raise TypeError("argument to reversed() must be a sequence")
|
||||
return reversed_iterator(sequence)
|
||||
|
||||
class reversed_iterator(object):
|
||||
|
||||
def __init__(self, seq):
|
||||
self.seq = seq
|
||||
self.remaining = len(seq)
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def next(self):
|
||||
i = self.remaining
|
||||
if i > 0:
|
||||
i -= 1
|
||||
item = self.seq[i]
|
||||
self.remaining = i
|
||||
return item
|
||||
raise StopIteration
|
||||
|
||||
def __length_hint__(self):
|
||||
return self.remaining
|
||||
|
||||
try:
|
||||
sorted = sorted
|
||||
except NameError:
|
||||
builtin_cmp = cmp # need to use cmp as keyword arg
|
||||
|
||||
def sorted(iterable, cmp=None, key=None, reverse=0):
|
||||
use_cmp = None
|
||||
if key is not None:
|
||||
if cmp is None:
|
||||
def use_cmp(x, y):
|
||||
return builtin_cmp(x[0], y[0])
|
||||
else:
|
||||
def use_cmp(x, y):
|
||||
return cmp(x[0], y[0])
|
||||
l = [(key(element), element) for element in iterable]
|
||||
else:
|
||||
if cmp is not None:
|
||||
use_cmp = cmp
|
||||
l = list(iterable)
|
||||
if use_cmp is not None:
|
||||
l.sort(use_cmp)
|
||||
else:
|
||||
l.sort()
|
||||
if reverse:
|
||||
l.reverse()
|
||||
if key is not None:
|
||||
return [element for (_, element) in l]
|
||||
return l
|
||||
|
||||
try:
|
||||
set, frozenset = set, frozenset
|
||||
except NameError:
|
||||
from sets import set, frozenset
|
||||
|
||||
# pass through
|
||||
enumerate = enumerate
|
|
@ -1,15 +0,0 @@
|
|||
|
||||
try:
|
||||
BaseException = BaseException
|
||||
except NameError:
|
||||
BaseException = Exception
|
||||
|
||||
try:
|
||||
GeneratorExit = GeneratorExit
|
||||
except NameError:
|
||||
class GeneratorExit(Exception):
|
||||
""" This exception is never raised, it is there to make it possible to
|
||||
write code compatible with CPython 2.5 even in lower CPython
|
||||
versions."""
|
||||
pass
|
||||
GeneratorExit.__module__ = 'exceptions'
|
|
@ -121,26 +121,26 @@ _py.apipkg.initpkg(__name__, dict(
|
|||
# backports and additions of builtins
|
||||
builtin = {
|
||||
'__doc__' : '_py.builtin:__doc__',
|
||||
'enumerate' : '_py.builtin.builtin24:enumerate',
|
||||
'reversed' : '_py.builtin.builtin24:reversed',
|
||||
'sorted' : '_py.builtin.builtin24:sorted',
|
||||
'set' : '_py.builtin.builtin24:set',
|
||||
'frozenset' : '_py.builtin.builtin24:frozenset',
|
||||
'BaseException' : '_py.builtin.builtin25:BaseException',
|
||||
'GeneratorExit' : '_py.builtin.builtin25:GeneratorExit',
|
||||
'print_' : '_py.builtin.builtin31:print_',
|
||||
'_reraise' : '_py.builtin.builtin31:_reraise',
|
||||
'_tryimport' : '_py.builtin.builtin31:_tryimport',
|
||||
'exec_' : '_py.builtin.builtin31:exec_',
|
||||
'_basestring' : '_py.builtin.builtin31:_basestring',
|
||||
'_totext' : '_py.builtin.builtin31:_totext',
|
||||
'_isbytes' : '_py.builtin.builtin31:_isbytes',
|
||||
'_istext' : '_py.builtin.builtin31:_istext',
|
||||
'_getimself' : '_py.builtin.builtin31:_getimself',
|
||||
'_getfuncdict' : '_py.builtin.builtin31:_getfuncdict',
|
||||
'builtins' : '_py.builtin.builtin31:builtins',
|
||||
'execfile' : '_py.builtin.builtin31:execfile',
|
||||
'callable' : '_py.builtin.builtin31:callable',
|
||||
'enumerate' : '_py.builtin:enumerate',
|
||||
'reversed' : '_py.builtin:reversed',
|
||||
'sorted' : '_py.builtin:sorted',
|
||||
'set' : '_py.builtin:set',
|
||||
'frozenset' : '_py.builtin:frozenset',
|
||||
'BaseException' : '_py.builtin:BaseException',
|
||||
'GeneratorExit' : '_py.builtin:GeneratorExit',
|
||||
'print_' : '_py.builtin:print_',
|
||||
'_reraise' : '_py.builtin:_reraise',
|
||||
'_tryimport' : '_py.builtin:_tryimport',
|
||||
'exec_' : '_py.builtin:exec_',
|
||||
'_basestring' : '_py.builtin:_basestring',
|
||||
'_totext' : '_py.builtin:_totext',
|
||||
'_isbytes' : '_py.builtin:_isbytes',
|
||||
'_istext' : '_py.builtin:_istext',
|
||||
'_getimself' : '_py.builtin:_getimself',
|
||||
'_getfuncdict' : '_py.builtin:_getfuncdict',
|
||||
'builtins' : '_py.builtin:builtins',
|
||||
'execfile' : '_py.builtin:execfile',
|
||||
'callable' : '_py.builtin:callable',
|
||||
},
|
||||
|
||||
# input-output helping
|
||||
|
|
Loading…
Reference in New Issue