diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-07-28 17:05:50 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-07-28 17:05:50 -0400 |
| commit | 22ba1c43b792953ae6f791512d276739c8c09eae (patch) | |
| tree | bdf9f639b01426a8a2e1c8c61d35533026dd4265 /examples | |
| parent | 27913554a85c308d81e6c018669d0246ceecc639 (diff) | |
| download | sqlalchemy-22ba1c43b792953ae6f791512d276739c8c09eae.tar.gz | |
-whitespace bonanza, contd
Diffstat (limited to 'examples')
31 files changed, 153 insertions, 153 deletions
diff --git a/examples/association/__init__.py b/examples/association/__init__.py index 12d2ea697..df736f4fb 100644 --- a/examples/association/__init__.py +++ b/examples/association/__init__.py @@ -6,7 +6,7 @@ classes that are associated in a many-to-many pattern. This directory includes the following examples: -* basic_association.py - illustrate a many-to-many relationship between an +* basic_association.py - illustrate a many-to-many relationship between an "Order" and a collection of "Item" objects, associating a purchase price with each via an association object called "OrderItem" * proxied_association.py - same example as basic_association, adding in diff --git a/examples/association/basic_association.py b/examples/association/basic_association.py index cd86aa504..29a473fce 100644 --- a/examples/association/basic_association.py +++ b/examples/association/basic_association.py @@ -3,7 +3,7 @@ The association object pattern is a form of many-to-many which associates additional data with each association between parent/child. -The example illustrates an "order", referencing a collection +The example illustrates an "order", referencing a collection of "items", with a particular price paid associated with each "item". """ @@ -83,7 +83,7 @@ if __name__ == '__main__': # query the order, print items order = session.query(Order).filter_by(customer_name='john smith').one() - print [(order_item.item.description, order_item.price) + print [(order_item.item.description, order_item.price) for order_item in order.order_items] # print customers who bought 'MySQL Crowbar' on sale diff --git a/examples/association/dict_of_sets_with_default.py b/examples/association/dict_of_sets_with_default.py index 0720fdab9..63c0f4531 100644 --- a/examples/association/dict_of_sets_with_default.py +++ b/examples/association/dict_of_sets_with_default.py @@ -44,7 +44,7 @@ class B(Base): key = Column(String) values = association_proxy("elements", "value") - """Bridge the association from 'elements' over to the + """Bridge the association from 'elements' over to the 'value' element of C.""" def __init__(self, key, values=None): diff --git a/examples/beaker_caching/__init__.py b/examples/beaker_caching/__init__.py index cc9f71d8b..7e7b62791 100644 --- a/examples/beaker_caching/__init__.py +++ b/examples/beaker_caching/__init__.py @@ -1,18 +1,18 @@ """ Illustrates how to embed Beaker cache functionality within the Query object, allowing full cache control as well as the -ability to pull "lazy loaded" attributes from long term cache +ability to pull "lazy loaded" attributes from long term cache as well. In this demo, the following techniques are illustrated: * Using custom subclasses of Query -* Basic technique of circumventing Query to pull from a +* Basic technique of circumventing Query to pull from a custom cache source instead of the database. * Rudimental caching with Beaker, using "regions" which allow global control over a fixed set of configurations. -* Using custom MapperOption objects to configure options on - a Query, including the ability to invoke the options +* Using custom MapperOption objects to configure options on + a Query, including the ability to invoke the options deep within an object graph when lazy loads occur. E.g.:: @@ -49,10 +49,10 @@ The demo scripts themselves, in order of complexity, are run as follows:: Listing of files: environment.py - Establish the Session, the Beaker cache - manager, data / cache file paths, and configurations, + manager, data / cache file paths, and configurations, bootstrap fixture data if necessary. - caching_query.py - Represent functions and classes + caching_query.py - Represent functions and classes which allow the usage of Beaker caching with SQLAlchemy. Introduces a query option called FromCache. diff --git a/examples/beaker_caching/advanced.py b/examples/beaker_caching/advanced.py index c16e02f33..31beeff6f 100644 --- a/examples/beaker_caching/advanced.py +++ b/examples/beaker_caching/advanced.py @@ -1,6 +1,6 @@ """advanced.py -Illustrate usage of Query combined with the FromCache option, +Illustrate usage of Query combined with the FromCache option, including front-end loading, cache invalidation, namespace techniques and collection caching. @@ -17,12 +17,12 @@ def load_name_range(start, end, invalidate=False): start/end are integers, range is then "person <start>" - "person <end>". - The cache option we set up is called "name_range", indicating + The cache option we set up is called "name_range", indicating a range of names for the Person class. The `Person.addresses` collections are also cached. Its basically another level of tuning here, as that particular cache option - can be transparently replaced with joinedload(Person.addresses). + can be transparently replaced with joinedload(Person.addresses). The effect is that each Person and his/her Address collection is cached either together or separately, affecting the kind of SQL that emits for unloaded Person objects as well as the distribution @@ -63,13 +63,13 @@ print ", ".join([p.name for p in load_name_range(2, 12)]) print "\ntwenty five through forty, invalidate first:\n" print ", ".join([p.name for p in load_name_range(25, 40, True)]) -# illustrate the address loading from either cache/already +# illustrate the address loading from either cache/already # on the Person print "\n\nPeople plus addresses, two through twelve, addresses possibly from cache" for p in load_name_range(2, 12): print p.format_full() -# illustrate the address loading from either cache/already +# illustrate the address loading from either cache/already # on the Person print "\n\nPeople plus addresses, two through twelve, addresses from cache" for p in load_name_range(2, 12): diff --git a/examples/beaker_caching/caching_query.py b/examples/beaker_caching/caching_query.py index a6a126111..ae0c9c903 100644 --- a/examples/beaker_caching/caching_query.py +++ b/examples/beaker_caching/caching_query.py @@ -11,7 +11,7 @@ The three new concepts introduced here are: parameters on a Query * RelationshipCache - a variant of FromCache which is specific to a query invoked during a lazy load. - * _params_from_query - extracts value parameters from + * _params_from_query - extracts value parameters from a Query. The rest of what's here are standard SQLAlchemy and @@ -23,30 +23,30 @@ from sqlalchemy.orm.query import Query from sqlalchemy.sql import visitors class CachingQuery(Query): - """A Query subclass which optionally loads full results from a Beaker + """A Query subclass which optionally loads full results from a Beaker cache region. The CachingQuery stores additional state that allows it to consult a Beaker cache before accessing the database: - * A "region", which is a cache region argument passed to a + * A "region", which is a cache region argument passed to a Beaker CacheManager, specifies a particular cache configuration (including backend implementation, expiration times, etc.) * A "namespace", which is a qualifying name that identifies a - group of keys within the cache. A query that filters on a name - might use the name "by_name", a query that filters on a date range + group of keys within the cache. A query that filters on a name + might use the name "by_name", a query that filters on a date range to a joined table might use the name "related_date_range". When the above state is present, a Beaker cache is retrieved. - The "namespace" name is first concatenated with - a string composed of the individual entities and columns the Query + The "namespace" name is first concatenated with + a string composed of the individual entities and columns the Query requests, i.e. such as ``Query(User.id, User.name)``. The Beaker cache is then loaded from the cache manager based on the region and composed namespace. The key within the cache itself is then constructed against the bind parameters specified - by this query, which are usually literals defined in the + by this query, which are usually literals defined in the WHERE clause. The FromCache and RelationshipCache mapper options below represent @@ -137,7 +137,7 @@ def _get_cache_parameters(query): return cache, cache_key def _namespace_from_query(namespace, query): - # cache namespace - the token handed in by the + # cache namespace - the token handed in by the # option + class we're querying against namespace = " ".join([namespace] + [str(x) for x in query._entities]) @@ -151,7 +151,7 @@ def _set_cache_parameters(query, region, namespace, cache_key): if hasattr(query, '_cache_parameters'): region, namespace, cache_key = query._cache_parameters raise ValueError("This query is already configured " - "for region %r namespace %r" % + "for region %r namespace %r" % (region, namespace) ) query._cache_parameters = region, namespace, cache_key @@ -171,10 +171,10 @@ class FromCache(MapperOption): be a name uniquely describing the target Query's lexical structure. - :param cache_key: optional. A string cache key + :param cache_key: optional. A string cache key that will serve as the key to the query. Use this if your query has a huge amount of parameters (such - as when using in_()) which correspond more simply to + as when using in_()) which correspond more simply to some other identifier. """ @@ -188,7 +188,7 @@ class FromCache(MapperOption): _set_cache_parameters(query, self.region, self.namespace, self.cache_key) class RelationshipCache(MapperOption): - """Specifies that a Query as called within a "lazy load" + """Specifies that a Query as called within a "lazy load" should load results from a cache.""" propagate_to_loaders = True @@ -228,9 +228,9 @@ class RelationshipCache(MapperOption): if (cls, key) in self._relationship_options: relationship_option = self._relationship_options[(cls, key)] _set_cache_parameters( - query, - relationship_option.region, - relationship_option.namespace, + query, + relationship_option.region, + relationship_option.namespace, None) def and_(self, option): diff --git a/examples/beaker_caching/environment.py b/examples/beaker_caching/environment.py index 740c5977a..ccc625117 100644 --- a/examples/beaker_caching/environment.py +++ b/examples/beaker_caching/environment.py @@ -1,6 +1,6 @@ """environment.py -Establish data / cache file paths, and configurations, +Establish data / cache file paths, and configurations, bootstrap fixture data if necessary. """ diff --git a/examples/beaker_caching/fixture_data.py b/examples/beaker_caching/fixture_data.py index 09f020cea..b77bbcb95 100644 --- a/examples/beaker_caching/fixture_data.py +++ b/examples/beaker_caching/fixture_data.py @@ -37,7 +37,7 @@ def install(): person = Person( "person %.2d" % i, Address( - street="street %.2d" % i, + street="street %.2d" % i, postal_code=all_post_codes[random.randint(0, len(all_post_codes) - 1)] ) ) diff --git a/examples/beaker_caching/helloworld.py b/examples/beaker_caching/helloworld.py index f64fcdd2e..6f696c502 100644 --- a/examples/beaker_caching/helloworld.py +++ b/examples/beaker_caching/helloworld.py @@ -15,12 +15,12 @@ people = Session.query(Person).options(FromCache("default", "all_people")).all() # remove the Session. next query starts from scratch. Session.remove() -# load again, using the same FromCache option. now they're cached +# load again, using the same FromCache option. now they're cached # under "all_people", no SQL is emitted. print "loading people....again!" people = Session.query(Person).options(FromCache("default", "all_people")).all() -# want to load on some different kind of query ? change the namespace +# want to load on some different kind of query ? change the namespace # you send to FromCache print "loading people two through twelve" people_two_through_twelve = Session.query(Person).\ @@ -30,7 +30,7 @@ people_two_through_twelve = Session.query(Person).\ # the data is cached under the "namespace" you send to FromCache, *plus* # the bind parameters of the query. So this query, having -# different literal parameters under "Person.name.between()" than the +# different literal parameters under "Person.name.between()" than the # previous one, issues new SQL... print "loading people five through fifteen" people_five_through_fifteen = Session.query(Person).\ @@ -48,8 +48,8 @@ people_two_through_twelve = Session.query(Person).\ # invalidate the cache for the three queries we've done. Recreate -# each Query, which includes at the very least the same FromCache, -# same list of objects to be loaded, and the same parameters in the +# each Query, which includes at the very least the same FromCache, +# same list of objects to be loaded, and the same parameters in the # same order, then call invalidate(). print "invalidating everything" Session.query(Person).options(FromCache("default", "all_people")).invalidate() diff --git a/examples/beaker_caching/local_session_caching.py b/examples/beaker_caching/local_session_caching.py index b63858362..2d8035578 100644 --- a/examples/beaker_caching/local_session_caching.py +++ b/examples/beaker_caching/local_session_caching.py @@ -12,7 +12,7 @@ from beaker import cache, container import collections class ScopedSessionNamespace(container.MemoryNamespaceManager): - """A Beaker cache type which will cache objects locally on + """A Beaker cache type which will cache objects locally on the current session. When used with the query_cache system, the effect is that the objects @@ -86,10 +86,10 @@ if __name__ == '__main__': # identity is preserved - person10 is the *same* object that's # ultimately inside the cache. So it is safe to manipulate - # the not-queried-for attributes of objects when using such a - # cache without the need to invalidate - however, any change - # that would change the results of a cached query, such as - # inserts, deletes, or modification to attributes that are + # the not-queried-for attributes of objects when using such a + # cache without the need to invalidate - however, any change + # that would change the results of a cached query, such as + # inserts, deletes, or modification to attributes that are # part of query criterion, still require careful invalidation. from caching_query import _get_cache_parameters cache, key = _get_cache_parameters(q) diff --git a/examples/beaker_caching/model.py b/examples/beaker_caching/model.py index 629b263a7..a6733962d 100644 --- a/examples/beaker_caching/model.py +++ b/examples/beaker_caching/model.py @@ -1,5 +1,5 @@ """Model. We are modeling Person objects with a collection -of Address objects. Each Address has a PostalCode, which +of Address objects. Each Address has a PostalCode, which in turn references a City and then a Country: Person --(1..n)--> Address @@ -70,7 +70,7 @@ class Address(Base): def __str__(self): return "%s\t"\ "%s, %s\t"\ - "%s" % (self.street, self.city.name, + "%s" % (self.street, self.city.name, self.postal_code.code, self.country.name) class Person(Base): diff --git a/examples/beaker_caching/relation_caching.py b/examples/beaker_caching/relation_caching.py index 1691b071b..f1e5c7886 100644 --- a/examples/beaker_caching/relation_caching.py +++ b/examples/beaker_caching/relation_caching.py @@ -1,7 +1,7 @@ """relationship_caching.py -Load a set of Person and Address objects, specifying that -related PostalCode, City, Country objects should be pulled from long +Load a set of Person and Address objects, specifying that +related PostalCode, City, Country objects should be pulled from long term cache. """ diff --git a/examples/custom_attributes/custom_management.py b/examples/custom_attributes/custom_management.py index 5ab2236e7..12b745db6 100644 --- a/examples/custom_attributes/custom_management.py +++ b/examples/custom_attributes/custom_management.py @@ -1,10 +1,10 @@ """Illustrates customized class instrumentation, using the :mod:`sqlalchemy.ext.instrumentation` extension package. -In this example, mapped classes are modified to +In this example, mapped classes are modified to store their state in a dictionary attached to an attribute named "_goofy_dict", instead of using __dict__. -this example illustrates how to replace SQLAlchemy's class +this example illustrates how to replace SQLAlchemy's class descriptors with a user-defined system. @@ -66,12 +66,12 @@ class MyClass(object): if __name__ == '__main__': meta = MetaData(create_engine('sqlite://')) - table1 = Table('table1', meta, - Column('id', Integer, primary_key=True), + table1 = Table('table1', meta, + Column('id', Integer, primary_key=True), Column('name', Text)) - table2 = Table('table2', meta, - Column('id', Integer, primary_key=True), - Column('name', Text), + table2 = Table('table2', meta, + Column('id', Integer, primary_key=True), + Column('name', Text), Column('t1id', Integer, ForeignKey('table1.id'))) meta.create_all() diff --git a/examples/dynamic_dict/__init__.py b/examples/dynamic_dict/__init__.py index 69ac40952..3df907cc5 100644 --- a/examples/dynamic_dict/__init__.py +++ b/examples/dynamic_dict/__init__.py @@ -1,5 +1,5 @@ """Illustrates how to place a dictionary-like facade on top of a "dynamic" relation, so -that dictionary operations (assuming simple string keys) can operate upon a large +that dictionary operations (assuming simple string keys) can operate upon a large collection without loading the full collection at once. """
\ No newline at end of file diff --git a/examples/elementtree/__init__.py b/examples/elementtree/__init__.py index 8d47f4ace..ee1e9e193 100644 --- a/examples/elementtree/__init__.py +++ b/examples/elementtree/__init__.py @@ -15,8 +15,8 @@ In order of complexity: represented in a separate table. The nodes are associated in a hierarchy using an adjacency list structure. A query function is introduced which can search for nodes along any path with a given structure of attributes, basically a (very narrow) subset of xpath. -* ``optimized_al.py`` - Uses the same strategy as ``adjacency_list.py``, but associates each - DOM row with its owning document row, so that a full document of DOM nodes can be +* ``optimized_al.py`` - Uses the same strategy as ``adjacency_list.py``, but associates each + DOM row with its owning document row, so that a full document of DOM nodes can be loaded using O(1) queries - the construction of the "hierarchy" is performed after the load in a non-recursive fashion and is much more efficient. @@ -27,7 +27,7 @@ E.g.:: session.add(Document(file, doc)) session.commit() - # locate documents with a certain path/attribute structure + # locate documents with a certain path/attribute structure for document in find_document('/somefile/header/field2[@attr=foo]'): # dump the XML print document diff --git a/examples/elementtree/optimized_al.py b/examples/elementtree/optimized_al.py index 102f6c373..1cec61366 100644 --- a/examples/elementtree/optimized_al.py +++ b/examples/elementtree/optimized_al.py @@ -1,6 +1,6 @@ """This script duplicates adjacency_list.py, but optimizes the loading -of XML nodes to be based on a "flattened" datamodel. Any number of XML documents, -each of arbitrary complexity, can be loaded in their entirety via a single query +of XML nodes to be based on a "flattened" datamodel. Any number of XML documents, +each of arbitrary complexity, can be loaded in their entirety via a single query which joins on only three tables. """ @@ -25,7 +25,7 @@ documents = Table('documents', meta, Column('filename', String(30), unique=True), ) -# stores XML nodes in an adjacency list model. This corresponds to +# stores XML nodes in an adjacency list model. This corresponds to # Element and SubElement objects. elements = Table('elements', meta, Column('element_id', Integer, primary_key=True), @@ -61,15 +61,15 @@ class Document(object): ########################## PART IV - Persistence Mapping ##################### -# Node class. a non-public class which will represent +# Node class. a non-public class which will represent # the DB-persisted Element/SubElement object. We cannot create mappers for -# ElementTree elements directly because they are at the very least not new-style +# ElementTree elements directly because they are at the very least not new-style # classes, and also may be backed by native implementations. # so here we construct an adapter. class _Node(object): pass -# Attribute class. also internal, this will represent the key/value attributes stored for +# Attribute class. also internal, this will represent the key/value attributes stored for # a particular Node. class _Attribute(object): def __init__(self, name, value): diff --git a/examples/elementtree/pickle.py b/examples/elementtree/pickle.py index 28bee4672..d40af275b 100644 --- a/examples/elementtree/pickle.py +++ b/examples/elementtree/pickle.py @@ -1,6 +1,6 @@ """illustrates a quick and dirty way to persist an XML document expressed using ElementTree and pickle. -This is a trivial example using PickleType to marshal/unmarshal the ElementTree +This is a trivial example using PickleType to marshal/unmarshal the ElementTree document into a binary column. Compare to explicit.py which stores the individual components of the ElementTree structure in distinct rows using two additional mapped entities. Note that the usage of both styles of persistence are identical, as is the structure of the main Document class. diff --git a/examples/generic_associations/__init__.py b/examples/generic_associations/__init__.py index b166d9161..36d50266e 100644 --- a/examples/generic_associations/__init__.py +++ b/examples/generic_associations/__init__.py @@ -1,8 +1,8 @@ """ -Illustrates various methods of associating multiple types of +Illustrates various methods of associating multiple types of parents with a particular child object. -The examples all use the declarative extension along with +The examples all use the declarative extension along with declarative mixins. Each one presents the identical use case at the end - two classes, ``Customer`` and ``Supplier``, both subclassing the ``HasAddresses`` mixin, which ensures that the diff --git a/examples/generic_associations/discriminator_on_association.py b/examples/generic_associations/discriminator_on_association.py index a73b4df1d..3c170d5c8 100644 --- a/examples/generic_associations/discriminator_on_association.py +++ b/examples/generic_associations/discriminator_on_association.py @@ -12,8 +12,8 @@ that refers to a particular table is present, the extra association table is used so that traditional foreign key constraints may be used. This configuration has the advantage that a fixed set of tables -are used, with no extra-table-per-parent needed. The individual -Address record can also locate its parent with no need to scan +are used, with no extra-table-per-parent needed. The individual +Address record can also locate its parent with no need to scan amongst many tables. """ @@ -26,7 +26,7 @@ from sqlalchemy.ext.associationproxy import association_proxy class Base(object): """Base class which provides automated table name and surrogate primary key column. - + """ @declared_attr def __tablename__(cls): @@ -37,17 +37,17 @@ Base = declarative_base(cls=Base) class AddressAssociation(Base): """Associates a collection of Address objects with a particular parent. - + """ __tablename__ = "address_association" @classmethod def creator(cls, discriminator): - """Provide a 'creator' function to use with + """Provide a 'creator' function to use with the association proxy.""" return lambda addresses:AddressAssociation( - addresses=addresses, + addresses=addresses, discriminator=discriminator) discriminator = Column(String) @@ -59,37 +59,37 @@ class AddressAssociation(Base): return getattr(self, "%s_parent" % self.discriminator) class Address(Base): - """The Address class. - - This represents all address records in a + """The Address class. + + This represents all address records in a single table. - + """ - association_id = Column(Integer, + association_id = Column(Integer, ForeignKey("address_association.id") ) street = Column(String) city = Column(String) zip = Column(String) association = relationship( - "AddressAssociation", + "AddressAssociation", backref="addresses") parent = association_proxy("association", "parent") def __repr__(self): return "%s(street=%r, city=%r, zip=%r)" % \ - (self.__class__.__name__, self.street, + (self.__class__.__name__, self.street, self.city, self.zip) class HasAddresses(object): """HasAddresses mixin, creates a relationship to the address_association table for each parent. - + """ @declared_attr def address_association_id(cls): - return Column(Integer, + return Column(Integer, ForeignKey("address_association.id")) @declared_attr @@ -99,8 +99,8 @@ class HasAddresses(object): "address_association", "addresses", creator=AddressAssociation.creator(discriminator) ) - return relationship("AddressAssociation", - backref=backref("%s_parent" % discriminator, + return relationship("AddressAssociation", + backref=backref("%s_parent" % discriminator, uselist=False)) @@ -117,7 +117,7 @@ session = Session(engine) session.add_all([ Customer( - name='customer 1', + name='customer 1', addresses=[ Address( street='123 anywhere street', diff --git a/examples/generic_associations/table_per_association.py b/examples/generic_associations/table_per_association.py index 86ee212dc..e1ff2be5b 100644 --- a/examples/generic_associations/table_per_association.py +++ b/examples/generic_associations/table_per_association.py @@ -6,7 +6,7 @@ for all parents. This configuration has the advantage that all Address rows are in one table, so that the definition of "Address" -can be maintained in one place. The association table +can be maintained in one place. The association table contains the foreign key to Address so that Address has no dependency on the system. @@ -20,7 +20,7 @@ from sqlalchemy.orm import Session, relationship class Base(object): """Base class which provides automated table name and surrogate primary key column. - + """ @declared_attr def __tablename__(cls): @@ -29,11 +29,11 @@ class Base(object): Base = declarative_base(cls=Base) class Address(Base): - """The Address class. - - This represents all address records in a + """The Address class. + + This represents all address records in a single table. - + """ street = Column(String) city = Column(String) @@ -41,23 +41,23 @@ class Address(Base): def __repr__(self): return "%s(street=%r, city=%r, zip=%r)" % \ - (self.__class__.__name__, self.street, + (self.__class__.__name__, self.street, self.city, self.zip) class HasAddresses(object): """HasAddresses mixin, creates a new address_association table for each parent. - + """ @declared_attr def addresses(cls): address_association = Table( "%s_addresses" % cls.__tablename__, cls.metadata, - Column("address_id", ForeignKey("address.id"), + Column("address_id", ForeignKey("address.id"), primary_key=True), - Column("%s_id" % cls.__tablename__, - ForeignKey("%s.id" % cls.__tablename__), + Column("%s_id" % cls.__tablename__, + ForeignKey("%s.id" % cls.__tablename__), primary_key=True), ) return relationship(Address, secondary=address_association) @@ -75,7 +75,7 @@ session = Session(engine) session.add_all([ Customer( - name='customer 1', + name='customer 1', addresses=[ Address( street='123 anywhere street', diff --git a/examples/generic_associations/table_per_related.py b/examples/generic_associations/table_per_related.py index 3130960b0..693908189 100644 --- a/examples/generic_associations/table_per_related.py +++ b/examples/generic_associations/table_per_related.py @@ -17,7 +17,7 @@ from sqlalchemy.orm import Session, relationship class Base(object): """Base class which provides automated table name and surrogate primary key column. - + """ @declared_attr def __tablename__(cls): @@ -26,13 +26,13 @@ class Base(object): Base = declarative_base(cls=Base) class Address(object): - """Define columns that will be present in each + """Define columns that will be present in each 'Address' table. - + This is a declarative mixin, so additional mapped attributes beyond simple columns specified here should be set up using @declared_attr. - + """ street = Column(String) city = Column(String) @@ -40,13 +40,13 @@ class Address(object): def __repr__(self): return "%s(street=%r, city=%r, zip=%r)" % \ - (self.__class__.__name__, self.street, + (self.__class__.__name__, self.street, self.city, self.zip) class HasAddresses(object): """HasAddresses mixin, creates a new Address class for each parent. - + """ @declared_attr def addresses(cls): @@ -54,9 +54,9 @@ class HasAddresses(object): "%sAddress" % cls.__name__, (Address, Base,), dict( - __tablename__ = "%s_address" % + __tablename__ = "%s_address" % cls.__tablename__, - parent_id = Column(Integer, + parent_id = Column(Integer, ForeignKey("%s.id" % cls.__tablename__)), parent = relationship(cls) ) @@ -76,7 +76,7 @@ session = Session(engine) session.add_all([ Customer( - name='customer 1', + name='customer 1', addresses=[ Customer.Address( street='123 anywhere street', diff --git a/examples/graphs/directed_graph.py b/examples/graphs/directed_graph.py index 3ba602f00..b822cda89 100644 --- a/examples/graphs/directed_graph.py +++ b/examples/graphs/directed_graph.py @@ -29,19 +29,19 @@ class Node(Base): class Edge(Base): __tablename__ = 'edge' - lower_id = Column(Integer, - ForeignKey('node.node_id'), + lower_id = Column(Integer, + ForeignKey('node.node_id'), primary_key=True) - higher_id = Column(Integer, - ForeignKey('node.node_id'), + higher_id = Column(Integer, + ForeignKey('node.node_id'), primary_key=True) lower_node = relationship(Node, - primaryjoin=lower_id==Node.node_id, + primaryjoin=lower_id==Node.node_id, backref='lower_edges') higher_node = relationship(Node, - primaryjoin=higher_id==Node.node_id, + primaryjoin=higher_id==Node.node_id, backref='higher_edges') # here we have lower.node_id <= higher.node_id diff --git a/examples/inheritance/concrete.py b/examples/inheritance/concrete.py index 84fc79cd5..75741df6d 100644 --- a/examples/inheritance/concrete.py +++ b/examples/inheritance/concrete.py @@ -4,13 +4,13 @@ from sqlalchemy.orm import mapper, sessionmaker, polymorphic_union metadata = MetaData() -managers_table = Table('managers', metadata, +managers_table = Table('managers', metadata, Column('employee_id', Integer, primary_key=True), Column('name', String(50)), Column('manager_data', String(40)) ) -engineers_table = Table('engineers', metadata, +engineers_table = Table('engineers', metadata, Column('employee_id', Integer, primary_key=True), Column('name', String(50)), Column('engineer_info', String(40)) diff --git a/examples/inheritance/joined.py b/examples/inheritance/joined.py index aa4c18518..4d3dc08d0 100644 --- a/examples/inheritance/joined.py +++ b/examples/inheritance/joined.py @@ -12,7 +12,7 @@ class Company(Base): id = Column(Integer, primary_key=True) name = Column(String(50)) - employees = relationship("Person", + employees = relationship("Person", backref='company', cascade='all, delete-orphan') @@ -46,7 +46,7 @@ class Engineer(Person): def __repr__(self): return "Engineer %s, status %s, engineer_name %s, "\ "primary_language %s" % \ - (self.name, self.status, + (self.name, self.status, self.engineer_name, self.primary_language) class Manager(Person): @@ -70,19 +70,19 @@ session = Session(engine) c = Company(name='company1', employees=[ Manager( - name='pointy haired boss', + name='pointy haired boss', status='AAB', manager_name='manager1'), - Engineer(name='dilbert', + Engineer(name='dilbert', status='BBA', - engineer_name='engineer1', + engineer_name='engineer1', primary_language='java'), Person(name='joesmith'), - Engineer(name='wally', + Engineer(name='wally', status='CGG', - engineer_name='engineer2', + engineer_name='engineer2', primary_language='python'), - Manager(name='jsmith', + Manager(name='jsmith', status='ABA', manager_name='manager2') ]) @@ -109,7 +109,7 @@ c = session.query(Company).get(1) for e in c.employees: print e -# query using with_polymorphic. +# query using with_polymorphic. eng_manager = with_polymorphic(Person, [Engineer, Manager], aliased=True) print session.query(eng_manager).\ filter( @@ -127,7 +127,7 @@ print session.query(Company).\ eng_manager, Company.employees ).filter( - or_(eng_manager.Engineer.engineer_name=='engineer1', + or_(eng_manager.Engineer.engineer_name=='engineer1', eng_manager.Manager.manager_name=='manager2') ).all() diff --git a/examples/inheritance/single.py b/examples/inheritance/single.py index a7883fcbf..b2f934120 100644 --- a/examples/inheritance/single.py +++ b/examples/inheritance/single.py @@ -5,11 +5,11 @@ from sqlalchemy.orm import mapper, relationship, sessionmaker metadata = MetaData() # a table to store companies -companies = Table('companies', metadata, +companies = Table('companies', metadata, Column('company_id', Integer, primary_key=True), Column('name', String(50))) -employees_table = Table('employees', metadata, +employees_table = Table('employees', metadata, Column('employee_id', Integer, primary_key=True), Column('company_id', Integer, ForeignKey('companies.company_id')), Column('name', String(50)), @@ -31,7 +31,7 @@ class Engineer(Person): def __repr__(self): return "Engineer %s, status %s, engineer_name %s, "\ "primary_language %s" % \ - (self.name, self.status, + (self.name, self.status, self.engineer_name, self.primary_language) class Manager(Person): def __repr__(self): diff --git a/examples/nested_sets/nested_sets.py b/examples/nested_sets/nested_sets.py index 55d734d4e..e35ea61c3 100644 --- a/examples/nested_sets/nested_sets.py +++ b/examples/nested_sets/nested_sets.py @@ -45,7 +45,7 @@ class NestedSetExtension(MapperExtension): class Employee(Base): __tablename__ = 'personnel' __mapper_args__ = { - 'extension':NestedSetExtension(), + 'extension':NestedSetExtension(), 'batch':False # allows extension to fire for each instance before going to the next. } diff --git a/examples/postgis/postgis.py b/examples/postgis/postgis.py index a1a93c732..247265e17 100644 --- a/examples/postgis/postgis.py +++ b/examples/postgis/postgis.py @@ -32,7 +32,7 @@ class PersistentGisElement(GisElement): class TextualGisElement(GisElement, expression.Function): """Represents a Geometry value as expressed within application code; i.e. in wkt format. - Extends expression.Function so that the value is interpreted as + Extends expression.Function so that the value is interpreted as GeomFromText(value) in a SQL expression context. """ @@ -74,7 +74,7 @@ class Geometry(TypeEngine): return value return process -# other datatypes can be added as needed, which +# other datatypes can be added as needed, which # currently only affect DDL statements. class Point(Geometry): @@ -92,7 +92,7 @@ class LineString(Curve): # DDL integration class GISDDL(object): - """A DDL extension which integrates SQLAlchemy table create/drop + """A DDL extension which integrates SQLAlchemy table create/drop methods with PostGis' AddGeometryColumn/DropGeometryColumn functions. Usage:: @@ -162,7 +162,7 @@ def _to_postgis(value): class GisAttribute(AttributeExtension): - """Intercepts 'set' events on a mapped instance attribute and + """Intercepts 'set' events on a mapped instance attribute and converts the incoming value to a GIS expression. """ @@ -198,8 +198,8 @@ def GISColumn(*args, **kw): """ return column_property( - Column(*args, **kw), - extension=GisAttribute(), + Column(*args, **kw), + extension=GisAttribute(), comparator_factory=GisComparator ) diff --git a/examples/sharding/__init__.py b/examples/sharding/__init__.py index d4b463949..dacc815f9 100644 --- a/examples/sharding/__init__.py +++ b/examples/sharding/__init__.py @@ -10,8 +10,8 @@ The basic components of a "sharded" mapping are: * a function which can return a list of shard ids which apply to a particular instance identifier; this is called "id_chooser". If it returns all shard ids, all shards will be searched. -* a function which can return a list of shard ids to try, given a particular - Query ("query_chooser"). If it returns all shard ids, all shards will be +* a function which can return a list of shard ids to try, given a particular + Query ("query_chooser"). If it returns all shard ids, all shards will be queried and the results joined together. In this example, four sqlite databases will store information about weather @@ -22,9 +22,9 @@ single shard being requested. The construction of generic sharding routines is an ambitious approach to the issue of organizing instances among multiple databases. For a -more plain-spoken alternative, the "distinct entity" approach +more plain-spoken alternative, the "distinct entity" approach is a simple method of assigning objects to different tables (and potentially -database nodes) in an explicit way - described on the wiki at +database nodes) in an explicit way - described on the wiki at `EntityName <http://www.sqlalchemy.org/trac/wiki/UsageRecipes/EntityName>`_. """ diff --git a/examples/versioning/_lib.py b/examples/versioning/_lib.py index d5f2cb0b7..ec0da4709 100644 --- a/examples/versioning/_lib.py +++ b/examples/versioning/_lib.py @@ -1,7 +1,7 @@ """copy of ComparableEntity and eq_() from test.lib. This is just to support running the example outside of -the SQLA testing environment which is no longer part of +the SQLA testing environment which is no longer part of SQLAlchemy as of 0.7. """ diff --git a/examples/versioning/history_meta.py b/examples/versioning/history_meta.py index 1226a8f62..533599394 100644 --- a/examples/versioning/history_meta.py +++ b/examples/versioning/history_meta.py @@ -71,9 +71,9 @@ def _history_mapper(local_mapper): versioned_cls = type.__new__(type, "%sHistory" % cls.__name__, bases, {}) m = mapper( - versioned_cls, - table, - inherits=super_history_mapper, + versioned_cls, + table, + inherits=super_history_mapper, polymorphic_on=polymorphic_on, polymorphic_identity=local_mapper.polymorphic_identity ) @@ -129,9 +129,9 @@ def create_version(obj, session, deleted = False): try: prop = obj_mapper.get_property_by_column(obj_col) except UnmappedColumnError: - # in the case of single table inheritance, there may be + # in the case of single table inheritance, there may be # columns on the mapped table intended for the subclass only. - # the "unmapped" status of the subclass column on the + # the "unmapped" status of the subclass column on the # base class is a feature of the declarative module as of sqla 0.5.2. continue diff --git a/examples/versioning/test_versioning.py b/examples/versioning/test_versioning.py index 389dba918..9781fdc5d 100644 --- a/examples/versioning/test_versioning.py +++ b/examples/versioning/test_versioning.py @@ -185,8 +185,8 @@ class TestVersioning(TestCase): eq_( sess.query(BaseClassHistory).order_by(BaseClassHistory.id).all(), [ - SubClassSeparatePkHistory(id=1, name=u'sep1', type=u'sep', version=1), - BaseClassHistory(id=2, name=u'base1', type=u'base', version=1), + SubClassSeparatePkHistory(id=1, name=u'sep1', type=u'sep', version=1), + BaseClassHistory(id=2, name=u'base1', type=u'base', version=1), SubClassSamePkHistory(id=3, name=u'same1', type=u'same', version=1) ] ) @@ -196,9 +196,9 @@ class TestVersioning(TestCase): eq_( sess.query(BaseClassHistory).order_by(BaseClassHistory.id, BaseClassHistory.version).all(), [ - SubClassSeparatePkHistory(id=1, name=u'sep1', type=u'sep', version=1), - BaseClassHistory(id=2, name=u'base1', type=u'base', version=1), - SubClassSamePkHistory(id=3, name=u'same1', type=u'same', version=1), + SubClassSeparatePkHistory(id=1, name=u'sep1', type=u'sep', version=1), + BaseClassHistory(id=2, name=u'base1', type=u'base', version=1), + SubClassSamePkHistory(id=3, name=u'same1', type=u'same', version=1), SubClassSamePkHistory(id=3, name=u'same1', type=u'same', version=2) ] ) @@ -207,10 +207,10 @@ class TestVersioning(TestCase): eq_( sess.query(BaseClassHistory).order_by(BaseClassHistory.id, BaseClassHistory.version).all(), [ - SubClassSeparatePkHistory(id=1, name=u'sep1', type=u'sep', version=1), - BaseClassHistory(id=2, name=u'base1', type=u'base', version=1), - BaseClassHistory(id=2, name=u'base1mod', type=u'base', version=2), - SubClassSamePkHistory(id=3, name=u'same1', type=u'same', version=1), + SubClassSeparatePkHistory(id=1, name=u'sep1', type=u'sep', version=1), + BaseClassHistory(id=2, name=u'base1', type=u'base', version=1), + BaseClassHistory(id=2, name=u'base1mod', type=u'base', version=2), + SubClassSamePkHistory(id=3, name=u'same1', type=u'same', version=1), SubClassSamePkHistory(id=3, name=u'same1', type=u'same', version=2) ] ) |
