diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-04-27 21:01:54 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-04-27 21:01:54 -0400 |
commit | 1c647a879cbec0a301eb2cb021a30553abdced54 (patch) | |
tree | d57d83841b81964158c5d3f7d3132da7d82ce5f9 | |
parent | 32e0a1624bf1ae3cb6309062adefd2f5c89b541c (diff) | |
download | sqlalchemy-1c647a879cbec0a301eb2cb021a30553abdced54.tar.gz |
cleanup
-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: |