summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/util/langhelpers.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-03-30 12:30:54 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2011-03-30 12:30:54 -0400
commit218c3cb365e7354a312bc3e24e1cb21a2487459c (patch)
tree0a96a04800026db85839eb04fae51907aa1c2783 /lib/sqlalchemy/util/langhelpers.py
parent90aa366fb3731892fd75455c81cdcc9e11268130 (diff)
downloadsqlalchemy-218c3cb365e7354a312bc3e24e1cb21a2487459c.tar.gz
- AssertionPool now stores the traceback indicating
where the currently checked out connection was acquired; this traceback is reported within the assertion raised upon a second concurrent checkout; courtesy Gunnlaugur Briem [ticket:2103]
Diffstat (limited to 'lib/sqlalchemy/util/langhelpers.py')
-rw-r--r--lib/sqlalchemy/util/langhelpers.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py
index 64997706c..cbe0d2a4f 100644
--- a/lib/sqlalchemy/util/langhelpers.py
+++ b/lib/sqlalchemy/util/langhelpers.py
@@ -11,6 +11,7 @@ modules, classes, hierarchies, attributes, functions, and methods.
import itertools
import inspect
import operator
+import re
import sys
import types
import warnings
@@ -757,4 +758,26 @@ def warn(msg, stacklevel=3):
else:
warnings.warn(msg, stacklevel=stacklevel)
+_SQLA_RE = re.compile(r'sqlalchemy/([a-z_]+/){0,2}[a-z_]+\.py')
+_UNITTEST_RE = re.compile(r'unit(?:2|test2?/)')
+def chop_traceback(tb, exclude_prefix=_UNITTEST_RE, exclude_suffix=_SQLA_RE):
+ """Chop extraneous lines off beginning and end of a traceback.
+
+ :param tb:
+ a list of traceback lines as returned by ``traceback.format_stack()``
+
+ :param exclude_prefix:
+ a regular expression object matching lines to skip at beginning of ``tb``
+
+ :param exclude_suffix:
+ a regular expression object matching lines to skip at end of ``tb``
+ """
+ start = 0
+ end = len(tb) - 1
+ while start <= end and exclude_prefix.search(tb[start]):
+ start += 1
+ while start <= end and exclude_suffix.search(tb[end]):
+ end -= 1
+ return tb[start:end+1]
+
NoneType = type(None)