]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
cleanup
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 28 Apr 2013 01:01:54 +0000 (21:01 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 28 Apr 2013 01:01:54 +0000 (21:01 -0400)
lib/sqlalchemy/util/compat.py

index 5042d505bb7c4fa9fab2f536d88cbb4910ab0cb8..bdeb69d1e15424bc2e6251a2e4cc21b21ac83eca 100644 (file)
@@ -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: