summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/sqlalchemy/orm/sessionmaker.py28
1 files changed, 13 insertions, 15 deletions
diff --git a/lib/sqlalchemy/orm/sessionmaker.py b/lib/sqlalchemy/orm/sessionmaker.py
index adf80f9a7..13e28fd1a 100644
--- a/lib/sqlalchemy/orm/sessionmaker.py
+++ b/lib/sqlalchemy/orm/sessionmaker.py
@@ -66,20 +66,8 @@ def sessionmaker(autoflush, transactional, bind=None, scope=None, enhance_classe
default_scope=scope
- class ScopedProps(type):
- pass
- def makeprop(name):
- def set(self, attr):
- setattr(registry(), name, attr)
- def get(self):
- return getattr(registry(), name)
- return property(get, set)
- for prop in ('bind', 'dirty', 'identity_map'):
- setattr(ScopedProps, prop, makeprop(prop))
-
class ScopedSess(Sess):
- __metaclass__ = ScopedProps
- def __new__(cls, **kwargs):
+ def __call__(self, **kwargs):
if len(kwargs):
scope = kwargs.pop('scope', default_scope)
if scope is not None:
@@ -93,14 +81,24 @@ def sessionmaker(autoflush, transactional, bind=None, scope=None, enhance_classe
return Sess(**kwargs)
else:
return registry()
+
def instrument(name):
def do(cls, *args, **kwargs):
return getattr(registry(), name)(*args, **kwargs)
- return classmethod(do)
+ return do
for meth in ('get', 'close', 'save', 'commit', 'update', 'flush', 'query', 'delete'):
setattr(ScopedSess, meth, instrument(meth))
- return ScopedSess
+ def makeprop(name):
+ def set(self, attr):
+ setattr(registry(), name, attr)
+ def get(self):
+ return getattr(registry(), name)
+ return property(get, set)
+ for prop in ('bind', 'dirty', 'identity_map'):
+ setattr(ScopedSess, prop, makeprop(prop))
+
+ return ScopedSess()
elif scope is not None:
raise exceptions.ArgumentError("Unknown scope '%s'" % scope)
else: