diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-01-05 16:47:32 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-01-05 16:47:32 -0500 |
commit | 50bb5df56743b4f4982a7f4df3e5ef65a4ea2831 (patch) | |
tree | e415a7c4f5e98322324057350bfd43bc8458ee3c | |
parent | f7d5d551fe147ee83138c2d06dce5e118f7f94d9 (diff) | |
download | sqlalchemy-50bb5df56743b4f4982a7f4df3e5ef65a4ea2831.tar.gz |
- compat
Change-Id: I33024885c8c7c98294f27460a1531be165b78f37
-rw-r--r-- | lib/sqlalchemy/util/compat.py | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/lib/sqlalchemy/util/compat.py b/lib/sqlalchemy/util/compat.py index 780a05fc2..870fc6439 100644 --- a/lib/sqlalchemy/util/compat.py +++ b/lib/sqlalchemy/util/compat.py @@ -8,18 +8,16 @@ """Handle Python version/platform incompatibilities.""" import collections -from collections import namedtuple +from collections import namedtuple # noqa from contextlib import contextmanager -from operator import attrgetter as dottedgetter +from operator import attrgetter as dottedgetter # noqa import sys import time - - try: import threading except ImportError: - import dummy_threading as threading + import dummy_threading as threading # noqa py36 = sys.version_info >= (3, 6) py33 = sys.version_info >= (3, 3) @@ -33,7 +31,7 @@ pypy = hasattr(sys, "pypy_version_info") win32 = sys.platform.startswith("win") cpython = not pypy and not jython # TODO: something better for this ? -next = next +next = next # noqa if py3k: import pickle @@ -41,11 +39,11 @@ else: try: import cPickle as pickle except ImportError: - import pickle + import pickle # noqa # work around http://bugs.python.org/issue2646 if py265: - safe_kwarg = lambda arg: arg + safe_kwarg = lambda arg: arg # noqa else: safe_kwarg = str @@ -89,10 +87,10 @@ if py3k: return s.encode("latin-1") if py32: - callable = callable + callable = callable # noqa else: - def callable(fn): + def callable(fn): # noqa return hasattr(fn, "__call__") def cmp(a, b): @@ -124,17 +122,17 @@ else: from inspect import getargspec as inspect_getfullargspec inspect_getargspec = inspect_getfullargspec - from urllib import quote_plus, unquote_plus, quote, unquote - from urlparse import parse_qsl - import ConfigParser as configparser - from StringIO import StringIO - from cStringIO import StringIO as byte_buffer + from urllib import quote_plus, unquote_plus, quote, unquote # noqa + from urlparse import parse_qsl # noqa + import ConfigParser as configparser # noqa + from StringIO import StringIO # noqa + from cStringIO import StringIO as byte_buffer # noqa - string_types = (basestring,) + string_types = (basestring,) # noqa binary_types = (bytes,) binary_type = str - text_type = unicode - int_types = int, long + text_type = unicode # noqa + int_types = int, long # noqa def iterbytes(buf): return (ord(byte) for byte in buf) @@ -144,10 +142,10 @@ else: # strings - we only use u() with # literal source strings, and all our source files with non-ascii # in them (all are tests) are utf-8 encoded. - return unicode(s, "utf-8") + return unicode(s, "utf-8") # noqa def ue(s): - return unicode(s, "unicode_escape") + return unicode(s, "unicode_escape") # noqa def b(s): return s @@ -157,7 +155,7 @@ else: args = args[0:3] + ([str(arg) for arg in args[3]],) return __import__(*args) - callable = callable + callable = callable # noqa cmp = cmp reduce = reduce @@ -171,7 +169,7 @@ else: if fp is None: return for arg in enumerate(args): - if not isinstance(arg, basestring): + if not isinstance(arg, basestring): # noqa arg = str(arg) fp.write(arg) @@ -180,7 +178,7 @@ else: itertools_filterfalse = itertools.ifilterfalse itertools_filter = itertools.ifilter itertools_imap = itertools.imap - from itertools import izip_longest as zip_longest + from itertools import izip_longest as zip_longest # noqa if py35: from inspect import formatannotation @@ -248,7 +246,7 @@ if py35: else: - from inspect import formatargspec as inspect_formatargspec + from inspect import formatargspec as inspect_formatargspec # noqa if win32 or jython: time_func = time.clock @@ -330,20 +328,19 @@ def nested(*managers): """ exits = [] - vars = [] exc = (None, None, None) try: for mgr in managers: - exit = mgr.__exit__ + exit_ = mgr.__exit__ enter = mgr.__enter__ vars.append(enter()) - exits.append(exit) + exits.append(exit_) yield vars except: exc = sys.exc_info() finally: while exits: - exit = exits.pop() + exit_ = exits.pop() try: if exit(*exc): exc = (None, None, None) @@ -358,4 +355,4 @@ def nested(*managers): if py33: import collections.abc as collections_abc else: - import collections as collections_abc + import collections as collections_abc # noqa |