diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-11-10 19:00:28 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-11-10 19:00:28 -0500 |
commit | 3564ea86e7cd982a353b42be4105a40bdf9415a3 (patch) | |
tree | b1c9369a285e6e290e70c7817869c9326db9a810 /lib/sqlalchemy/orm/scoping.py | |
parent | a9b270a3ed4faf85f772897a867caf6762ff9160 (diff) | |
download | sqlalchemy-3564ea86e7cd982a353b42be4105a40bdf9415a3.tar.gz |
- move deprecated interfaces down to bottom of TOC, update verbiage
- more docs for engine, pool, DDL events
- update DDL sequences documentation to use events
- update DDL() docstring to refer to execute_if()
- document parameters for DDLElement.execute_if()
- add retval=True flag to Engine.on_before_execute(), on_before_cursor_execute().
wrap the function if retval=False, check for appropriate usage of the flag, add
tests.
- remove ScopedSession.mapper and tests entirely
- remove ExtensionCarrier and tests
- change remaining tests that use MapperExtension to use MapperEvents
Diffstat (limited to 'lib/sqlalchemy/orm/scoping.py')
-rw-r--r-- | lib/sqlalchemy/orm/scoping.py | 86 |
1 files changed, 2 insertions, 84 deletions
diff --git a/lib/sqlalchemy/orm/scoping.py b/lib/sqlalchemy/orm/scoping.py index 140328e24..53336e5f4 100644 --- a/lib/sqlalchemy/orm/scoping.py +++ b/lib/sqlalchemy/orm/scoping.py @@ -5,12 +5,8 @@ # the MIT License: http://www.opensource.org/licenses/mit-license.php import sqlalchemy.exceptions as sa_exc -from sqlalchemy.util import ScopedRegistry, ThreadLocalRegistry, \ - to_list, get_cls_kwargs, deprecated,\ - warn -from sqlalchemy.orm import ( - EXT_CONTINUE, MapperExtension, class_mapper, object_session - ) +from sqlalchemy.util import ScopedRegistry, ThreadLocalRegistry, warn +from sqlalchemy.orm import class_mapper from sqlalchemy.orm import exc as orm_exc from sqlalchemy.orm.session import Session @@ -39,7 +35,6 @@ class ScopedSession(object): self.registry = ScopedRegistry(session_factory, scopefunc) else: self.registry = ThreadLocalRegistry(session_factory) - self.extension = _ScopedExt(self) def __call__(self, **kwargs): if kwargs: @@ -64,27 +59,6 @@ class ScopedSession(object): self.registry().close() self.registry.clear() - @deprecated("0.5", ":meth:`.ScopedSession.mapper` is deprecated. " - "Please see http://www.sqlalchemy.org/trac/wiki/UsageRecipes/SessionAwareMapper " - "for information on how to replicate its behavior.") - def mapper(self, *args, **kwargs): - """return a :func:`.mapper` function which associates this ScopedSession with the Mapper. - - """ - - from sqlalchemy.orm import mapper - - extension_args = dict((arg, kwargs.pop(arg)) - for arg in get_cls_kwargs(_ScopedExt) - if arg in kwargs) - - kwargs['extension'] = extension = to_list(kwargs.get('extension', [])) - if extension_args: - extension.append(self.extension.configure(**extension_args)) - else: - extension.append(self.extension) - return mapper(*args, **kwargs) - def configure(self, **kwargs): """reconfigure the sessionmaker used by this ScopedSession.""" @@ -157,59 +131,3 @@ def clslevel(name): for prop in ('close_all', 'object_session', 'identity_key'): setattr(ScopedSession, prop, clslevel(prop)) -class _ScopedExt(MapperExtension): - def __init__(self, context, validate=False, save_on_init=True): - self.context = context - self.validate = validate - self.save_on_init = save_on_init - self.set_kwargs_on_init = True - - def validating(self): - return _ScopedExt(self.context, validate=True) - - def configure(self, **kwargs): - return _ScopedExt(self.context, **kwargs) - - def instrument_class(self, mapper, class_): - class query(object): - def __getattr__(s, key): - return getattr(self.context.registry().query(class_), key) - def __call__(s): - return self.context.registry().query(class_) - def __get__(self, instance, cls): - return self - - if not 'query' in class_.__dict__: - class_.query = query() - - if self.set_kwargs_on_init and class_.__init__ is object.__init__: - class_.__init__ = self._default__init__(mapper) - - def _default__init__(ext, mapper): - def __init__(self, **kwargs): - for key, value in kwargs.iteritems(): - if ext.validate: - if not mapper.get_property(key, resolve_synonyms=False, - raiseerr=False): - raise sa_exc.ArgumentError( - "Invalid __init__ argument: '%s'" % key) - setattr(self, key, value) - return __init__ - - def init_instance(self, mapper, class_, oldinit, instance, args, kwargs): - if self.save_on_init: - session = kwargs.pop('_sa_session', None) - if session is None: - session = self.context.registry() - session._save_without_cascade(instance) - return EXT_CONTINUE - - def init_failed(self, mapper, class_, oldinit, instance, args, kwargs): - sess = object_session(instance) - if sess: - sess.expunge(instance) - return EXT_CONTINUE - - def dispose_class(self, mapper, class_): - if hasattr(class_, 'query'): - delattr(class_, 'query') |