Remove Elixir library
Update SQLAlchemy
This commit is contained in:
+155
-183
@@ -1,5 +1,5 @@
|
||||
# util/compat.py
|
||||
# Copyright (C) 2005-2013 the SQLAlchemy authors and contributors <see AUTHORS file>
|
||||
# Copyright (C) 2005-2014 the SQLAlchemy authors and contributors <see AUTHORS file>
|
||||
#
|
||||
# This module is part of SQLAlchemy and is released under
|
||||
# the MIT License: http://www.opensource.org/licenses/mit-license.php
|
||||
@@ -8,45 +8,24 @@
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
try:
|
||||
import threading
|
||||
except ImportError:
|
||||
import dummy_threading as threading
|
||||
|
||||
py33 = sys.version_info >= (3, 3)
|
||||
py32 = sys.version_info >= (3, 2)
|
||||
py3k_warning = getattr(sys, 'py3kwarning', False) or sys.version_info >= (3, 0)
|
||||
py3k = sys.version_info >= (3, 0)
|
||||
py2k = sys.version_info < (3, 0)
|
||||
jython = sys.platform.startswith('java')
|
||||
pypy = hasattr(sys, 'pypy_version_info')
|
||||
win32 = sys.platform.startswith('win')
|
||||
cpython = not pypy and not jython # TODO: something better for this ?
|
||||
|
||||
if py3k_warning:
|
||||
set_types = set
|
||||
elif sys.version_info < (2, 6):
|
||||
import sets
|
||||
set_types = set, sets.Set
|
||||
else:
|
||||
# 2.6 deprecates sets.Set, but we still need to be able to detect them
|
||||
# in user code and as return values from DB-APIs
|
||||
ignore = ('ignore', None, DeprecationWarning, None, 0)
|
||||
import warnings
|
||||
try:
|
||||
warnings.filters.insert(0, ignore)
|
||||
except Exception:
|
||||
import sets
|
||||
else:
|
||||
import sets
|
||||
warnings.filters.remove(ignore)
|
||||
import collections
|
||||
next = next
|
||||
|
||||
set_types = set, sets.Set
|
||||
|
||||
if sys.version_info < (2, 6):
|
||||
def next(iter):
|
||||
return iter.next()
|
||||
else:
|
||||
next = next
|
||||
if py3k_warning:
|
||||
if py3k:
|
||||
import pickle
|
||||
else:
|
||||
try:
|
||||
@@ -54,146 +33,121 @@ else:
|
||||
except ImportError:
|
||||
import pickle
|
||||
|
||||
# a controversial feature, required by MySQLdb currently
|
||||
def buffer(x):
|
||||
return x
|
||||
ArgSpec = collections.namedtuple("ArgSpec",
|
||||
["args", "varargs", "keywords", "defaults"])
|
||||
|
||||
# Py2K
|
||||
buffer = buffer
|
||||
# end Py2K
|
||||
if py3k:
|
||||
import builtins
|
||||
|
||||
try:
|
||||
from contextlib import contextmanager
|
||||
except ImportError:
|
||||
def contextmanager(fn):
|
||||
return fn
|
||||
from inspect import getfullargspec as inspect_getfullargspec
|
||||
from urllib.parse import quote_plus, unquote_plus, parse_qsl, quote, unquote
|
||||
import configparser
|
||||
from io import StringIO
|
||||
|
||||
try:
|
||||
from functools import update_wrapper
|
||||
except ImportError:
|
||||
def update_wrapper(wrapper, wrapped,
|
||||
assigned=('__doc__', '__module__', '__name__'),
|
||||
updated=('__dict__',)):
|
||||
for attr in assigned:
|
||||
setattr(wrapper, attr, getattr(wrapped, attr))
|
||||
for attr in updated:
|
||||
getattr(wrapper, attr).update(getattr(wrapped, attr, ()))
|
||||
return wrapper
|
||||
from io import BytesIO as byte_buffer
|
||||
|
||||
try:
|
||||
from functools import partial
|
||||
except ImportError:
|
||||
def partial(func, *args, **keywords):
|
||||
def newfunc(*fargs, **fkeywords):
|
||||
newkeywords = keywords.copy()
|
||||
newkeywords.update(fkeywords)
|
||||
return func(*(args + fargs), **newkeywords)
|
||||
return newfunc
|
||||
def inspect_getargspec(func):
|
||||
return ArgSpec(
|
||||
*inspect_getfullargspec(func)[0:4]
|
||||
)
|
||||
|
||||
string_types = str,
|
||||
binary_type = bytes
|
||||
text_type = str
|
||||
int_types = int,
|
||||
iterbytes = iter
|
||||
|
||||
if sys.version_info < (2, 6):
|
||||
# emits a nasty deprecation warning
|
||||
# in newer pythons
|
||||
from cgi import parse_qsl
|
||||
else:
|
||||
from urlparse import parse_qsl
|
||||
def u(s):
|
||||
return s
|
||||
|
||||
# Py3K
|
||||
#from inspect import getfullargspec as inspect_getfullargspec
|
||||
# Py2K
|
||||
from inspect import getargspec as inspect_getfullargspec
|
||||
# end Py2K
|
||||
def ue(s):
|
||||
return s
|
||||
|
||||
def b(s):
|
||||
return s.encode("latin-1")
|
||||
|
||||
if py32:
|
||||
callable = callable
|
||||
else:
|
||||
def callable(fn):
|
||||
return hasattr(fn, '__call__')
|
||||
|
||||
if py3k_warning:
|
||||
# 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)
|
||||
|
||||
from functools import reduce
|
||||
|
||||
print_ = getattr(builtins, "print")
|
||||
|
||||
import_ = getattr(builtins, '__import__')
|
||||
|
||||
import itertools
|
||||
itertools_filterfalse = itertools.filterfalse
|
||||
itertools_filter = filter
|
||||
itertools_imap = map
|
||||
|
||||
import base64
|
||||
def b64encode(x):
|
||||
return base64.b64encode(x).decode('ascii')
|
||||
def b64decode(x):
|
||||
return base64.b64decode(x.encode('ascii'))
|
||||
|
||||
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
|
||||
|
||||
string_types = basestring,
|
||||
binary_type = str
|
||||
text_type = unicode
|
||||
int_types = int, long
|
||||
def iterbytes(buf):
|
||||
return (ord(byte) for byte in buf)
|
||||
|
||||
def u(s):
|
||||
# this differs from what six does, which doesn't support non-ASCII
|
||||
# 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")
|
||||
|
||||
def ue(s):
|
||||
return unicode(s, "unicode_escape")
|
||||
|
||||
def b(s):
|
||||
return s
|
||||
|
||||
def import_(*args):
|
||||
if len(args) == 4:
|
||||
args = args[0:3] + ([str(arg) for arg in args[3]],)
|
||||
return __import__(*args)
|
||||
|
||||
callable = callable
|
||||
cmp = cmp
|
||||
reduce = reduce
|
||||
|
||||
try:
|
||||
from collections import defaultdict
|
||||
except ImportError:
|
||||
class defaultdict(dict):
|
||||
def __init__(self, default_factory=None, *a, **kw):
|
||||
if (default_factory is not None and
|
||||
not hasattr(default_factory, '__call__')):
|
||||
raise TypeError('first argument must be callable')
|
||||
dict.__init__(self, *a, **kw)
|
||||
self.default_factory = default_factory
|
||||
def __getitem__(self, key):
|
||||
try:
|
||||
return dict.__getitem__(self, key)
|
||||
except KeyError:
|
||||
return self.__missing__(key)
|
||||
def __missing__(self, key):
|
||||
if self.default_factory is None:
|
||||
raise KeyError(key)
|
||||
self[key] = value = self.default_factory()
|
||||
return value
|
||||
def __reduce__(self):
|
||||
if self.default_factory is None:
|
||||
args = tuple()
|
||||
else:
|
||||
args = self.default_factory,
|
||||
return type(self), args, None, None, self.iteritems()
|
||||
def copy(self):
|
||||
return self.__copy__()
|
||||
def __copy__(self):
|
||||
return type(self)(self.default_factory, self)
|
||||
def __deepcopy__(self, memo):
|
||||
import copy
|
||||
return type(self)(self.default_factory,
|
||||
copy.deepcopy(self.items()))
|
||||
def __repr__(self):
|
||||
return 'defaultdict(%s, %s)' % (self.default_factory,
|
||||
dict.__repr__(self))
|
||||
import base64
|
||||
b64encode = base64.b64encode
|
||||
b64decode = base64.b64decode
|
||||
|
||||
def print_(*args, **kwargs):
|
||||
fp = kwargs.pop("file", sys.stdout)
|
||||
if fp is None:
|
||||
return
|
||||
for arg in enumerate(args):
|
||||
if not isinstance(arg, basestring):
|
||||
arg = str(arg)
|
||||
fp.write(arg)
|
||||
|
||||
# find or create a dict implementation that supports __missing__
|
||||
class _probe(dict):
|
||||
def __missing__(self, key):
|
||||
return 1
|
||||
import itertools
|
||||
itertools_filterfalse = itertools.ifilterfalse
|
||||
itertools_filter = itertools.ifilter
|
||||
itertools_imap = itertools.imap
|
||||
|
||||
try:
|
||||
try:
|
||||
_probe()['missing']
|
||||
py25_dict = dict
|
||||
except KeyError:
|
||||
class py25_dict(dict):
|
||||
def __getitem__(self, key):
|
||||
try:
|
||||
return dict.__getitem__(self, key)
|
||||
except KeyError:
|
||||
try:
|
||||
missing = self.__missing__
|
||||
except AttributeError:
|
||||
raise KeyError(key)
|
||||
else:
|
||||
return missing(key)
|
||||
finally:
|
||||
del _probe
|
||||
|
||||
|
||||
try:
|
||||
import hashlib
|
||||
_md5 = hashlib.md5
|
||||
except ImportError:
|
||||
import md5
|
||||
_md5 = md5.new
|
||||
|
||||
def md5_hex(x):
|
||||
# Py3K
|
||||
#x = x.encode('utf-8')
|
||||
m = _md5()
|
||||
m.update(x)
|
||||
return m.hexdigest()
|
||||
|
||||
import time
|
||||
if win32 or jython:
|
||||
@@ -201,43 +155,61 @@ if win32 or jython:
|
||||
else:
|
||||
time_func = time.time
|
||||
|
||||
if sys.version_info >= (2, 5):
|
||||
any = any
|
||||
from collections import namedtuple
|
||||
from operator import attrgetter as dottedgetter
|
||||
|
||||
|
||||
if py3k:
|
||||
def reraise(tp, value, tb=None, cause=None):
|
||||
if cause is not None:
|
||||
value.__cause__ = cause
|
||||
if value.__traceback__ is not tb:
|
||||
raise value.with_traceback(tb)
|
||||
raise value
|
||||
|
||||
def raise_from_cause(exception, exc_info=None):
|
||||
if exc_info is None:
|
||||
exc_info = sys.exc_info()
|
||||
exc_type, exc_value, exc_tb = exc_info
|
||||
reraise(type(exception), exception, tb=exc_tb, cause=exc_value)
|
||||
else:
|
||||
def any(iterator):
|
||||
for item in iterator:
|
||||
if bool(item):
|
||||
return True
|
||||
exec("def reraise(tp, value, tb=None, cause=None):\n"
|
||||
" raise tp, value, tb\n")
|
||||
|
||||
def raise_from_cause(exception, exc_info=None):
|
||||
# not as nice as that of Py3K, but at least preserves
|
||||
# the code line where the issue occurred
|
||||
if exc_info is None:
|
||||
exc_info = sys.exc_info()
|
||||
exc_type, exc_value, exc_tb = exc_info
|
||||
reraise(type(exception), exception, tb=exc_tb)
|
||||
|
||||
if py3k:
|
||||
exec_ = getattr(builtins, 'exec')
|
||||
else:
|
||||
def exec_(func_text, globals_, lcl=None):
|
||||
if lcl is None:
|
||||
exec('exec func_text in globals_')
|
||||
else:
|
||||
return False
|
||||
|
||||
if sys.version_info >= (2, 5):
|
||||
def decode_slice(slc):
|
||||
"""decode a slice object as sent to __getitem__.
|
||||
|
||||
takes into account the 2.5 __index__() method, basically.
|
||||
|
||||
"""
|
||||
ret = []
|
||||
for x in slc.start, slc.stop, slc.step:
|
||||
if hasattr(x, '__index__'):
|
||||
x = x.__index__()
|
||||
ret.append(x)
|
||||
return tuple(ret)
|
||||
else:
|
||||
def decode_slice(slc):
|
||||
return (slc.start, slc.stop, slc.step)
|
||||
|
||||
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
|
||||
exec('exec func_text in globals_, lcl')
|
||||
|
||||
|
||||
import decimal
|
||||
def with_metaclass(meta, *bases):
|
||||
"""Create a base class with a metaclass.
|
||||
|
||||
Drops the middle class upon creation.
|
||||
|
||||
Source: http://lucumr.pocoo.org/2013/5/21/porting-to-python-3-redux/
|
||||
|
||||
"""
|
||||
|
||||
class metaclass(meta):
|
||||
__call__ = type.__call__
|
||||
__init__ = type.__init__
|
||||
def __new__(cls, name, this_bases, d):
|
||||
if this_bases is None:
|
||||
return type.__new__(cls, name, (), d)
|
||||
return meta(name, bases, d)
|
||||
return metaclass('temporary_class', None, {})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user