Ronny Pfannschmidt avatar Ronny Pfannschmidt committed c71a57f

six stuff

Comments (0)

Files changed (3)

+# HG changeset patch
+# Parent 8bba910ff5ec676feb87571c3c94a1dff0734906
+
+diff --git a/py/_builtin.py b/py/_builtin.py
+--- a/py/_builtin.py
++++ b/py/_builtin.py
+@@ -1,20 +1,5 @@
+ import sys
+ 
+-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'
+-
+ _sysex = (KeyboardInterrupt, SystemExit, MemoryError, GeneratorExit)
+ 
+ import six
+diff --git a/tox.ini b/tox.ini
+--- a/tox.ini
++++ b/tox.ini
+@@ -1,5 +1,5 @@
+ [tox]
+-envlist=py26,py27,py31,py32,py27-xdist,py25,py24
++envlist=py26,py27,py31,py32,py27-xdist,py25
+ #indexserver=
+ #    default=http://pypi.testrun.org
+ 
+six
+killpy24
 tw-reline-remove
 decode-errors
 capture-bytes
+# HG changeset patch
+# Parent 2c042feb5b3b1acebc7ceb565cac0a3b72d2a732
+
+diff --git a/py/__init__.py b/py/__init__.py
+--- a/py/__init__.py
++++ b/py/__init__.py
+@@ -80,20 +80,20 @@ sys.modules['py.error'] = _apipkg.AliasM
+     # backports and additions of builtins
+     'builtin' : {
+         '__doc__'        : '._builtin:__doc__',
+-        'enumerate'      : '._builtin:enumerate',
+-        'reversed'       : '._builtin:reversed',
+-        'sorted'         : '._builtin:sorted',
+-        'any'            : '._builtin:any',
+-        'all'            : '._builtin:all',
+-        'set'            : '._builtin:set',
+-        'frozenset'      : '._builtin:frozenset',
++        'enumerate'      : 'six.moves:builtins.enumerate',
++        'reversed'       : 'six.moves:builtins.reversed',
++        'sorted'         : 'six.moves:builtins.sorted',
++        'any'            : 'six.moves:builtins.any',
++        'all'            : 'six.moves:builtins.all',
++        'set'            : 'six.moves:builtins.set',
++        'frozenset'      : 'six.moves:builtins.frozenset',
+         'BaseException'  : '._builtin:BaseException',
+         'GeneratorExit'  : '._builtin:GeneratorExit',
+         '_sysex'         : '._builtin:_sysex',
+-        'print_'         : '._builtin:print_',
+-        '_reraise'       : '._builtin:_reraise',
++        'print_'         : 'six:print_',
++        '_reraise'       : 'six:reraise',
+         '_tryimport'     : '._builtin:_tryimport',
+-        'exec_'          : '._builtin:exec_',
++        'exec_'          : 'six:exec_',
+         '_basestring'    : '._builtin:_basestring',
+         '_totext'        : '._builtin:_totext',
+         '_isbytes'       : '._builtin:_isbytes',
+@@ -101,9 +101,9 @@ sys.modules['py.error'] = _apipkg.AliasM
+         '_getimself'     : '._builtin:_getimself',
+         '_getfuncdict'   : '._builtin:_getfuncdict',
+         '_getcode'       : '._builtin:_getcode',
+-        'builtins'       : '._builtin:builtins',
++        'builtins'       : 'six.moves:builtins',
+         'execfile'       : '._builtin:execfile',
+-        'callable'       : '._builtin:callable',
++        'callable'       : 'six:callable',
+     },
+ 
+     # input-output helping
+diff --git a/py/_builtin.py b/py/_builtin.py
+--- a/py/_builtin.py
++++ b/py/_builtin.py
+@@ -1,96 +1,6 @@
+ 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:
+-    any = any
+-except NameError:
+-    def any(iterable):
+-        for x in iterable:
+-            if x:
+-                return True
+-        return False
+-
+-try:
+-    all = all
+-except NameError:
+-    def all(iterable):
+-        for x in iterable:
+-            if not x:
+-                return False
+-        return True
+-
+-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
+@@ -107,8 +17,23 @@ except NameError:
+ 
+ _sysex = (KeyboardInterrupt, SystemExit, MemoryError, GeneratorExit)
+ 
++import six
++
++def _getfuncdict(function):
++    return getattr(function, "__dict__", None)
++
++def _getcode(function):
++    return getattr(function, six._func_code, None)
++
++def _getimself(function):
++    return getattr(function, six._meth_self, None)
++
++def _isbytes(x):
++    return isinstance(x, six.binary_type)
++def _istext(x):
++    return isinstance(x, six.text_type)
++
+ if sys.version_info >= (3, 0):
+-    exec ("print_ = print ; exec_=exec")
+     import builtins
+ 
+     # some backward compatibility helpers
+@@ -120,20 +45,6 @@ if sys.version_info >= (3, 0):
+             obj = str(obj)
+         return obj
+ 
+-    def _isbytes(x):
+-        return isinstance(x, bytes)
+-    def _istext(x):
+-        return isinstance(x, str)
+-
+-    def _getimself(function):
+-        return getattr(function, '__self__', None)
+-
+-    def _getfuncdict(function):
+-        return getattr(function, "__dict__", None)
+-
+-    def _getcode(function):
+-        return getattr(function, "__code__", None)
+-
+     def execfile(fn, globs=None, locs=None):
+         if globs is None:
+             back = sys._getframe(1)
+@@ -150,78 +61,14 @@ if sys.version_info >= (3, 0):
+         co = compile(source, fn, "exec", dont_inherit=True)
+         exec_(co, globs, locs)
+ 
+-    def callable(obj):
+-        return hasattr(obj, "__call__")
+-
+ else:
+     import __builtin__ as builtins
+     _totext = unicode
+     _basestring = basestring
+     execfile = execfile
+-    callable = callable
+-    def _isbytes(x):
+-        return isinstance(x, str)
+-    def _istext(x):
+-        return isinstance(x, unicode)
+ 
+-    def _getimself(function):
+-        return getattr(function, 'im_self', None)
+ 
+-    def _getfuncdict(function):
+-        return getattr(function, "__dict__", None)
+ 
+-    def _getcode(function):
+-        try:
+-            return getattr(function, "__code__")
+-        except AttributeError:
+-            return getattr(function, "func_code", None)
+-
+-    def print_(*args, **kwargs):
+-        """ minimal backport of py3k print statement. """
+-        sep = ' '
+-        if 'sep' in kwargs:
+-            sep = kwargs.pop('sep')
+-        end = '\n'
+-        if 'end' in kwargs:
+-            end = kwargs.pop('end')
+-        file = 'file' in kwargs and kwargs.pop('file') or sys.stdout
+-        if kwargs:
+-            args = ", ".join([str(x) for x in kwargs])
+-            raise TypeError("invalid keyword arguments: %s" % args)
+-        at_start = True
+-        for x in args:
+-            if not at_start:
+-                file.write(sep)
+-            file.write(str(x))
+-            at_start = False
+-        file.write(end)
+-
+-    def exec_(obj, globals=None, locals=None):
+-        """ minimal backport of py3k exec statement. """
+-        __tracebackhide__ = True
+-        if globals is None:
+-            frame = sys._getframe(1)
+-            globals = frame.f_globals
+-            if locals is None:
+-                locals = frame.f_locals
+-        elif locals is None:
+-            locals = globals
+-        exec2(obj, globals, locals)
+-
+-if sys.version_info >= (3,0):
+-    def _reraise(cls, val, tb):
+-        __tracebackhide__ = True
+-        assert hasattr(val, '__traceback__')
+-        raise val
+-else:
+-    exec ("""
+-def _reraise(cls, val, tb):
+-    __tracebackhide__ = True
+-    raise cls, val, tb
+-def exec2(obj, globals, locals):
+-    __tracebackhide__ = True
+-    exec obj in globals, locals
+-""")
+ 
+ def _tryimport(*names):
+     """ return the first successfully imported module. """
+@@ -231,4 +78,4 @@ def _tryimport(*names):
+             return __import__(name, None, None, '__doc__')
+         except ImportError:
+             excinfo = sys.exc_info()
+-    _reraise(*excinfo)
++    six.reraise(*excinfo)
+diff --git a/setup.py b/setup.py
+--- a/setup.py
++++ b/setup.py
+@@ -36,8 +36,9 @@ def main():
+                   'py._path',
+                   'py._process',
+         ],
++        install_requires=['six'],
+         zip_safe=False,
+     )
+ 
+ if __name__ == '__main__':
+-    main()
+\ No newline at end of file
++    main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.