]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
most folks dont put "./lib/" in their PYTHONPATH. so replace with the same approach...
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 30 Jan 2009 15:38:09 +0000 (15:38 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 30 Jan 2009 15:38:09 +0000 (15:38 +0000)
test/testlib/compat.py

index 6e1f7605483c9b804b86028beebb68db0c4474dc..a0226869c20db2575bcb6cabade0b1e373aeb5b7 100644 (file)
@@ -1,5 +1,26 @@
+import sys, types, __builtin__
 
 __all__ = '_function_named', 'callable'
 
-from sqlalchemy.util import callable, function_named as _function_named
+py3k = getattr(sys, 'py3kwarning', False) or sys.version_info >= (3, 0)
+
+def _function_named(fn, name):
+    """Return a function with a given __name__.
+
+    Will assign to __name__ and return the original function if possible on
+    the Python implementation, otherwise a new function will be constructed.
+
+    """
+    try:
+        fn.__name__ = name
+    except TypeError:
+        fn = types.FunctionType(fn.func_code, fn.func_globals, name,
+                          fn.func_defaults, fn.func_closure)
+    return fn
+
+if py3k:
+    def callable(fn):
+        return hasattr(fn, '__call__')
+else:
+    callable = __builtin__.callable