diff options
Diffstat (limited to 'lib/sqlalchemy/util')
| -rw-r--r-- | lib/sqlalchemy/util/__init__.py | 274 | ||||
| -rw-r--r-- | lib/sqlalchemy/util/_collections.py | 28 | ||||
| -rw-r--r-- | lib/sqlalchemy/util/compat.py | 68 | ||||
| -rw-r--r-- | lib/sqlalchemy/util/deprecations.py | 9 | ||||
| -rw-r--r-- | lib/sqlalchemy/util/langhelpers.py | 23 | ||||
| -rw-r--r-- | lib/sqlalchemy/util/queue.py | 1 | ||||
| -rw-r--r-- | lib/sqlalchemy/util/topological.py | 3 |
7 files changed, 204 insertions, 202 deletions
diff --git a/lib/sqlalchemy/util/__init__.py b/lib/sqlalchemy/util/__init__.py index 103225e2a..13bcc37e7 100644 --- a/lib/sqlalchemy/util/__init__.py +++ b/lib/sqlalchemy/util/__init__.py @@ -5,150 +5,142 @@ # This module is part of SQLAlchemy and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php -from .compat import ( - callable, - cmp, - reduce, - threading, - py3k, - py33, - py36, - py2k, - jython, - pypy, - cpython, - win32, - pickle, - dottedgetter, - parse_qsl, - namedtuple, - next, - reraise, - raise_from_cause, - text_type, - safe_kwarg, - string_types, - int_types, - binary_type, - nested, - quote_plus, - with_metaclass, - print_, - itertools_filterfalse, - u, - ue, - b, - unquote_plus, - unquote, - b64decode, - b64encode, - byte_buffer, - itertools_filter, - iterbytes, - StringIO, - inspect_getargspec, - zip_longest, -) -from ._collections import ( - KeyedTuple, - ImmutableContainer, - immutabledict, - Properties, - OrderedProperties, - ImmutableProperties, - OrderedDict, - OrderedSet, - IdentitySet, - OrderedIdentitySet, - column_set, - column_dict, - ordered_column_set, - populate_column_dict, - unique_list, - UniqueAppender, - PopulateDict, - EMPTY_SET, - to_list, - to_set, - to_column_set, - update_copy, - flatten_iterator, - has_intersection, - LRUCache, - ScopedRegistry, - ThreadLocalRegistry, - WeakSequence, - coerce_generator_arg, - lightweight_named_tuple, - collections_abc, - has_dupes, -) +from collections import defaultdict # noqa +from contextlib import contextmanager # noqa +from functools import partial # noqa +from functools import update_wrapper # noqa -from .langhelpers import ( - iterate_attributes, - class_hierarchy, - portable_instancemethod, - unbound_method_to_callable, - getargspec_init, - format_argspec_init, - format_argspec_plus, - get_func_kwargs, - get_cls_kwargs, - decorator, - as_interface, - memoized_property, - memoized_instancemethod, - md5_hex, - group_expirable_memoized_property, - dependencies, - decode_slice, - monkeypatch_proxied_specials, - asbool, - bool_or_str, - coerce_kw_type, - duck_type_collection, - assert_arg_type, - symbol, - dictlike_iteritems, - classproperty, - set_creation_order, - warn_exception, - warn, - NoneType, - constructor_copy, - methods_equivalent, - chop_traceback, - asint, - generic_repr, - counter, - PluginLoader, - hybridproperty, - hybridmethod, - safe_reraise, - quoted_token_parser, - get_callable_argspec, - only_once, - attrsetter, - ellipses_string, - warn_limited, - map_bits, - MemoizedSlots, - EnsureKWArgType, - wrap_callable, -) +from ._collections import coerce_generator_arg # noqa +from ._collections import collections_abc # noqa +from ._collections import column_dict # noqa +from ._collections import column_set # noqa +from ._collections import EMPTY_SET # noqa +from ._collections import flatten_iterator # noqa +from ._collections import has_dupes # noqa +from ._collections import has_intersection # noqa +from ._collections import IdentitySet # noqa +from ._collections import ImmutableContainer # noqa +from ._collections import immutabledict # noqa +from ._collections import ImmutableProperties # noqa +from ._collections import KeyedTuple # noqa +from ._collections import lightweight_named_tuple # noqa +from ._collections import LRUCache # noqa +from ._collections import ordered_column_set # noqa +from ._collections import OrderedDict # noqa +from ._collections import OrderedIdentitySet # noqa +from ._collections import OrderedProperties # noqa +from ._collections import OrderedSet # noqa +from ._collections import populate_column_dict # noqa +from ._collections import PopulateDict # noqa +from ._collections import Properties # noqa +from ._collections import ScopedRegistry # noqa +from ._collections import ThreadLocalRegistry # noqa +from ._collections import to_column_set # noqa +from ._collections import to_list # noqa +from ._collections import to_set # noqa +from ._collections import unique_list # noqa +from ._collections import UniqueAppender # noqa +from ._collections import update_copy # noqa +from ._collections import WeakSequence # noqa +from .compat import b # noqa +from .compat import b64decode # noqa +from .compat import b64encode # noqa +from .compat import binary_type # noqa +from .compat import byte_buffer # noqa +from .compat import callable # noqa +from .compat import cmp # noqa +from .compat import cpython # noqa +from .compat import dottedgetter # noqa +from .compat import inspect_getargspec # noqa +from .compat import int_types # noqa +from .compat import iterbytes # noqa +from .compat import itertools_filter # noqa +from .compat import itertools_filterfalse # noqa +from .compat import jython # noqa +from .compat import namedtuple # noqa +from .compat import nested # noqa +from .compat import next # noqa +from .compat import parse_qsl # noqa +from .compat import pickle # noqa +from .compat import print_ # noqa +from .compat import py2k # noqa +from .compat import py33 # noqa +from .compat import py36 # noqa +from .compat import py3k # noqa +from .compat import pypy # noqa +from .compat import quote_plus # noqa +from .compat import raise_from_cause # noqa +from .compat import reduce # noqa +from .compat import reraise # noqa +from .compat import safe_kwarg # noqa +from .compat import string_types # noqa +from .compat import StringIO # noqa +from .compat import text_type # noqa +from .compat import threading # noqa +from .compat import u # noqa +from .compat import ue # noqa +from .compat import unquote # noqa +from .compat import unquote_plus # noqa +from .compat import win32 # noqa +from .compat import with_metaclass # noqa +from .compat import zip_longest # noqa +from .deprecations import deprecated # noqa +from .deprecations import inject_docstring_text # noqa +from .deprecations import pending_deprecation # noqa +from .deprecations import warn_deprecated # noqa +from .deprecations import warn_pending_deprecation # noqa +from .langhelpers import as_interface # noqa +from .langhelpers import asbool # noqa +from .langhelpers import asint # noqa +from .langhelpers import assert_arg_type # noqa +from .langhelpers import attrsetter # noqa +from .langhelpers import bool_or_str # noqa +from .langhelpers import chop_traceback # noqa +from .langhelpers import class_hierarchy # noqa +from .langhelpers import classproperty # noqa +from .langhelpers import coerce_kw_type # noqa +from .langhelpers import constructor_copy # noqa +from .langhelpers import counter # noqa +from .langhelpers import decode_slice # noqa +from .langhelpers import decorator # noqa +from .langhelpers import dependencies # noqa +from .langhelpers import dictlike_iteritems # noqa +from .langhelpers import duck_type_collection # noqa +from .langhelpers import ellipses_string # noqa +from .langhelpers import EnsureKWArgType # noqa +from .langhelpers import format_argspec_init # noqa +from .langhelpers import format_argspec_plus # noqa +from .langhelpers import generic_repr # noqa +from .langhelpers import get_callable_argspec # noqa +from .langhelpers import get_cls_kwargs # noqa +from .langhelpers import get_func_kwargs # noqa +from .langhelpers import getargspec_init # noqa +from .langhelpers import group_expirable_memoized_property # noqa +from .langhelpers import hybridmethod # noqa +from .langhelpers import hybridproperty # noqa +from .langhelpers import iterate_attributes # noqa +from .langhelpers import map_bits # noqa +from .langhelpers import md5_hex # noqa +from .langhelpers import memoized_instancemethod # noqa +from .langhelpers import memoized_property # noqa +from .langhelpers import MemoizedSlots # noqa +from .langhelpers import methods_equivalent # noqa +from .langhelpers import monkeypatch_proxied_specials # noqa +from .langhelpers import NoneType # noqa +from .langhelpers import only_once # noqa +from .langhelpers import PluginLoader # noqa +from .langhelpers import portable_instancemethod # noqa +from .langhelpers import quoted_token_parser # noqa +from .langhelpers import safe_reraise # noqa +from .langhelpers import set_creation_order # noqa +from .langhelpers import symbol # noqa +from .langhelpers import unbound_method_to_callable # noqa +from .langhelpers import warn # noqa +from .langhelpers import warn_exception # noqa +from .langhelpers import warn_limited # noqa +from .langhelpers import wrap_callable # noqa -from .deprecations import ( - warn_deprecated, - warn_pending_deprecation, - deprecated, - pending_deprecation, - inject_docstring_text, -) # things that used to be not always available, # but are now as of current support Python versions -from collections import defaultdict -from functools import partial -from functools import update_wrapper -from contextlib import contextmanager diff --git a/lib/sqlalchemy/util/_collections.py b/lib/sqlalchemy/util/_collections.py index 67be0e6bf..13575d12d 100644 --- a/lib/sqlalchemy/util/_collections.py +++ b/lib/sqlalchemy/util/_collections.py @@ -8,17 +8,17 @@ """Collection classes and helpers.""" from __future__ import absolute_import -import weakref + import operator -from .compat import ( - threading, - itertools_filterfalse, - string_types, - binary_types, - collections_abc, -) -from . import py2k import types +import weakref + +from .compat import binary_types +from .compat import collections_abc +from .compat import itertools_filterfalse +from .compat import py2k +from .compat import string_types +from .compat import threading EMPTY_SET = frozenset() @@ -196,8 +196,8 @@ class Properties(object): def __add__(self, other): return list(self) + list(other) - def __setitem__(self, key, object): - self._data[key] = object + def __setitem__(self, key, obj): + self._data[key] = obj def __getitem__(self, key): return self._data[key] @@ -339,7 +339,7 @@ class OrderedDict(dict): def iteritems(self): return iter(self.items()) - def __setitem__(self, key, object): + def __setitem__(self, key, obj): if key not in self: try: self._list.append(key) @@ -347,7 +347,7 @@ class OrderedDict(dict): # work around Python pickle loads() with # dict subclass (seems to ignore __setstate__?) self._list = [key] - dict.__setitem__(self, key, object) + dict.__setitem__(self, key, obj) def __delitem__(self, key): dict.__delitem__(self, key) @@ -822,7 +822,7 @@ def to_list(x, default=None): def has_intersection(set_, iterable): - """return True if any items of set_ are present in iterable. + r"""return True if any items of set\_ are present in iterable. Goes through special effort to ensure __hash__ is not called on items in iterable that don't support it. diff --git a/lib/sqlalchemy/util/compat.py b/lib/sqlalchemy/util/compat.py index 553624b49..7963eebb6 100644 --- a/lib/sqlalchemy/util/compat.py +++ b/lib/sqlalchemy/util/compat.py @@ -9,10 +9,11 @@ import collections import contextlib -import sys import operator +import sys import time + py36 = sys.version_info >= (3, 6) py33 = sys.version_info >= (3, 3) py35 = sys.version_info >= (3, 5) @@ -28,7 +29,7 @@ cpython = not pypy and not jython # TODO: something better for this ? contextmanager = contextlib.contextmanager dottedgetter = operator.attrgetter namedtuple = collections.namedtuple -next = next +next = next # noqa ArgSpec = collections.namedtuple( "ArgSpec", ["args", "varargs", "keywords", "defaults"] @@ -37,12 +38,12 @@ ArgSpec = collections.namedtuple( try: import threading except ImportError: - import dummy_threading as threading + import dummy_threading as threading # 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 @@ -112,41 +113,44 @@ if py3k: return s if py32: - callable = callable + callable = callable # noqa else: - def callable(fn): + def callable(fn): # noqa return hasattr(fn, "__call__") else: import base64 - import ConfigParser as configparser + import ConfigParser as configparser # noqa import itertools - from StringIO import StringIO - from cStringIO import StringIO as byte_buffer - from inspect import getargspec as inspect_getfullargspec - from itertools import izip_longest as zip_longest - from urllib import quote_plus, unquote_plus, quote, unquote - from urlparse import parse_qsl + from StringIO import StringIO # noqa + from cStringIO import StringIO as byte_buffer # noqa + from inspect import getargspec as inspect_getfullargspec # noqa + from itertools import izip_longest as zip_longest # noqa + from urllib import quote # noqa + from urllib import quote_plus # noqa + from urllib import unquote # noqa + from urllib import unquote_plus # noqa + from urlparse import parse_qsl # noqa try: import cPickle as pickle except ImportError: - import pickle + import pickle # 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 inspect_getargspec = inspect_getfullargspec - callable = callable - cmp = cmp - reduce = reduce + callable = callable # noqa + cmp = cmp # noqa + reduce = reduce # noqa b64encode = base64.b64encode b64decode = base64.b64decode @@ -177,7 +181,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) @@ -186,10 +190,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 # not as nice as that of Py3K, but at least preserves # the code line where the issue occurred @@ -271,7 +275,7 @@ if py35: else: - from inspect import formatargspec as inspect_formatargspec + from inspect import formatargspec as inspect_formatargspec # noqa if win32 or jython: @@ -284,7 +288,7 @@ else: if py33: import collections.abc as collections_abc else: - import collections as collections_abc + import collections as collections_abc # noqa @contextlib.contextmanager @@ -299,22 +303,22 @@ def nested(*managers): """ exits = [] - vars = [] + 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) - yield vars + vars_.append(enter()) + exits.append(exit_) + yield vars_ except: exc = sys.exc_info() finally: while exits: - exit = exits.pop() + exit_ = exits.pop() # noqa try: - if exit(*exc): + if exit_(*exc): exc = (None, None, None) except: exc = sys.exc_info() diff --git a/lib/sqlalchemy/util/deprecations.py b/lib/sqlalchemy/util/deprecations.py index e6612f075..945323530 100644 --- a/lib/sqlalchemy/util/deprecations.py +++ b/lib/sqlalchemy/util/deprecations.py @@ -8,10 +8,12 @@ """Helpers related to deprecation of functions, methods, classes, other functionality.""" -from .. import exc -import warnings import re +import textwrap +import warnings + from .langhelpers import decorator +from .. import exc def warn_deprecated(msg, stacklevel=3): @@ -127,9 +129,6 @@ def _decorate_with_warning(func, wtype, message, docstring_header=None): return decorated -import textwrap - - def _dedent_docstring(text): split_text = text.split("\n", 1) if len(split_text) == 1: diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py index 6a286998b..49b5eb87f 100644 --- a/lib/sqlalchemy/util/langhelpers.py +++ b/lib/sqlalchemy/util/langhelpers.py @@ -9,6 +9,8 @@ modules, classes, hierarchies, attributes, functions, and methods. """ +from functools import update_wrapper +import hashlib import inspect import itertools import operator @@ -16,11 +18,10 @@ import re import sys import types import warnings -from functools import update_wrapper -from .. import exc -import hashlib -from . import compat + from . import _collections +from . import compat +from .. import exc def md5_hex(x): @@ -857,7 +858,10 @@ def memoized_instancemethod(fn): def oneshot(self, *args, **kw): result = fn(self, *args, **kw) - memo = lambda *a, **kw: result + + def memo(*a, **kw): + return result + memo.__name__ = fn.__name__ memo.__doc__ = fn.__doc__ self.__dict__[fn.__name__] = memo @@ -914,7 +918,10 @@ class MemoizedSlots(object): def oneshot(*args, **kw): result = fn(*args, **kw) - memo = lambda *a, **kw: result + + def memo(*a, **kw): + return result + memo.__name__ = fn.__name__ memo.__doc__ = fn.__doc__ setattr(self, key, memo) @@ -928,8 +935,6 @@ class MemoizedSlots(object): def dependency_for(modulename, add_to_all=False): def decorate(obj): - # TODO: would be nice to improve on this import silliness, - # unfortunately importlib doesn't work that great either tokens = modulename.split(".") mod = compat.import_( ".".join(tokens[0:-1]), globals(), locals(), [tokens[-1]] @@ -1461,7 +1466,7 @@ def attrsetter(attrname): class EnsureKWArgType(type): - """Apply translation of functions to accept **kw arguments if they + r"""Apply translation of functions to accept \**kw arguments if they don't already. """ diff --git a/lib/sqlalchemy/util/queue.py b/lib/sqlalchemy/util/queue.py index 5e56e855a..bb5df99e9 100644 --- a/lib/sqlalchemy/util/queue.py +++ b/lib/sqlalchemy/util/queue.py @@ -20,6 +20,7 @@ condition. from collections import deque from time import time as _time + from .compat import threading diff --git a/lib/sqlalchemy/util/topological.py b/lib/sqlalchemy/util/topological.py index 95391c31b..3cc5ef04f 100644 --- a/lib/sqlalchemy/util/topological.py +++ b/lib/sqlalchemy/util/topological.py @@ -7,8 +7,9 @@ """Topological sorting algorithms.""" -from ..exc import CircularDependencyError from .. import util +from ..exc import CircularDependencyError + __all__ = ["sort", "sort_as_subsets", "find_cycles"] |
