From 218a7f0b03eb64472049a25e8a911c678097dc51 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 30 Jan 2009 15:38:09 +0000 Subject: [PATCH] most folks dont put "./lib/" in their PYTHONPATH. so replace with the same approach as that of util. --- test/testlib/compat.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/test/testlib/compat.py b/test/testlib/compat.py index 6e1f760548..a0226869c2 100644 --- a/test/testlib/compat.py +++ b/test/testlib/compat.py @@ -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 -- 2.47.3