summaryrefslogtreecommitdiff
path: root/examples/dogpile_caching
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-04-27 19:53:57 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-04-27 19:53:57 -0400
commit4b614b9b35cd2baddb7ca67c04bee5d70ec6a172 (patch)
tree7483cd269f5823f903f96709eb864fff9b6d9383 /examples/dogpile_caching
parent9716a5c45e6185c5871555722d8495880f0e8c7a (diff)
downloadsqlalchemy-4b614b9b35cd2baddb7ca67c04bee5d70ec6a172.tar.gz
- the raw 2to3 run
- went through examples/ and cleaned out excess list() calls
Diffstat (limited to 'examples/dogpile_caching')
-rw-r--r--examples/dogpile_caching/advanced.py34
-rw-r--r--examples/dogpile_caching/caching_query.py4
-rw-r--r--examples/dogpile_caching/environment.py6
-rw-r--r--examples/dogpile_caching/fixture_data.py6
-rw-r--r--examples/dogpile_caching/helloworld.py18
-rw-r--r--examples/dogpile_caching/local_session_caching.py6
-rw-r--r--examples/dogpile_caching/model.py4
-rw-r--r--examples/dogpile_caching/relation_caching.py10
8 files changed, 44 insertions, 44 deletions
diff --git a/examples/dogpile_caching/advanced.py b/examples/dogpile_caching/advanced.py
index 6bfacfcf0..f1a18a4d7 100644
--- a/examples/dogpile_caching/advanced.py
+++ b/examples/dogpile_caching/advanced.py
@@ -6,9 +6,9 @@ and collection caching.
"""
-from environment import Session
-from model import Person, Address, cache_address_bits
-from caching_query import FromCache, RelationshipCache
+from .environment import Session
+from .model import Person, Address, cache_address_bits
+from .caching_query import FromCache, RelationshipCache
from sqlalchemy.orm import joinedload
def load_name_range(start, end, invalidate=False):
@@ -49,31 +49,31 @@ def load_name_range(start, end, invalidate=False):
return q.all()
-print "two through twelve, possibly from cache:\n"
-print ", ".join([p.name for p in load_name_range(2, 12)])
+print("two through twelve, possibly from cache:\n")
+print(", ".join([p.name for p in load_name_range(2, 12)]))
-print "\ntwenty five through forty, possibly from cache:\n"
-print ", ".join([p.name for p in load_name_range(25, 40)])
+print("\ntwenty five through forty, possibly from cache:\n")
+print(", ".join([p.name for p in load_name_range(25, 40)]))
# loading them again, no SQL is emitted
-print "\ntwo through twelve, from the cache:\n"
-print ", ".join([p.name for p in load_name_range(2, 12)])
+print("\ntwo through twelve, from the cache:\n")
+print(", ".join([p.name for p in load_name_range(2, 12)]))
# but with invalidate, they are
-print "\ntwenty five through forty, invalidate first:\n"
-print ", ".join([p.name for p in load_name_range(25, 40, True)])
+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
# on the Person
-print "\n\nPeople plus addresses, two through twelve, addresses possibly from cache"
+print("\n\nPeople plus addresses, two through twelve, addresses possibly from cache")
for p in load_name_range(2, 12):
- print p.format_full()
+ print(p.format_full())
# illustrate the address loading from either cache/already
# on the Person
-print "\n\nPeople plus addresses, two through twelve, addresses from cache"
+print("\n\nPeople plus addresses, two through twelve, addresses from cache")
for p in load_name_range(2, 12):
- print p.format_full()
+ print(p.format_full())
-print "\n\nIf this was the first run of advanced.py, try "\
- "a second run. Only one SQL statement will be emitted."
+print("\n\nIf this was the first run of advanced.py, try "\
+ "a second run. Only one SQL statement will be emitted.")
diff --git a/examples/dogpile_caching/caching_query.py b/examples/dogpile_caching/caching_query.py
index f4724fb0b..18eb2b908 100644
--- a/examples/dogpile_caching/caching_query.py
+++ b/examples/dogpile_caching/caching_query.py
@@ -143,8 +143,8 @@ def _key_from_query(query, qualifier=None):
# here we return the key as a long string. our "key mangler"
# set up with the region will boil it down to an md5.
return " ".join(
- [unicode(compiled)] +
- [unicode(params[k]) for k in sorted(params)])
+ [str(compiled)] +
+ [str(params[k]) for k in sorted(params)])
class FromCache(MapperOption):
"""Specifies that a Query should load results from a cache."""
diff --git a/examples/dogpile_caching/environment.py b/examples/dogpile_caching/environment.py
index f210d26ac..36b9585b2 100644
--- a/examples/dogpile_caching/environment.py
+++ b/examples/dogpile_caching/environment.py
@@ -4,7 +4,7 @@ Establish data / cache file paths, and configurations,
bootstrap fixture data if necessary.
"""
-import caching_query
+from . import caching_query
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
@@ -31,7 +31,7 @@ Base = declarative_base()
root = "./dogpile_data/"
if not os.path.exists(root):
- raw_input("Will create datafiles in %r.\n"
+ input("Will create datafiles in %r.\n"
"To reset the cache + database, delete this directory.\n"
"Press enter to continue.\n" % root
)
@@ -77,7 +77,7 @@ installed = False
def bootstrap():
global installed
- import fixture_data
+ from . import fixture_data
if not os.path.exists(dbfile):
fixture_data.install()
installed = True \ No newline at end of file
diff --git a/examples/dogpile_caching/fixture_data.py b/examples/dogpile_caching/fixture_data.py
index 1db75ea05..f93f32fd9 100644
--- a/examples/dogpile_caching/fixture_data.py
+++ b/examples/dogpile_caching/fixture_data.py
@@ -5,8 +5,8 @@ Canadian cities. Then, 100 Person records are installed, each with a
randomly selected postal code.
"""
-from environment import Session, Base
-from model import City, Country, PostalCode, Person, Address
+from .environment import Session, Base
+from .model import City, Country, PostalCode, Person, Address
import random
def install():
@@ -35,7 +35,7 @@ def install():
Session.add_all(pc)
all_post_codes.extend(pc)
- for i in xrange(1, 51):
+ for i in range(1, 51):
person = Person(
"person %.2d" % i,
Address(
diff --git a/examples/dogpile_caching/helloworld.py b/examples/dogpile_caching/helloworld.py
index e2e4d4f78..4561097b6 100644
--- a/examples/dogpile_caching/helloworld.py
+++ b/examples/dogpile_caching/helloworld.py
@@ -4,12 +4,12 @@ Illustrate how to load some data, and cache the results.
"""
-from environment import Session
-from model import Person
-from caching_query import FromCache
+from .environment import Session
+from .model import Person
+from .caching_query import FromCache
# load Person objects. cache the result under the namespace "all_people".
-print "loading people...."
+print("loading people....")
people = Session.query(Person).options(FromCache("default")).all()
# remove the Session. next query starts from scratch.
@@ -17,12 +17,12 @@ Session.remove()
# load again, using the same FromCache option. now they're cached
# under "all_people", no SQL is emitted.
-print "loading people....again!"
+print("loading people....again!")
people = Session.query(Person).options(FromCache("default")).all()
# want to load on some different kind of query ? change the namespace
# you send to FromCache
-print "loading people two through twelve"
+print("loading people two through twelve")
people_two_through_twelve = Session.query(Person).\
options(FromCache("default")).\
filter(Person.name.between("person 02", "person 12")).\
@@ -32,7 +32,7 @@ people_two_through_twelve = Session.query(Person).\
# the bind parameters of the query. So this query, having
# different literal parameters under "Person.name.between()" than the
# previous one, issues new SQL...
-print "loading people five through fifteen"
+print("loading people five through fifteen")
people_five_through_fifteen = Session.query(Person).\
options(FromCache("default")).\
filter(Person.name.between("person 05", "person 15")).\
@@ -40,7 +40,7 @@ people_five_through_fifteen = Session.query(Person).\
# ... but using the same params as are already cached, no SQL
-print "loading people two through twelve...again!"
+print("loading people two through twelve...again!")
people_two_through_twelve = Session.query(Person).\
options(FromCache("default")).\
filter(Person.name.between("person 02", "person 12")).\
@@ -51,7 +51,7 @@ people_two_through_twelve = Session.query(Person).\
# 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"
+print("invalidating everything")
Session.query(Person).options(FromCache("default")).invalidate()
Session.query(Person).\
options(FromCache("default")).\
diff --git a/examples/dogpile_caching/local_session_caching.py b/examples/dogpile_caching/local_session_caching.py
index 383b31c11..cf0083d2e 100644
--- a/examples/dogpile_caching/local_session_caching.py
+++ b/examples/dogpile_caching/local_session_caching.py
@@ -53,8 +53,8 @@ register_backend("sqlalchemy.session", __name__, "ScopedSessionBackend")
if __name__ == '__main__':
- from environment import Session, regions
- from caching_query import FromCache
+ from .environment import Session, regions
+ from .caching_query import FromCache
from dogpile.cache import make_region
# set up a region based on the ScopedSessionBackend,
@@ -67,7 +67,7 @@ if __name__ == '__main__':
}
)
- from model import Person
+ from .model import Person
# query to load Person by name, with criterion
# of "person 10"
diff --git a/examples/dogpile_caching/model.py b/examples/dogpile_caching/model.py
index 6f1cffedf..622d31e6a 100644
--- a/examples/dogpile_caching/model.py
+++ b/examples/dogpile_caching/model.py
@@ -10,8 +10,8 @@ City --(has a)--> Country
"""
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.orm import relationship
-from caching_query import FromCache, RelationshipCache
-from environment import Base, bootstrap
+from .caching_query import FromCache, RelationshipCache
+from .environment import Base, bootstrap
class Country(Base):
__tablename__ = 'country'
diff --git a/examples/dogpile_caching/relation_caching.py b/examples/dogpile_caching/relation_caching.py
index 7a5779620..d40752e48 100644
--- a/examples/dogpile_caching/relation_caching.py
+++ b/examples/dogpile_caching/relation_caching.py
@@ -5,16 +5,16 @@ related PostalCode, City, Country objects should be pulled from long
term cache.
"""
-from environment import Session, root
-from model import Person, cache_address_bits
+from .environment import Session, root
+from .model import Person, cache_address_bits
from sqlalchemy.orm import joinedload
import os
for p in Session.query(Person).options(joinedload(Person.addresses), cache_address_bits):
- print p.format_full()
+ print(p.format_full())
-print "\n\nIf this was the first run of relationship_caching.py, SQL was likely emitted to "\
+print("\n\nIf this was the first run of relationship_caching.py, SQL was likely emitted to "\
"load postal codes, cities, countries.\n"\
"If run a second time, assuming the cache is still valid, "\
"only a single SQL statement will run - all "\
@@ -22,4 +22,4 @@ print "\n\nIf this was the first run of relationship_caching.py, SQL was likely
"To clear the cache, delete the file %r. \n"\
"This will cause a re-load of cities, postal codes and countries on "\
"the next run.\n"\
- % os.path.join(root, 'cache.dbm')
+ % os.path.join(root, 'cache.dbm'))