summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/util
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-04-27 20:38:53 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-04-27 20:38:53 -0400
commitc926f0a9d8910c67554f053ed0f7902542679f0d (patch)
tree85db2c4de6f43e4eee491b58b60e233b6b20a16e /lib/sqlalchemy/util
parent2709ae46884f405d95dc16be0667a6cbbebcfb69 (diff)
downloadsqlalchemy-c926f0a9d8910c67554f053ed0f7902542679f0d.tar.gz
plugging away
Diffstat (limited to 'lib/sqlalchemy/util')
-rw-r--r--lib/sqlalchemy/util/__init__.py5
-rw-r--r--lib/sqlalchemy/util/compat.py41
-rw-r--r--lib/sqlalchemy/util/langhelpers.py40
3 files changed, 40 insertions, 46 deletions
diff --git a/lib/sqlalchemy/util/__init__.py b/lib/sqlalchemy/util/__init__.py
index 2fcfabefd..9e562402d 100644
--- a/lib/sqlalchemy/util/__init__.py
+++ b/lib/sqlalchemy/util/__init__.py
@@ -5,9 +5,10 @@
# the MIT License: http://www.opensource.org/licenses/mit-license.php
from .compat import callable, cmp, reduce, \
- threading, py3k, py3k_warning, jython, pypy, cpython, win32, set_types, \
+ threading, py3k, py2k, jython, pypy, cpython, win32, \
pickle, dottedgetter, parse_qsl, namedtuple, next, WeakSet, reraise, \
- raise_from_cause, text_type, string_type, binary_type, quote_plus
+ raise_from_cause, text_type, string_types, int_types, binary_type, \
+ quote_plus, with_metaclass
from ._collections import KeyedTuple, ImmutableContainer, immutabledict, \
Properties, OrderedProperties, ImmutableProperties, OrderedDict, \
diff --git a/lib/sqlalchemy/util/compat.py b/lib/sqlalchemy/util/compat.py
index d00e3ab23..5042d505b 100644
--- a/lib/sqlalchemy/util/compat.py
+++ b/lib/sqlalchemy/util/compat.py
@@ -14,29 +14,13 @@ except ImportError:
import dummy_threading as threading
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 = not py3k
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:
- set_types = 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)
-
- set_types = set, sets.Set
if sys.version_info < (2, 6):
def next(iter):
@@ -51,23 +35,28 @@ else:
except ImportError:
import pickle
-from urllib.parse import parse_qsl
if py3k:
from inspect import getfullargspec as inspect_getfullargspec
- from urllib.parse import quote_plus, unquote_plus
+ from urllib.parse import quote_plus, unquote_plus, parse_qsl
string_types = str,
binary_type = bytes
text_type = str
+ int_types = int,
+ iterbytes = iter
else:
from inspect import getargspec as inspect_getfullargspec
from urllib import quote_plus, unquote_plus
+ from urlparse import parse_qsl
string_types = basestring,
binary_type = str
text_type = unicode
+ int_types = int, long
+ def iterbytes(buf):
+ return (ord(byte) for byte in buf)
-if py3k_warning:
+if py3k:
# they're bringing it back in 3.2. brilliant !
def callable(fn):
return hasattr(fn, '__call__')
@@ -149,19 +138,25 @@ if py3k:
raise value.with_traceback(tb)
raise value
- def raise_from_cause(exception, exc_info):
+ 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:
exec("def reraise(tp, value, tb=None, cause=None):\n"
" raise tp, value, tb\n")
- def raise_from_cause(exception, exc_info):
+ 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)
+def with_metaclass(meta, *bases):
+ """Create a base class with a metaclass."""
-
+ return meta("MetaBase", bases, {})
diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py
index 26dd97549..f65803dc6 100644
--- a/lib/sqlalchemy/util/langhelpers.py
+++ b/lib/sqlalchemy/util/langhelpers.py
@@ -15,8 +15,8 @@ import re
import sys
import types
import warnings
-from .compat import set_types, threading, \
- callable, inspect_getfullargspec
+from .compat import threading, \
+ callable, inspect_getfullargspec, py3k
from functools import update_wrapper
from .. import exc
import hashlib
@@ -265,23 +265,21 @@ def format_argspec_plus(fn, grouped=True):
else:
self_arg = None
-# start Py3K
- apply_pos = inspect.formatargspec(spec[0], spec[1],
- spec[2], None, spec[4])
- num_defaults = 0
- if spec[3]:
- num_defaults += len(spec[3])
- if spec[4]:
- num_defaults += len(spec[4])
- name_args = spec[0] + spec[4]
-# end Py3K
-# start Py2K
-# apply_pos = inspect.formatargspec(spec[0], spec[1], spec[2])
-# num_defaults = 0
-# if spec[3]:
-# num_defaults += len(spec[3])
-# name_args = spec[0]
-# end Py2K
+ if py3k:
+ apply_pos = inspect.formatargspec(spec[0], spec[1],
+ spec[2], None, spec[4])
+ num_defaults = 0
+ if spec[3]:
+ num_defaults += len(spec[3])
+ if spec[4]:
+ num_defaults += len(spec[4])
+ name_args = spec[0] + spec[4]
+ else:
+ apply_pos = inspect.formatargspec(spec[0], spec[1], spec[2])
+ num_defaults = 0
+ if spec[3]:
+ num_defaults += len(spec[3])
+ name_args = spec[0]
if num_defaults:
defaulted_vals = name_args[0 - num_defaults:]
@@ -842,7 +840,7 @@ def duck_type_collection(specimen, default=None):
if hasattr(specimen, '__emulates__'):
# canonicalize set vs sets.Set to a standard: the builtin set
if (specimen.__emulates__ is not None and
- issubclass(specimen.__emulates__, set_types)):
+ issubclass(specimen.__emulates__, set)):
return set
else:
return specimen.__emulates__
@@ -850,7 +848,7 @@ def duck_type_collection(specimen, default=None):
isa = isinstance(specimen, type) and issubclass or isinstance
if isa(specimen, list):
return list
- elif isa(specimen, set_types):
+ elif isa(specimen, set):
return set
elif isa(specimen, dict):
return dict