diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-08-27 20:17:37 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-08-27 20:17:37 -0400 |
commit | 63c1800c568824b6828ac791f83fd2bf7626adcc (patch) | |
tree | fe1e8dd2643b3eea3ab0700fdcd28a1abeee82fd /lib/sqlalchemy/engine/base.py | |
parent | dc31eb352aed6b578b7cf0bbc0d4290b6d11f2b2 (diff) | |
download | sqlalchemy-63c1800c568824b6828ac791f83fd2bf7626adcc.tar.gz |
- its probably worthwhile to make the primary listen() interface humane, i.e.:
def listen(target, args)
so here we provide a "wrapper" approach that allows this, and it is
basically pass-by-value. a pass-by-value event *may* support rewriting
some of the args in the dictionary.
the current
listen will become "listen_raw" since it saves about 100% overhead versus
the coercion to dict, and will be used internally, and will remain
pass-by-reference.
proxyconnection probably will rely upon the newer style of pass-by-value
for "rewrite the args" types of calls.
Diffstat (limited to 'lib/sqlalchemy/engine/base.py')
-rw-r--r-- | lib/sqlalchemy/engine/base.py | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index dbba2b62f..4843d02da 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -1557,43 +1557,47 @@ class EngineEvents(event.Events): target.dispatch) event.Events.listen(fn, identifier, target) + @classmethod + def unwrap(cls, identifier, args): + return args + def on_execute(self, conn, execute, clauseelement, *multiparams, **params): """Intercept high level execute() events.""" - + def on_cursor_execute(self, conn, execute, cursor, statement, parameters, context, executemany): """Intercept low-level cursor execute() events.""" def on_begin(self, conn, begin): """Intercept begin() events.""" - + def on_rollback(self, conn, rollback): """Intercept rollback() events.""" - + def on_commit(self, conn, commit): """Intercept commit() events.""" - + def on_savepoint(self, conn, savepoint, name=None): """Intercept savepoint() events.""" - + def on_rollback_savepoint(self, conn, rollback_savepoint, name, context): """Intercept rollback_savepoint() events.""" - + def on_release_savepoint(self, conn, release_savepoint, name, context): """Intercept release_savepoint() events.""" - + def on_begin_twophase(self, conn, begin_twophase, xid): """Intercept begin_twophase() events.""" - + def on_prepare_twophase(self, conn, prepare_twophase, xid): """Intercept prepare_twophase() events.""" - + def on_rollback_twophase(self, conn, rollback_twophase, xid, is_prepared): """Intercept rollback_twophase() events.""" - + def on_commit_twophase(self, conn, commit_twophase, xid, is_prepared): """Intercept commit_twophase() events.""" - + class Engine(Connectable, log.Identified): """ Connects a :class:`~sqlalchemy.pool.Pool` and @@ -1846,18 +1850,27 @@ class Engine(Connectable, log.Identified): return self.pool.unique_connection() def _proxy_connection_cls(cls, dispatch): + # TODO: this is insane. + # consider some different method of + # event propagation / control, possibly + # requiring the (target, args) style of calling. + # arguments can simply be modified within the "args" + # dictionary. + + # perhaps: +# def execute(self, clauseelement, *multiparams, **params): +# for fn in dispatch.on_execute: +# ret = fn(clauseelement, multiparams, params) +# if ret: +# clauseelement, multiparams, params = \ +# ret['clauseelment'], ret['multiparams'], ret['params'] + def _exec_recursive(conn, fns, orig): if not fns: return orig def go(*arg, **kw): nested = _exec_recursive(conn, fns[1:], orig) ret = fns[0](conn, nested, *arg, **kw) - # TODO: need to get consistent way to check - # for "they called the fn, they didn't", or otherwise - # make some decision here how this is to work - #if ret is None: - # return nested(*arg, **kw) - #else: return ret return go |