summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/util.py
diff options
context:
space:
mode:
authorJason Kirtland <jek@discorporate.us>2008-04-02 11:39:26 +0000
committerJason Kirtland <jek@discorporate.us>2008-04-02 11:39:26 +0000
commitf12969a4d8dd8a4f91a9da4cc9d855457a5a0060 (patch)
tree274125cdcd73dbcea79575b7a82810032ae0be36 /lib/sqlalchemy/util.py
parenta0000075437370ae23d0db48c706a4237f4e43f3 (diff)
downloadsqlalchemy-f12969a4d8dd8a4f91a9da4cc9d855457a5a0060.tar.gz
- Revamped the Connection memoize decorator a bit, moved to engine
- MySQL character set caching is more aggressive but will invalidate the cache if a SET is issued. - MySQL connection memos are namespaced: info[('mysql', 'server_variable')]
Diffstat (limited to 'lib/sqlalchemy/util.py')
-rw-r--r--lib/sqlalchemy/util.py26
1 files changed, 19 insertions, 7 deletions
diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py
index 26b6dbe9a..101ef1462 100644
--- a/lib/sqlalchemy/util.py
+++ b/lib/sqlalchemy/util.py
@@ -4,7 +4,7 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-import inspect, itertools, sets, sys, warnings, weakref
+import inspect, itertools, new, sets, sys, warnings, weakref
import __builtin__
types = __import__('types')
@@ -1055,7 +1055,22 @@ class symbol(object):
return sym
finally:
symbol._lock.release()
-
+
+
+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 = new.function(fn.func_code, fn.func_globals, name,
+ fn.func_defaults, fn.func_closure)
+ return fn
+
def conditional_cache_decorator(func):
"""apply conditional caching to the return value of a function."""
@@ -1166,8 +1181,5 @@ def _decorate_with_warning(func, wtype, message, docstring_header=None):
func_with_warning.__doc__ = doc
func_with_warning.__dict__.update(func.__dict__)
- try:
- func_with_warning.__name__ = func.__name__
- except TypeError:
- pass
- return func_with_warning
+
+ return function_named(func_with_warning, func.__name__)