diff options
Diffstat (limited to 'lib/sqlalchemy/util/compat.py')
-rw-r--r-- | lib/sqlalchemy/util/compat.py | 66 |
1 files changed, 21 insertions, 45 deletions
diff --git a/lib/sqlalchemy/util/compat.py b/lib/sqlalchemy/util/compat.py index 5042d505b..bdeb69d1e 100644 --- a/lib/sqlalchemy/util/compat.py +++ b/lib/sqlalchemy/util/compat.py @@ -22,11 +22,8 @@ win32 = sys.platform.startswith('win') cpython = not pypy and not jython # TODO: something better for this ? -if sys.version_info < (2, 6): - def next(iter): - return iter.__next__() -else: - next = next +next = next + if py3k: import pickle else: @@ -35,8 +32,6 @@ else: except ImportError: import pickle - - if py3k: from inspect import getfullargspec as inspect_getfullargspec from urllib.parse import quote_plus, unquote_plus, parse_qsl @@ -45,6 +40,21 @@ if py3k: text_type = str int_types = int, iterbytes = iter + + def b(s): + return s.encode("latin-1") + + if py32: + callable = callable + else: + def callable(fn): + return hasattr(fn, '__call__') + + def cmp(a, b): + return (a > b) - (a < b) + + from functools import reduce + else: from inspect import getargspec as inspect_getfullargspec from urllib import quote_plus, unquote_plus @@ -56,31 +66,13 @@ else: def iterbytes(buf): return (ord(byte) for byte in buf) -if py3k: - # they're bringing it back in 3.2. brilliant ! - def callable(fn): - return hasattr(fn, '__call__') - - def cmp(a, b): - return (a > b) - (a < b) + def b(s): + return s - from functools import reduce -else: callable = callable cmp = cmp reduce = reduce -try: - from collections import namedtuple -except ImportError: - def namedtuple(typename, fieldnames): - def __new__(cls, *values): - tup = tuple.__new__(cls, values) - for i, fname in enumerate(fieldnames): - setattr(tup, fname, tup[i]) - return tup - tuptype = type(typename, (tuple, ), {'__new__': __new__}) - return tuptype try: from weakref import WeakSet @@ -110,24 +102,8 @@ if win32 or jython: else: time_func = time.time - -if sys.version_info >= (2, 6): - from operator import attrgetter as dottedgetter -else: - def dottedgetter(attr): - def g(obj): - for name in attr.split("."): - obj = getattr(obj, name) - return obj - return g - -# Adapted from six.py -if py3k: - def b(s): - return s.encode("latin-1") -else: - def b(s): - return s +from collections import namedtuple +from operator import attrgetter as dottedgetter if py3k: |