From: Mike Bayer Date: Wed, 4 Oct 2006 00:00:22 +0000 (+0000) Subject: various cleanup etc. X-Git-Tag: rel_0_3_0~87 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4c23534039e6c325c22475d8271cc8b621c3a936;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git various cleanup etc. --- diff --git a/CHANGES b/CHANGES index 0f6ca8a04d..9b2d2af550 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,4 @@ -0.2.9 +0.3.0 - General: - logging is now implemented via standard python "logging" module. "echo" keyword parameters are still functional but set/unset @@ -6,7 +6,7 @@ can be controlled directly through the Python API by setting INFO and DEBUG levels for loggers in the "sqlalchemy" namespace. class-level logging is under "sqlalchemy..", - instance-level logging under "sqlalchemy...". + instance-level logging under "sqlalchemy...0x..<00-FF>". Test suite includes "--log-info" and "--log-debug" arguments which work independently of --verbose/--quiet. Logging added to orm to allow tracking of mapper configurations, row iteration. @@ -75,10 +75,11 @@ ColumnProperty and PropertyLoader define their loading behaivor via switchable "strategies", and MapperOptions no longer use mapper/property copying in order to function; they are instead propigated via QueryContext - and SelectionContext objects at query/instnaces time. - All of the copying of mappers and properties that was used to handle + and SelectionContext objects at query/instances time. + All of the internal copying of mappers and properties that was used to handle inheritance as well as options() has been removed; the structure - of mappers and properties is simpler than before and clearly laid out. + of mappers and properties is much simpler than before and is clearly laid out + in the new 'interfaces' module. - related to the mapper/property overhaul, internal refactoring to mapper instances() method to use a SelectionContext object to track state during the operation. diff --git a/doc/build/compile_docstrings.py b/doc/build/compile_docstrings.py index 528da388a8..59909d8f26 100644 --- a/doc/build/compile_docstrings.py +++ b/doc/build/compile_docstrings.py @@ -21,12 +21,10 @@ objects = [] def make_doc(obj, classes=None, functions=None): objects.append(docstring.ObjectDoc(obj, classes=classes, functions=functions)) -make_doc(obj=sql, classes=[sql.Engine, sql.AbstractDialect, sql.ClauseParameters, sql.Compiled, sql.ClauseElement, sql.TableClause, sql.ColumnClause]) +make_doc(obj=sql, classes=[]) make_doc(obj=schema) make_doc(obj=engine, classes=[engine.Connectable, engine.ComposedSQLEngine, engine.Connection, engine.Transaction, engine.Dialect, engine.ConnectionProvider, engine.ExecutionContext, engine.ResultProxy, engine.RowProxy]) -make_doc(obj=strategies) -make_doc(obj=orm, classes=[orm.Mapper, orm.MapperExtension, orm.SelectionContext]) -make_doc(obj=orm.query, classes=[orm.query.Query]) +make_doc(obj=orm) make_doc(obj=orm.session, classes=[orm.session.Session, orm.session.SessionTransaction]) make_doc(obj=pool, classes=[pool.DBProxy, pool.Pool, pool.QueuePool, pool.SingletonThreadPool]) make_doc(obj=sessioncontext) diff --git a/doc/build/content/plugins.txt b/doc/build/content/plugins.txt index 31dc8c43b4..565a3aea01 100644 --- a/doc/build/content/plugins.txt +++ b/doc/build/content/plugins.txt @@ -7,7 +7,7 @@ SQLAlchemy has a variety of extensions and "mods" available which provide extra **Author:** Daniel Miller -This plugin is used to instantiate and manage Session objects. It provides several services: +This plugin is used to instantiate and manage Session objects. As of SQLAlchemy 0.2 it is the preferred way to provide thread-local session functionality to an application. It provides several services: * serves as a factory to create sessions of a particular configuration. This factory may either call `create_session()` with a particular set of arguments, or instantiate a different implementation of `Session` if one is available. * for the `Session` objects it creates, provides the ability to maintain a single `Session` per distinct application thread. The `Session` returned by a `SessionContext` is called the *contextual session.* Providing at least a thread-local context to sessions is important because the `Session` object is not threadsafe, and is intended to be used with localized sets of data, as opposed to a single session being used application wide. diff --git a/lib/sqlalchemy/attributes.py b/lib/sqlalchemy/attributes.py index 7628aa0980..388c10bcee 100644 --- a/lib/sqlalchemy/attributes.py +++ b/lib/sqlalchemy/attributes.py @@ -675,7 +675,6 @@ class AttributeManager(object): the callable will only be executed if the given 'passive' flag is False. """ attr = getattr(obj.__class__, key) - print "ATTR IS A", attr, "OBJ IS A", obj x = attr.get(obj, passive=passive) if x is InstrumentedAttribute.PASSIVE_NORESULT: return [] diff --git a/lib/sqlalchemy/orm/__init__.py b/lib/sqlalchemy/orm/__init__.py index b00151e943..7339d0fabf 100644 --- a/lib/sqlalchemy/orm/__init__.py +++ b/lib/sqlalchemy/orm/__init__.py @@ -11,6 +11,7 @@ packages and tying operations to class properties and constructors. from sqlalchemy import sql, schema, engine, util, exceptions from mapper import * from mapper import mapper_registry +import mapper as mapperlib from query import Query from util import polymorphic_union import properties, strategies @@ -36,35 +37,35 @@ def backref(name, **kwargs): return properties.BackRef(name, **kwargs) def deferred(*columns, **kwargs): - """returns a DeferredColumnProperty, which indicates this object attributes should only be loaded + """return a DeferredColumnProperty, which indicates this object attributes should only be loaded from its corresponding table column when first accessed.""" return properties.ColumnProperty(deferred=True, *columns, **kwargs) def mapper(class_, table=None, *args, **params): - """returns a newMapper object.""" + """return a new Mapper object.""" return Mapper(class_, table, *args, **params) def synonym(name): return SynonymProperty(name) def clear_mappers(): - """removes all mappers that have been created thus far. when new mappers are + """remove all mappers that have been created thus far. when new mappers are created, they will be assigned to their classes as their primary mapper.""" mapper_registry.clear() def clear_mapper(m): - """removes the given mapper from the storage of mappers. when a new mapper is + """remove the given mapper from the storage of mappers. when a new mapper is created for the previous mapper's class, it will be used as that classes' new primary mapper.""" del mapper_registry[m.hash_key] def eagerload(name): - """returns a MapperOption that will convert the property of the given name + """return a MapperOption that will convert the property of the given name into an eager load.""" return strategies.EagerLazyOption(name, lazy=False) def lazyload(name): - """returns a MapperOption that will convert the property of the given name + """return a MapperOption that will convert the property of the given name into a lazy load""" return strategies.EagerLazyOption(name, lazy=True) diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py index abca41ed63..ed48d40cf1 100644 --- a/lib/sqlalchemy/orm/interfaces.py +++ b/lib/sqlalchemy/orm/interfaces.py @@ -127,12 +127,15 @@ class StrategizedOption(MapperOption): class LoaderStrategy(object): """describes the loading behavior of a StrategizedProperty object. The LoaderStrategy interacts with the querying process in three ways: + * it controls the configuration of the InstrumentedAttribute placed on a class to handle the behavior of the attribute. this may involve setting up class-level callable functions to fire off a select operation when the attribute is first accessed (i.e. a lazy load) + * it processes the QueryContext at statement construction time, where it can modify the SQL statement that is being produced. simple column attributes may add their represented column to the list of selected columns, "eager loading" properties may add LEFT OUTER JOIN clauses to the statement. + * it processes the SelectionContext at row-processing time. This may involve setting instance-level lazyloader functions on newly constructed instances, or may involve recursively appending child items to a list in response to additionally eager-loaded objects in the query. diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index cdfff2de6e..b60d9c0342 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -1188,15 +1188,6 @@ class SelectionContext(OperationContext): self.identity_map = {} super(SelectionContext, self).__init__(mapper, kwargs.pop('with_options', []), **kwargs) - -class ExtensionOption(MapperOption): - """adds a new MapperExtension to a mapper's chain of extensions""" - def __init__(self, ext): - self.ext = ext - def process(self, mapper): - self.ext.next = mapper.extension - mapper.extension = self.ext - class MapperExtension(object): """base implementation for an object that provides overriding behavior to various Mapper functions. For each method in MapperExtension, a result of EXT_PASS indicates @@ -1336,16 +1327,6 @@ class ClassKey(object): def __repr__(self): return "ClassKey(%s, %s)" % (repr(self.class_), repr(self.entity_name)) -def hash_key(obj): - if obj is None: - return 'None' - elif isinstance(obj, list): - return repr([hash_key(o) for o in obj]) - elif hasattr(obj, 'hash_key'): - return obj.hash_key() - else: - return repr(obj) - def has_identity(object): return hasattr(object, '_instance_key')