From 4b614b9b35cd2baddb7ca67c04bee5d70ec6a172 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 27 Apr 2013 19:53:57 -0400 Subject: - the raw 2to3 run - went through examples/ and cleaned out excess list() calls --- clean_2to3.diff | 13522 +++++++++++++++++++ examples/adjacency_list/adjacency_list.py | 6 +- examples/association/basic_association.py | 6 +- examples/association/dict_of_sets_with_default.py | 4 +- examples/association/proxied_association.py | 10 +- examples/custom_attributes/listen_for_events.py | 2 +- examples/dogpile_caching/advanced.py | 34 +- examples/dogpile_caching/caching_query.py | 4 +- examples/dogpile_caching/environment.py | 6 +- examples/dogpile_caching/fixture_data.py | 6 +- examples/dogpile_caching/helloworld.py | 18 +- examples/dogpile_caching/local_session_caching.py | 6 +- examples/dogpile_caching/model.py | 4 +- examples/dogpile_caching/relation_caching.py | 10 +- examples/dynamic_dict/dynamic_dict.py | 176 +- examples/elementtree/adjacency_list.py | 40 +- examples/elementtree/optimized_al.py | 42 +- .../discriminator_on_association.py | 4 +- .../generic_associations/table_per_association.py | 2 +- examples/generic_associations/table_per_related.py | 4 +- examples/inheritance/concrete.py | 2 +- examples/inheritance/joined.py | 14 +- examples/inheritance/single.py | 10 +- examples/large_collection/large_collection.py | 16 +- examples/postgis/postgis.py | 2 +- examples/versioning/_lib.py | 2 +- examples/versioning/history_meta.py | 2 +- examples/versioning/test_versioning.py | 36 +- examples/vertical/dictlike-polymorphic.py | 66 +- examples/vertical/dictlike.py | 58 +- lib/sqlalchemy/__init__.py | 2 +- lib/sqlalchemy/connectors/mxodbc.py | 2 +- lib/sqlalchemy/connectors/pyodbc.py | 26 +- lib/sqlalchemy/dialects/firebird/base.py | 4 +- lib/sqlalchemy/dialects/informix/base.py | 9 +- lib/sqlalchemy/dialects/mssql/adodbapi.py | 2 +- lib/sqlalchemy/dialects/mssql/base.py | 20 +- .../dialects/mssql/information_schema.py | 8 +- lib/sqlalchemy/dialects/mssql/pyodbc.py | 2 +- lib/sqlalchemy/dialects/mysql/base.py | 44 +- lib/sqlalchemy/dialects/mysql/cymysql.py | 17 +- lib/sqlalchemy/dialects/mysql/oursql.py | 17 +- lib/sqlalchemy/dialects/mysql/zxjdbc.py | 2 +- lib/sqlalchemy/dialects/oracle/base.py | 30 +- lib/sqlalchemy/dialects/oracle/cx_oracle.py | 97 +- lib/sqlalchemy/dialects/oracle/zxjdbc.py | 4 +- lib/sqlalchemy/dialects/postgresql/base.py | 61 +- lib/sqlalchemy/dialects/postgresql/hstore.py | 4 +- lib/sqlalchemy/dialects/postgresql/psycopg2.py | 30 +- lib/sqlalchemy/dialects/sqlite/base.py | 4 +- lib/sqlalchemy/dialects/sqlite/pysqlite.py | 7 +- lib/sqlalchemy/dialects/sybase/__init__.py | 2 +- lib/sqlalchemy/dialects/sybase/base.py | 36 +- lib/sqlalchemy/engine/base.py | 22 +- lib/sqlalchemy/engine/ddl.py | 8 +- lib/sqlalchemy/engine/default.py | 60 +- lib/sqlalchemy/engine/reflection.py | 18 +- lib/sqlalchemy/engine/result.py | 38 +- lib/sqlalchemy/engine/strategies.py | 25 +- lib/sqlalchemy/engine/url.py | 18 +- lib/sqlalchemy/event.py | 10 +- lib/sqlalchemy/exc.py | 2 +- lib/sqlalchemy/ext/associationproxy.py | 32 +- lib/sqlalchemy/ext/declarative/api.py | 2 +- lib/sqlalchemy/ext/declarative/base.py | 8 +- lib/sqlalchemy/ext/declarative/clsregistry.py | 6 +- lib/sqlalchemy/ext/mutable.py | 4 +- lib/sqlalchemy/ext/orderinglist.py | 24 +- lib/sqlalchemy/ext/serializer.py | 26 +- lib/sqlalchemy/orm/__init__.py | 2 +- lib/sqlalchemy/orm/attributes.py | 2 +- lib/sqlalchemy/orm/collections.py | 79 +- lib/sqlalchemy/orm/descriptor_props.py | 2 +- lib/sqlalchemy/orm/evaluator.py | 12 +- lib/sqlalchemy/orm/identity.py | 50 +- lib/sqlalchemy/orm/instrumentation.py | 30 +- lib/sqlalchemy/orm/interfaces.py | 4 +- lib/sqlalchemy/orm/loading.py | 12 +- lib/sqlalchemy/orm/mapper.py | 28 +- lib/sqlalchemy/orm/persistence.py | 22 +- lib/sqlalchemy/orm/properties.py | 4 +- lib/sqlalchemy/orm/query.py | 43 +- lib/sqlalchemy/orm/session.py | 20 +- lib/sqlalchemy/orm/state.py | 2 +- lib/sqlalchemy/orm/strategies.py | 8 +- lib/sqlalchemy/orm/unitofwork.py | 8 +- lib/sqlalchemy/orm/util.py | 24 +- lib/sqlalchemy/pool.py | 12 +- lib/sqlalchemy/processors.py | 6 +- lib/sqlalchemy/schema.py | 97 +- lib/sqlalchemy/sql/__init__.py | 2 +- lib/sqlalchemy/sql/compiler.py | 63 +- lib/sqlalchemy/sql/expression.py | 84 +- lib/sqlalchemy/sql/functions.py | 3 +- lib/sqlalchemy/sql/operators.py | 10 +- lib/sqlalchemy/sql/util.py | 16 +- lib/sqlalchemy/sql/visitors.py | 4 +- lib/sqlalchemy/testing/__init__.py | 2 +- lib/sqlalchemy/testing/assertions.py | 31 +- lib/sqlalchemy/testing/assertsql.py | 10 +- lib/sqlalchemy/testing/engines.py | 43 +- lib/sqlalchemy/testing/entities.py | 4 +- lib/sqlalchemy/testing/exclusions.py | 10 +- lib/sqlalchemy/testing/fixtures.py | 16 +- lib/sqlalchemy/testing/plugin/noseplugin.py | 10 +- lib/sqlalchemy/testing/profiling.py | 10 +- lib/sqlalchemy/testing/schema.py | 4 +- lib/sqlalchemy/testing/suite/test_ddl.py | 2 +- lib/sqlalchemy/testing/suite/test_reflection.py | 4 +- lib/sqlalchemy/testing/suite/test_types.py | 18 +- lib/sqlalchemy/testing/util.py | 18 +- lib/sqlalchemy/testing/warnings.py | 4 +- lib/sqlalchemy/types.py | 155 +- lib/sqlalchemy/util/_collections.py | 40 +- lib/sqlalchemy/util/compat.py | 15 +- lib/sqlalchemy/util/deprecations.py | 2 +- lib/sqlalchemy/util/langhelpers.py | 139 +- test/aaa_profiling/test_compiler.py | 2 +- test/aaa_profiling/test_memusage.py | 2 +- test/aaa_profiling/test_orm.py | 16 +- test/aaa_profiling/test_resultset.py | 6 +- test/aaa_profiling/test_zoomark.py | 102 +- test/aaa_profiling/test_zoomark_orm.py | 88 +- test/base/test_dependency.py | 6 +- test/base/test_events.py | 4 +- test/base/test_except.py | 31 +- test/base/test_utils.py | 159 +- test/dialect/test_firebird.py | 2 +- test/dialect/test_mssql.py | 30 +- test/dialect/test_mysql.py | 34 +- test/dialect/test_oracle.py | 32 +- test/dialect/test_postgresql.py | 44 +- test/dialect/test_sqlite.py | 10 +- test/dialect/test_sybase.py | 2 +- test/engine/test_bind.py | 6 +- test/engine/test_ddlemit.py | 2 +- test/engine/test_ddlevents.py | 2 +- test/engine/test_execute.py | 32 +- test/engine/test_parseconnect.py | 12 +- test/engine/test_pool.py | 30 +- test/engine/test_processors.py | 4 +- test/engine/test_reconnect.py | 24 +- test/engine/test_reflection.py | 18 +- test/engine/test_transaction.py | 20 +- test/ext/declarative/test_basic.py | 13 +- test/ext/declarative/test_clsregistry.py | 2 +- test/ext/declarative/test_inheritance.py | 2 +- test/ext/declarative/test_mixin.py | 24 +- test/ext/test_associationproxy.py | 32 +- test/ext/test_serializer.py | 14 +- test/orm/inheritance/test_assorted_poly.py | 16 +- test/orm/inheritance/test_basic.py | 10 +- test/orm/inheritance/test_concrete.py | 4 +- test/orm/inheritance/test_magazine.py | 8 +- test/orm/inheritance/test_manytomany.py | 16 +- test/orm/inheritance/test_polymorphic_rel.py | 256 +- test/orm/inheritance/test_productspec.py | 20 +- test/orm/inheritance/test_relationship.py | 2 +- test/orm/inheritance/test_with_poly.py | 22 +- test/orm/test_assorted_eager.py | 18 +- test/orm/test_attributes.py | 8 +- test/orm/test_collection.py | 18 +- test/orm/test_composites.py | 4 +- test/orm/test_deprecations.py | 2 +- test/orm/test_dynamic.py | 28 +- test/orm/test_eager_relations.py | 46 +- test/orm/test_expire.py | 2 +- test/orm/test_froms.py | 244 +- test/orm/test_generative.py | 37 +- test/orm/test_inspect.py | 4 +- test/orm/test_instrumentation.py | 49 +- test/orm/test_joins.py | 34 +- test/orm/test_loading.py | 4 +- test/orm/test_mapper.py | 63 +- test/orm/test_merge.py | 6 +- test/orm/test_naturalpks.py | 6 +- test/orm/test_pickled.py | 12 +- test/orm/test_query.py | 83 +- test/orm/test_relationships.py | 26 +- test/orm/test_session.py | 12 +- test/orm/test_subquery_relations.py | 6 +- test/orm/test_unitofwork.py | 49 +- test/orm/test_unitofworkv2.py | 12 +- test/orm/test_update_delete.py | 24 +- test/orm/test_utils.py | 30 +- test/perf/insertspeed.py | 18 +- test/perf/objselectspeed.py | 8 +- test/perf/objupdatespeed.py | 8 +- test/perf/orm2010.py | 18 +- test/perf/ormsession.py | 8 +- test/perf/stress_all.py | 30 +- test/perf/stresstest.py | 28 +- test/perf/threaded_compile.py | 22 +- test/sql/test_compiler.py | 18 +- test/sql/test_defaults.py | 28 +- test/sql/test_functions.py | 4 +- test/sql/test_generative.py | 16 +- test/sql/test_metadata.py | 4 +- test/sql/test_query.py | 42 +- test/sql/test_quote.py | 10 +- test/sql/test_rowcount.py | 6 +- test/sql/test_selectable.py | 34 +- test/sql/test_types.py | 91 +- test/sql/test_unicode.py | 80 +- test/sql/test_update.py | 12 +- 205 files changed, 16043 insertions(+), 2463 deletions(-) create mode 100644 clean_2to3.diff diff --git a/clean_2to3.diff b/clean_2to3.diff new file mode 100644 index 000000000..7020fb956 --- /dev/null +++ b/clean_2to3.diff @@ -0,0 +1,13522 @@ +diff -r 9d0639b9d3be examples/adjacency_list/adjacency_list.py +--- a/examples/adjacency_list/adjacency_list.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/adjacency_list/adjacency_list.py Sat Apr 27 19:42:17 2013 -0400 +@@ -47,7 +47,7 @@ + "\n" + \ + "".join([ + c.dump(_indent +1) +- for c in self.children.values()] ++ for c in list(self.children.values())] + ) + + if __name__ == '__main__': +@@ -55,9 +55,9 @@ + + def msg(msg, *args): + msg = msg % args +- print "\n\n\n" + "-" * len(msg.split("\n")[0]) +- print msg +- print "-" * len(msg.split("\n")[0]) ++ print("\n\n\n" + "-" * len(msg.split("\n")[0])) ++ print(msg) ++ print("-" * len(msg.split("\n")[0])) + + msg("Creating Tree Table:") + +diff -r 9d0639b9d3be examples/association/basic_association.py +--- a/examples/association/basic_association.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/association/basic_association.py Sat Apr 27 19:42:17 2013 -0400 +@@ -83,12 +83,12 @@ + + # query the order, print items + order = session.query(Order).filter_by(customer_name='john smith').one() +- print [(order_item.item.description, order_item.price) +- for order_item in order.order_items] ++ print([(order_item.item.description, order_item.price) ++ for order_item in order.order_items]) + + # print customers who bought 'MySQL Crowbar' on sale + q = session.query(Order).join('order_items', 'item') + q = q.filter(and_(Item.description == 'MySQL Crowbar', + Item.price > OrderItem.price)) + +- print [order.customer_name for order in q] ++ print([order.customer_name for order in q]) +diff -r 9d0639b9d3be examples/association/dict_of_sets_with_default.py +--- a/examples/association/dict_of_sets_with_default.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/association/dict_of_sets_with_default.py Sat Apr 27 19:42:17 2013 -0400 +@@ -75,13 +75,13 @@ + session.commit() + + a1 = session.query(A).first() +- print a1.collections["1"] ++ print(a1.collections["1"]) + a1.collections["1"].add(4) + session.commit() + + a1.collections["2"].update([7, 8, 9]) + session.commit() + +- print a1.collections["2"] ++ print(a1.collections["2"]) + + +diff -r 9d0639b9d3be examples/association/proxied_association.py +--- a/examples/association/proxied_association.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/association/proxied_association.py Sat Apr 27 19:42:17 2013 -0400 +@@ -86,16 +86,16 @@ + order = session.query(Order).filter_by(customer_name='john smith').one() + + # print items based on the OrderItem collection directly +- print [(assoc.item.description, assoc.price, assoc.item.price) +- for assoc in order.order_items] ++ print([(assoc.item.description, assoc.price, assoc.item.price) ++ for assoc in order.order_items]) + + # print items based on the "proxied" items collection +- print [(item.description, item.price) +- for item in order.items] ++ print([(item.description, item.price) ++ for item in order.items]) + + # print customers who bought 'MySQL Crowbar' on sale + orders = session.query(Order).\ + join('order_items', 'item').\ + filter(Item.description == 'MySQL Crowbar').\ + filter(Item.price > OrderItem.price) +- print [o.customer_name for o in orders] ++ print([o.customer_name for o in orders]) +diff -r 9d0639b9d3be examples/custom_attributes/listen_for_events.py +--- a/examples/custom_attributes/listen_for_events.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/custom_attributes/listen_for_events.py Sat Apr 27 19:42:17 2013 -0400 +@@ -34,7 +34,7 @@ + if oldvalue: + s += "which replaced the value '%s', " % oldvalue + s += "on object %s" % self +- print s ++ print(s) + + Base = declarative_base(cls=Base) + +diff -r 9d0639b9d3be examples/dogpile_caching/advanced.py +--- a/examples/dogpile_caching/advanced.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/dogpile_caching/advanced.py Sat Apr 27 19:42:17 2013 -0400 +@@ -6,9 +6,9 @@ + + """ + +-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 @@ + + 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 -r 9d0639b9d3be examples/dogpile_caching/caching_query.py +--- a/examples/dogpile_caching/caching_query.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/dogpile_caching/caching_query.py Sat Apr 27 19:42:17 2013 -0400 +@@ -143,8 +143,8 @@ + # 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 -r 9d0639b9d3be examples/dogpile_caching/environment.py +--- a/examples/dogpile_caching/environment.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/dogpile_caching/environment.py Sat Apr 27 19:42:17 2013 -0400 +@@ -4,7 +4,7 @@ + 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 @@ + 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 @@ + + 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 -r 9d0639b9d3be examples/dogpile_caching/fixture_data.py +--- a/examples/dogpile_caching/fixture_data.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/dogpile_caching/fixture_data.py Sat Apr 27 19:42:17 2013 -0400 +@@ -5,8 +5,8 @@ + 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 @@ + 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 -r 9d0639b9d3be examples/dogpile_caching/helloworld.py +--- a/examples/dogpile_caching/helloworld.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/dogpile_caching/helloworld.py Sat Apr 27 19:42:17 2013 -0400 +@@ -4,12 +4,12 @@ + + """ + +-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 @@ + + # 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 @@ + # 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 @@ + + + # ... 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 @@ + # 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 -r 9d0639b9d3be examples/dogpile_caching/local_session_caching.py +--- a/examples/dogpile_caching/local_session_caching.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/dogpile_caching/local_session_caching.py Sat Apr 27 19:42:17 2013 -0400 +@@ -53,8 +53,8 @@ + + + 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 @@ + } + ) + +- from model import Person ++ from .model import Person + + # query to load Person by name, with criterion + # of "person 10" +diff -r 9d0639b9d3be examples/dogpile_caching/model.py +--- a/examples/dogpile_caching/model.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/dogpile_caching/model.py Sat Apr 27 19:42:17 2013 -0400 +@@ -10,8 +10,8 @@ + """ + 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 -r 9d0639b9d3be examples/dogpile_caching/relation_caching.py +--- a/examples/dogpile_caching/relation_caching.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/dogpile_caching/relation_caching.py Sat Apr 27 19:42:17 2013 -0400 +@@ -5,16 +5,16 @@ + 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 @@ + "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')) +diff -r 9d0639b9d3be examples/dynamic_dict/dynamic_dict.py +--- a/examples/dynamic_dict/dynamic_dict.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/dynamic_dict/dynamic_dict.py Sat Apr 27 19:42:17 2013 -0400 +@@ -1,88 +1,88 @@ +-class ProxyDict(object): +- def __init__(self, parent, collection_name, childclass, keyname): +- self.parent = parent +- self.collection_name = collection_name +- self.childclass = childclass +- self.keyname = keyname +- +- @property +- def collection(self): +- return getattr(self.parent, self.collection_name) +- +- def keys(self): +- descriptor = getattr(self.childclass, self.keyname) +- return [x[0] for x in self.collection.values(descriptor)] +- +- def __getitem__(self, key): +- x = self.collection.filter_by(**{self.keyname:key}).first() +- if x: +- return x +- else: +- raise KeyError(key) +- +- def __setitem__(self, key, value): +- try: +- existing = self[key] +- self.collection.remove(existing) +- except KeyError: +- pass +- self.collection.append(value) +- +-from sqlalchemy.ext.declarative import declarative_base +-from sqlalchemy import create_engine, Column, Integer, String, ForeignKey +-from sqlalchemy.orm import sessionmaker, relationship +- +-engine = create_engine('sqlite://', echo=True) +-Base = declarative_base(engine) +- +-class Parent(Base): +- __tablename__ = 'parent' +- id = Column(Integer, primary_key=True) +- name = Column(String(50)) +- _collection = relationship("Child", lazy="dynamic", +- cascade="all, delete-orphan") +- +- @property +- def child_map(self): +- return ProxyDict(self, '_collection', Child, 'key') +- +-class Child(Base): +- __tablename__ = 'child' +- id = Column(Integer, primary_key=True) +- key = Column(String(50)) +- parent_id = Column(Integer, ForeignKey('parent.id')) +- +- def __repr__(self): +- return "Child(key=%r)" % self.key +- +-Base.metadata.create_all() +- +-sess = sessionmaker()() +- +-p1 = Parent(name='p1') +-sess.add(p1) +- +-print "\n---------begin setting nodes, autoflush occurs\n" +-p1.child_map['k1'] = Child(key='k1') +-p1.child_map['k2'] = Child(key='k2') +- +-# this will autoflush the current map. +-# ['k1', 'k2'] +-print "\n---------print keys - flushes first\n" +-print p1.child_map.keys() +- +-# k1 +-print "\n---------print 'k1' node\n" +-print p1.child_map['k1'] +- +-print "\n---------update 'k2' node - must find existing, and replace\n" +-p1.child_map['k2'] = Child(key='k2') +- +-print "\n---------print 'k2' key - flushes first\n" +-# k2 +-print p1.child_map['k2'] +- +-print "\n---------print all child nodes\n" +-# [k1, k2b] +-print sess.query(Child).all() +- ++class ProxyDict(object): ++ def __init__(self, parent, collection_name, childclass, keyname): ++ self.parent = parent ++ self.collection_name = collection_name ++ self.childclass = childclass ++ self.keyname = keyname ++ ++ @property ++ def collection(self): ++ return getattr(self.parent, self.collection_name) ++ ++ def keys(self): ++ descriptor = getattr(self.childclass, self.keyname) ++ return [x[0] for x in self.collection.values(descriptor)] ++ ++ def __getitem__(self, key): ++ x = self.collection.filter_by(**{self.keyname:key}).first() ++ if x: ++ return x ++ else: ++ raise KeyError(key) ++ ++ def __setitem__(self, key, value): ++ try: ++ existing = self[key] ++ self.collection.remove(existing) ++ except KeyError: ++ pass ++ self.collection.append(value) ++ ++from sqlalchemy.ext.declarative import declarative_base ++from sqlalchemy import create_engine, Column, Integer, String, ForeignKey ++from sqlalchemy.orm import sessionmaker, relationship ++ ++engine = create_engine('sqlite://', echo=True) ++Base = declarative_base(engine) ++ ++class Parent(Base): ++ __tablename__ = 'parent' ++ id = Column(Integer, primary_key=True) ++ name = Column(String(50)) ++ _collection = relationship("Child", lazy="dynamic", ++ cascade="all, delete-orphan") ++ ++ @property ++ def child_map(self): ++ return ProxyDict(self, '_collection', Child, 'key') ++ ++class Child(Base): ++ __tablename__ = 'child' ++ id = Column(Integer, primary_key=True) ++ key = Column(String(50)) ++ parent_id = Column(Integer, ForeignKey('parent.id')) ++ ++ def __repr__(self): ++ return "Child(key=%r)" % self.key ++ ++Base.metadata.create_all() ++ ++sess = sessionmaker()() ++ ++p1 = Parent(name='p1') ++sess.add(p1) ++ ++print("\n---------begin setting nodes, autoflush occurs\n") ++p1.child_map['k1'] = Child(key='k1') ++p1.child_map['k2'] = Child(key='k2') ++ ++# this will autoflush the current map. ++# ['k1', 'k2'] ++print("\n---------print keys - flushes first\n") ++print(list(p1.child_map.keys())) ++ ++# k1 ++print("\n---------print 'k1' node\n") ++print(p1.child_map['k1']) ++ ++print("\n---------update 'k2' node - must find existing, and replace\n") ++p1.child_map['k2'] = Child(key='k2') ++ ++print("\n---------print 'k2' key - flushes first\n") ++# k2 ++print(p1.child_map['k2']) ++ ++print("\n---------print all child nodes\n") ++# [k1, k2b] ++print(sess.query(Child).all()) ++ +diff -r 9d0639b9d3be examples/elementtree/adjacency_list.py +--- a/examples/elementtree/adjacency_list.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/elementtree/adjacency_list.py Sat Apr 27 19:42:17 2013 -0400 +@@ -11,7 +11,7 @@ + Unicode, and_, create_engine) + from sqlalchemy.orm import mapper, relationship, Session, lazyload + +-import sys, os, StringIO, re ++import sys, os, io, re + + from xml.etree import ElementTree + +@@ -56,7 +56,7 @@ + self.element = element + + def __str__(self): +- buf = StringIO.StringIO() ++ buf = io.StringIO() + self.element.write(buf) + return buf.getvalue() + +@@ -120,11 +120,11 @@ + def __set__(self, document, element): + def traverse(node): + n = _Node() +- n.tag = unicode(node.tag) +- n.text = unicode(node.text) +- n.tail = unicode(node.tail) ++ n.tag = str(node.tag) ++ n.text = str(node.text) ++ n.tail = str(node.tail) + n.children = [traverse(n2) for n2 in node] +- n.attributes = [_Attribute(unicode(k), unicode(v)) for k, v in node.attrib.iteritems()] ++ n.attributes = [_Attribute(str(k), str(v)) for k, v in node.attrib.items()] + return n + + document._root = traverse(element.getroot()) +@@ -150,23 +150,23 @@ + doc = ElementTree.parse(filename) + session.add(Document(file, doc)) + +-print "\nSaving three documents...", line ++print("\nSaving three documents...", line) + session.commit() +-print "Done." ++print("Done.") + +-print "\nFull text of document 'text.xml':", line ++print("\nFull text of document 'text.xml':", line) + document = session.query(Document).filter_by(filename="test.xml").first() + +-print document ++print(document) + + ############################################ PART VI - Searching for Paths ######################### + + # manually search for a document which contains "/somefile/header/field1:hi" +-d = session.query(Document).join('_root', aliased=True).filter(_Node.tag==u'somefile').\ +- join('children', aliased=True, from_joinpoint=True).filter(_Node.tag==u'header').\ ++d = session.query(Document).join('_root', aliased=True).filter(_Node.tag=='somefile').\ ++ join('children', aliased=True, from_joinpoint=True).filter(_Node.tag=='header').\ + join('children', aliased=True, from_joinpoint=True).filter( +- and_(_Node.tag==u'field1', _Node.text==u'hi')).one() +-print d ++ and_(_Node.tag=='field1', _Node.text=='hi')).one() ++print(d) + + # generalize the above approach into an extremely impoverished xpath function: + def find_document(path, compareto): +@@ -188,11 +188,11 @@ + return query.options(lazyload('_root')).filter(_Node.text==compareto).all() + + for path, compareto in ( +- (u'/somefile/header/field1', u'hi'), +- (u'/somefile/field1', u'hi'), +- (u'/somefile/header/field2', u'there'), +- (u'/somefile/header/field2[@attr=foo]', u'there') ++ ('/somefile/header/field1', 'hi'), ++ ('/somefile/field1', 'hi'), ++ ('/somefile/header/field2', 'there'), ++ ('/somefile/header/field2[@attr=foo]', 'there') + ): +- print "\nDocuments containing '%s=%s':" % (path, compareto), line +- print [d.filename for d in find_document(path, compareto)] ++ print("\nDocuments containing '%s=%s':" % (path, compareto), line) ++ print([d.filename for d in find_document(path, compareto)]) + +diff -r 9d0639b9d3be examples/elementtree/optimized_al.py +--- a/examples/elementtree/optimized_al.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/elementtree/optimized_al.py Sat Apr 27 19:42:17 2013 -0400 +@@ -10,7 +10,7 @@ + Unicode, and_, create_engine) + from sqlalchemy.orm import mapper, relationship, Session, lazyload + +-import sys, os, StringIO, re ++import sys, os, io, re + + from xml.etree import ElementTree + +@@ -55,7 +55,7 @@ + self.element = element + + def __str__(self): +- buf = StringIO.StringIO() ++ buf = io.StringIO() + self.element.write(buf) + return buf.getvalue() + +@@ -127,12 +127,12 @@ + def __set__(self, document, element): + def traverse(node): + n = _Node() +- n.tag = unicode(node.tag) +- n.text = unicode(node.text) +- n.tail = unicode(node.tail) ++ n.tag = str(node.tag) ++ n.text = str(node.text) ++ n.tail = str(node.tail) + document._nodes.append(n) + n.children = [traverse(n2) for n2 in node] +- n.attributes = [_Attribute(unicode(k), unicode(v)) for k, v in node.attrib.iteritems()] ++ n.attributes = [_Attribute(str(k), str(v)) for k, v in node.attrib.items()] + return n + + traverse(element.getroot()) +@@ -158,27 +158,27 @@ + doc = ElementTree.parse(filename) + session.add(Document(file, doc)) + +-print "\nSaving three documents...", line ++print("\nSaving three documents...", line) + session.commit() +-print "Done." ++print("Done.") + +-print "\nFull text of document 'text.xml':", line ++print("\nFull text of document 'text.xml':", line) + document = session.query(Document).filter_by(filename="test.xml").first() + +-print document ++print(document) + + ######################## PART VI - Searching for Paths ####################### + + # manually search for a document which contains "/somefile/header/field1:hi" +-print "\nManual search for /somefile/header/field1=='hi':", line ++print("\nManual search for /somefile/header/field1=='hi':", line) + d = session.query(Document).join('_nodes', aliased=True).\ +- filter(and_(_Node.parent_id==None, _Node.tag==u'somefile')).\ ++ filter(and_(_Node.parent_id==None, _Node.tag=='somefile')).\ + join('children', aliased=True, from_joinpoint=True).\ +- filter(_Node.tag==u'header').\ ++ filter(_Node.tag=='header').\ + join('children', aliased=True, from_joinpoint=True).\ +- filter(and_(_Node.tag==u'field1', _Node.text==u'hi')).\ ++ filter(and_(_Node.tag=='field1', _Node.text=='hi')).\ + one() +-print d ++print(d) + + # generalize the above approach into an extremely impoverished xpath function: + def find_document(path, compareto): +@@ -203,11 +203,11 @@ + return query.options(lazyload('_nodes')).filter(_Node.text==compareto).all() + + for path, compareto in ( +- (u'/somefile/header/field1', u'hi'), +- (u'/somefile/field1', u'hi'), +- (u'/somefile/header/field2', u'there'), +- (u'/somefile/header/field2[@attr=foo]', u'there') ++ ('/somefile/header/field1', 'hi'), ++ ('/somefile/field1', 'hi'), ++ ('/somefile/header/field2', 'there'), ++ ('/somefile/header/field2[@attr=foo]', 'there') + ): +- print "\nDocuments containing '%s=%s':" % (path, compareto), line +- print [d.filename for d in find_document(path, compareto)] ++ print("\nDocuments containing '%s=%s':" % (path, compareto), line) ++ print([d.filename for d in find_document(path, compareto)]) + +diff -r 9d0639b9d3be examples/generic_associations/discriminator_on_association.py +--- a/examples/generic_associations/discriminator_on_association.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/generic_associations/discriminator_on_association.py Sat Apr 27 19:42:17 2013 -0400 +@@ -144,5 +144,5 @@ + + for customer in session.query(Customer): + for address in customer.addresses: +- print address +- print address.parent +\ No newline at end of file ++ print(address) ++ print(address.parent) +\ No newline at end of file +diff -r 9d0639b9d3be examples/generic_associations/table_per_association.py +--- a/examples/generic_associations/table_per_association.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/generic_associations/table_per_association.py Sat Apr 27 19:42:17 2013 -0400 +@@ -102,5 +102,5 @@ + + for customer in session.query(Customer): + for address in customer.addresses: +- print address ++ print(address) + # no parent here +\ No newline at end of file +diff -r 9d0639b9d3be examples/generic_associations/table_per_related.py +--- a/examples/generic_associations/table_per_related.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/generic_associations/table_per_related.py Sat Apr 27 19:42:17 2013 -0400 +@@ -103,5 +103,5 @@ + + for customer in session.query(Customer): + for address in customer.addresses: +- print address +- print address.parent +\ No newline at end of file ++ print(address) ++ print(address.parent) +\ No newline at end of file +diff -r 9d0639b9d3be examples/inheritance/concrete.py +--- a/examples/inheritance/concrete.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/inheritance/concrete.py Sat Apr 27 19:42:17 2013 -0400 +@@ -68,5 +68,5 @@ + session.add(e2) + session.commit() + +-print session.query(Employee).all() ++print(session.query(Employee).all()) + +diff -r 9d0639b9d3be examples/inheritance/joined.py +--- a/examples/inheritance/joined.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/inheritance/joined.py Sat Apr 27 19:42:17 2013 -0400 +@@ -92,10 +92,10 @@ + + c = session.query(Company).get(1) + for e in c.employees: +- print e, inspect(e).key, e.company ++ print(e, inspect(e).key, e.company) + assert set([e.name for e in c.employees]) == set(['pointy haired boss', + 'dilbert', 'joesmith', 'wally', 'jsmith']) +-print "\n" ++print("\n") + + dilbert = session.query(Person).filter_by(name='dilbert').one() + dilbert2 = session.query(Engineer).filter_by(name='dilbert').one() +@@ -107,29 +107,29 @@ + + c = session.query(Company).get(1) + for e in c.employees: +- print e ++ print(e) + + # query using with_polymorphic. + eng_manager = with_polymorphic(Person, [Engineer, Manager], aliased=True) +-print session.query(eng_manager).\ ++print(session.query(eng_manager).\ + filter( + or_(eng_manager.Engineer.engineer_name=='engineer1', + eng_manager.Manager.manager_name=='manager2' + ) +- ).all() ++ ).all()) + + # illustrate join from Company, + # We use aliased=True + # to help when the selectable is used as the target of a join. + eng_manager = with_polymorphic(Person, [Engineer, Manager], aliased=True) +-print session.query(Company).\ ++print(session.query(Company).\ + join( + eng_manager, + Company.employees + ).filter( + or_(eng_manager.Engineer.engineer_name=='engineer1', + eng_manager.Manager.manager_name=='manager2') +- ).all() ++ ).all()) + + session.commit() + +diff -r 9d0639b9d3be examples/inheritance/single.py +--- a/examples/inheritance/single.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/inheritance/single.py Sat Apr 27 19:42:17 2013 -0400 +@@ -23,7 +23,7 @@ + + class Person(object): + def __init__(self, **kwargs): +- for key, value in kwargs.iteritems(): ++ for key, value in kwargs.items(): + setattr(self, key, value) + def __repr__(self): + return "Ordinary person %s" % self.name +@@ -39,7 +39,7 @@ + (self.name, self.status, self.manager_name) + class Company(object): + def __init__(self, **kwargs): +- for key, value in kwargs.iteritems(): ++ for key, value in kwargs.items(): + setattr(self, key, value) + def __repr__(self): + return "Company %s" % self.name +@@ -79,9 +79,9 @@ + + c = session.query(Company).get(1) + for e in c.employees: +- print e, e.company ++ print(e, e.company) + +-print "\n" ++print("\n") + + dilbert = session.query(Person).filter_by(name='dilbert').one() + dilbert2 = session.query(Engineer).filter_by(name='dilbert').one() +@@ -94,7 +94,7 @@ + + c = session.query(Company).get(1) + for e in c.employees: +- print e ++ print(e) + + session.delete(c) + session.commit() +diff -r 9d0639b9d3be examples/large_collection/large_collection.py +--- a/examples/large_collection/large_collection.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/large_collection/large_collection.py Sat Apr 27 19:42:17 2013 -0400 +@@ -63,14 +63,14 @@ + + sess.add(org) + +- print "-------------------------\nflush one - save org + 3 members\n" ++ print("-------------------------\nflush one - save org + 3 members\n") + sess.commit() + + # the 'members' collection is a Query. it issues + # SQL as needed to load subsets of the collection. +- print "-------------------------\nload subset of members\n" ++ print("-------------------------\nload subset of members\n") + members = org.members.filter(member_table.c.name.like('%member t%')).all() +- print members ++ print(members) + + # new Members can be appended without any + # SQL being emitted to load the full collection +@@ -78,19 +78,19 @@ + org.members.append(Member('member five')) + org.members.append(Member('member six')) + +- print "-------------------------\nflush two - save 3 more members\n" ++ print("-------------------------\nflush two - save 3 more members\n") + sess.commit() + + # delete the object. Using ON DELETE CASCADE + # SQL is only emitted for the head row - the Member rows + # disappear automatically without the need for additional SQL. + sess.delete(org) +- print "-------------------------\nflush three - delete org, delete members in one statement\n" ++ print("-------------------------\nflush three - delete org, delete members in one statement\n") + sess.commit() + +- print "-------------------------\nno Member rows should remain:\n" +- print sess.query(Member).count() ++ print("-------------------------\nno Member rows should remain:\n") ++ print(sess.query(Member).count()) + sess.close() + +- print "------------------------\ndone. dropping tables." ++ print("------------------------\ndone. dropping tables.") + meta.drop_all(engine) +\ No newline at end of file +diff -r 9d0639b9d3be examples/nested_sets/nested_sets.py +--- a/examples/nested_sets/nested_sets.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/nested_sets/nested_sets.py Sat Apr 27 19:42:17 2013 -0400 +@@ -86,19 +86,19 @@ + session.add_all([albert, bert, chuck, donna, eddie, fred]) + session.commit() + +-print(session.query(Employee).all()) ++print((session.query(Employee).all())) + + # 1. Find an employee and all his/her supervisors, no matter how deep the tree. + ealias = aliased(Employee) +-print(session.query(Employee).\ ++print((session.query(Employee).\ + filter(ealias.left.between(Employee.left, Employee.right)).\ +- filter(ealias.emp == 'Eddie').all()) ++ filter(ealias.emp == 'Eddie').all())) + + #2. Find the employee and all his/her subordinates. + # (This query has a nice symmetry with the first query.) +-print(session.query(Employee).\ ++print((session.query(Employee).\ + filter(Employee.left.between(ealias.left, ealias.right)).\ +- filter(ealias.emp == 'Chuck').all()) ++ filter(ealias.emp == 'Chuck').all())) + + #3. Find the level of each node, so you can print the tree + # as an indented listing. +@@ -107,5 +107,5 @@ + filter(ealias.left.between(Employee.left, Employee.right)).\ + group_by(ealias.emp).\ + order_by(ealias.left): +- print(" " * indentation + str(employee)) ++ print((" " * indentation + str(employee))) + +diff -r 9d0639b9d3be examples/postgis/postgis.py +--- a/examples/postgis/postgis.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/postgis/postgis.py Sat Apr 27 19:42:17 2013 -0400 +@@ -251,7 +251,7 @@ + + road_table = Road.__table__ + stmt = select([road_table]).where(road_table.c.road_geom.intersects(r1.road_geom)) +- print session.execute(stmt).fetchall() ++ print(session.execute(stmt).fetchall()) + + # TODO: for some reason the auto-generated labels have the internal replacement + # strings exposed, even though PG doesn't complain +diff -r 9d0639b9d3be examples/versioning/_lib.py +--- a/examples/versioning/_lib.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/versioning/_lib.py Sat Apr 27 19:42:17 2013 -0400 +@@ -17,7 +17,7 @@ + _repr_stack = set() + class BasicEntity(object): + def __init__(self, **kw): +- for key, value in kw.iteritems(): ++ for key, value in kw.items(): + setattr(self, key, value) + + def __repr__(self): +@@ -74,7 +74,7 @@ + a = self + b = other + +- for attr in a.__dict__.keys(): ++ for attr in list(a.__dict__.keys()): + if attr.startswith('_'): + continue + value = getattr(a, attr) +diff -r 9d0639b9d3be examples/versioning/history_meta.py +--- a/examples/versioning/history_meta.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/versioning/history_meta.py Sat Apr 27 19:42:17 2013 -0400 +@@ -49,7 +49,7 @@ + cols.append(Column('version', Integer, primary_key=True)) + + if super_fks: +- cols.append(ForeignKeyConstraint(*zip(*super_fks))) ++ cols.append(ForeignKeyConstraint(*list(zip(*super_fks)))) + + table = Table(local_mapper.local_table.name + '_history', local_mapper.local_table.metadata, + *cols +@@ -166,7 +166,7 @@ + + attr['version'] = obj.version + hist = history_cls() +- for key, value in attr.iteritems(): ++ for key, value in attr.items(): + setattr(hist, key, value) + session.add(hist) + obj.version += 1 +diff -r 9d0639b9d3be examples/versioning/test_versioning.py +--- a/examples/versioning/test_versioning.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/versioning/test_versioning.py Sat Apr 27 19:42:17 2013 -0400 +@@ -1,9 +1,9 @@ + from unittest import TestCase + from sqlalchemy.ext.declarative import declarative_base +-from history_meta import Versioned, versioned_session ++from .history_meta import Versioned, versioned_session + from sqlalchemy import create_engine, Column, Integer, String, ForeignKey + from sqlalchemy.orm import clear_mappers, sessionmaker, deferred, relationship +-from _lib import ComparableEntity, eq_ ++from ._lib import ComparableEntity, eq_ + + engine = Session = None + +@@ -188,9 +188,9 @@ + 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), +- SubClassSamePkHistory(id=3, name=u'same1', type=u'same', version=1) ++ SubClassSeparatePkHistory(id=1, name='sep1', type='sep', version=1), ++ BaseClassHistory(id=2, name='base1', type='base', version=1), ++ SubClassSamePkHistory(id=3, name='same1', type='same', version=1) + ] + ) + +@@ -199,10 +199,10 @@ + 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), +- SubClassSamePkHistory(id=3, name=u'same1', type=u'same', version=2) ++ SubClassSeparatePkHistory(id=1, name='sep1', type='sep', version=1), ++ BaseClassHistory(id=2, name='base1', type='base', version=1), ++ SubClassSamePkHistory(id=3, name='same1', type='same', version=1), ++ SubClassSamePkHistory(id=3, name='same1', type='same', version=2) + ] + ) + +@@ -210,11 +210,11 @@ + 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), +- SubClassSamePkHistory(id=3, name=u'same1', type=u'same', version=2) ++ SubClassSeparatePkHistory(id=1, name='sep1', type='sep', version=1), ++ BaseClassHistory(id=2, name='base1', type='base', version=1), ++ BaseClassHistory(id=2, name='base1mod', type='base', version=2), ++ SubClassSamePkHistory(id=3, name='same1', type='same', version=1), ++ SubClassSamePkHistory(id=3, name='same1', type='same', version=2) + ] + ) + +@@ -249,7 +249,7 @@ + + eq_( + sess.query(BaseClassHistory).order_by(BaseClassHistory.id, BaseClassHistory.version).all(), +- [BaseClassHistory(id=1, name=u'b1', type=u'base', version=1)] ++ [BaseClassHistory(id=1, name='b1', type='base', version=1)] + ) + + sc.name ='s1modified' +@@ -258,9 +258,9 @@ + eq_( + sess.query(BaseClassHistory).order_by(BaseClassHistory.id, BaseClassHistory.version).all(), + [ +- BaseClassHistory(id=1, name=u'b1', type=u'base', version=1), +- BaseClassHistory(id=1, name=u'b1modified', type=u'base', version=2), +- SubClassHistory(id=2, name=u's1', type=u'sub', version=1) ++ BaseClassHistory(id=1, name='b1', type='base', version=1), ++ BaseClassHistory(id=1, name='b1modified', type='base', version=2), ++ SubClassHistory(id=2, name='s1', type='sub', version=1) + ] + ) + +diff -r 9d0639b9d3be examples/vertical/dictlike-polymorphic.py +--- a/examples/vertical/dictlike-polymorphic.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/vertical/dictlike-polymorphic.py Sat Apr 27 19:42:17 2013 -0400 +@@ -33,7 +33,7 @@ + from sqlalchemy.ext.hybrid import hybrid_property + + # Using the VerticalPropertyDictMixin from the base example +-from dictlike import VerticalPropertyDictMixin ++from .dictlike import VerticalPropertyDictMixin + + class PolymorphicVerticalProperty(object): + """A key/value pair with polymorphic value storage. +@@ -80,7 +80,7 @@ + + @hybrid_property + def value(self): +- for discriminator, field in self.type_map.values(): ++ for discriminator, field in list(self.type_map.values()): + if self.type == discriminator: + return getattr(self, field) + return None +@@ -114,7 +114,7 @@ + + def _case(self): + whens = [(text("'%s'" % p[0]), cast(getattr(self.cls, p[1]), String)) +- for p in self.cls.type_map.values() ++ for p in list(self.cls.type_map.values()) + if p[1] is not None] + return case(whens, self.cls.type, null()) + def __eq__(self, other): +@@ -150,9 +150,9 @@ + + class AnimalFact(PolymorphicVerticalProperty): + type_map = { +- int: (u'integer', 'int_value'), +- unicode: (u'char', 'char_value'), +- bool: (u'boolean', 'boolean_value'), ++ int: ('integer', 'int_value'), ++ str: ('char', 'char_value'), ++ bool: ('boolean', 'boolean_value'), + type(None): (None, None), + } + +@@ -190,42 +190,42 @@ + metadata.create_all(engine) + session = Session(engine) + +- stoat = Animal(u'stoat') +- stoat[u'color'] = u'red' +- stoat[u'cuteness'] = 7 +- stoat[u'weasel-like'] = True ++ stoat = Animal('stoat') ++ stoat['color'] = 'red' ++ stoat['cuteness'] = 7 ++ stoat['weasel-like'] = True + + session.add(stoat) + session.commit() + +- critter = session.query(Animal).filter(Animal.name == u'stoat').one() +- print critter[u'color'] +- print critter[u'cuteness'] ++ critter = session.query(Animal).filter(Animal.name == 'stoat').one() ++ print(critter['color']) ++ print(critter['cuteness']) + +- print "changing cuteness value and type:" +- critter[u'cuteness'] = u'very cute' ++ print("changing cuteness value and type:") ++ critter['cuteness'] = 'very cute' + + session.commit() + +- marten = Animal(u'marten') +- marten[u'cuteness'] = 5 +- marten[u'weasel-like'] = True +- marten[u'poisonous'] = False ++ marten = Animal('marten') ++ marten['cuteness'] = 5 ++ marten['weasel-like'] = True ++ marten['poisonous'] = False + session.add(marten) + +- shrew = Animal(u'shrew') +- shrew[u'cuteness'] = 5 +- shrew[u'weasel-like'] = False +- shrew[u'poisonous'] = True ++ shrew = Animal('shrew') ++ shrew['cuteness'] = 5 ++ shrew['weasel-like'] = False ++ shrew['poisonous'] = True + + session.add(shrew) + session.commit() + + q = (session.query(Animal). + filter(Animal.facts.any( +- and_(AnimalFact.key == u'weasel-like', ++ and_(AnimalFact.key == 'weasel-like', + AnimalFact.value == True)))) +- print 'weasel-like animals', q.all() ++ print('weasel-like animals', q.all()) + + # Save some typing by wrapping that up in a function: + with_characteristic = lambda key, value: and_(AnimalFact.key == key, +@@ -233,24 +233,24 @@ + + q = (session.query(Animal). + filter(Animal.facts.any( +- with_characteristic(u'weasel-like', True)))) +- print 'weasel-like animals again', q.all() ++ with_characteristic('weasel-like', True)))) ++ print('weasel-like animals again', q.all()) + + q = (session.query(Animal). +- filter(Animal.facts.any(with_characteristic(u'poisonous', False)))) +- print 'animals with poisonous=False', q.all() ++ filter(Animal.facts.any(with_characteristic('poisonous', False)))) ++ print('animals with poisonous=False', q.all()) + + q = (session.query(Animal). + filter(or_(Animal.facts.any( +- with_characteristic(u'poisonous', False)), +- not_(Animal.facts.any(AnimalFact.key == u'poisonous'))))) +- print 'non-poisonous animals', q.all() ++ with_characteristic('poisonous', False)), ++ not_(Animal.facts.any(AnimalFact.key == 'poisonous'))))) ++ print('non-poisonous animals', q.all()) + + q = (session.query(Animal). + filter(Animal.facts.any(AnimalFact.value == 5))) +- print 'any animal with a .value of 5', q.all() ++ print('any animal with a .value of 5', q.all()) + + # Facts can be queried as well. + q = (session.query(AnimalFact). +- filter(with_characteristic(u'cuteness', u'very cute'))) +- print q.all() ++ filter(with_characteristic('cuteness', 'very cute'))) ++ print(q.all()) +diff -r 9d0639b9d3be examples/vertical/dictlike.py +--- a/examples/vertical/dictlike.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/examples/vertical/dictlike.py Sat Apr 27 19:42:17 2013 -0400 +@@ -110,16 +110,16 @@ + + # Implement other dict methods to taste. Here are some examples: + def keys(self): +- return self.__map.keys() ++ return list(self.__map.keys()) + + def values(self): +- return [prop.value for prop in self.__map.values()] ++ return [prop.value for prop in list(self.__map.values())] + + def items(self): +- return [(key, prop.value) for key, prop in self.__map.items()] ++ return [(key, prop.value) for key, prop in list(self.__map.items())] + + def __iter__(self): +- return iter(self.keys()) ++ return iter(list(self.keys())) + + + if __name__ == '__main__': +@@ -176,49 +176,49 @@ + metadata.create_all(engine) + session = Session(bind=engine) + +- stoat = Animal(u'stoat') +- stoat[u'color'] = u'reddish' +- stoat[u'cuteness'] = u'somewhat' ++ stoat = Animal('stoat') ++ stoat['color'] = 'reddish' ++ stoat['cuteness'] = 'somewhat' + + # dict-like assignment transparently creates entries in the + # stoat.facts collection: +- print stoat.facts[u'color'] ++ print(stoat.facts['color']) + + session.add(stoat) + session.commit() + +- critter = session.query(Animal).filter(Animal.name == u'stoat').one() +- print critter[u'color'] +- print critter[u'cuteness'] ++ critter = session.query(Animal).filter(Animal.name == 'stoat').one() ++ print(critter['color']) ++ print(critter['cuteness']) + +- critter[u'cuteness'] = u'very' ++ critter['cuteness'] = 'very' + +- print 'changing cuteness:' ++ print('changing cuteness:') + engine.echo = True + session.commit() + engine.echo = False + +- marten = Animal(u'marten') +- marten[u'color'] = u'brown' +- marten[u'cuteness'] = u'somewhat' ++ marten = Animal('marten') ++ marten['color'] = 'brown' ++ marten['cuteness'] = 'somewhat' + session.add(marten) + +- shrew = Animal(u'shrew') +- shrew[u'cuteness'] = u'somewhat' +- shrew[u'poisonous-part'] = u'saliva' ++ shrew = Animal('shrew') ++ shrew['cuteness'] = 'somewhat' ++ shrew['poisonous-part'] = 'saliva' + session.add(shrew) + +- loris = Animal(u'slow loris') +- loris[u'cuteness'] = u'fairly' +- loris[u'poisonous-part'] = u'elbows' ++ loris = Animal('slow loris') ++ loris['cuteness'] = 'fairly' ++ loris['poisonous-part'] = 'elbows' + session.add(loris) + session.commit() + + q = (session.query(Animal). + filter(Animal.facts.any( +- and_(AnimalFact.key == u'color', +- AnimalFact.value == u'reddish')))) +- print 'reddish animals', q.all() ++ and_(AnimalFact.key == 'color', ++ AnimalFact.value == 'reddish')))) ++ print('reddish animals', q.all()) + + # Save some typing by wrapping that up in a function: + with_characteristic = lambda key, value: and_(AnimalFact.key == key, +@@ -226,21 +226,21 @@ + + q = (session.query(Animal). + filter(Animal.facts.any( +- with_characteristic(u'color', u'brown')))) +- print 'brown animals', q.all() ++ with_characteristic('color', 'brown')))) ++ print('brown animals', q.all()) + + q = (session.query(Animal). + filter(not_(Animal.facts.any( +- with_characteristic(u'poisonous-part', u'elbows'))))) +- print 'animals without poisonous-part == elbows', q.all() ++ with_characteristic('poisonous-part', 'elbows'))))) ++ print('animals without poisonous-part == elbows', q.all()) + + q = (session.query(Animal). +- filter(Animal.facts.any(AnimalFact.value == u'somewhat'))) +- print 'any animal with any .value of "somewhat"', q.all() ++ filter(Animal.facts.any(AnimalFact.value == 'somewhat'))) ++ print('any animal with any .value of "somewhat"', q.all()) + + # Facts can be queried as well. + q = (session.query(AnimalFact). +- filter(with_characteristic(u'cuteness', u'very'))) +- print 'just the facts', q.all() ++ filter(with_characteristic('cuteness', 'very'))) ++ print('just the facts', q.all()) + + +diff -r 9d0639b9d3be lib/sqlalchemy/__init__.py +--- a/lib/sqlalchemy/__init__.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/__init__.py Sat Apr 27 19:42:17 2013 -0400 +@@ -117,7 +117,7 @@ + from .engine import create_engine, engine_from_config + + +-__all__ = sorted(name for name, obj in locals().items() ++__all__ = sorted(name for name, obj in locals().items()) + if not (name.startswith('_') or _inspect.ismodule(obj))) + + __version__ = '0.8.1' +diff -r 9d0639b9d3be lib/sqlalchemy/connectors/mxodbc.py +--- a/lib/sqlalchemy/connectors/mxodbc.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/connectors/mxodbc.py Sat Apr 27 19:42:17 2013 -0400 +@@ -82,7 +82,7 @@ + category=errorclass, + stacklevel=2) + else: +- raise errorclass, errorvalue ++ raise errorclass(errorvalue) + return error_handler + + def create_connect_args(self, url): +diff -r 9d0639b9d3be lib/sqlalchemy/connectors/pyodbc.py +--- a/lib/sqlalchemy/connectors/pyodbc.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/connectors/pyodbc.py Sat Apr 27 19:42:17 2013 -0400 +@@ -9,7 +9,7 @@ + + import sys + import re +-import urllib ++import urllib.request, urllib.parse, urllib.error + + + class PyODBCConnector(Connector): +@@ -59,7 +59,7 @@ + connect_args[param] = asbool(keys.pop(param)) + + if 'odbc_connect' in keys: +- connectors = [urllib.unquote_plus(keys.pop('odbc_connect'))] ++ connectors = [urllib.parse.unquote_plus(keys.pop('odbc_connect'))] + else: + dsn_connection = 'dsn' in keys or \ + ('host' in keys and 'database' not in keys) +@@ -91,7 +91,7 @@ + connectors.append("AutoTranslate=%s" % + keys.pop("odbc_autotranslate")) + +- connectors.extend(['%s=%s' % (k, v) for k, v in keys.iteritems()]) ++ connectors.extend(['%s=%s' % (k, v) for k, v in keys.items()]) + return [[";".join(connectors)], connect_args] + + def is_disconnect(self, e, connection, cursor): +@@ -123,16 +123,16 @@ + + # the "Py2K only" part here is theoretical. + # have not tried pyodbc + python3.1 yet. +- # Py2K +- self.supports_unicode_statements = ( +- not self.freetds and not self.easysoft) +- if self._user_supports_unicode_binds is not None: +- self.supports_unicode_binds = self._user_supports_unicode_binds +- else: +- self.supports_unicode_binds = ( +- not self.freetds or self.freetds_driver_version >= '0.91' +- ) and not self.easysoft +- # end Py2K ++# start Py2K ++# self.supports_unicode_statements = ( ++# not self.freetds and not self.easysoft) ++# if self._user_supports_unicode_binds is not None: ++# self.supports_unicode_binds = self._user_supports_unicode_binds ++# else: ++# self.supports_unicode_binds = ( ++# not self.freetds or self.freetds_driver_version >= '0.91' ++# ) and not self.easysoft ++# end Py2K + + # run other initialization which asks for user name, etc. + super(PyODBCConnector, self).initialize(connection) +diff -r 9d0639b9d3be lib/sqlalchemy/dialects/firebird/base.py +--- a/lib/sqlalchemy/dialects/firebird/base.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/dialects/firebird/base.py Sat Apr 27 19:42:17 2013 -0400 +@@ -685,7 +685,7 @@ + self.normalize_name(row['fname'])) + fk['referred_columns'].append( + self.normalize_name(row['targetfname'])) +- return fks.values() ++ return list(fks.values()) + + @reflection.cache + def get_indexes(self, connection, table_name, schema=None, **kw): +@@ -716,7 +716,7 @@ + indexrec['column_names'].append( + self.normalize_name(row['field_name'])) + +- return indexes.values() ++ return list(indexes.values()) + + def do_execute(self, cursor, statement, parameters, context=None): + # kinterbase does not accept a None, but wants an empty list +diff -r 9d0639b9d3be lib/sqlalchemy/dialects/informix/base.py +--- a/lib/sqlalchemy/dialects/informix/base.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/dialects/informix/base.py Sat Apr 27 19:42:17 2013 -0400 +@@ -24,6 +24,7 @@ + from sqlalchemy.sql import compiler, text + from sqlalchemy.engine import default, reflection + from sqlalchemy import types as sqltypes ++from functools import reduce + + RESERVED_WORDS = set( + ["abs", "absolute", "access", "access_method", "acos", "active", "add", +@@ -298,7 +299,7 @@ + + def get_column_default_string(self, column): + if (isinstance(column.server_default, schema.DefaultClause) and +- isinstance(column.server_default.arg, basestring)): ++ isinstance(column.server_default.arg, str)): + if isinstance(column.type, (sqltypes.Integer, sqltypes.Numeric)): + return self.sql_compiler.process(text(column.server_default.arg)) + +@@ -322,10 +323,10 @@ + remote_table = list(constraint._elements.values())[0].column.table + text = "FOREIGN KEY (%s) REFERENCES %s (%s)" % ( + ', '.join(preparer.quote(f.parent.name, f.parent.quote) +- for f in constraint._elements.values()), ++ for f in list(constraint._elements.values())), + preparer.format_table(remote_table), + ', '.join(preparer.quote(f.column.name, f.column.quote) +- for f in constraint._elements.values()) ++ for f in list(constraint._elements.values())) + ) + text += self.define_constraint_cascades(constraint) + text += self.define_constraint_deferrability(constraint) +@@ -506,7 +507,7 @@ + if remote_column not in remote_cols: + remote_cols.append(remote_column) + +- return fkeys.values() ++ return list(fkeys.values()) + + @reflection.cache + def get_pk_constraint(self, connection, table_name, schema=None, **kw): +diff -r 9d0639b9d3be lib/sqlalchemy/dialects/mssql/adodbapi.py +--- a/lib/sqlalchemy/dialects/mssql/adodbapi.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/dialects/mssql/adodbapi.py Sat Apr 27 19:42:17 2013 -0400 +@@ -44,7 +44,7 @@ + + @classmethod + def import_dbapi(cls): +- import adodbapi as module ++ from . import adodbapi as module + return module + + colspecs = util.update_copy( +diff -r 9d0639b9d3be lib/sqlalchemy/dialects/mssql/base.py +--- a/lib/sqlalchemy/dialects/mssql/base.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/dialects/mssql/base.py Sat Apr 27 19:42:17 2013 -0400 +@@ -295,7 +295,7 @@ + def process(value): + if isinstance(value, datetime.datetime): + return value.date() +- elif isinstance(value, basestring): ++ elif isinstance(value, str): + return datetime.date(*[ + int(x or 0) + for x in self._reg.match(value).groups() +@@ -328,7 +328,7 @@ + def process(value): + if isinstance(value, datetime.datetime): + return value.time() +- elif isinstance(value, basestring): ++ elif isinstance(value, str): + return datetime.time(*[ + int(x or 0) + for x in self._reg.match(value).groups()]) +@@ -1002,7 +1002,7 @@ + # handle other included columns + if index.kwargs.get("mssql_include"): + inclusions = [index.table.c[col] +- if isinstance(col, basestring) else col ++ if isinstance(col, str) else col + for col in index.kwargs["mssql_include"]] + + text += " INCLUDE (%s)" \ +@@ -1103,7 +1103,7 @@ + query_timeout=None, + use_scope_identity=True, + max_identifier_length=None, +- schema_name=u"dbo", **opts): ++ schema_name="dbo", **opts): + self.query_timeout = int(query_timeout or 0) + self.schema_name = schema_name + +@@ -1123,7 +1123,7 @@ + + def initialize(self, connection): + super(MSDialect, self).initialize(connection) +- if self.server_version_info[0] not in range(8, 17): ++ if self.server_version_info[0] not in list(range(8, 17)): + # FreeTDS with version 4.2 seems to report here + # a number like "95.10.255". Don't know what + # that is. So emit warning. +@@ -1150,7 +1150,7 @@ + try: + default_schema_name = connection.scalar(query, name=user_name) + if default_schema_name is not None: +- return unicode(default_schema_name) ++ return str(default_schema_name) + except: + pass + return self.schema_name +@@ -1188,7 +1188,7 @@ + s = sql.select([tables.c.table_name], + sql.and_( + tables.c.table_schema == owner, +- tables.c.table_type == u'BASE TABLE' ++ tables.c.table_type == 'BASE TABLE' + ), + order_by=[tables.c.table_name] + ) +@@ -1202,7 +1202,7 @@ + s = sql.select([tables.c.table_name], + sql.and_( + tables.c.table_schema == owner, +- tables.c.table_type == u'VIEW' ++ tables.c.table_type == 'VIEW' + ), + order_by=[tables.c.table_name] + ) +@@ -1267,7 +1267,7 @@ + if row['index_id'] in indexes: + indexes[row['index_id']]['column_names'].append(row['name']) + +- return indexes.values() ++ return list(indexes.values()) + + @reflection.cache + @_db_plus_owner +@@ -1474,4 +1474,4 @@ + local_cols.append(scol) + remote_cols.append(rcol) + +- return fkeys.values() ++ return list(fkeys.values()) +diff -r 9d0639b9d3be lib/sqlalchemy/dialects/mssql/information_schema.py +--- a/lib/sqlalchemy/dialects/mssql/information_schema.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/dialects/mssql/information_schema.py Sat Apr 27 19:42:17 2013 -0400 +@@ -17,10 +17,10 @@ + impl = Unicode + + def process_bind_param(self, value, dialect): +- # Py2K +- if isinstance(value, str): +- value = value.decode(dialect.encoding) +- # end Py2K ++# start Py2K ++# if isinstance(value, str): ++# value = value.decode(dialect.encoding) ++# end Py2K + return value + + def bind_expression(self, bindvalue): +diff -r 9d0639b9d3be lib/sqlalchemy/dialects/mssql/pyodbc.py +--- a/lib/sqlalchemy/dialects/mssql/pyodbc.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/dialects/mssql/pyodbc.py Sat Apr 27 19:42:17 2013 -0400 +@@ -219,7 +219,7 @@ + # without closing it (FreeTDS particularly) + row = self.cursor.fetchall()[0] + break +- except self.dialect.dbapi.Error, e: ++ except self.dialect.dbapi.Error as e: + # no way around this - nextset() consumes the previous set + # so we need to just keep flipping + self.cursor.nextset() +diff -r 9d0639b9d3be lib/sqlalchemy/dialects/mysql/base.py +--- a/lib/sqlalchemy/dialects/mysql/base.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/dialects/mysql/base.py Sat Apr 27 19:42:17 2013 -0400 +@@ -652,7 +652,7 @@ + + def process(value): + if value is not None: +- v = 0L ++ v = 0 + for i in map(ord, value): + v = v << 8 | i + return v +@@ -1171,7 +1171,7 @@ + super_convert = super(SET, self).bind_processor(dialect) + + def process(value): +- if value is None or isinstance(value, (int, long, basestring)): ++ if value is None or isinstance(value, (int, str)): + pass + else: + if None in value: +@@ -1352,7 +1352,7 @@ + of a SELECT. + + """ +- if isinstance(select._distinct, basestring): ++ if isinstance(select._distinct, str): + return select._distinct.upper() + " " + elif select._distinct: + return "DISTINCT " +@@ -1441,7 +1441,7 @@ + MySQLDDLCompiler, self).create_table_constraints(table) + + engine_key = '%s_engine' % self.dialect.name +- is_innodb = table.kwargs.has_key(engine_key) and \ ++ is_innodb = engine_key in table.kwargs and \ + table.kwargs[engine_key].lower() == 'innodb' + + auto_inc_column = table._autoincrement_column +@@ -1494,7 +1494,7 @@ + k[len(self.dialect.name) + 1:].upper(), + v + ) +- for k, v in table.kwargs.items() ++ for k, v in list(table.kwargs.items()) + if k.startswith('%s_' % self.dialect.name) + ) + +@@ -2045,7 +2045,7 @@ + have = rs.fetchone() is not None + rs.close() + return have +- except exc.DBAPIError, e: ++ except exc.DBAPIError as e: + if self._extract_error_code(e.orig) == 1146: + return False + raise +@@ -2328,7 +2328,7 @@ + rp = None + try: + rp = connection.execute(st) +- except exc.DBAPIError, e: ++ except exc.DBAPIError as e: + if self._extract_error_code(e.orig) == 1146: + raise exc.NoSuchTableError(full_name) + else: +@@ -2352,7 +2352,7 @@ + try: + try: + rp = connection.execute(st) +- except exc.DBAPIError, e: ++ except exc.DBAPIError as e: + if self._extract_error_code(e.orig) == 1146: + raise exc.NoSuchTableError(full_name) + else: +@@ -2485,7 +2485,7 @@ + for nope in ('auto_increment', 'data directory', 'index directory'): + options.pop(nope, None) + +- for opt, val in options.items(): ++ for opt, val in list(options.items()): + state.table_options['%s_%s' % (self.dialect.name, opt)] = val + + def _parse_column(self, line, state): +@@ -2626,11 +2626,11 @@ + + _final = self.preparer.final_quote + +- quotes = dict(zip(('iq', 'fq', 'esc_fq'), ++ quotes = dict(list(zip(('iq', 'fq', 'esc_fq'), + [re.escape(s) for s in + (self.preparer.initial_quote, + _final, +- self.preparer._escape_identifier(_final))])) ++ self.preparer._escape_identifier(_final))]))) + + self._pr_name = _pr_compile( + r'^CREATE (?:\w+ +)?TABLE +' +@@ -2802,11 +2802,12 @@ + item = self.rowproxy[index] + if isinstance(item, _array): + item = item.tostring() +- # Py2K +- if self.charset and isinstance(item, str): +- # end Py2K +- # Py3K +- #if self.charset and isinstance(item, bytes): ++# start Py2K ++# if self.charset and isinstance(item, str): ++# end Py2K ++# start Py3K ++ if self.charset and isinstance(item, bytes): ++# end Py3K + return item.decode(self.charset) + else: + return item +@@ -2815,11 +2816,12 @@ + item = getattr(self.rowproxy, attr) + if isinstance(item, _array): + item = item.tostring() +- # Py2K +- if self.charset and isinstance(item, str): +- # end Py2K +- # Py3K +- #if self.charset and isinstance(item, bytes): ++# start Py2K ++# if self.charset and isinstance(item, str): ++# end Py2K ++# start Py3K ++ if self.charset and isinstance(item, bytes): ++# end Py3K + return item.decode(self.charset) + else: + return item +diff -r 9d0639b9d3be lib/sqlalchemy/dialects/mysql/cymysql.py +--- a/lib/sqlalchemy/dialects/mysql/cymysql.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/dialects/mysql/cymysql.py Sat Apr 27 19:42:17 2013 -0400 +@@ -25,15 +25,16 @@ + + def process(value): + if value is not None: +- # Py2K +- v = 0L +- for i in map(ord, value): ++# start Py2K ++# v = 0L ++# for i in map(ord, value): ++# v = v << 8 | i ++# end Py2K ++# start Py3K ++ v = 0 ++ for i in value: + v = v << 8 | i +- # end Py2K +- # Py3K +- #v = 0 +- #for i in value: +- # v = v << 8 | i ++# end Py3K + return v + return value + return process +diff -r 9d0639b9d3be lib/sqlalchemy/dialects/mysql/oursql.py +--- a/lib/sqlalchemy/dialects/mysql/oursql.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/dialects/mysql/oursql.py Sat Apr 27 19:42:17 2013 -0400 +@@ -55,9 +55,9 @@ + + class MySQLDialect_oursql(MySQLDialect): + driver = 'oursql' +-# Py2K +- supports_unicode_binds = True +- supports_unicode_statements = True ++# start Py2K ++# supports_unicode_binds = True ++# supports_unicode_statements = True + # end Py2K + + supports_native_decimal = True +@@ -90,12 +90,13 @@ + connection.cursor().execute('BEGIN', plain_query=True) + + def _xa_query(self, connection, query, xid): +-# Py2K +- arg = connection.connection._escape_string(xid) ++# start Py2K ++# arg = connection.connection._escape_string(xid) + # end Py2K +-# Py3K +-# charset = self._connection_charset +-# arg = connection.connection._escape_string(xid.encode(charset)).decode(charset) ++# start Py3K ++ charset = self._connection_charset ++ arg = connection.connection._escape_string(xid.encode(charset)).decode(charset) ++# end Py3K + arg = "'%s'" % arg + connection.execution_options(_oursql_plain_query=True).execute(query % arg) + +diff -r 9d0639b9d3be lib/sqlalchemy/dialects/mysql/zxjdbc.py +--- a/lib/sqlalchemy/dialects/mysql/zxjdbc.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/dialects/mysql/zxjdbc.py Sat Apr 27 19:42:17 2013 -0400 +@@ -37,7 +37,7 @@ + return value + if isinstance(value, bool): + return int(value) +- v = 0L ++ v = 0 + for i in value: + v = v << 8 | (i & 0xff) + value = v +diff -r 9d0639b9d3be lib/sqlalchemy/dialects/oracle/base.py +--- a/lib/sqlalchemy/dialects/oracle/base.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/dialects/oracle/base.py Sat Apr 27 19:42:17 2013 -0400 +@@ -437,7 +437,7 @@ + + def get_select_hint_text(self, byfroms): + return " ".join( +- "/*+ %s */" % text for table, text in byfroms.items() ++ "/*+ %s */" % text for table, text in list(byfroms.items()) + ) + + def function_argspec(self, fn, **kw): +@@ -654,14 +654,14 @@ + class OracleIdentifierPreparer(compiler.IdentifierPreparer): + + reserved_words = set([x.lower() for x in RESERVED_WORDS]) +- illegal_initial_characters = set(xrange(0, 10)).union(["_", "$"]) ++ illegal_initial_characters = set(range(0, 10)).union(["_", "$"]) + + def _bindparam_requires_quotes(self, value): + """Return True if the given identifier requires quoting.""" + lc_value = value.lower() + return (lc_value in self.reserved_words + or value[0] in self.illegal_initial_characters +- or not self.legal_characters.match(unicode(value)) ++ or not self.legal_characters.match(str(value)) + ) + + def format_savepoint(self, savepoint): +@@ -765,10 +765,10 @@ + def normalize_name(self, name): + if name is None: + return None +- # Py2K +- if isinstance(name, str): +- name = name.decode(self.encoding) +- # end Py2K ++# start Py2K ++# if isinstance(name, str): ++# name = name.decode(self.encoding) ++# end Py2K + if name.upper() == name and \ + not self.identifier_preparer._requires_quotes(name.lower()): + return name.lower() +@@ -780,16 +780,16 @@ + return None + elif name.lower() == name and not self.identifier_preparer._requires_quotes(name.lower()): + name = name.upper() +- # Py2K +- if not self.supports_unicode_binds: +- name = name.encode(self.encoding) +- else: +- name = unicode(name) +- # end Py2K ++# start Py2K ++# if not self.supports_unicode_binds: ++# name = name.encode(self.encoding) ++# else: ++# name = unicode(name) ++# end Py2K + return name + + def _get_default_schema_name(self, connection): +- return self.normalize_name(connection.execute(u'SELECT USER FROM DUAL').scalar()) ++ return self.normalize_name(connection.execute('SELECT USER FROM DUAL').scalar()) + + def _resolve_synonym(self, connection, desired_owner=None, desired_synonym=None, desired_table=None): + """search for a local synonym matching the given desired owner/name. +@@ -1167,7 +1167,7 @@ + local_cols.append(local_column) + remote_cols.append(remote_column) + +- return fkeys.values() ++ return list(fkeys.values()) + + @reflection.cache + def get_view_definition(self, connection, view_name, schema=None, +diff -r 9d0639b9d3be lib/sqlalchemy/dialects/oracle/cx_oracle.py +--- a/lib/sqlalchemy/dialects/oracle/cx_oracle.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/dialects/oracle/cx_oracle.py Sat Apr 27 19:42:17 2013 -0400 +@@ -182,7 +182,7 @@ + + """ + +-from __future__ import absolute_import ++ + + from .base import OracleCompiler, OracleDialect, OracleExecutionContext + from . import base as oracle +@@ -268,20 +268,21 @@ + + + class _NativeUnicodeMixin(object): +- # Py3K +- #pass +- # Py2K +- def bind_processor(self, dialect): +- if dialect._cx_oracle_with_unicode: +- def process(value): +- if value is None: +- return value +- else: +- return unicode(value) +- return process +- else: +- return super(_NativeUnicodeMixin, self).bind_processor(dialect) +- # end Py2K ++# start Py3K ++ pass ++# end Py3K ++# start Py2K ++# def bind_processor(self, dialect): ++# if dialect._cx_oracle_with_unicode: ++# def process(value): ++# if value is None: ++# return value ++# else: ++# return unicode(value) ++# return process ++# else: ++# return super(_NativeUnicodeMixin, self).bind_processor(dialect) ++# end Py2K + + # we apply a connection output handler that returns + # unicode in all cases, so the "native_unicode" flag +@@ -391,10 +392,10 @@ + (fromname.encode(self.dialect.encoding), + toname.encode(self.dialect.encoding)) + for fromname, toname in +- quoted_bind_names.items() ++ list(quoted_bind_names.items()) + ) + for param in self.parameters: +- for fromname, toname in quoted_bind_names.items(): ++ for fromname, toname in list(quoted_bind_names.items()): + param[toname] = param[fromname] + del param[fromname] + +@@ -408,7 +409,7 @@ + + # if a single execute, check for outparams + if len(self.compiled_parameters) == 1: +- for bindparam in self.compiled.binds.values(): ++ for bindparam in list(self.compiled.binds.values()): + if bindparam.isoutparam: + dbtype = bindparam.type.dialect_impl(self.dialect).\ + get_dbapi_type(self.dialect.dbapi) +@@ -437,7 +438,7 @@ + if hasattr(self, 'out_parameters') and self.compiled.returning: + returning_params = dict( + (k, v.getvalue()) +- for k, v in self.out_parameters.items() ++ for k, v in list(self.out_parameters.items()) + ) + return ReturningResultProxy(self, returning_params) + +@@ -456,7 +457,7 @@ + len(self.compiled_parameters) == 1: + result.out_parameters = out_parameters = {} + +- for bind, name in self.compiled.bind_names.items(): ++ for bind, name in list(self.compiled.bind_names.items()): + if name in self.out_parameters: + type = bind.type + impl_type = type.dialect_impl(self.dialect) +@@ -472,7 +473,7 @@ + else: + result.out_parameters = dict( + (k, v.getvalue()) +- for k, v in self.out_parameters.items() ++ for k, v in list(self.out_parameters.items()) + ) + + return result +@@ -493,11 +494,11 @@ + """ + def __init__(self, *arg, **kw): + OracleExecutionContext_cx_oracle.__init__(self, *arg, **kw) +- self.statement = unicode(self.statement) ++ self.statement = str(self.statement) + + def _execute_scalar(self, stmt): + return super(OracleExecutionContext_cx_oracle_with_unicode, self).\ +- _execute_scalar(unicode(stmt)) ++ _execute_scalar(str(stmt)) + + + class ReturningResultProxy(_result.FullyBufferedResultProxy): +@@ -607,19 +608,19 @@ + self.supports_unicode_statements = True + self.supports_unicode_binds = True + self._cx_oracle_with_unicode = True +- # Py2K +- # There's really no reason to run with WITH_UNICODE under Python 2.x. +- # Give the user a hint. +- util.warn("cx_Oracle is compiled under Python 2.xx using the " +- "WITH_UNICODE flag. Consider recompiling cx_Oracle without " +- "this flag, which is in no way necessary for full support of Unicode. " +- "Otherwise, all string-holding bind parameters must " +- "be explicitly typed using SQLAlchemy's String type or one of its subtypes," +- "or otherwise be passed as Python unicode. Plain Python strings " +- "passed as bind parameters will be silently corrupted by cx_Oracle." +- ) +- self.execution_ctx_cls = OracleExecutionContext_cx_oracle_with_unicode +- # end Py2K ++# start Py2K ++# # There's really no reason to run with WITH_UNICODE under Python 2.x. ++# # Give the user a hint. ++# util.warn("cx_Oracle is compiled under Python 2.xx using the " ++# "WITH_UNICODE flag. Consider recompiling cx_Oracle without " ++# "this flag, which is in no way necessary for full support of Unicode. " ++# "Otherwise, all string-holding bind parameters must " ++# "be explicitly typed using SQLAlchemy's String type or one of its subtypes," ++# "or otherwise be passed as Python unicode. Plain Python strings " ++# "passed as bind parameters will be silently corrupted by cx_Oracle." ++# ) ++# self.execution_ctx_cls = OracleExecutionContext_cx_oracle_with_unicode ++# end Py2K + else: + self._cx_oracle_with_unicode = False + +@@ -731,7 +732,7 @@ + arraysize=cursor.arraysize) + # allow all strings to come back natively as Unicode + elif defaultType in (cx_Oracle.STRING, cx_Oracle.FIXED_CHAR): +- return cursor.var(unicode, size, cursor.arraysize) ++ return cursor.var(str, size, cursor.arraysize) + + def on_connect(conn): + conn.outputtypehandler = output_type_handler +@@ -766,20 +767,20 @@ + twophase=self.allow_twophase, + ) + +- # Py2K +- if self._cx_oracle_with_unicode: +- for k, v in opts.items(): +- if isinstance(v, str): +- opts[k] = unicode(v) +- else: +- for k, v in opts.items(): +- if isinstance(v, unicode): +- opts[k] = str(v) +- # end Py2K ++# start Py2K ++# if self._cx_oracle_with_unicode: ++# for k, v in opts.items(): ++# if isinstance(v, str): ++# opts[k] = unicode(v) ++# else: ++# for k, v in opts.items(): ++# if isinstance(v, unicode): ++# opts[k] = str(v) ++# end Py2K + + if 'mode' in url.query: + opts['mode'] = url.query['mode'] +- if isinstance(opts['mode'], basestring): ++ if isinstance(opts['mode'], str): + mode = opts['mode'].upper() + if mode == 'SYSDBA': + opts['mode'] = self.dbapi.SYSDBA +diff -r 9d0639b9d3be lib/sqlalchemy/dialects/oracle/zxjdbc.py +--- a/lib/sqlalchemy/dialects/oracle/zxjdbc.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/dialects/oracle/zxjdbc.py Sat Apr 27 19:42:17 2013 -0400 +@@ -95,8 +95,8 @@ + try: + try: + rrs = self.statement.__statement__.getReturnResultSet() +- rrs.next() +- except SQLException, sqle: ++ next(rrs) ++ except SQLException as sqle: + msg = '%s [SQLCode: %d]' % (sqle.getMessage(), sqle.getErrorCode()) + if sqle.getSQLState() is not None: + msg += ' [SQLState: %s]' % sqle.getSQLState() +diff -r 9d0639b9d3be lib/sqlalchemy/dialects/postgresql/base.py +--- a/lib/sqlalchemy/dialects/postgresql/base.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/dialects/postgresql/base.py Sat Apr 27 19:42:17 2013 -0400 +@@ -1419,7 +1419,7 @@ + query, + bindparams=[ + sql.bindparam( +- 'schema', unicode(schema.lower()), ++ 'schema', str(schema.lower()), + type_=sqltypes.Unicode)] + ) + ) +@@ -1435,7 +1435,7 @@ + "n.oid=c.relnamespace where n.nspname=current_schema() and " + "relname=:name", + bindparams=[ +- sql.bindparam('name', unicode(table_name), ++ sql.bindparam('name', str(table_name), + type_=sqltypes.Unicode)] + ) + ) +@@ -1447,9 +1447,9 @@ + "relname=:name", + bindparams=[ + sql.bindparam('name', +- unicode(table_name), type_=sqltypes.Unicode), ++ str(table_name), type_=sqltypes.Unicode), + sql.bindparam('schema', +- unicode(schema), type_=sqltypes.Unicode)] ++ str(schema), type_=sqltypes.Unicode)] + ) + ) + return bool(cursor.first()) +@@ -1463,7 +1463,7 @@ + "n.nspname=current_schema() " + "and relname=:name", + bindparams=[ +- sql.bindparam('name', unicode(sequence_name), ++ sql.bindparam('name', str(sequence_name), + type_=sqltypes.Unicode) + ] + ) +@@ -1475,10 +1475,10 @@ + "n.oid=c.relnamespace where relkind='S' and " + "n.nspname=:schema and relname=:name", + bindparams=[ +- sql.bindparam('name', unicode(sequence_name), ++ sql.bindparam('name', str(sequence_name), + type_=sqltypes.Unicode), + sql.bindparam('schema', +- unicode(schema), type_=sqltypes.Unicode) ++ str(schema), type_=sqltypes.Unicode) + ] + ) + ) +@@ -1488,9 +1488,9 @@ + def has_type(self, connection, type_name, schema=None): + bindparams = [ + sql.bindparam('typname', +- unicode(type_name), type_=sqltypes.Unicode), ++ str(type_name), type_=sqltypes.Unicode), + sql.bindparam('nspname', +- unicode(schema), type_=sqltypes.Unicode), ++ str(schema), type_=sqltypes.Unicode), + ] + if schema is not None: + query = """ +@@ -1546,9 +1546,9 @@ + """ % schema_where_clause + # Since we're binding to unicode, table_name and schema_name must be + # unicode. +- table_name = unicode(table_name) ++ table_name = str(table_name) + if schema is not None: +- schema = unicode(schema) ++ schema = str(schema) + s = sql.text(query, bindparams=[ + sql.bindparam('table_name', type_=sqltypes.Unicode), + sql.bindparam('schema', type_=sqltypes.Unicode) +@@ -1570,13 +1570,14 @@ + """ + rp = connection.execute(s) + # what about system tables? +- # Py3K +- #schema_names = [row[0] for row in rp \ +- # if not row[0].startswith('pg_')] +- # Py2K +- schema_names = [row[0].decode(self.encoding) for row in rp \ ++# start Py3K ++ schema_names = [row[0] for row in rp \ + if not row[0].startswith('pg_')] +- # end Py2K ++# end Py3K ++# start Py2K ++# schema_names = [row[0].decode(self.encoding) for row in rp \ ++# if not row[0].startswith('pg_')] ++# end Py2K + return schema_names + + @reflection.cache +@@ -1587,7 +1588,7 @@ + current_schema = self.default_schema_name + + result = connection.execute( +- sql.text(u"SELECT relname FROM pg_class c " ++ sql.text("SELECT relname FROM pg_class c " + "WHERE relkind = 'r' " + "AND '%s' = (select nspname from pg_namespace n " + "where n.oid = c.relnamespace) " % +@@ -1610,12 +1611,13 @@ + AND '%(schema)s' = (select nspname from pg_namespace n + where n.oid = c.relnamespace) + """ % dict(schema=current_schema) +- # Py3K +- #view_names = [row[0] for row in connection.execute(s)] +- # Py2K +- view_names = [row[0].decode(self.encoding) +- for row in connection.execute(s)] +- # end Py2K ++# start Py3K ++ view_names = [row[0] for row in connection.execute(s)] ++# end Py3K ++# start Py2K ++# view_names = [row[0].decode(self.encoding) ++# for row in connection.execute(s)] ++# end Py2K + return view_names + + @reflection.cache +@@ -1632,11 +1634,12 @@ + rp = connection.execute(sql.text(s), + view_name=view_name, schema=current_schema) + if rp: +- # Py3K +- #view_def = rp.scalar() +- # Py2K +- view_def = rp.scalar().decode(self.encoding) +- # end Py2K ++# start Py3K ++ view_def = rp.scalar() ++# end Py3K ++# start Py2K ++# view_def = rp.scalar().decode(self.encoding) ++# end Py2K + return view_def + + @reflection.cache +diff -r 9d0639b9d3be lib/sqlalchemy/dialects/postgresql/hstore.py +--- a/lib/sqlalchemy/dialects/postgresql/hstore.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/dialects/postgresql/hstore.py Sat Apr 27 19:42:17 2013 -0400 +@@ -96,14 +96,14 @@ + def esc(s, position): + if position == 'value' and s is None: + return 'NULL' +- elif isinstance(s, basestring): ++ elif isinstance(s, str): + return '"%s"' % s.replace('"', r'\"') + else: + raise ValueError("%r in %s position is not a string." % + (s, position)) + + return ', '.join('%s=>%s' % (esc(k, 'key'), esc(v, 'value')) +- for k, v in val.iteritems()) ++ for k, v in val.items()) + + + class HSTORE(sqltypes.Concatenable, sqltypes.TypeEngine): +diff -r 9d0639b9d3be lib/sqlalchemy/dialects/postgresql/psycopg2.py +--- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py Sat Apr 27 19:42:17 2013 -0400 +@@ -142,7 +142,7 @@ + effect for other DBAPIs. + + """ +-from __future__ import absolute_import ++ + import re + import logging + +@@ -190,22 +190,22 @@ + class _PGEnum(ENUM): + def __init__(self, *arg, **kw): + super(_PGEnum, self).__init__(*arg, **kw) +- # Py2K +- if self.convert_unicode: +- self.convert_unicode = "force" +- # end Py2K ++# start Py2K ++# if self.convert_unicode: ++# self.convert_unicode = "force" ++# end Py2K + + + class _PGArray(ARRAY): + def __init__(self, *arg, **kw): + super(_PGArray, self).__init__(*arg, **kw) +- # Py2K +- # FIXME: this check won't work for setups that +- # have convert_unicode only on their create_engine(). +- if isinstance(self.item_type, sqltypes.String) and \ +- self.item_type.convert_unicode: +- self.item_type.convert_unicode = "force" +- # end Py2K ++# start Py2K ++# # FIXME: this check won't work for setups that ++# # have convert_unicode only on their create_engine(). ++# if isinstance(self.item_type, sqltypes.String) and \ ++# self.item_type.convert_unicode: ++# self.item_type.convert_unicode = "force" ++# end Py2K + + + class _PGHStore(HSTORE): +@@ -294,9 +294,9 @@ + + class PGDialect_psycopg2(PGDialect): + driver = 'psycopg2' +- # Py2K +- supports_unicode_statements = False +- # end Py2K ++# start Py2K ++# supports_unicode_statements = False ++# end Py2K + default_paramstyle = 'pyformat' + supports_sane_multi_rowcount = False + execution_ctx_cls = PGExecutionContext_psycopg2 +diff -r 9d0639b9d3be lib/sqlalchemy/dialects/sqlite/base.py +--- a/lib/sqlalchemy/dialects/sqlite/base.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/dialects/sqlite/base.py Sat Apr 27 19:42:17 2013 -0400 +@@ -508,7 +508,7 @@ + + def visit_foreign_key_constraint(self, constraint): + +- local_table = constraint._elements.values()[0].parent.table ++ local_table = list(constraint._elements.values())[0].parent.table + remote_table = list(constraint._elements.values())[0].column.table + + if local_table.schema != remote_table.schema: +@@ -812,7 +812,7 @@ + coltype = sqltypes.NullType() + + if default is not None: +- default = unicode(default) ++ default = str(default) + + return { + 'name': name, +diff -r 9d0639b9d3be lib/sqlalchemy/dialects/sqlite/pysqlite.py +--- a/lib/sqlalchemy/dialects/sqlite/pysqlite.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/dialects/sqlite/pysqlite.py Sat Apr 27 19:42:17 2013 -0400 +@@ -267,8 +267,9 @@ + } + ) + +- # Py3K +- #description_encoding = None ++# start Py3K ++ description_encoding = None ++# end Py3K + + driver = 'pysqlite' + +@@ -288,7 +289,7 @@ + def dbapi(cls): + try: + from pysqlite2 import dbapi2 as sqlite +- except ImportError, e: ++ except ImportError as e: + try: + from sqlite3 import dbapi2 as sqlite # try 2.5+ stdlib name. + except ImportError: +diff -r 9d0639b9d3be lib/sqlalchemy/dialects/sybase/__init__.py +--- a/lib/sqlalchemy/dialects/sybase/__init__.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/dialects/sybase/__init__.py Sat Apr 27 19:42:17 2013 -0400 +@@ -9,7 +9,7 @@ + # default dialect + base.dialect = pyodbc.dialect + +-from base import CHAR, VARCHAR, TIME, NCHAR, NVARCHAR,\ ++from .base import CHAR, VARCHAR, TIME, NCHAR, NVARCHAR,\ + TEXT, DATE, DATETIME, FLOAT, NUMERIC,\ + BIGINT, INT, INTEGER, SMALLINT, BINARY,\ + VARBINARY, UNITEXT, UNICHAR, UNIVARCHAR,\ +diff -r 9d0639b9d3be lib/sqlalchemy/dialects/sybase/base.py +--- a/lib/sqlalchemy/dialects/sybase/base.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/dialects/sybase/base.py Sat Apr 27 19:42:17 2013 -0400 +@@ -475,12 +475,12 @@ + AND o.type in ('U', 'V') + """) + +- # Py2K +- if isinstance(schema, unicode): +- schema = schema.encode("ascii") +- if isinstance(table_name, unicode): +- table_name = table_name.encode("ascii") +- # end Py2K ++# start Py2K ++# if isinstance(schema, unicode): ++# schema = schema.encode("ascii") ++# if isinstance(table_name, unicode): ++# table_name = table_name.encode("ascii") ++# end Py2K + result = connection.execute(TABLEID_SQL, + schema_name=schema, + table_name=table_name) +@@ -759,10 +759,10 @@ + AND o.type = 'U' + """) + +- # Py2K +- if isinstance(schema, unicode): +- schema = schema.encode("ascii") +- # end Py2K ++# start Py2K ++# if isinstance(schema, unicode): ++# schema = schema.encode("ascii") ++# end Py2K + tables = connection.execute(TABLE_SQL, schema_name=schema) + + return [t["name"] for t in tables] +@@ -779,10 +779,10 @@ + AND o.type = 'V' + """) + +- # Py2K +- if isinstance(view_name, unicode): +- view_name = view_name.encode("ascii") +- # end Py2K ++# start Py2K ++# if isinstance(view_name, unicode): ++# view_name = view_name.encode("ascii") ++# end Py2K + view = connection.execute(VIEW_DEF_SQL, view_name=view_name) + + return view.scalar() +@@ -799,10 +799,10 @@ + AND o.type = 'V' + """) + +- # Py2K +- if isinstance(schema, unicode): +- schema = schema.encode("ascii") +- # end Py2K ++# start Py2K ++# if isinstance(schema, unicode): ++# schema = schema.encode("ascii") ++# end Py2K + views = connection.execute(VIEW_SQL, schema_name=schema) + + return [v["name"] for v in views] +diff -r 9d0639b9d3be lib/sqlalchemy/engine/base.py +--- a/lib/sqlalchemy/engine/base.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/engine/base.py Sat Apr 27 19:42:17 2013 -0400 +@@ -9,7 +9,7 @@ + + """ + +-from __future__ import with_statement ++ + import sys + from .. import exc, schema, util, log, interfaces + from ..sql import expression, util as sql_util +@@ -460,7 +460,7 @@ + + try: + self.engine.dialect.do_begin(self.connection) +- except Exception, e: ++ except Exception as e: + self._handle_dbapi_exception(e, None, None, None, None) + + def _rollback_impl(self): +@@ -473,7 +473,7 @@ + try: + self.engine.dialect.do_rollback(self.connection) + self.__transaction = None +- except Exception, e: ++ except Exception as e: + self._handle_dbapi_exception(e, None, None, None, None) + else: + self.__transaction = None +@@ -487,7 +487,7 @@ + try: + self.engine.dialect.do_commit(self.connection) + self.__transaction = None +- except Exception, e: ++ except Exception as e: + self._handle_dbapi_exception(e, None, None, None, None) + + def _savepoint_impl(self, name=None): +@@ -688,7 +688,7 @@ + dialect = self.dialect + ctx = dialect.execution_ctx_cls._init_default( + dialect, self, conn) +- except Exception, e: ++ except Exception as e: + self._handle_dbapi_exception(e, None, None, None, None) + + ret = ctx._exec_default(default, None) +@@ -734,7 +734,7 @@ + + distilled_params = _distill_params(multiparams, params) + if distilled_params: +- keys = distilled_params[0].keys() ++ keys = list(distilled_params[0].keys()) + else: + keys = [] + +@@ -822,7 +822,7 @@ + conn = self._revalidate_connection() + + context = constructor(dialect, self, conn, *args) +- except Exception, e: ++ except Exception as e: + self._handle_dbapi_exception(e, + str(statement), parameters, + None, None) +@@ -865,7 +865,7 @@ + statement, + parameters, + context) +- except Exception, e: ++ except Exception as e: + self._handle_dbapi_exception( + e, + statement, +@@ -939,7 +939,7 @@ + cursor, + statement, + parameters) +- except Exception, e: ++ except Exception as e: + self._handle_dbapi_exception( + e, + statement, +@@ -954,7 +954,7 @@ + """ + try: + cursor.close() +- except Exception, e: ++ except Exception as e: + try: + ex_text = str(e) + except TypeError: +@@ -1045,7 +1045,7 @@ + Compiled: _execute_compiled, + schema.SchemaItem: _execute_default, + schema.DDLElement: _execute_ddl, +- basestring: _execute_text ++ str: _execute_text + } + + def default_schema_name(self): +diff -r 9d0639b9d3be lib/sqlalchemy/engine/ddl.py +--- a/lib/sqlalchemy/engine/ddl.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/engine/ddl.py Sat Apr 27 19:42:17 2013 -0400 +@@ -52,10 +52,10 @@ + if self.tables is not None: + tables = self.tables + else: +- tables = metadata.tables.values() ++ tables = list(metadata.tables.values()) + collection = [t for t in sql_util.sort_tables(tables) + if self._can_create_table(t)] +- seq_coll = [s for s in metadata._sequences.values() ++ seq_coll = [s for s in list(metadata._sequences.values()) + if s.column is None and self._can_create_sequence(s)] + + metadata.dispatch.before_create(metadata, self.connection, +@@ -120,7 +120,7 @@ + if self.tables is not None: + tables = self.tables + else: +- tables = metadata.tables.values() ++ tables = list(metadata.tables.values()) + + collection = [ + t +@@ -130,7 +130,7 @@ + + seq_coll = [ + s +- for s in metadata._sequences.values() ++ for s in list(metadata._sequences.values()) + if s.column is None and self._can_drop_sequence(s) + ] + +diff -r 9d0639b9d3be lib/sqlalchemy/engine/default.py +--- a/lib/sqlalchemy/engine/default.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/engine/default.py Sat Apr 27 19:42:17 2013 -0400 +@@ -57,17 +57,18 @@ + # *not* the FLOAT type however. + supports_native_decimal = False + +- # Py3K +- #supports_unicode_statements = True +- #supports_unicode_binds = True +- #returns_unicode_strings = True +- #description_encoding = None +- # Py2K +- supports_unicode_statements = False +- supports_unicode_binds = False +- returns_unicode_strings = False +- description_encoding = 'use_encoding' +- # end Py2K ++# start Py3K ++ supports_unicode_statements = True ++ supports_unicode_binds = True ++ returns_unicode_strings = True ++ description_encoding = None ++# end Py3K ++# start Py2K ++# supports_unicode_statements = False ++# supports_unicode_binds = False ++# returns_unicode_strings = False ++# description_encoding = 'use_encoding' ++# end Py2K + + name = 'default' + +@@ -201,14 +202,15 @@ + return None + + def _check_unicode_returns(self, connection): +- # Py2K +- if self.supports_unicode_statements: +- cast_to = unicode +- else: +- cast_to = str +- # end Py2K +- # Py3K +- #cast_to = str ++# start Py2K ++# if self.supports_unicode_statements: ++# cast_to = unicode ++# else: ++# cast_to = str ++# end Py2K ++# start Py3K ++ cast_to = str ++# end Py3K + + def check_unicode(formatstr, type_): + cursor = connection.connection.cursor() +@@ -226,8 +228,8 @@ + ) + row = cursor.fetchone() + +- return isinstance(row[0], unicode) +- except self.dbapi.Error, de: ++ return isinstance(row[0], str) ++ except self.dbapi.Error as de: + util.warn("Exception attempting to " + "detect unicode returns: %r" % de) + return False +@@ -373,10 +375,10 @@ + self.execution_options.update(connection._execution_options) + + if not dialect.supports_unicode_statements: +- self.unicode_statement = unicode(compiled) ++ self.unicode_statement = str(compiled) + self.statement = dialect._encoder(self.unicode_statement)[0] + else: +- self.statement = self.unicode_statement = unicode(compiled) ++ self.statement = self.unicode_statement = str(compiled) + + self.cursor = self.create_cursor() + self.compiled_parameters = [] +@@ -414,7 +416,7 @@ + + self.result_map = compiled.result_map + +- self.unicode_statement = unicode(compiled) ++ self.unicode_statement = str(compiled) + if not dialect.supports_unicode_statements: + self.statement = self.unicode_statement.encode( + self.dialect.encoding) +@@ -519,7 +521,7 @@ + self.executemany = len(parameters) > 1 + + if not dialect.supports_unicode_statements and \ +- isinstance(statement, unicode): ++ isinstance(statement, str): + self.unicode_statement = statement + self.statement = dialect._encoder(statement)[0] + else: +@@ -573,7 +575,7 @@ + """ + + conn = self.root_connection +- if isinstance(stmt, unicode) and \ ++ if isinstance(stmt, str) and \ + not self.dialect.supports_unicode_statements: + stmt = self.dialect._encoder(stmt)[0] + +@@ -734,12 +736,12 @@ + inputsizes.append(dbtype) + try: + self.cursor.setinputsizes(*inputsizes) +- except Exception, e: ++ except Exception as e: + self.root_connection._handle_dbapi_exception( + e, None, None, None, self) + else: + inputsizes = {} +- for key in self.compiled.bind_names.values(): ++ for key in list(self.compiled.bind_names.values()): + typeengine = types[key] + dbtype = typeengine.dialect_impl(self.dialect).\ + get_dbapi_type(self.dialect.dbapi) +@@ -752,7 +754,7 @@ + inputsizes[key] = dbtype + try: + self.cursor.setinputsizes(**inputsizes) +- except Exception, e: ++ except Exception as e: + self.root_connection._handle_dbapi_exception( + e, None, None, None, self) + +diff -r 9d0639b9d3be lib/sqlalchemy/engine/reflection.py +--- a/lib/sqlalchemy/engine/reflection.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/engine/reflection.py Sat Apr 27 19:42:17 2013 -0400 +@@ -41,8 +41,8 @@ + return fn(self, con, *args, **kw) + key = ( + fn.__name__, +- tuple(a for a in args if isinstance(a, basestring)), +- tuple((k, v) for k, v in kw.iteritems() if isinstance(v, (basestring, int, float))) ++ tuple(a for a in args if isinstance(a, str)), ++ tuple((k, v) for k, v in kw.items() if isinstance(v, (str, int, float))) + ) + ret = info_cache.get(key) + if ret is None: +@@ -381,16 +381,16 @@ + # table.kwargs will need to be passed to each reflection method. Make + # sure keywords are strings. + tblkw = table.kwargs.copy() +- for (k, v) in tblkw.items(): ++ for (k, v) in list(tblkw.items()): + del tblkw[k] + tblkw[str(k)] = v + +- # Py2K +- if isinstance(schema, str): +- schema = schema.decode(dialect.encoding) +- if isinstance(table_name, str): +- table_name = table_name.decode(dialect.encoding) +- # end Py2K ++# start Py2K ++# if isinstance(schema, str): ++# schema = schema.decode(dialect.encoding) ++# if isinstance(table_name, str): ++# table_name = table_name.decode(dialect.encoding) ++# end Py2K + + # columns + found_table = False +diff -r 9d0639b9d3be lib/sqlalchemy/engine/result.py +--- a/lib/sqlalchemy/engine/result.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/engine/result.py Sat Apr 27 19:42:17 2013 -0400 +@@ -8,7 +8,7 @@ + and :class:`.RowProxy.""" + + +-from itertools import izip ++ + from .. import exc, types, util + from ..sql import expression + import collections +@@ -55,7 +55,7 @@ + return list(self) + + def __iter__(self): +- for processor, value in izip(self._processors, self._row): ++ for processor, value in zip(self._processors, self._row): + if processor is None: + yield value + else: +@@ -72,7 +72,7 @@ + except TypeError: + if isinstance(key, slice): + l = [] +- for processor, value in izip(self._processors[key], ++ for processor, value in zip(self._processors[key], + self._row[key]): + if processor is None: + l.append(value) +@@ -93,7 +93,7 @@ + def __getattr__(self, name): + try: + return self[name] +- except KeyError, e: ++ except KeyError as e: + raise AttributeError(e.args[0]) + + +@@ -142,7 +142,7 @@ + def items(self): + """Return a list of tuples, each tuple containing a key/value pair.""" + # TODO: no coverage here +- return [(key, self[key]) for key in self.iterkeys()] ++ return [(key, self[key]) for key in self.keys()] + + def keys(self): + """Return the list of keys as strings represented by this RowProxy.""" +@@ -274,7 +274,7 @@ + def _key_fallback(self, key, raiseerr=True): + map = self._keymap + result = None +- if isinstance(key, basestring): ++ if isinstance(key, str): + result = map.get(key if self.case_sensitive else key.lower()) + # fallback for targeting a ColumnElement to a textual expression + # this is a rare use case which only occurs when matching text() +@@ -328,8 +328,8 @@ + return { + '_pickled_keymap': dict( + (key, index) +- for key, (processor, obj, index) in self._keymap.iteritems() +- if isinstance(key, (basestring, int)) ++ for key, (processor, obj, index) in self._keymap.items() ++ if isinstance(key, (str, int)) + ), + 'keys': self.keys, + "case_sensitive": self.case_sensitive, +@@ -338,9 +338,9 @@ + def __setstate__(self, state): + # the row has been processed at pickling time so we don't need any + # processor anymore +- self._processors = [None for _ in xrange(len(state['keys']))] ++ self._processors = [None for _ in range(len(state['keys']))] + self._keymap = keymap = {} +- for key, index in state['_pickled_keymap'].iteritems(): ++ for key, index in state['_pickled_keymap'].items(): + # not preserving "obj" here, unfortunately our + # proxy comparison fails with the unpickle + keymap[key] = (None, None, index) +@@ -440,7 +440,7 @@ + """ + try: + return self.context.rowcount +- except Exception, e: ++ except Exception as e: + self.connection._handle_dbapi_exception( + e, None, None, self.cursor, self.context) + +@@ -462,7 +462,7 @@ + """ + try: + return self._saved_cursor.lastrowid +- except Exception, e: ++ except Exception as e: + self.connection._handle_dbapi_exception( + e, None, None, + self._saved_cursor, self.context) +@@ -746,7 +746,7 @@ + l = self.process_rows(self._fetchall_impl()) + self.close() + return l +- except Exception, e: ++ except Exception as e: + self.connection._handle_dbapi_exception( + e, None, None, + self.cursor, self.context) +@@ -765,7 +765,7 @@ + if len(l) == 0: + self.close() + return l +- except Exception, e: ++ except Exception as e: + self.connection._handle_dbapi_exception( + e, None, None, + self.cursor, self.context) +@@ -784,7 +784,7 @@ + else: + self.close() + return None +- except Exception, e: ++ except Exception as e: + self.connection._handle_dbapi_exception( + e, None, None, + self.cursor, self.context) +@@ -800,7 +800,7 @@ + + try: + row = self._fetchone_impl() +- except Exception, e: ++ except Exception as e: + self.connection._handle_dbapi_exception( + e, None, None, + self.cursor, self.context) +@@ -966,9 +966,9 @@ + # constructed. + metadata._orig_processors = metadata._processors + # replace the all type processors by None processors. +- metadata._processors = [None for _ in xrange(len(metadata.keys))] ++ metadata._processors = [None for _ in range(len(metadata.keys))] + keymap = {} +- for k, (func, obj, index) in metadata._keymap.iteritems(): ++ for k, (func, obj, index) in metadata._keymap.items(): + keymap[k] = (None, obj, index) + self._metadata._keymap = keymap + +@@ -989,7 +989,7 @@ + if size is None: + return self.fetchall() + l = [] +- for i in xrange(size): ++ for i in range(size): + row = self.fetchone() + if row is None: + break +diff -r 9d0639b9d3be lib/sqlalchemy/engine/strategies.py +--- a/lib/sqlalchemy/engine/strategies.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/engine/strategies.py Sat Apr 27 19:42:17 2013 -0400 +@@ -78,20 +78,21 @@ + def connect(): + try: + return dialect.connect(*cargs, **cparams) +- except Exception, e: ++ except Exception as e: + invalidated = dialect.is_disconnect(e, None, None) +- # Py3K +- #raise exc.DBAPIError.instance(None, None, +- # e, dialect.dbapi.Error, +- # connection_invalidated=invalidated +- #) from e +- # Py2K +- import sys +- raise exc.DBAPIError.instance( +- None, None, e, dialect.dbapi.Error, ++# start Py3K ++ raise exc.DBAPIError.instance(None, None, ++ e, dialect.dbapi.Error, + connection_invalidated=invalidated +- ), None, sys.exc_info()[2] +- # end Py2K ++ ) from e ++# end Py3K ++# start Py2K ++# import sys ++# raise exc.DBAPIError.instance( ++# None, None, e, dialect.dbapi.Error, ++# connection_invalidated=invalidated ++# ), None, sys.exc_info()[2] ++# end Py2K + + creator = kwargs.pop('creator', connect) + +diff -r 9d0639b9d3be lib/sqlalchemy/engine/url.py +--- a/lib/sqlalchemy/engine/url.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/engine/url.py Sat Apr 27 19:42:17 2013 -0400 +@@ -14,7 +14,7 @@ + """ + + import re +-import urllib ++import urllib.request, urllib.parse, urllib.error + from .. import exc, util + from . import Dialect + +@@ -67,7 +67,7 @@ + if self.username is not None: + s += self.username + if self.password is not None: +- s += ':' + urllib.quote_plus(self.password) ++ s += ':' + urllib.parse.quote_plus(self.password) + s += "@" + if self.host is not None: + s += self.host +@@ -76,7 +76,7 @@ + if self.database is not None: + s += '/' + self.database + if self.query: +- keys = self.query.keys() ++ keys = list(self.query.keys()) + keys.sort() + s += '?' + "&".join("%s=%s" % (k, self.query[k]) for k in keys) + return s +@@ -150,7 +150,7 @@ + existing URL object is passed, just returns the object. + """ + +- if isinstance(name_or_url, basestring): ++ if isinstance(name_or_url, str): + return _parse_rfc1738_args(name_or_url) + else: + return name_or_url +@@ -177,17 +177,17 @@ + tokens = components['database'].split('?', 2) + components['database'] = tokens[0] + query = (len(tokens) > 1 and dict(util.parse_qsl(tokens[1]))) or None +- # Py2K +- if query is not None: +- query = dict((k.encode('ascii'), query[k]) for k in query) +- # end Py2K ++# start Py2K ++# if query is not None: ++# query = dict((k.encode('ascii'), query[k]) for k in query) ++# end Py2K + else: + query = None + components['query'] = query + + if components['password'] is not None: + components['password'] = \ +- urllib.unquote_plus(components['password']) ++ urllib.parse.unquote_plus(components['password']) + + name = components.pop('name') + return URL(name, **components) +diff -r 9d0639b9d3be lib/sqlalchemy/event.py +--- a/lib/sqlalchemy/event.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/event.py Sat Apr 27 19:42:17 2013 -0400 +@@ -201,11 +201,9 @@ + del _registrars[k] + + +-class Events(object): ++class Events(object, metaclass=_EventMeta): + """Define event listening functions for a particular target type.""" + +- __metaclass__ = _EventMeta +- + @classmethod + def _accept_with(cls, target): + # Mapper, ClassManager, Session override this to +@@ -302,7 +300,7 @@ + def clear(self): + """Clear all class level listeners""" + +- for dispatcher in self._clslevel.values(): ++ for dispatcher in list(self._clslevel.values()): + dispatcher[:] = [] + + def for_modify(self, obj): +@@ -377,7 +375,7 @@ + def __iter__(self): + return iter(self.parent_listeners) + +- def __nonzero__(self): ++ def __bool__(self): + return bool(self.parent_listeners) + + +@@ -414,7 +412,7 @@ + def __iter__(self): + return chain(self.parent_listeners, self.listeners) + +- def __nonzero__(self): ++ def __bool__(self): + return bool(self.listeners or self.parent_listeners) + + +diff -r 9d0639b9d3be lib/sqlalchemy/exc.py +--- a/lib/sqlalchemy/exc.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/exc.py Sat Apr 27 19:42:17 2013 -0400 +@@ -285,7 +285,7 @@ + text = str(orig) + except (KeyboardInterrupt, SystemExit): + raise +- except Exception, e: ++ except Exception as e: + text = 'Error in str() of DB-API-generated exception: ' + str(e) + StatementError.__init__( + self, +diff -r 9d0639b9d3be lib/sqlalchemy/ext/associationproxy.py +--- a/lib/sqlalchemy/ext/associationproxy.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/ext/associationproxy.py Sat Apr 27 19:42:17 2013 -0400 +@@ -475,7 +475,7 @@ + def __len__(self): + return len(self.col) + +- def __nonzero__(self): ++ def __bool__(self): + return bool(self.col) + + def __getstate__(self): +@@ -514,7 +514,7 @@ + stop = index.stop + step = index.step or 1 + +- rng = range(index.start or 0, stop, step) ++ rng = list(range(index.start or 0, stop, step)) + if step == 1: + for i in rng: + del self[index.start] +@@ -569,7 +569,7 @@ + + def count(self, value): + return sum([1 for _ in +- itertools.ifilter(lambda v: v == value, iter(self))]) ++ filter(lambda v: v == value, iter(self))]) + + def extend(self, values): + for v in values: +@@ -668,8 +668,8 @@ + def __hash__(self): + raise TypeError("%s objects are unhashable" % type(self).__name__) + +- for func_name, func in locals().items(): +- if (util.callable(func) and func.func_name == func_name and ++ for func_name, func in list(locals().items()): ++ if (util.callable(func) and func.__name__ == func_name and + not func.__doc__ and hasattr(list, func_name)): + func.__doc__ = getattr(list, func_name).__doc__ + del func_name, func +@@ -711,7 +711,7 @@ + return key in self.col + + def __iter__(self): +- return self.col.iterkeys() ++ return iter(self.col.keys()) + + def clear(self): + self.col.clear() +@@ -738,7 +738,7 @@ + return cmp(dict(self), other) + + def __repr__(self): +- return repr(dict(self.items())) ++ return repr(dict(list(self.items()))) + + def get(self, key, default=None): + try: +@@ -754,13 +754,13 @@ + return self[key] + + def keys(self): +- return self.col.keys() ++ return list(self.col.keys()) + + def iterkeys(self): +- return self.col.iterkeys() ++ return iter(self.col.keys()) + + def values(self): +- return [self._get(member) for member in self.col.values()] ++ return [self._get(member) for member in list(self.col.values())] + + def itervalues(self): + for key in self.col: +@@ -811,13 +811,13 @@ + self[key] = value + + def copy(self): +- return dict(self.items()) ++ return dict(list(self.items())) + + def __hash__(self): + raise TypeError("%s objects are unhashable" % type(self).__name__) + +- for func_name, func in locals().items(): +- if (util.callable(func) and func.func_name == func_name and ++ for func_name, func in list(locals().items()): ++ if (util.callable(func) and func.__name__ == func_name and + not func.__doc__ and hasattr(dict, func_name)): + func.__doc__ = getattr(dict, func_name).__doc__ + del func_name, func +@@ -838,7 +838,7 @@ + def __len__(self): + return len(self.col) + +- def __nonzero__(self): ++ def __bool__(self): + if self.col: + return True + else: +@@ -1014,8 +1014,8 @@ + def __hash__(self): + raise TypeError("%s objects are unhashable" % type(self).__name__) + +- for func_name, func in locals().items(): +- if (util.callable(func) and func.func_name == func_name and ++ for func_name, func in list(locals().items()): ++ if (util.callable(func) and func.__name__ == func_name and + not func.__doc__ and hasattr(set, func_name)): + func.__doc__ = getattr(set, func_name).__doc__ + del func_name, func +diff -r 9d0639b9d3be lib/sqlalchemy/ext/declarative/api.py +--- a/lib/sqlalchemy/ext/declarative/api.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/ext/declarative/api.py Sat Apr 27 19:42:17 2013 -0400 +@@ -424,7 +424,7 @@ + def prepare(cls, engine): + """Reflect all :class:`.Table` objects for all current + :class:`.DeferredReflection` subclasses""" +- to_map = [m for m in _MapperConfig.configs.values() ++ to_map = [m for m in list(_MapperConfig.configs.values()) + if issubclass(m.cls, cls)] + for thingy in to_map: + cls._sa_decl_prepare(thingy.local_table, engine) +diff -r 9d0639b9d3be lib/sqlalchemy/ext/declarative/base.py +--- a/lib/sqlalchemy/ext/declarative/base.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/ext/declarative/base.py Sat Apr 27 19:42:17 2013 -0400 +@@ -57,7 +57,7 @@ + + class_mapped = _declared_mapping_info(base) is not None + +- for name, obj in vars(base).items(): ++ for name, obj in list(vars(base).items()): + if name == '__mapper_args__': + if not mapper_args_fn and ( + not class_mapped or +@@ -129,7 +129,7 @@ + ret.doc = obj.__doc__ + + # apply inherited columns as we should +- for k, v in potential_columns.items(): ++ for k, v in list(potential_columns.items()): + dict_[k] = v + + if inherited_table_args and not tablename: +@@ -173,7 +173,7 @@ + + # extract columns from the class dict + declared_columns = set() +- for key, c in our_stuff.iteritems(): ++ for key, c in our_stuff.items(): + if isinstance(c, (ColumnProperty, CompositeProperty)): + for col in c.columns: + if isinstance(col, Column) and \ +@@ -354,7 +354,7 @@ + # in which case the mapper makes this combination). + # See if the superclass has a similar column property. + # If so, join them together. +- for k, col in properties.items(): ++ for k, col in list(properties.items()): + if not isinstance(col, expression.ColumnElement): + continue + if k in inherited_mapper._props: +diff -r 9d0639b9d3be lib/sqlalchemy/ext/declarative/clsregistry.py +--- a/lib/sqlalchemy/ext/declarative/clsregistry.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/ext/declarative/clsregistry.py Sat Apr 27 19:42:17 2013 -0400 +@@ -255,7 +255,7 @@ + return x.cls + else: + return x +- except NameError, n: ++ except NameError as n: + raise exc.InvalidRequestError( + "When initializing mapper %s, expression %r failed to " + "locate a name (%r). If this is a class name, consider " +@@ -275,14 +275,14 @@ + for attr in ('argument', 'order_by', 'primaryjoin', 'secondaryjoin', + 'secondary', '_user_defined_foreign_keys', 'remote_side'): + v = getattr(prop, attr) +- if isinstance(v, basestring): ++ if isinstance(v, str): + setattr(prop, attr, resolve_arg(v)) + + if prop.backref and isinstance(prop.backref, tuple): + key, kwargs = prop.backref + for attr in ('primaryjoin', 'secondaryjoin', 'secondary', + 'foreign_keys', 'remote_side', 'order_by'): +- if attr in kwargs and isinstance(kwargs[attr], basestring): ++ if attr in kwargs and isinstance(kwargs[attr], str): + kwargs[attr] = resolve_arg(kwargs[attr]) + + return prop +diff -r 9d0639b9d3be lib/sqlalchemy/ext/mutable.py +--- a/lib/sqlalchemy/ext/mutable.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/ext/mutable.py Sat Apr 27 19:42:17 2013 -0400 +@@ -485,7 +485,7 @@ + def changed(self): + """Subclasses should call this method whenever change events occur.""" + +- for parent, key in self._parents.items(): ++ for parent, key in list(self._parents.items()): + flag_modified(parent, key) + + @classmethod +@@ -579,7 +579,7 @@ + def changed(self): + """Subclasses should call this method whenever change events occur.""" + +- for parent, key in self._parents.items(): ++ for parent, key in list(self._parents.items()): + + prop = object_mapper(parent).get_property(key) + for value, attr_name in zip( +diff -r 9d0639b9d3be lib/sqlalchemy/ext/orderinglist.py +--- a/lib/sqlalchemy/ext/orderinglist.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/ext/orderinglist.py Sat Apr 27 19:42:17 2013 -0400 +@@ -324,7 +324,7 @@ + if stop < 0: + stop += len(self) + +- for i in xrange(start, stop, step): ++ for i in range(start, stop, step): + self.__setitem__(i, entity[i]) + else: + self._order_entity(index, entity, True) +@@ -334,21 +334,21 @@ + super(OrderingList, self).__delitem__(index) + self._reorder() + +- # Py2K +- def __setslice__(self, start, end, values): +- super(OrderingList, self).__setslice__(start, end, values) +- self._reorder() +- +- def __delslice__(self, start, end): +- super(OrderingList, self).__delslice__(start, end) +- self._reorder() +- # end Py2K ++# start Py2K ++# def __setslice__(self, start, end, values): ++# super(OrderingList, self).__setslice__(start, end, values) ++# self._reorder() ++# ++# def __delslice__(self, start, end): ++# super(OrderingList, self).__delslice__(start, end) ++# self._reorder() ++# end Py2K + + def __reduce__(self): + return _reconstitute, (self.__class__, self.__dict__, list(self)) + +- for func_name, func in locals().items(): +- if (util.callable(func) and func.func_name == func_name and ++ for func_name, func in list(locals().items()): ++ if (util.callable(func) and func.__name__ == func_name and + not func.__doc__ and hasattr(list, func_name)): + func.__doc__ = getattr(list, func_name).__doc__ + del func_name, func +diff -r 9d0639b9d3be lib/sqlalchemy/ext/serializer.py +--- a/lib/sqlalchemy/ext/serializer.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/ext/serializer.py Sat Apr 27 19:42:17 2013 -0400 +@@ -61,20 +61,22 @@ + from ..util import pickle + import re + import base64 +-# Py3K +-#from io import BytesIO as byte_buffer +-# Py2K +-from cStringIO import StringIO as byte_buffer ++# start Py3K ++from io import BytesIO as byte_buffer ++# end Py3K ++# start Py2K ++#from cStringIO import StringIO as byte_buffer + # end Py2K + +-# Py3K +-#def b64encode(x): +-# return base64.b64encode(x).decode('ascii') +-#def b64decode(x): +-# return base64.b64decode(x.encode('ascii')) +-# Py2K +-b64encode = base64.b64encode +-b64decode = base64.b64decode ++# start Py3K ++def b64encode(x): ++ return base64.b64encode(x).decode('ascii') ++def b64decode(x): ++ return base64.b64decode(x.encode('ascii')) ++# end Py3K ++# start Py2K ++#b64encode = base64.b64encode ++#b64decode = base64.b64decode + # end Py2K + + __all__ = ['Serializer', 'Deserializer', 'dumps', 'loads'] +diff -r 9d0639b9d3be lib/sqlalchemy/orm/__init__.py +--- a/lib/sqlalchemy/orm/__init__.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/orm/__init__.py Sat Apr 27 19:42:17 2013 -0400 +@@ -1628,7 +1628,7 @@ + alias = kwargs.pop('alias', None) + if kwargs: + raise exc.ArgumentError( +- 'Invalid kwargs for contains_eager: %r' % kwargs.keys()) ++ 'Invalid kwargs for contains_eager: %r' % list(kwargs.keys())) + return strategies.EagerLazyOption(keys, lazy='joined', + propagate_to_loaders=False, chained=True), \ + strategies.LoadEagerFromAliasOption(keys, alias=alias, chained=True) +diff -r 9d0639b9d3be lib/sqlalchemy/orm/attributes.py +--- a/lib/sqlalchemy/orm/attributes.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/orm/attributes.py Sat Apr 27 19:42:17 2013 -0400 +@@ -1214,7 +1214,7 @@ + + """ + +- def __nonzero__(self): ++ def __bool__(self): + return self != HISTORY_BLANK + + def empty(self): +diff -r 9d0639b9d3be lib/sqlalchemy/orm/collections.py +--- a/lib/sqlalchemy/orm/collections.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/orm/collections.py Sat Apr 27 19:42:17 2013 -0400 +@@ -657,11 +657,12 @@ + if getattr(obj, '_sa_adapter', None) is not None: + return getattr(obj, '_sa_adapter') + elif setting_type == dict: +- # Py3K +- #return obj.values() +- # Py2K +- return getattr(obj, 'itervalues', getattr(obj, 'values'))() +- # end Py2K ++# start Py3K ++ return list(obj.values()) ++# end Py3K ++# start Py2K ++# return getattr(obj, 'itervalues', getattr(obj, 'values'))() ++# end Py2K + else: + return iter(obj) + +@@ -705,14 +706,15 @@ + def __iter__(self): + """Iterate over entities in the collection.""" + +- # Py3K requires iter() here ++# start Py3K ++# end Py3K + return iter(getattr(self._data(), '_sa_iterator')()) + + def __len__(self): + """Count entities in the collection.""" + return len(list(getattr(self._data(), '_sa_iterator')())) + +- def __nonzero__(self): ++ def __bool__(self): + return True + + def fire_append_event(self, item, initiator=None): +@@ -883,7 +885,7 @@ + # search for _sa_instrument_role-decorated methods in + # method resolution order, assign to roles + for supercls in cls.__mro__: +- for name, method in vars(supercls).items(): ++ for name, method in list(vars(supercls).items()): + if not util.callable(method): + continue + +@@ -917,11 +919,11 @@ + collection_type = util.duck_type_collection(cls) + if collection_type in __interfaces: + canned_roles, decorators = __interfaces[collection_type] +- for role, name in canned_roles.items(): ++ for role, name in list(canned_roles.items()): + roles.setdefault(role, name) + + # apply ABC auto-decoration to methods that need it +- for method, decorator in decorators.items(): ++ for method, decorator in list(decorators.items()): + fn = getattr(cls, method, None) + if (fn and method not in methods and + not hasattr(fn, '_sa_instrumented')): +@@ -952,12 +954,12 @@ + + # apply ad-hoc instrumentation from decorators, class-level defaults + # and implicit role declarations +- for method_name, (before, argument, after) in methods.items(): ++ for method_name, (before, argument, after) in list(methods.items()): + setattr(cls, method_name, + _instrument_membership_mutator(getattr(cls, method_name), + before, argument, after)) + # intern the role map +- for role, method_name in roles.items(): ++ for role, method_name in list(roles.items()): + setattr(cls, '_sa_%s' % role, getattr(cls, method_name)) + + setattr(cls, '_sa_instrumented', id(cls)) +@@ -1094,14 +1096,14 @@ + stop += len(self) + + if step == 1: +- for i in xrange(start, stop, step): ++ for i in range(start, stop, step): + if len(self) > start: + del self[start] + + for i, item in enumerate(value): + self.insert(i + start, item) + else: +- rng = range(start, stop, step) ++ rng = list(range(start, stop, step)) + if len(value) != len(rng): + raise ValueError( + "attempt to assign sequence of size %s to " +@@ -1128,24 +1130,24 @@ + _tidy(__delitem__) + return __delitem__ + +- # Py2K +- def __setslice__(fn): +- def __setslice__(self, start, end, values): +- for value in self[start:end]: +- __del(self, value) +- values = [__set(self, value) for value in values] +- fn(self, start, end, values) +- _tidy(__setslice__) +- return __setslice__ +- +- def __delslice__(fn): +- def __delslice__(self, start, end): +- for value in self[start:end]: +- __del(self, value) +- fn(self, start, end) +- _tidy(__delslice__) +- return __delslice__ +- # end Py2K ++# start Py2K ++# def __setslice__(fn): ++# def __setslice__(self, start, end, values): ++# for value in self[start:end]: ++# __del(self, value) ++# values = [__set(self, value) for value in values] ++# fn(self, start, end, values) ++# _tidy(__setslice__) ++# return __setslice__ ++# ++# def __delslice__(fn): ++# def __delslice__(self, start, end): ++# for value in self[start:end]: ++# __del(self, value) ++# fn(self, start, end) ++# _tidy(__delslice__) ++# return __delslice__ ++# end Py2K + + def extend(fn): + def extend(self, iterable): +@@ -1251,7 +1253,7 @@ + def update(self, __other=Unspecified, **kw): + if __other is not Unspecified: + if hasattr(__other, 'keys'): +- for key in __other.keys(): ++ for key in list(__other.keys()): + if (key not in self or + self[key] is not __other[key]): + self[key] = __other[key] +@@ -1467,11 +1469,12 @@ + ), + + # decorators are required for dicts and object collections. +- # Py3K +- #dict: ({'iterator': 'values'}, _dict_decorators()), +- # Py2K +- dict: ({'iterator': 'itervalues'}, _dict_decorators()), +- # end Py2K ++# start Py3K ++ dict: ({'iterator': 'values'}, _dict_decorators()), ++# end Py3K ++# start Py2K ++# dict: ({'iterator': 'itervalues'}, _dict_decorators()), ++# end Py2K + } + + +diff -r 9d0639b9d3be lib/sqlalchemy/orm/descriptor_props.py +--- a/lib/sqlalchemy/orm/descriptor_props.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/orm/descriptor_props.py Sat Apr 27 19:42:17 2013 -0400 +@@ -184,7 +184,7 @@ + def _init_props(self): + self.props = props = [] + for attr in self.attrs: +- if isinstance(attr, basestring): ++ if isinstance(attr, str): + prop = self.parent.get_property(attr) + elif isinstance(attr, schema.Column): + prop = self.parent._columntoproperty[attr] +diff -r 9d0639b9d3be lib/sqlalchemy/orm/evaluator.py +--- a/lib/sqlalchemy/orm/evaluator.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/orm/evaluator.py Sat Apr 27 19:42:17 2013 -0400 +@@ -13,9 +13,9 @@ + + _straight_ops = set(getattr(operators, op) + for op in ('add', 'mul', 'sub', +- # Py2K +- 'div', +- # end Py2K ++# start Py2K ++# 'div', ++# end Py2K + 'mod', 'truediv', + 'lt', 'le', 'ne', 'gt', 'ge', 'eq')) + +@@ -50,7 +50,7 @@ + return lambda obj: get_corresponding_attr(obj) + + def visit_clauselist(self, clause): +- evaluators = map(self.process, clause.clauses) ++ evaluators = list(map(self.process, clause.clauses)) + if clause.operator is operators.or_: + def evaluate(obj): + has_null = False +@@ -79,8 +79,8 @@ + return evaluate + + def visit_binary(self, clause): +- eval_left, eval_right = map(self.process, +- [clause.left, clause.right]) ++ eval_left, eval_right = list(map(self.process, ++ [clause.left, clause.right])) + operator = clause.operator + if operator is operators.is_: + def evaluate(obj): +diff -r 9d0639b9d3be lib/sqlalchemy/orm/identity.py +--- a/lib/sqlalchemy/orm/identity.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/orm/identity.py Sat Apr 27 19:42:17 2013 -0400 +@@ -75,7 +75,7 @@ + state = dict.__getitem__(self, key) + o = state.obj() + if o is None: +- raise KeyError, key ++ raise KeyError(key) + return o + + def __contains__(self, key): +@@ -152,30 +152,32 @@ + + return result + +- # Py3K +- #def items(self): +- # return iter(self._items()) +- # +- #def values(self): +- # return iter(self._values()) +- # Py2K +- items = _items +- +- def iteritems(self): +- return iter(self.items()) +- +- values = _values +- +- def itervalues(self): +- return iter(self.values()) +- # end Py2K ++# start Py3K ++ def items(self): ++ return iter(self._items()) ++ ++ def values(self): ++ return iter(self._values()) ++# end Py3K ++# start Py2K ++# items = _items ++# ++# def iteritems(self): ++# return iter(self.items()) ++# ++# values = _values ++# ++# def itervalues(self): ++# return iter(self.values()) ++# end Py2K + + def all_states(self): +- # Py3K +- # return list(dict.values(self)) +- # Py2K +- return dict.values(self) +- # end Py2K ++# start Py3K ++ return list(dict.values(self)) ++# end Py3K ++# start Py2K ++# return dict.values(self) ++# end Py2K + + def discard(self, state): + st = dict.get(self, state.key, None) +@@ -189,7 +191,7 @@ + + class StrongInstanceDict(IdentityMap): + def all_states(self): +- return [attributes.instance_state(o) for o in self.itervalues()] ++ return [attributes.instance_state(o) for o in self.values()] + + def contains_state(self, state): + return ( +diff -r 9d0639b9d3be lib/sqlalchemy/orm/instrumentation.py +--- a/lib/sqlalchemy/orm/instrumentation.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/orm/instrumentation.py Sat Apr 27 19:42:17 2013 -0400 +@@ -279,7 +279,7 @@ + + @property + def attributes(self): +- return self.itervalues() ++ return iter(self.values()) + + ## InstanceState management + +@@ -325,7 +325,7 @@ + """TODO""" + return self.get_impl(key).hasparent(state, optimistic=optimistic) + +- def __nonzero__(self): ++ def __bool__(self): + """All ClassManagers are non-zero regardless of attribute state.""" + return True + +@@ -444,21 +444,23 @@ + func_vars = util.format_argspec_init(original__init__, grouped=False) + func_text = func_body % func_vars + +- # Py3K +- #func_defaults = getattr(original__init__, '__defaults__', None) +- #func_kw_defaults = getattr(original__init__, '__kwdefaults__', None) +- # Py2K +- func = getattr(original__init__, 'im_func', original__init__) +- func_defaults = getattr(func, 'func_defaults', None) +- # end Py2K ++# start Py3K ++ func_defaults = getattr(original__init__, '__defaults__', None) ++ func_kw_defaults = getattr(original__init__, '__kwdefaults__', None) ++# end Py3K ++# start Py2K ++# func = getattr(original__init__, 'im_func', original__init__) ++# func_defaults = getattr(func, 'func_defaults', None) ++# end Py2K + + env = locals().copy() +- exec func_text in env ++ exec(func_text, env) + __init__ = env['__init__'] + __init__.__doc__ = original__init__.__doc__ + if func_defaults: +- __init__.func_defaults = func_defaults +- # Py3K +- #if func_kw_defaults: +- # __init__.__kwdefaults__ = func_kw_defaults ++ __init__.__defaults__ = func_defaults ++# start Py3K ++ if func_kw_defaults: ++ __init__.__kwdefaults__ = func_kw_defaults ++# end Py3K + return __init__ +diff -r 9d0639b9d3be lib/sqlalchemy/orm/interfaces.py +--- a/lib/sqlalchemy/orm/interfaces.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/orm/interfaces.py Sat Apr 27 19:42:17 2013 -0400 +@@ -15,7 +15,7 @@ + classes within should be considered mostly private. + + """ +-from __future__ import absolute_import ++ + + from .. import exc as sa_exc, util, inspect + from ..sql import operators +@@ -659,7 +659,7 @@ + tokens = deque(self.key) + while tokens: + token = tokens.popleft() +- if isinstance(token, basestring): ++ if isinstance(token, str): + # wildcard token + if token.endswith(':*'): + return [path.token(token)] +diff -r 9d0639b9d3be lib/sqlalchemy/orm/loading.py +--- a/lib/sqlalchemy/orm/loading.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/orm/loading.py Sat Apr 27 19:42:17 2013 -0400 +@@ -11,7 +11,7 @@ + as well as some of the attribute loading strategies. + + """ +-from __future__ import absolute_import ++ + + from .. import util + from . import attributes, exc as orm_exc, state as statelib +@@ -47,11 +47,11 @@ + query._entities[0].mapper.dispatch.append_result + + (process, labels) = \ +- zip(*[ ++ list(zip(*[ + query_entity.row_processor(query, + context, custom_rows) + for query_entity in query._entities +- ]) ++ ])) + + while True: + context.progress = {} +@@ -84,11 +84,11 @@ + context.progress.pop(context.refresh_state) + + statelib.InstanceState._commit_all_states( +- context.progress.items(), ++ list(context.progress.items()), + session.identity_map + ) + +- for state, (dict_, attrs) in context.partials.iteritems(): ++ for state, (dict_, attrs) in context.partials.items(): + state._commit(dict_, attrs) + + for row in rows: +@@ -507,7 +507,7 @@ + pops = (new_populators, existing_populators, delayed_populators, + eager_populators) + +- for prop in mapper._props.itervalues(): ++ for prop in mapper._props.values(): + + for i, pop in enumerate(prop.create_row_processor( + context, +diff -r 9d0639b9d3be lib/sqlalchemy/orm/mapper.py +--- a/lib/sqlalchemy/orm/mapper.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/orm/mapper.py Sat Apr 27 19:42:17 2013 -0400 +@@ -13,7 +13,7 @@ + available in :class:`~sqlalchemy.orm.`. + + """ +-from __future__ import absolute_import ++ + import types + import weakref + from itertools import chain +@@ -581,7 +581,7 @@ + if with_polymorphic == '*': + self.with_polymorphic = ('*', None) + elif isinstance(with_polymorphic, (tuple, list)): +- if isinstance(with_polymorphic[0], (basestring, tuple, list)): ++ if isinstance(with_polymorphic[0], (str, tuple, list)): + self.with_polymorphic = with_polymorphic + else: + self.with_polymorphic = (with_polymorphic, None) +@@ -626,7 +626,7 @@ + self.inherits._inheriting_mappers.add(self) + self.passive_updates = self.inherits.passive_updates + self._all_tables = self.inherits._all_tables +- for key, prop in mapper._props.iteritems(): ++ for key, prop in mapper._props.items(): + if key not in self._props and \ + not self._should_exclude(key, key, local=False, + column=None): +@@ -866,12 +866,12 @@ + + # load custom properties + if self._init_properties: +- for key, prop in self._init_properties.iteritems(): ++ for key, prop in self._init_properties.items(): + self._configure_property(key, prop, False) + + # pull properties from the inherited mapper if any. + if self.inherits: +- for key, prop in self.inherits._props.iteritems(): ++ for key, prop in self.inherits._props.items(): + if key not in self._props and \ + not self._should_exclude(key, key, local=False, + column=None): +@@ -919,7 +919,7 @@ + if self.polymorphic_on is not None: + setter = True + +- if isinstance(self.polymorphic_on, basestring): ++ if isinstance(self.polymorphic_on, str): + # polymorphic_on specified as as string - link + # it to mapped ColumnProperty + try: +@@ -1235,7 +1235,7 @@ + """ + + self._log("_post_configure_properties() started") +- l = [(key, prop) for key, prop in self._props.iteritems()] ++ l = [(key, prop) for key, prop in self._props.items()] + for key, prop in l: + self._log("initialize prop %s", key) + +@@ -1253,7 +1253,7 @@ + using `add_property`. + + """ +- for key, value in dict_of_properties.iteritems(): ++ for key, value in dict_of_properties.items(): + self.add_property(key, value) + + def add_property(self, key, prop): +@@ -1350,7 +1350,7 @@ + """return an iterator of all MapperProperty objects.""" + if _new_mappers: + configure_mappers() +- return self._props.itervalues() ++ return iter(self._props.values()) + + def _mappers_from_spec(self, spec, selectable): + """given a with_polymorphic() argument, return the set of mappers it +@@ -1623,7 +1623,7 @@ + if _new_mappers: + configure_mappers() + return util.ImmutableProperties(util.OrderedDict( +- (k, v) for k, v in self._props.iteritems() ++ (k, v) for k, v in self._props.items() + if isinstance(v, type_) + )) + +@@ -1972,7 +1972,7 @@ + visited_states = set() + prp, mpp = object(), object() + +- visitables = deque([(deque(self._props.values()), prp, ++ visitables = deque([(deque(list(self._props.values())), prp, + state, state.dict)]) + + while visitables: +@@ -1994,7 +1994,7 @@ + corresponding_dict = iterator.popleft() + yield instance, instance_mapper, \ + corresponding_state, corresponding_dict +- visitables.append((deque(instance_mapper._props.values()), ++ visitables.append((deque(list(instance_mapper._props.values())), + prp, corresponding_state, + corresponding_dict)) + +@@ -2011,7 +2011,7 @@ + table_to_mapper.setdefault(t, mapper) + + extra_dependencies = [] +- for table, mapper in table_to_mapper.items(): ++ for table, mapper in list(table_to_mapper.items()): + super_ = mapper.inherits + if super_: + extra_dependencies.extend([ +@@ -2040,7 +2040,7 @@ + return fk.parent not in cols + return False + +- sorted_ = sql_util.sort_tables(table_to_mapper.iterkeys(), ++ sorted_ = sql_util.sort_tables(iter(table_to_mapper.keys()), + skip_fn=skip, + extra_dependencies=extra_dependencies) + +diff -r 9d0639b9d3be lib/sqlalchemy/orm/persistence.py +--- a/lib/sqlalchemy/orm/persistence.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/orm/persistence.py Sat Apr 27 19:42:17 2013 -0400 +@@ -45,7 +45,7 @@ + + cached_connections = _cached_connection_dict(base_mapper) + +- for table, mapper in base_mapper._sorted_tables.iteritems(): ++ for table, mapper in base_mapper._sorted_tables.items(): + insert = _collect_insert_commands(base_mapper, uowtransaction, + table, states_to_insert) + +@@ -77,7 +77,7 @@ + base_mapper, + states, uowtransaction) + +- for table, mapper in base_mapper._sorted_tables.iteritems(): ++ for table, mapper in base_mapper._sorted_tables.items(): + update = _collect_post_update_commands(base_mapper, uowtransaction, + table, states_to_update, + post_update_cols) +@@ -105,7 +105,7 @@ + + table_to_mapper = base_mapper._sorted_tables + +- for table in reversed(table_to_mapper.keys()): ++ for table in reversed(list(table_to_mapper.keys())): + delete = _collect_delete_commands(base_mapper, uowtransaction, + table, states_to_delete) + +@@ -318,7 +318,7 @@ + # history is only + # in a different table than the one + # where the version_id_col is. +- for prop in mapper._columntoproperty.itervalues(): ++ for prop in mapper._columntoproperty.values(): + history = attributes.get_state_history( + state, prop.key, + attributes.PASSIVE_NO_INITIALIZE) +@@ -526,7 +526,7 @@ + for (connection, pkeys, hasvalue, has_all_pks), \ + records in groupby(insert, + lambda rec: (rec[4], +- rec[2].keys(), ++ list(rec[2].keys()), + bool(rec[5]), + rec[6]) + ): +@@ -612,7 +612,7 @@ + # also group them into common (connection, cols) sets + # to support executemany(). + for key, grouper in groupby( +- update, lambda rec: (rec[4], rec[2].keys()) ++ update, lambda rec: (rec[4], list(rec[2].keys())) + ): + connection = key[0] + multiparams = [params for state, state_dict, +@@ -646,7 +646,7 @@ + + return table.delete(clause) + +- for connection, del_objects in delete.iteritems(): ++ for connection, del_objects in delete.items(): + statement = base_mapper._memo(('delete', table), delete_stmt) + + connection = cached_connections[connection] +@@ -803,7 +803,7 @@ + raise sa_exc.ArgumentError( + "Valid strategies for session synchronization " + "are %s" % (", ".join(sorted(repr(x) +- for x in lookup.keys())))) ++ for x in list(lookup.keys()))))) + else: + return klass(*arg) + +@@ -868,7 +868,7 @@ + #TODO: detect when the where clause is a trivial primary key match + self.matched_objects = [ + obj for (cls, pk), obj in +- query.session.identity_map.iteritems() ++ query.session.identity_map.items() + if issubclass(cls, target_cls) and + eval_condition(obj)] + +@@ -951,7 +951,7 @@ + + def _additional_evaluators(self, evaluator_compiler): + self.value_evaluators = {} +- for key, value in self.values.iteritems(): ++ for key, value in self.values.items(): + key = _attr_as_key(key) + self.value_evaluators[key] = evaluator_compiler.process( + expression._literal_as_binds(value)) +@@ -959,7 +959,7 @@ + def _do_post_synchronize(self): + session = self.query.session + states = set() +- evaluated_keys = self.value_evaluators.keys() ++ evaluated_keys = list(self.value_evaluators.keys()) + for obj in self.matched_objects: + state, dict_ = attributes.instance_state(obj),\ + attributes.instance_dict(obj) +diff -r 9d0639b9d3be lib/sqlalchemy/orm/properties.py +--- a/lib/sqlalchemy/orm/properties.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/orm/properties.py Sat Apr 27 19:42:17 2013 -0400 +@@ -27,7 +27,7 @@ + mapperlib = util.importlater("sqlalchemy.orm", "mapperlib") + NoneType = type(None) + +-from descriptor_props import CompositeProperty, SynonymProperty, \ ++from .descriptor_props import CompositeProperty, SynonymProperty, \ + ComparableProperty, ConcreteInheritedProperty + + __all__ = ['ColumnProperty', 'CompositeProperty', 'SynonymProperty', +@@ -1204,7 +1204,7 @@ + if not self.is_primary(): + return + if self.backref is not None and not self.back_populates: +- if isinstance(self.backref, basestring): ++ if isinstance(self.backref, str): + backref_key, kwargs = self.backref, {} + else: + backref_key, kwargs = self.backref +diff -r 9d0639b9d3be lib/sqlalchemy/orm/query.py +--- a/lib/sqlalchemy/orm/query.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/orm/query.py Sat Apr 27 19:42:17 2013 -0400 +@@ -47,7 +47,7 @@ + def generate(fn, *args, **kw): + self = args[0]._clone() + for assertion in assertions: +- assertion(self, fn.func_name) ++ assertion(self, fn.__name__) + fn(self, *args[1:], **kw) + return self + return generate +@@ -981,11 +981,12 @@ + """Return a scalar result corresponding to the given + column expression.""" + try: +- # Py3K +- #return self.values(column).__next__()[0] +- # Py2K +- return self.values(column).next()[0] +- # end Py2K ++# start Py3K ++ return self.values(column).__next__()[0] ++# end Py3K ++# start Py2K ++# return self.values(column).next()[0] ++# end Py2K + except StopIteration: + return None + +@@ -1231,7 +1232,7 @@ + """ + + clauses = [_entity_descriptor(self._joinpoint_zero(), key) == value +- for key, value in kwargs.iteritems()] ++ for key, value in kwargs.items()] + return self.filter(sql.and_(*clauses)) + + @_generative(_no_statement_condition, _no_limit_offset) +@@ -1296,7 +1297,7 @@ + + """ + +- if isinstance(criterion, basestring): ++ if isinstance(criterion, str): + criterion = sql.text(criterion) + + if criterion is not None and \ +@@ -1655,7 +1656,7 @@ + kwargs.pop('from_joinpoint', False) + if kwargs: + raise TypeError("unknown arguments: %s" % +- ','.join(kwargs.iterkeys())) ++ ','.join(iter(kwargs.keys()))) + return self._join(props, + outerjoin=False, create_aliases=aliased, + from_joinpoint=from_joinpoint) +@@ -1671,7 +1672,7 @@ + kwargs.pop('from_joinpoint', False) + if kwargs: + raise TypeError("unknown arguments: %s" % +- ','.join(kwargs.iterkeys())) ++ ','.join(iter(kwargs.keys()))) + return self._join(props, + outerjoin=True, create_aliases=aliased, + from_joinpoint=from_joinpoint) +@@ -1701,7 +1702,7 @@ + if len(keys) == 2 and \ + isinstance(keys[0], (expression.FromClause, + type, AliasedClass)) and \ +- isinstance(keys[1], (basestring, expression.ClauseElement, ++ isinstance(keys[1], (str, expression.ClauseElement, + interfaces.PropComparator)): + # detect 2-arg form of join and + # convert to a tuple. +@@ -1721,14 +1722,14 @@ + # is a little bit of legacy behavior still at work here + # which means they might be in either order. may possibly + # lock this down to (right_entity, onclause) in 0.6. +- if isinstance(arg1, (interfaces.PropComparator, basestring)): ++ if isinstance(arg1, (interfaces.PropComparator, str)): + right_entity, onclause = arg2, arg1 + else: + right_entity, onclause = arg1, arg2 + + left_entity = prop = None + +- if isinstance(onclause, basestring): ++ if isinstance(onclause, str): + left_entity = self._joinpoint_zero() + + descriptor = _entity_descriptor(left_entity, onclause) +@@ -1922,7 +1923,7 @@ + clause = orm_join(clause, + right, + onclause, isouter=outerjoin) +- except sa_exc.ArgumentError, ae: ++ except sa_exc.ArgumentError as ae: + raise sa_exc.InvalidRequestError( + "Could not find a FROM clause to join from. " + "Tried joining to %s, but got: %s" % (right, ae)) +@@ -1947,7 +1948,7 @@ + + try: + clause = orm_join(clause, right, onclause, isouter=outerjoin) +- except sa_exc.ArgumentError, ae: ++ except sa_exc.ArgumentError as ae: + raise sa_exc.InvalidRequestError( + "Could not find a FROM clause to join from. " + "Tried joining to %s, but got: %s" % (right, ae)) +@@ -2115,7 +2116,7 @@ + appropriate to the entity class represented by this ``Query``. + + """ +- if isinstance(statement, basestring): ++ if isinstance(statement, str): + statement = sql.text(statement) + + if not isinstance(statement, +@@ -2609,7 +2610,7 @@ + use_labels=context.labels) + + from_clause = inner +- for eager_join in context.eager_joins.values(): ++ for eager_join in list(context.eager_joins.values()): + # EagerLoader places a 'stop_on' attribute on the join, + # giving us a marker as to where the "splice point" of + # the join should be +@@ -2674,7 +2675,7 @@ + subtypes are selected from the total results. + + """ +- for (ext_info, adapter) in self._mapper_adapter_map.values(): ++ for (ext_info, adapter) in list(self._mapper_adapter_map.values()): + if ext_info in self._join_entities: + continue + single_crit = ext_info.mapper._single_table_criterion +@@ -2697,7 +2698,7 @@ + def __new__(cls, *args, **kwargs): + if cls is _QueryEntity: + entity = args[1] +- if not isinstance(entity, basestring) and \ ++ if not isinstance(entity, str) and \ + _is_mapped_class(entity): + cls = _MapperEntity + else: +@@ -2905,7 +2906,7 @@ + self.expr = column + self.namespace = namespace + +- if isinstance(column, basestring): ++ if isinstance(column, str): + column = sql.literal_column(column) + self._label_name = column.name + elif isinstance(column, ( +@@ -3080,7 +3081,7 @@ + self.alias = alias + + def process_query(self, query): +- if isinstance(self.alias, basestring): ++ if isinstance(self.alias, str): + alias = query._mapper_zero().mapped_table.alias(self.alias) + else: + alias = self.alias +diff -r 9d0639b9d3be lib/sqlalchemy/orm/session.py +--- a/lib/sqlalchemy/orm/session.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/orm/session.py Sat Apr 27 19:42:17 2013 -0400 +@@ -5,7 +5,7 @@ + # the MIT License: http://www.opensource.org/licenses/mit-license.php + """Provides the Session class and related utilities.""" + +-from __future__ import with_statement ++ + + import weakref + from .. import util, sql, engine, exc as sa_exc, event +@@ -35,7 +35,7 @@ + def close_all(cls): + """Close *all* sessions in memory.""" + +- for sess in _sessions.values(): ++ for sess in list(_sessions.values()): + sess.close() + + @classmethod +@@ -249,7 +249,7 @@ + if s.key: + del s.key + +- for s, (oldkey, newkey) in self._key_switches.items(): ++ for s, (oldkey, newkey) in list(self._key_switches.items()): + self.session.identity_map.discard(s) + s.key = oldkey + self.session.identity_map.replace(s) +@@ -327,7 +327,7 @@ + subtransaction.commit() + + if not self.session._flushing: +- for _flush_guard in xrange(100): ++ for _flush_guard in range(100): + if self.session._is_clean(): + break + self.session.flush() +@@ -604,7 +604,7 @@ + SessionExtension._adapt_listener(self, ext) + + if binds is not None: +- for mapperortable, bind in binds.iteritems(): ++ for mapperortable, bind in binds.items(): + if isinstance(mapperortable, (type, Mapper)): + self.bind_mapper(mapperortable, bind) + else: +@@ -1775,7 +1775,7 @@ + Session. + + """ +- return iter(list(self._new.values()) + self.identity_map.values()) ++ return iter(list(self._new.values()) + list(self.identity_map.values())) + + def _contains_state(self, state): + return state in self._new or self.identity_map.contains_state(state) +@@ -2138,13 +2138,13 @@ + def deleted(self): + "The set of all instances marked as 'deleted' within this ``Session``" + +- return util.IdentitySet(self._deleted.values()) ++ return util.IdentitySet(list(self._deleted.values())) + + @property + def new(self): + "The set of all instances marked as 'new' within this ``Session``." + +- return util.IdentitySet(self._new.values()) ++ return util.IdentitySet(list(self._new.values())) + + + class sessionmaker(_SessionClassMethods): +@@ -2236,7 +2236,7 @@ + session = Session() # invokes sessionmaker.__call__() + + """ +- for k, v in self.kw.items(): ++ for k, v in list(self.kw.items()): + local_kw.setdefault(k, v) + return self.class_(**local_kw) + +@@ -2255,7 +2255,7 @@ + return "%s(class_=%r%s)" % ( + self.__class__.__name__, + self.class_.__name__, +- ", ".join("%s=%r" % (k, v) for k, v in self.kw.items()) ++ ", ".join("%s=%r" % (k, v) for k, v in list(self.kw.items())) + ) + + _sessions = weakref.WeakValueDictionary() +diff -r 9d0639b9d3be lib/sqlalchemy/orm/state.py +--- a/lib/sqlalchemy/orm/state.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/orm/state.py Sat Apr 27 19:42:17 2013 -0400 +@@ -417,7 +417,7 @@ + against this set when a refresh operation occurs. + + """ +- return set([k for k, v in self.callables.items() if v is self]) ++ return set([k for k, v in list(self.callables.items()) if v is self]) + + def _instance_dict(self): + return None +diff -r 9d0639b9d3be lib/sqlalchemy/orm/strategies.py +--- a/lib/sqlalchemy/orm/strategies.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/orm/strategies.py Sat Apr 27 19:42:17 2013 -0400 +@@ -359,7 +359,7 @@ + ) + + if self.use_get: +- for col in self._equated_columns.keys(): ++ for col in list(self._equated_columns.keys()): + if col in self.mapper._equivalent_columns: + for c in self.mapper._equivalent_columns[col]: + self._equated_columns[c] = self._equated_columns[col] +@@ -1332,7 +1332,7 @@ + def __init__(self, key, lazy=True, chained=False, + propagate_to_loaders=True + ): +- if isinstance(key[0], basestring) and key[0] == '*': ++ if isinstance(key[0], str) and key[0] == '*': + if len(key) != 1: + raise sa_exc.ArgumentError( + "Wildcard identifier '*' must " +@@ -1384,7 +1384,7 @@ + def __init__(self, key, alias=None, chained=False): + super(LoadEagerFromAliasOption, self).__init__(key) + if alias is not None: +- if not isinstance(alias, basestring): ++ if not isinstance(alias, str): + info = inspect(alias) + alias = info.selectable + self.alias = alias +@@ -1401,7 +1401,7 @@ + + root_mapper, prop = paths[-1].path[-2:] + if self.alias is not None: +- if isinstance(self.alias, basestring): ++ if isinstance(self.alias, str): + self.alias = prop.target.alias(self.alias) + paths[-1].set(query, "user_defined_eager_row_processor", + sql_util.ColumnAdapter(self.alias, +diff -r 9d0639b9d3be lib/sqlalchemy/orm/unitofwork.py +--- a/lib/sqlalchemy/orm/unitofwork.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/orm/unitofwork.py Sat Apr 27 19:42:17 2013 -0400 +@@ -315,7 +315,7 @@ + # see if the graph of mapper dependencies has cycles. + self.cycles = cycles = topological.find_cycles( + self.dependencies, +- self.postsort_actions.values()) ++ list(self.postsort_actions.values())) + + if cycles: + # if yes, break the per-mapper actions into +@@ -342,7 +342,7 @@ + for dep in convert[edge[1]]: + self.dependencies.add((edge[0], dep)) + +- return set([a for a in self.postsort_actions.values() ++ return set([a for a in list(self.postsort_actions.values()) + if not a.disabled + ] + ).difference(cycles) +@@ -381,7 +381,7 @@ + """ + states = set(self.states) + isdel = set( +- s for (s, (isdelete, listonly)) in self.states.iteritems() ++ s for (s, (isdelete, listonly)) in self.states.items() + if isdelete + ) + other = states.difference(isdel) +@@ -461,7 +461,7 @@ + def __repr__(self): + return "%s(%s)" % ( + self.__class__.__name__, +- ",".join(str(x) for x in self.__dict__.values()) ++ ",".join(str(x) for x in list(self.__dict__.values())) + ) + + +diff -r 9d0639b9d3be lib/sqlalchemy/orm/util.py +--- a/lib/sqlalchemy/orm/util.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/orm/util.py Sat Apr 27 19:42:17 2013 -0400 +@@ -120,7 +120,7 @@ + colnames = util.OrderedSet() + colnamemaps = {} + types = {} +- for key in table_map.keys(): ++ for key in list(table_map.keys()): + table = table_map[key] + + # mysql doesnt like selecting from a select; +@@ -146,7 +146,7 @@ + return sql.type_coerce(sql.null(), types[name]).label(name) + + result = [] +- for type, table in table_map.iteritems(): ++ for type, table in table_map.items(): + if typecolname is not None: + result.append( + sql.select([col(name, table) for name in colnames] + +@@ -203,7 +203,7 @@ + "positional arguments, got %s" % len(args)) + if kwargs: + raise sa_exc.ArgumentError("unknown keyword arguments: %s" +- % ", ".join(kwargs.keys())) ++ % ", ".join(list(kwargs.keys()))) + mapper = class_mapper(class_) + if "ident" in locals(): + return mapper.identity_key_from_primary_key(util.to_list(ident)) +@@ -211,7 +211,7 @@ + instance = kwargs.pop("instance") + if kwargs: + raise sa_exc.ArgumentError("unknown keyword arguments: %s" +- % ", ".join(kwargs.keys())) ++ % ", ".join(list(kwargs.keys()))) + mapper = object_mapper(instance) + return mapper.identity_key_from_instance(instance) + +@@ -300,7 +300,7 @@ + + def pairs(self): + path = self.path +- for i in xrange(0, len(path), 2): ++ for i in range(0, len(path), 2): + yield path[i], path[i + 1] + + def contains_mapper(self, mapper): +@@ -314,10 +314,10 @@ + + def serialize(self): + path = self.path +- return zip( ++ return list(zip( + [m.class_ for m in [path[i] for i in range(0, len(path), 2)]], + [path[i].key for i in range(1, len(path), 2)] + [None] +- ) ++ )) + + @classmethod + def deserialize(cls, path): +@@ -411,7 +411,7 @@ + + self.path = parent.path + (entity,) + +- def __nonzero__(self): ++ def __bool__(self): + return True + + def __getitem__(self, entity): +@@ -589,8 +589,8 @@ + return self.__adapt_prop(attr, key) + elif hasattr(attr, 'func_code'): + is_method = getattr(self.__target, key, None) +- if is_method and is_method.im_self is not None: +- return util.types.MethodType(attr.im_func, self, self) ++ if is_method and is_method.__self__ is not None: ++ return util.types.MethodType(attr.__func__, self, self) + else: + return None + elif hasattr(attr, '__get__'): +@@ -880,7 +880,7 @@ + + self._joined_from_info = right_info + +- if isinstance(onclause, basestring): ++ if isinstance(onclause, str): + onclause = getattr(left_orm_info.entity, onclause) + + if isinstance(onclause, attributes.QueryableAttribute): +@@ -1001,7 +1001,7 @@ + parent/child relationship. + + """ +- if isinstance(prop, basestring): ++ if isinstance(prop, str): + mapper = object_mapper(instance) + prop = getattr(mapper.class_, prop).property + elif isinstance(prop, attributes.QueryableAttribute): +diff -r 9d0639b9d3be lib/sqlalchemy/pool.py +--- a/lib/sqlalchemy/pool.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/pool.py Sat Apr 27 19:42:17 2013 -0400 +@@ -57,7 +57,7 @@ + All pools and connections are disposed. + """ + +- for manager in proxies.itervalues(): ++ for manager in proxies.values(): + manager.close() + proxies.clear() + +@@ -368,7 +368,7 @@ + connection = self.__pool._creator() + self.__pool.logger.debug("Created new connection %r", connection) + return connection +- except Exception, e: ++ except Exception as e: + self.__pool.logger.debug("Error on connect(): %s", e) + raise + +@@ -391,7 +391,7 @@ + # Immediately close detached instances + if connection_record is None: + pool._close_connection(connection) +- except Exception, e: ++ except Exception as e: + if connection_record is not None: + connection_record.invalidate(e=e) + if isinstance(e, (SystemExit, KeyboardInterrupt)): +@@ -499,7 +499,7 @@ + self._connection_record, + self) + return self +- except exc.DisconnectionError, e: ++ except exc.DisconnectionError as e: + self._pool.logger.info( + "Disconnection detected on checkout: %s", e) + self._connection_record.invalidate(e) +@@ -755,7 +755,7 @@ + wait = self._max_overflow > -1 and \ + self._overflow >= self._max_overflow + return self._pool.get(wait, self._timeout) +- except sqla_queue.SAAbort, aborted: ++ except sqla_queue.SAAbort as aborted: + return aborted.context._do_get() + except sqla_queue.Empty: + if self._max_overflow > -1 and \ +@@ -1004,7 +1004,7 @@ + self._create_pool_mutex = threading.Lock() + + def close(self): +- for key in self.pools.keys(): ++ for key in list(self.pools.keys()): + del self.pools[key] + + def __del__(self): +diff -r 9d0639b9d3be lib/sqlalchemy/processors.py +--- a/lib/sqlalchemy/processors.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/processors.py Sat Apr 27 19:42:17 2013 -0400 +@@ -38,10 +38,10 @@ + "'%s'" % (type_.__name__, value)) + if has_named_groups: + groups = m.groupdict(0) +- return type_(**dict(zip(groups.iterkeys(), +- map(int, groups.itervalues())))) ++ return type_(**dict(list(zip(iter(groups.keys()), ++ list(map(int, iter(groups.values()))))))) + else: +- return type_(*map(int, m.groups(0))) ++ return type_(*list(map(int, m.groups(0)))) + return process + + +diff -r 9d0639b9d3be lib/sqlalchemy/schema.py +--- a/lib/sqlalchemy/schema.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/schema.py Sat Apr 27 19:42:17 2013 -0400 +@@ -27,7 +27,7 @@ + as components in SQL expressions. + + """ +-from __future__ import with_statement ++ + import re + import inspect + from . import exc, util, dialects, event, events, inspection +@@ -683,7 +683,7 @@ + continue + Index(index.name, + unique=index.unique, +- *[table.c[col] for col in index.columns.keys()], ++ *[table.c[col] for col in list(index.columns.keys())], + **index.kwargs) + table.dispatch._update(self.dispatch) + return table +@@ -898,7 +898,7 @@ + type_ = kwargs.pop('type_', None) + args = list(args) + if args: +- if isinstance(args[0], basestring): ++ if isinstance(args[0], str): + if name is not None: + raise exc.ArgumentError( + "May not pass name positionally and as a keyword.") +@@ -944,11 +944,12 @@ + args.append(self.default) + else: + if getattr(self.type, '_warn_on_bytestring', False): +- # Py3K +- #if isinstance(self.default, bytes): +- # Py2K +- if isinstance(self.default, str): +- # end Py2K ++# start Py3K ++ if isinstance(self.default, bytes): ++# end Py3K ++# start Py2K ++# if isinstance(self.default, str): ++# end Py2K + util.warn("Unicode column received non-unicode " + "default value.") + args.append(ColumnDefault(self.default)) +@@ -983,7 +984,7 @@ + + if kwargs: + raise exc.ArgumentError( +- "Unknown arguments passed to Column: " + repr(kwargs.keys())) ++ "Unknown arguments passed to Column: " + repr(list(kwargs.keys()))) + + def __str__(self): + if self.name is None: +@@ -1069,7 +1070,7 @@ + self.table = table + + if self.index: +- if isinstance(self.index, basestring): ++ if isinstance(self.index, str): + raise exc.ArgumentError( + "The 'index' keyword argument on Column is boolean only. " + "To create indexes with a specific name, create an " +@@ -1077,7 +1078,7 @@ + Index(expression._truncated_label('ix_%s' % self._label), + self, unique=self.unique) + elif self.unique: +- if isinstance(self.unique, basestring): ++ if isinstance(self.unique, str): + raise exc.ArgumentError( + "The 'unique' keyword argument on Column is boolean " + "only. To create unique constraints or indexes with a " +@@ -1153,23 +1154,24 @@ + nullable=self.nullable, + quote=self.quote, + _proxies=[self], *fk) +- except TypeError, e: +- # Py3K +- #raise TypeError( +- # "Could not create a copy of this %r object. " +- # "Ensure the class includes a _constructor() " +- # "attribute or method which accepts the " +- # "standard Column constructor arguments, or " +- # "references the Column class itself." % self.__class__) from e +- # Py2K ++ except TypeError as e: ++# start Py3K + raise TypeError( + "Could not create a copy of this %r object. " + "Ensure the class includes a _constructor() " + "attribute or method which accepts the " + "standard Column constructor arguments, or " +- "references the Column class itself. " +- "Original error: %s" % (self.__class__, e)) +- # end Py2K ++ "references the Column class itself." % self.__class__) from e ++# end Py3K ++# start Py2K ++# raise TypeError( ++# "Could not create a copy of this %r object. " ++# "Ensure the class includes a _constructor() " ++# "attribute or method which accepts the " ++# "standard Column constructor arguments, or " ++# "references the Column class itself. " ++# "Original error: %s" % (self.__class__, e)) ++# end Py2K + + c.table = selectable + selectable._columns.add(c) +@@ -1345,7 +1347,7 @@ + if schema: + return schema + "." + self.column.table.name + \ + "." + self.column.key +- elif isinstance(self._colspec, basestring): ++ elif isinstance(self._colspec, str): + return self._colspec + elif hasattr(self._colspec, '__clause_element__'): + _column = self._colspec.__clause_element__() +@@ -1390,7 +1392,7 @@ + """ + # ForeignKey inits its remote column as late as possible, so tables + # can be defined without dependencies +- if isinstance(self._colspec, basestring): ++ if isinstance(self._colspec, str): + # locate the parent table this foreign key is attached to. we + # use the "original" column which our parent column represents + # (its a list of columns/other ColumnElements if the parent +@@ -1657,7 +1659,8 @@ + defaulted = argspec[3] is not None and len(argspec[3]) or 0 + positionals = len(argspec[0]) - defaulted + +- # Py3K compat - no unbound methods ++# start Py3K ++# end Py3K + if inspect.ismethod(inspectable) or inspect.isclass(fn): + positionals -= 1 + +@@ -1919,7 +1922,7 @@ + has_argument = True + + def __init__(self, arg, for_update=False, _reflected=False): +- util.assert_arg_type(arg, (basestring, ++ util.assert_arg_type(arg, (str, + expression.ClauseElement, + expression.TextClause), 'arg') + super(DefaultClause, self).__init__(for_update) +@@ -2029,7 +2032,7 @@ + + def _set_parent(self, table): + for col in self._pending_colargs: +- if isinstance(col, basestring): ++ if isinstance(col, str): + col = table.c[col] + self.columns.add(col) + +@@ -2066,7 +2069,7 @@ + + def copy(self, **kw): + c = self.__class__(name=self.name, deferrable=self.deferrable, +- initially=self.initially, *self.columns.keys()) ++ initially=self.initially, *list(self.columns.keys())) + c.dispatch._update(self.dispatch) + return c + +@@ -2256,19 +2259,19 @@ + + @property + def columns(self): +- return self._elements.keys() ++ return list(self._elements.keys()) + + @property + def elements(self): +- return self._elements.values() ++ return list(self._elements.values()) + + def _set_parent(self, table): + super(ForeignKeyConstraint, self)._set_parent(table) + +- for col, fk in self._elements.iteritems(): ++ for col, fk in self._elements.items(): + # string-specified column names now get + # resolved to Column objects +- if isinstance(col, basestring): ++ if isinstance(col, str): + try: + col = table.c[col] + except KeyError: +@@ -2293,8 +2296,8 @@ + + def copy(self, schema=None, **kw): + fkc = ForeignKeyConstraint( +- [x.parent.key for x in self._elements.values()], +- [x._get_colspec(schema=schema) for x in self._elements.values()], ++ [x.parent.key for x in list(self._elements.values())], ++ [x._get_colspec(schema=schema) for x in list(self._elements.values())], + name=self.name, + onupdate=self.onupdate, + ondelete=self.ondelete, +@@ -2569,7 +2572,7 @@ + return 'MetaData(bind=%r)' % self.bind + + def __contains__(self, table_or_key): +- if not isinstance(table_or_key, basestring): ++ if not isinstance(table_or_key, str): + table_or_key = table_or_key.key + return table_or_key in self.tables + +@@ -2584,7 +2587,7 @@ + dict.pop(self.tables, key, None) + if self._schemas: + self._schemas = set([t.schema +- for t in self.tables.values() ++ for t in list(self.tables.values()) + if t.schema is not None]) + + def __getstate__(self): +@@ -2629,7 +2632,7 @@ + def _bind_to(self, bind): + """Bind this MetaData to an Engine, Connection, string or URL.""" + +- if isinstance(bind, (basestring, url.URL)): ++ if isinstance(bind, (str, url.URL)): + from sqlalchemy import create_engine + self._bind = create_engine(bind) + else: +@@ -2662,7 +2665,7 @@ + :meth:`.Inspector.sorted_tables` + + """ +- return sqlutil.sort_tables(self.tables.itervalues()) ++ return sqlutil.sort_tables(iter(self.tables.values())) + + def reflect(self, bind=None, schema=None, views=False, only=None): + """Load all available table definitions from the database. +@@ -2723,7 +2726,7 @@ + bind.dialect.get_view_names(conn, schema) + ) + +- current = set(self.tables.iterkeys()) ++ current = set(self.tables.keys()) + + if only is None: + load = [name for name in available if name not in current] +@@ -2845,7 +2848,7 @@ + def _bind_to(self, bind): + """Bind to a Connectable in the caller's thread.""" + +- if isinstance(bind, (basestring, url.URL)): ++ if isinstance(bind, (str, url.URL)): + try: + self.context._engine = self.__engines[bind] + except KeyError: +@@ -2870,7 +2873,7 @@ + def dispose(self): + """Dispose all bound engines, in all thread contexts.""" + +- for e in self.__engines.itervalues(): ++ for e in self.__engines.values(): + if hasattr(e, 'dispose'): + e.dispose() + +@@ -3075,7 +3078,7 @@ + not self._should_execute_deprecated(None, target, bind, **kw): + return False + +- if isinstance(self.dialect, basestring): ++ if isinstance(self.dialect, str): + if self.dialect != bind.engine.name: + return False + elif isinstance(self.dialect, (tuple, list, set)): +@@ -3090,7 +3093,7 @@ + def _should_execute_deprecated(self, event, target, bind, **kw): + if self.on is None: + return True +- elif isinstance(self.on, basestring): ++ elif isinstance(self.on, str): + return self.on == bind.engine.name + elif isinstance(self.on, (tuple, list, set)): + return bind.engine.name in self.on +@@ -3105,7 +3108,7 @@ + + def _check_ddl_on(self, on): + if (on is not None and +- (not isinstance(on, (basestring, tuple, list, set)) and ++ (not isinstance(on, (str, tuple, list, set)) and + not util.callable(on))): + raise exc.ArgumentError( + "Expected the name of a database dialect, a tuple " +@@ -3230,7 +3233,7 @@ + + """ + +- if not isinstance(statement, basestring): ++ if not isinstance(statement, str): + raise exc.ArgumentError( + "Expected a string or unicode SQL statement, got '%r'" % + statement) +@@ -3262,7 +3265,7 @@ + def _to_schema_column_or_string(element): + if hasattr(element, '__clause_element__'): + element = element.__clause_element__() +- if not isinstance(element, (basestring, expression.ColumnElement)): ++ if not isinstance(element, (str, expression.ColumnElement)): + msg = "Element %r is not a string name or column element" + raise exc.ArgumentError(msg % element) + return element +diff -r 9d0639b9d3be lib/sqlalchemy/sql/__init__.py +--- a/lib/sqlalchemy/sql/__init__.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/sql/__init__.py Sat Apr 27 19:42:17 2013 -0400 +@@ -64,5 +64,5 @@ + + from .visitors import ClauseVisitor + +-__tmp = locals().keys() ++__tmp = list(locals().keys()) + __all__ = sorted([i for i in __tmp if not i.startswith('__')]) +diff -r 9d0639b9d3be lib/sqlalchemy/sql/compiler.py +--- a/lib/sqlalchemy/sql/compiler.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/sql/compiler.py Sat Apr 27 19:42:17 2013 -0400 +@@ -51,7 +51,7 @@ + 'using', 'verbose', 'when', 'where']) + + LEGAL_CHARACTERS = re.compile(r'^[A-Z0-9_$]+$', re.I) +-ILLEGAL_INITIAL_CHARACTERS = set([str(x) for x in xrange(0, 10)]).union(['$']) ++ILLEGAL_INITIAL_CHARACTERS = set([str(x) for x in range(0, 10)]).union(['$']) + + BIND_PARAMS = re.compile(r'(?> sys.stderr, "Error emptying table %s: %r" % ( +- table, ex) ++ except sa.exc.DBAPIError as ex: ++ print("Error emptying table %s: %r" % ( ++ table, ex), file=sys.stderr) + + def setup(self): + self._setup_each_tables() +@@ -187,10 +187,10 @@ + def _load_fixtures(cls): + """Insert rows as represented by the fixtures() method.""" + headers, rows = {}, {} +- for table, data in cls.fixtures().iteritems(): ++ for table, data in cls.fixtures().items(): + if len(data) < 2: + continue +- if isinstance(table, basestring): ++ if isinstance(table, str): + table = cls.tables[table] + headers[table] = data[0] + rows[table] = data[1:] +@@ -199,7 +199,7 @@ + continue + cls.bind.execute( + table.insert(), +- [dict(zip(headers[table], column_values)) ++ [dict(list(zip(headers[table], column_values))) + for column_values in rows[table]]) + + +@@ -284,8 +284,8 @@ + cls_registry[classname] = cls + return type.__init__(cls, classname, bases, dict_) + +- class _Base(object): +- __metaclass__ = FindFixture ++ class _Base(object, metaclass=FindFixture): ++ pass + + class Basic(BasicEntity, _Base): + pass +diff -r 9d0639b9d3be lib/sqlalchemy/testing/plugin/noseplugin.py +--- a/lib/sqlalchemy/testing/plugin/noseplugin.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/testing/plugin/noseplugin.py Sat Apr 27 19:42:17 2013 -0400 +@@ -9,10 +9,10 @@ + normally as "from sqlalchemy.testing.plugin import noseplugin". + + """ +-from __future__ import absolute_import ++ + + import os +-import ConfigParser ++import configparser + + from nose.plugins import Plugin + from nose import SkipTest +@@ -55,9 +55,9 @@ + + + def _list_dbs(*args): +- print "Available --db options (use --dburi to override)" ++ print("Available --db options (use --dburi to override)") + for macro in sorted(file_config.options('db')): +- print "%20s\t%s" % (macro, file_config.get('db', macro)) ++ print("%20s\t%s" % (macro, file_config.get('db', macro))) + sys.exit(0) + + +@@ -318,7 +318,7 @@ + opt("--write-profiles", action="store_true", dest="write_profiles", default=False, + help="Write/update profiling data.") + global file_config +- file_config = ConfigParser.ConfigParser() ++ file_config = configparser.ConfigParser() + file_config.read(['setup.cfg', 'test.cfg']) + + def configure(self, options, conf): +diff -r 9d0639b9d3be lib/sqlalchemy/testing/profiling.py +--- a/lib/sqlalchemy/testing/profiling.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/testing/profiling.py Sat Apr 27 19:42:17 2013 -0400 +@@ -60,9 +60,9 @@ + if report: + sort_ = target_opts.get('sort', profile_config['sort']) + limit = target_opts.get('limit', profile_config['limit']) +- print ("Profile report for target '%s' (%s)" % ( ++ print(("Profile report for target '%s' (%s)" % ( + target, filename) +- ) ++ )) + + stats = load_stats() + stats.sort_stats(*sort_) +@@ -198,7 +198,7 @@ + profile_f.close() + + def _write(self): +- print("Writing profile file %s" % self.fname) ++ print(("Writing profile file %s" % self.fname)) + profile_f = open(self.fname, "w") + profile_f.write(self._header()) + for test_key in sorted(self.data): +@@ -253,11 +253,11 @@ + else: + line_no, expected_count = expected + +- print("Pstats calls: %d Expected %s" % ( ++ print(("Pstats calls: %d Expected %s" % ( + callcount, + expected_count + ) +- ) ++ )) + stats.print_stats() + #stats.print_callers() + +diff -r 9d0639b9d3be lib/sqlalchemy/testing/schema.py +--- a/lib/sqlalchemy/testing/schema.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/testing/schema.py Sat Apr 27 19:42:17 2013 -0400 +@@ -11,7 +11,7 @@ + def Table(*args, **kw): + """A schema.Table wrapper/hook for dialect-specific tweaks.""" + +- test_opts = dict([(k, kw.pop(k)) for k in kw.keys() ++ test_opts = dict([(k, kw.pop(k)) for k in list(kw.keys()) + if k.startswith('test_')]) + + kw.update(table_options) +@@ -58,7 +58,7 @@ + def Column(*args, **kw): + """A schema.Column wrapper/hook for dialect-specific tweaks.""" + +- test_opts = dict([(k, kw.pop(k)) for k in kw.keys() ++ test_opts = dict([(k, kw.pop(k)) for k in list(kw.keys()) + if k.startswith('test_')]) + + if not config.requirements.foreign_key_ddl.enabled: +diff -r 9d0639b9d3be lib/sqlalchemy/testing/suite/test_ddl.py +--- a/lib/sqlalchemy/testing/suite/test_ddl.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/testing/suite/test_ddl.py Sat Apr 27 19:42:17 2013 -0400 +@@ -1,4 +1,4 @@ +-from __future__ import with_statement ++ + + from .. import fixtures, config, util + from ..config import requirements +diff -r 9d0639b9d3be lib/sqlalchemy/testing/suite/test_reflection.py +--- a/lib/sqlalchemy/testing/suite/test_reflection.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/testing/suite/test_reflection.py Sat Apr 27 19:42:17 2013 -0400 +@@ -1,4 +1,4 @@ +-from __future__ import with_statement ++ + + import sqlalchemy as sa + from sqlalchemy import exc as sa_exc +@@ -386,7 +386,7 @@ + self.tables.email_addresses, self.tables.dingalings + insp = inspect(meta.bind) + oid = insp.get_table_oid(table_name, schema) +- self.assert_(isinstance(oid, (int, long))) ++ self.assert_(isinstance(oid, int)) + + def test_get_table_oid(self): + self._test_get_table_oid('users') +diff -r 9d0639b9d3be lib/sqlalchemy/testing/suite/test_types.py +--- a/lib/sqlalchemy/testing/suite/test_types.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/testing/suite/test_types.py Sat Apr 27 19:42:17 2013 -0400 +@@ -15,9 +15,9 @@ + class _UnicodeFixture(object): + __requires__ = 'unicode_data', + +- data = u"Alors vous imaginez ma surprise, au lever du jour, "\ +- u"quand une drôle de petite voix m’a réveillé. Elle "\ +- u"disait: « S’il vous plaît… dessine-moi un mouton! »" ++ data = "Alors vous imaginez ma surprise, au lever du jour, "\ ++ "quand une drôle de petite voix m’a réveillé. Elle "\ ++ "disait: « S’il vous plaît… dessine-moi un mouton! »" + + @classmethod + def define_tables(cls, metadata): +@@ -47,7 +47,7 @@ + row, + (self.data, ) + ) +- assert isinstance(row[0], unicode) ++ assert isinstance(row[0], str) + + def test_round_trip_executemany(self): + unicode_table = self.tables.unicode_table +@@ -58,7 +58,7 @@ + { + 'unicode_data': self.data, + } +- for i in xrange(3) ++ for i in range(3) + ] + ) + +@@ -69,22 +69,22 @@ + ).fetchall() + eq_( + rows, +- [(self.data, ) for i in xrange(3)] ++ [(self.data, ) for i in range(3)] + ) + for row in rows: +- assert isinstance(row[0], unicode) ++ assert isinstance(row[0], str) + + def _test_empty_strings(self): + unicode_table = self.tables.unicode_table + + config.db.execute( + unicode_table.insert(), +- {"unicode_data": u''} ++ {"unicode_data": ''} + ) + row = config.db.execute( + select([unicode_table.c.unicode_data]) + ).first() +- eq_(row, (u'',)) ++ eq_(row, ('',)) + + + class UnicodeVarcharTest(_UnicodeFixture, fixtures.TablesTest): +diff -r 9d0639b9d3be lib/sqlalchemy/testing/util.py +--- a/lib/sqlalchemy/testing/util.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/testing/util.py Sat Apr 27 19:42:17 2013 -0400 +@@ -32,13 +32,13 @@ + + def picklers(): + picklers = set() +- # Py2K +- try: +- import cPickle +- picklers.add(cPickle) +- except ImportError: +- pass +- # end Py2K ++# start Py2K ++# try: ++# import cPickle ++# picklers.add(cPickle) ++# except ImportError: ++# pass ++# end Py2K + import pickle + picklers.add(pickle) + +@@ -130,8 +130,8 @@ + try: + fn.__name__ = name + except TypeError: +- fn = types.FunctionType(fn.func_code, fn.func_globals, name, +- fn.func_defaults, fn.func_closure) ++ fn = types.FunctionType(fn.__code__, fn.__globals__, name, ++ fn.__defaults__, fn.__closure__) + return fn + + +diff -r 9d0639b9d3be lib/sqlalchemy/testing/warnings.py +--- a/lib/sqlalchemy/testing/warnings.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/testing/warnings.py Sat Apr 27 19:42:17 2013 -0400 +@@ -1,4 +1,4 @@ +-from __future__ import absolute_import ++ + + import warnings + from .. import exc as sa_exc +@@ -10,7 +10,7 @@ + + filename = "sqlalchemy.testing.warnings" + lineno = 1 +- if isinstance(msg, basestring): ++ if isinstance(msg, str): + warnings.warn_explicit(msg, sa_exc.SAWarning, filename, lineno) + else: + warnings.warn_explicit(msg, filename, lineno) +diff -r 9d0639b9d3be lib/sqlalchemy/types.py +--- a/lib/sqlalchemy/types.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/types.py Sat Apr 27 19:42:17 2013 -0400 +@@ -156,8 +156,8 @@ + + """ + +- return self.__class__.column_expression.func_code \ +- is not TypeEngine.column_expression.func_code ++ return self.__class__.column_expression.__code__ \ ++ is not TypeEngine.column_expression.__code__ + + def bind_expression(self, bindvalue): + """"Given a bind value (i.e. a :class:`.BindParameter` instance), +@@ -194,8 +194,8 @@ + + """ + +- return self.__class__.bind_expression.func_code \ +- is not TypeEngine.bind_expression.func_code ++ return self.__class__.bind_expression.__code__ \ ++ is not TypeEngine.bind_expression.__code__ + + def compare_values(self, x, y): + """Compare two values for equality.""" +@@ -392,12 +392,13 @@ + return default.DefaultDialect() + + def __str__(self): +- # Py3K +- #return unicode(self.compile()) +- # Py2K +- return unicode(self.compile()).\ +- encode('ascii', 'backslashreplace') +- # end Py2K ++# start Py3K ++ return str(self.compile()) ++# end Py3K ++# start Py2K ++# return unicode(self.compile()).\ ++# encode('ascii', 'backslashreplace') ++# end Py2K + + def __init__(self, *args, **kwargs): + """Support implementations that were passing arguments""" +@@ -723,8 +724,8 @@ + + """ + +- return self.__class__.process_bind_param.func_code \ +- is not TypeDecorator.process_bind_param.func_code ++ return self.__class__.process_bind_param.__code__ \ ++ is not TypeDecorator.process_bind_param.__code__ + + def bind_processor(self, dialect): + """Provide a bound value processing function for the +@@ -769,8 +770,8 @@ + exception throw. + + """ +- return self.__class__.process_result_value.func_code \ +- is not TypeDecorator.process_result_value.func_code ++ return self.__class__.process_result_value.__code__ \ ++ is not TypeDecorator.process_result_value.__code__ + + def result_processor(self, dialect, coltype): + """Provide a result value processing function for the given +@@ -1114,11 +1115,12 @@ + self.convert_unicode != 'force': + if self._warn_on_bytestring: + def process(value): +- # Py3K +- #if isinstance(value, bytes): +- # Py2K +- if isinstance(value, str): +- # end Py2K ++# start Py3K ++ if isinstance(value, bytes): ++# end Py3K ++# start Py2K ++# if isinstance(value, str): ++# end Py2K + util.warn("Unicode type received non-unicode bind " + "param value.") + return value +@@ -1130,7 +1132,7 @@ + warn_on_bytestring = self._warn_on_bytestring + + def process(value): +- if isinstance(value, unicode): ++ if isinstance(value, str): + return encoder(value, self.unicode_error)[0] + elif warn_on_bytestring and value is not None: + util.warn("Unicode type received non-unicode bind " +@@ -1156,7 +1158,7 @@ + # habits. since we will be getting back unicode + # in most cases, we check for it (decode will fail). + def process(value): +- if isinstance(value, unicode): ++ if isinstance(value, str): + return value + else: + return to_unicode(value) +@@ -1171,7 +1173,7 @@ + @property + def python_type(self): + if self.convert_unicode: +- return unicode ++ return str + else: + return str + +@@ -1318,12 +1320,12 @@ + Integer: self.__class__, + Numeric: Numeric, + }, +- # Py2K +- operators.div: { +- Integer: self.__class__, +- Numeric: Numeric, +- }, +- # end Py2K ++# start Py2K ++# operators.div: { ++# Integer: self.__class__, ++# Numeric: Numeric, ++# }, ++# end Py2K + operators.truediv: { + Integer: self.__class__, + Numeric: Numeric, +@@ -1488,12 +1490,12 @@ + Numeric: self.__class__, + Integer: self.__class__, + }, +- # Py2K +- operators.div: { +- Numeric: self.__class__, +- Integer: self.__class__, +- }, +- # end Py2K ++# start Py2K ++# operators.div: { ++# Numeric: self.__class__, ++# Integer: self.__class__, ++# }, ++# end Py2K + operators.truediv: { + Numeric: self.__class__, + Integer: self.__class__, +@@ -1558,11 +1560,11 @@ + Interval: Interval, + Numeric: self.__class__, + }, +- # Py2K +- operators.div: { +- Numeric: self.__class__, +- }, +- # end Py2K ++# start Py2K ++# operators.div: { ++# Numeric: self.__class__, ++# }, ++# end Py2K + operators.truediv: { + Numeric: self.__class__, + }, +@@ -1693,11 +1695,12 @@ + + @property + def python_type(self): +- # Py3K +- #return bytes +- # Py2K +- return str +- # end Py2K ++# start Py3K ++ return bytes ++# end Py3K ++# start Py2K ++# return str ++# end Py2K + + # Python 3 - sqlite3 doesn't need the `Binary` conversion + # here, though pg8000 does to indicate "bytea" +@@ -1715,32 +1718,33 @@ + # Python 3 has native bytes() type + # both sqlite3 and pg8000 seem to return it, + # psycopg2 as of 2.5 returns 'memoryview' +- # Py3K +- #def result_processor(self, dialect, coltype): +- # def process(value): +- # if value is not None: +- # value = bytes(value) +- # return value +- # return process +- # Py2K ++# start Py3K + def result_processor(self, dialect, coltype): +- if util.jython: +- def process(value): +- if value is not None: +- if isinstance(value, array.array): +- return value.tostring() +- return str(value) +- else: +- return None +- else: +- process = processors.to_str ++ def process(value): ++ if value is not None: ++ value = bytes(value) ++ return value + return process +- # end Py2K ++# end Py3K ++# start Py2K ++# def result_processor(self, dialect, coltype): ++# if util.jython: ++# def process(value): ++# if value is not None: ++# if isinstance(value, array.array): ++# return value.tostring() ++# return str(value) ++# else: ++# return None ++# else: ++# process = processors.to_str ++# return process ++# end Py2K + + def coerce_compared_value(self, op, value): + """See :meth:`.TypeEngine.coerce_compared_value` for a description.""" + +- if isinstance(value, basestring): ++ if isinstance(value, str): + return self + else: + return super(_Binary, self).coerce_compared_value(op, value) +@@ -1997,7 +2001,7 @@ + convert_unicode = kw.pop('convert_unicode', None) + if convert_unicode is None: + for e in enums: +- if isinstance(e, unicode): ++ if isinstance(e, str): + convert_unicode = True + break + else: +@@ -2296,11 +2300,11 @@ + operators.truediv: { + Numeric: self.__class__ + }, +- # Py2K +- operators.div: { +- Numeric: self.__class__ +- } +- # end Py2K ++# start Py2K ++# operators.div: { ++# Numeric: self.__class__ ++# } ++# end Py2K + } + + @property +@@ -2451,11 +2455,12 @@ + + _type_map = { + str: String(), +- # Py3K +- #bytes: LargeBinary(), +- # Py2K +- unicode: Unicode(), +- # end Py2K ++# start Py3K ++ bytes: LargeBinary(), ++# end Py3K ++# start Py2K ++# unicode: Unicode(), ++# end Py2K + int: Integer(), + float: Numeric(), + bool: BOOLEANTYPE, +diff -r 9d0639b9d3be lib/sqlalchemy/util/_collections.py +--- a/lib/sqlalchemy/util/_collections.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/util/_collections.py Sat Apr 27 19:42:17 2013 -0400 +@@ -55,7 +55,7 @@ + t = tuple.__new__(cls, vals) + t._labels = [] + if labels: +- t.__dict__.update(zip(labels, vals)) ++ t.__dict__.update(list(zip(labels, vals))) + t._labels = labels + return t + +@@ -94,7 +94,7 @@ + .. versionadded:: 0.8 + + """ +- return dict((key, self.__dict__[key]) for key in self.keys()) ++ return dict((key, self.__dict__[key]) for key in list(self.keys())) + + + class ImmutableContainer(object): +@@ -142,7 +142,7 @@ + return len(self._data) + + def __iter__(self): +- return self._data.itervalues() ++ return iter(self._data.values()) + + def __add__(self, other): + return list(self) + list(other) +@@ -189,13 +189,13 @@ + return default + + def keys(self): +- return self._data.keys() ++ return list(self._data.keys()) + + def values(self): +- return self._data.values() ++ return list(self._data.values()) + + def items(self): +- return self._data.items() ++ return list(self._data.items()) + + def has_key(self, key): + return key in self._data +@@ -242,7 +242,7 @@ + def update(self, ____sequence=None, **kwargs): + if ____sequence is not None: + if hasattr(____sequence, 'keys'): +- for key in ____sequence.keys(): ++ for key in list(____sequence.keys()): + self.__setitem__(key, ____sequence[key]) + else: + for key, value in ____sequence: +@@ -270,13 +270,13 @@ + return list(self._list) + + def iterkeys(self): +- return iter(self.keys()) ++ return iter(list(self.keys())) + + def items(self): +- return [(key, self[key]) for key in self.keys()] ++ return [(key, self[key]) for key in list(self.keys())] + + def iteritems(self): +- return iter(self.items()) ++ return iter(list(self.items())) + + def __setitem__(self, key, object): + if key not in self: +@@ -470,8 +470,8 @@ + + if len(self) > len(other): + return False +- for m in itertools.ifilterfalse(other._members.__contains__, +- self._members.iterkeys()): ++ for m in itertools.filterfalse(other._members.__contains__, ++ iter(self._members.keys())): + return False + return True + +@@ -491,8 +491,8 @@ + if len(self) < len(other): + return False + +- for m in itertools.ifilterfalse(self._members.__contains__, +- other._members.iterkeys()): ++ for m in itertools.filterfalse(self._members.__contains__, ++ iter(other._members.keys())): + return False + return True + +@@ -582,7 +582,7 @@ + return result + + def _member_id_tuples(self): +- return ((id(v), v) for v in self._members.itervalues()) ++ return ((id(v), v) for v in self._members.values()) + + def __xor__(self, other): + if not isinstance(other, IdentitySet): +@@ -599,7 +599,7 @@ + return self + + def copy(self): +- return type(self)(self._members.itervalues()) ++ return type(self)(iter(self._members.values())) + + __copy__ = copy + +@@ -607,13 +607,13 @@ + return len(self._members) + + def __iter__(self): +- return self._members.itervalues() ++ return iter(self._members.values()) + + def __hash__(self): + raise TypeError('set objects are unhashable') + + def __repr__(self): +- return '%s(%r)' % (type(self).__name__, self._members.values()) ++ return '%s(%r)' % (type(self).__name__, list(self._members.values())) + + + class WeakSequence(object): +@@ -623,7 +623,7 @@ + ) + + def __iter__(self): +- return self._storage.itervalues() ++ return iter(self._storage.values()) + + def __getitem__(self, index): + try: +@@ -754,7 +754,7 @@ + + """ + for elem in x: +- if not isinstance(elem, basestring) and hasattr(elem, '__iter__'): ++ if not isinstance(elem, str) and hasattr(elem, '__iter__'): + for y in flatten_iterator(elem): + yield y + else: +diff -r 9d0639b9d3be lib/sqlalchemy/util/compat.py +--- a/lib/sqlalchemy/util/compat.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/util/compat.py Sat Apr 27 19:42:17 2013 -0400 +@@ -43,14 +43,14 @@ + + if sys.version_info < (2, 6): + def next(iter): +- return iter.next() ++ return iter.__next__() + else: + next = next + if py3k_warning: + import pickle + else: + try: +- import cPickle as pickle ++ import pickle as pickle + except ImportError: + import pickle + +@@ -59,12 +59,13 @@ + # in newer pythons + from cgi import parse_qsl + else: +- from urlparse import parse_qsl ++ from urllib.parse import parse_qsl + +-# Py3K +-#from inspect import getfullargspec as inspect_getfullargspec +-# Py2K +-from inspect import getargspec as inspect_getfullargspec ++# start Py3K ++from inspect import getfullargspec as inspect_getfullargspec ++# end Py3K ++# start Py2K ++#from inspect import getargspec as inspect_getfullargspec + # end Py2K + + if py3k_warning: +diff -r 9d0639b9d3be lib/sqlalchemy/util/deprecations.py +--- a/lib/sqlalchemy/util/deprecations.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/util/deprecations.py Sat Apr 27 19:42:17 2013 -0400 +@@ -10,7 +10,7 @@ + from .. import exc + import warnings + import re +-from langhelpers import decorator ++from .langhelpers import decorator + + + def warn_deprecated(msg, stacklevel=3): +diff -r 9d0639b9d3be lib/sqlalchemy/util/langhelpers.py +--- a/lib/sqlalchemy/util/langhelpers.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/lib/sqlalchemy/util/langhelpers.py Sat Apr 27 19:42:17 2013 -0400 +@@ -21,10 +21,12 @@ + from .. import exc + import hashlib + from . import compat ++import collections + + def md5_hex(x): +- # Py3K +- #x = x.encode('utf-8') ++# start Py3K ++ x = x.encode('utf-8') ++# end Py3K + m = hashlib.md5() + m.update(x) + return m.hexdigest() +@@ -77,8 +79,8 @@ + used = set(used) + for base in bases: + pool = itertools.chain((base,), +- itertools.imap(lambda i: base + str(i), +- xrange(1000))) ++ map(lambda i: base + str(i), ++ range(1000))) + for sym in pool: + if sym not in used: + used.add(sym) +@@ -95,7 +97,7 @@ + if not inspect.isfunction(fn): + raise Exception("not a decoratable function") + spec = inspect_getfullargspec(fn) +- names = tuple(spec[0]) + spec[1:3] + (fn.func_name,) ++ names = tuple(spec[0]) + spec[1:3] + (fn.__name__,) + targ_name, fn_name = _unique_symbols(names, 'target', 'fn') + + metadata = dict(target=targ_name, fn=fn_name) +@@ -104,7 +106,7 @@ + code = 'lambda %(args)s: %(target)s(%(fn)s, %(apply_kw)s)' % ( + metadata) + decorated = eval(code, {targ_name: target, fn_name: fn}) +- decorated.func_defaults = getattr(fn, 'im_func', fn).func_defaults ++ decorated.__defaults__ = getattr(fn, 'im_func', fn).__defaults__ + return update_wrapper(decorated, fn) + return update_wrapper(decorate, target) + +@@ -176,7 +178,7 @@ + ctr = class_.__dict__.get('__init__', False) + if (not ctr or + not isinstance(ctr, types.FunctionType) or +- not isinstance(ctr.func_code, types.CodeType)): ++ not isinstance(ctr.__code__, types.CodeType)): + stack.update(class_.__bases__) + continue + +@@ -194,7 +196,7 @@ + from inspect import CO_VARKEYWORDS + + def inspect_func_args(fn): +- co = fn.func_code ++ co = fn.__code__ + nargs = co.co_argcount + names = co.co_varnames + args = list(names[:nargs]) +@@ -250,7 +252,7 @@ + 'apply_pos': '(self, a, b, c, **d)'} + + """ +- if callable(fn): ++ if isinstance(fn, collections.Callable): + spec = inspect_getfullargspec(fn) + else: + # we accept an existing argspec... +@@ -263,22 +265,23 @@ + else: + self_arg = None + +- # Py3K +- #apply_pos = inspect.formatargspec(spec[0], spec[1], +- # spec[2], None, spec[4]) +- #num_defaults = 0 +- #if spec[3]: +- # num_defaults += len(spec[3]) +- #if spec[4]: +- # num_defaults += len(spec[4]) +- #name_args = spec[0] + spec[4] +- # Py2K +- apply_pos = inspect.formatargspec(spec[0], spec[1], spec[2]) ++# start Py3K ++ apply_pos = inspect.formatargspec(spec[0], spec[1], ++ spec[2], None, spec[4]) + num_defaults = 0 + if spec[3]: + num_defaults += len(spec[3]) +- name_args = spec[0] +- # end Py2K ++ if spec[4]: ++ num_defaults += len(spec[4]) ++ name_args = spec[0] + spec[4] ++# end Py3K ++# start Py2K ++# apply_pos = inspect.formatargspec(spec[0], spec[1], spec[2]) ++# num_defaults = 0 ++# if spec[3]: ++# num_defaults += len(spec[3]) ++# name_args = spec[0] ++# end Py2K + + if num_defaults: + defaulted_vals = name_args[0 - num_defaults:] +@@ -341,8 +344,8 @@ + + """ + +- if isinstance(func_or_cls, types.MethodType) and not func_or_cls.im_self: +- return func_or_cls.im_func ++ if isinstance(func_or_cls, types.MethodType) and not func_or_cls.__self__: ++ return func_or_cls.__func__ + else: + return func_or_cls + +@@ -399,7 +402,7 @@ + + """ + def __init__(self, meth): +- self.target = meth.im_self ++ self.target = meth.__self__ + self.name = meth.__name__ + + def __call__(self, *arg, **kw): +@@ -419,32 +422,34 @@ + will not be descended. + + """ +- # Py2K +- if isinstance(cls, types.ClassType): +- return list() +- # end Py2K ++# start Py2K ++# if isinstance(cls, types.ClassType): ++# return list() ++# end Py2K + hier = set([cls]) + process = list(cls.__mro__) + while process: + c = process.pop() +- # Py2K +- if isinstance(c, types.ClassType): +- continue ++# start Py2K ++# if isinstance(c, types.ClassType): ++# continue ++# for b in (_ for _ in c.__bases__ ++# if _ not in hier and not isinstance(_, types.ClassType)): ++# end Py2K ++# start Py3K + for b in (_ for _ in c.__bases__ +- if _ not in hier and not isinstance(_, types.ClassType)): +- # end Py2K +- # Py3K +- #for b in (_ for _ in c.__bases__ +- # if _ not in hier): ++ if _ not in hier): ++# end Py3K + process.append(b) + hier.add(b) +- # Py3K +- #if c.__module__ == 'builtins' or not hasattr(c, '__subclasses__'): +- # continue +- # Py2K +- if c.__module__ == '__builtin__' or not hasattr(c, '__subclasses__'): ++# start Py3K ++ if c.__module__ == 'builtins' or not hasattr(c, '__subclasses__'): + continue +- # end Py2K ++# end Py3K ++# start Py2K ++# if c.__module__ == '__builtin__' or not hasattr(c, '__subclasses__'): ++# continue ++# end Py2K + for s in [_ for _ in c.__subclasses__() if _ not in hier]: + process.append(s) + hier.add(s) +@@ -501,9 +506,9 @@ + "return %(name)s.%(method)s%(d_args)s" % locals()) + + env = from_instance is not None and {name: from_instance} or {} +- exec py in env ++ exec(py, env) + try: +- env[method].func_defaults = fn.func_defaults ++ env[method].__defaults__ = fn.__defaults__ + except AttributeError: + pass + setattr(into_cls, method, env[method]) +@@ -512,11 +517,12 @@ + def methods_equivalent(meth1, meth2): + """Return True if the two methods are the same implementation.""" + +- # Py3K +- #return getattr(meth1, '__func__', meth1) is getattr(meth2, '__func__', meth2) +- # Py2K +- return getattr(meth1, 'im_func', meth1) is getattr(meth2, 'im_func', meth2) +- # end Py2K ++# start Py3K ++ return getattr(meth1, '__func__', meth1) is getattr(meth2, '__func__', meth2) ++# end Py3K ++# start Py2K ++# return getattr(meth1, 'im_func', meth1) is getattr(meth2, 'im_func', meth2) ++# end Py2K + + + def as_interface(obj, cls=None, methods=None, required=None): +@@ -589,7 +595,7 @@ + for method, impl in dictlike_iteritems(obj): + if method not in interface: + raise TypeError("%r: unknown in this interface" % method) +- if not callable(impl): ++ if not isinstance(impl, collections.Callable): + raise TypeError("%r=%r is not callable" % (method, impl)) + setattr(AnonymousInterface, method, staticmethod(impl)) + found.add(method) +@@ -753,7 +759,7 @@ + + # from paste.deploy.converters + def asbool(obj): +- if isinstance(obj, (str, unicode)): ++ if isinstance(obj, str): + obj = obj.strip().lower() + if obj in ['true', 'yes', 'on', 'y', 't', '1']: + return True +@@ -814,13 +820,13 @@ + """Return a threadsafe counter function.""" + + lock = threading.Lock() +- counter = itertools.count(1L) ++ counter = itertools.count(1) + + # avoid the 2to3 "next" transformation... + def _next(): + lock.acquire() + try: +- return counter.next() ++ return next(counter) + finally: + lock.release() + +@@ -876,15 +882,16 @@ + def dictlike_iteritems(dictlike): + """Return a (key, value) iterator for almost any dict-like object.""" + +- # Py3K +- #if hasattr(dictlike, 'items'): +- # return dictlike.items() +- # Py2K +- if hasattr(dictlike, 'iteritems'): +- return dictlike.iteritems() +- elif hasattr(dictlike, 'items'): +- return iter(dictlike.items()) +- # end Py2K ++# start Py3K ++ if hasattr(dictlike, 'items'): ++ return list(dictlike.items()) ++# end Py3K ++# start Py2K ++# if hasattr(dictlike, 'iteritems'): ++# return dictlike.iteritems() ++# elif hasattr(dictlike, 'items'): ++# return iter(dictlike.items()) ++# end Py2K + + getter = getattr(dictlike, '__getitem__', getattr(dictlike, 'get', None)) + if getter is None: +@@ -893,11 +900,11 @@ + + if hasattr(dictlike, 'iterkeys'): + def iterator(): +- for key in dictlike.iterkeys(): ++ for key in dictlike.keys(): + yield key, getter(key) + return iterator() + elif hasattr(dictlike, 'keys'): +- return iter((key, getter(key)) for key in dictlike.keys()) ++ return iter((key, getter(key)) for key in list(dictlike.keys())) + else: + raise TypeError( + "Object '%r' is not dict-like" % dictlike) +@@ -1034,7 +1041,7 @@ + be controlled. + + """ +- if isinstance(msg, basestring): ++ if isinstance(msg, str): + warnings.warn(msg, exc.SAWarning, stacklevel=stacklevel) + else: + warnings.warn(msg, stacklevel=stacklevel) +diff -r 9d0639b9d3be test/aaa_profiling/test_compiler.py +--- a/test/aaa_profiling/test_compiler.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/aaa_profiling/test_compiler.py Sat Apr 27 19:42:17 2013 -0400 +@@ -29,7 +29,7 @@ + for c in t.c: + c.type._type_affinity + from sqlalchemy import types +- for t in types._type_map.values(): ++ for t in list(types._type_map.values()): + t._type_affinity + + cls.dialect = default.DefaultDialect() +diff -r 9d0639b9d3be test/aaa_profiling/test_memusage.py +--- a/test/aaa_profiling/test_memusage.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/aaa_profiling/test_memusage.py Sat Apr 27 19:42:17 2013 -0400 +@@ -47,7 +47,7 @@ + gc_collect() + samples[x] = len(get_objects_skipping_sqlite_issue()) + +- print "sample gc sizes:", samples ++ print("sample gc sizes:", samples) + + assert len(_sessions) == 0 + +diff -r 9d0639b9d3be test/aaa_profiling/test_orm.py +--- a/test/aaa_profiling/test_orm.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/aaa_profiling/test_orm.py Sat Apr 27 19:42:17 2013 -0400 +@@ -144,7 +144,7 @@ + + child.insert().execute([ + {'id':i, 'data':'c%d' % i} +- for i in xrange(1, 251) ++ for i in range(1, 251) + ]) + parent.insert().execute([ + { +@@ -152,7 +152,7 @@ + 'data':'p%dc%d' % (i, (i % 250) + 1), + 'child_id':(i % 250) + 1 + } +- for i in xrange(1, 1000) ++ for i in range(1, 1000) + ]) + + def test_many_to_one_load_no_identity(self): +@@ -234,11 +234,11 @@ + s = Session() + s.add_all([ + A(id=i, +- bs=[B(id=(i * 5) + j) for j in xrange(1, 5)], ++ bs=[B(id=(i * 5) + j) for j in range(1, 5)], + c=C(id=i), +- ds=[D(id=(i * 5) + j) for j in xrange(1, 5)] ++ ds=[D(id=(i * 5) + j) for j in range(1, 5)] + ) +- for i in xrange(1, 5) ++ for i in range(1, 5) + ]) + s.commit() + +@@ -249,11 +249,11 @@ + s = Session() + for a in [ + A(id=i, +- bs=[B(id=(i * 5) + j) for j in xrange(1, 5)], ++ bs=[B(id=(i * 5) + j) for j in range(1, 5)], + c=C(id=i), +- ds=[D(id=(i * 5) + j) for j in xrange(1, 5)] ++ ds=[D(id=(i * 5) + j) for j in range(1, 5)] + ) +- for i in xrange(1, 5) ++ for i in range(1, 5) + ]: + s.merge(a) + +diff -r 9d0639b9d3be test/aaa_profiling/test_resultset.py +--- a/test/aaa_profiling/test_resultset.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/aaa_profiling/test_resultset.py Sat Apr 27 19:42:17 2013 -0400 +@@ -19,10 +19,10 @@ + + def setup(self): + metadata.create_all() +- t.insert().execute([dict(('field%d' % fnum, u'value%d' % fnum) ++ t.insert().execute([dict(('field%d' % fnum, 'value%d' % fnum) + for fnum in range(NUM_FIELDS)) for r_num in + range(NUM_RECORDS)]) +- t2.insert().execute([dict(('field%d' % fnum, u'value%d' % fnum) ++ t2.insert().execute([dict(('field%d' % fnum, 'value%d' % fnum) + for fnum in range(NUM_FIELDS)) for r_num in + range(NUM_RECORDS)]) + +@@ -88,7 +88,7 @@ + + keymap = {} + for index, (keyobjs, processor, values) in \ +- enumerate(zip(keys, processors, row)): ++ enumerate(list(zip(keys, processors, row))): + for key in keyobjs: + keymap[key] = (processor, key, index) + keymap[index] = (processor, key, index) +diff -r 9d0639b9d3be test/aaa_profiling/test_zoomark.py +--- a/test/aaa_profiling/test_zoomark.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/aaa_profiling/test_zoomark.py Sat Apr 27 19:42:17 2013 -0400 +@@ -72,68 +72,68 @@ + Zoo = metadata.tables['Zoo'] + Animal = metadata.tables['Animal'] + engine = metadata.bind +- wap = engine.execute(Zoo.insert(), Name=u'Wild Animal Park', ++ wap = engine.execute(Zoo.insert(), Name='Wild Animal Park', + Founded=datetime.date(2000, 1, 1), + Opens=datetime.time(8, 15, 59), + LastEscape= + datetime.datetime(2004, 7, 29, 5, 6, 7), + Admission=4.95).inserted_primary_key[0] +- sdz = engine.execute(Zoo.insert(), Name=u'San Diego Zoo', ++ sdz = engine.execute(Zoo.insert(), Name='San Diego Zoo', + Founded=datetime.date(1935, 9, 13), + Opens=datetime.time(9, 0, 0), + Admission=0).inserted_primary_key[0] +- engine.execute(Zoo.insert(inline=True), Name=u'Montr\xe9al Biod\xf4me', ++ engine.execute(Zoo.insert(inline=True), Name='Montr\xe9al Biod\xf4me', + Founded=datetime.date(1992, 6, 19), + Opens=datetime.time(9, 0, 0), Admission=11.75) +- seaworld = engine.execute(Zoo.insert(), Name=u'Sea_World', ++ seaworld = engine.execute(Zoo.insert(), Name='Sea_World', + Admission=60).inserted_primary_key[0] + + # Let's add a crazy futuristic Zoo to test large date values. + +- lp = engine.execute(Zoo.insert(), Name=u'Luna Park', ++ lp = engine.execute(Zoo.insert(), Name='Luna Park', + Founded=datetime.date(2072, 7, 17), + Opens=datetime.time(0, 0, 0), + Admission=134.95).inserted_primary_key[0] + + # Animals + +- leopardid = engine.execute(Animal.insert(), Species=u'Leopard', ++ leopardid = engine.execute(Animal.insert(), Species='Leopard', + Lifespan=73.5).inserted_primary_key[0] + engine.execute(Animal.update(Animal.c.ID == leopardid), ZooID=wap, + LastEscape=datetime.datetime( 2004, 12, 21, 8, 15, 0, 999907,) + ) +- lion = engine.execute(Animal.insert(), Species=u'Lion', ++ lion = engine.execute(Animal.insert(), Species='Lion', + ZooID=wap).inserted_primary_key[0] +- engine.execute(Animal.insert(), Species=u'Slug', Legs=1, Lifespan=.75) +- tiger = engine.execute(Animal.insert(), Species=u'Tiger', ++ engine.execute(Animal.insert(), Species='Slug', Legs=1, Lifespan=.75) ++ tiger = engine.execute(Animal.insert(), Species='Tiger', + ZooID=sdz).inserted_primary_key[0] + + # Override Legs.default with itself just to make sure it works. + +- engine.execute(Animal.insert(inline=True), Species=u'Bear', Legs=4) +- engine.execute(Animal.insert(inline=True), Species=u'Ostrich', Legs=2, ++ engine.execute(Animal.insert(inline=True), Species='Bear', Legs=4) ++ engine.execute(Animal.insert(inline=True), Species='Ostrich', Legs=2, + Lifespan=103.2) +- engine.execute(Animal.insert(inline=True), Species=u'Centipede', ++ engine.execute(Animal.insert(inline=True), Species='Centipede', + Legs=100) +- emp = engine.execute(Animal.insert(), Species=u'Emperor Penguin', ++ emp = engine.execute(Animal.insert(), Species='Emperor Penguin', + Legs=2, ZooID=seaworld).inserted_primary_key[0] +- adelie = engine.execute(Animal.insert(), Species=u'Adelie Penguin', ++ adelie = engine.execute(Animal.insert(), Species='Adelie Penguin', + Legs=2, ZooID=seaworld).inserted_primary_key[0] +- engine.execute(Animal.insert(inline=True), Species=u'Millipede', ++ engine.execute(Animal.insert(inline=True), Species='Millipede', + Legs=1000000, ZooID=sdz) + + # Add a mother and child to test relationships + +- bai_yun = engine.execute(Animal.insert(), Species=u'Ape', +- Name=u'Bai Yun', Legs=2).inserted_primary_key[0] +- engine.execute(Animal.insert(inline=True), Species=u'Ape', +- Name=u'Hua Mei', Legs=2, MotherID=bai_yun) ++ bai_yun = engine.execute(Animal.insert(), Species='Ape', ++ Name='Bai Yun', Legs=2).inserted_primary_key[0] ++ engine.execute(Animal.insert(inline=True), Species='Ape', ++ Name='Hua Mei', Legs=2, MotherID=bai_yun) + + def test_baseline_2_insert(self): + Animal = metadata.tables['Animal'] + i = Animal.insert(inline=True) +- for x in xrange(ITERATIONS): +- tick = i.execute(Species=u'Tick', Name=u'Tick %d' % x, ++ for x in range(ITERATIONS): ++ tick = i.execute(Species='Tick', Name='Tick %d' % x, + Legs=8) + + def test_baseline_3_properties(self): +@@ -146,28 +146,28 @@ + + return list(engine.execute(select).first()) + +- for x in xrange(ITERATIONS): ++ for x in range(ITERATIONS): + + # Zoos + + WAP = fullobject(Zoo.select(Zoo.c.Name +- == u'Wild Animal Park')) ++ == 'Wild Animal Park')) + SDZ = fullobject(Zoo.select(Zoo.c.Founded + == datetime.date(1935, 9, 13))) + Biodome = fullobject(Zoo.select(Zoo.c.Name +- == u'Montr\xe9al Biod\xf4me')) ++ == 'Montr\xe9al Biod\xf4me')) + seaworld = fullobject(Zoo.select(Zoo.c.Admission + == float(60))) + + # Animals + + leopard = fullobject(Animal.select(Animal.c.Species +- == u'Leopard')) ++ == 'Leopard')) + ostrich = fullobject(Animal.select(Animal.c.Species +- == u'Ostrich')) ++ == 'Ostrich')) + millipede = fullobject(Animal.select(Animal.c.Legs + == 1000000)) +- ticks = fullobject(Animal.select(Animal.c.Species == u'Tick' ++ ticks = fullobject(Animal.select(Animal.c.Species == 'Tick' + )) + + def test_baseline_4_expressions(self): +@@ -180,7 +180,7 @@ + + return [list(row) for row in engine.execute(select).fetchall()] + +- for x in xrange(ITERATIONS): ++ for x in range(ITERATIONS): + assert len(fulltable(Zoo.select())) == 5 + assert len(fulltable(Animal.select())) == ITERATIONS + 12 + assert len(fulltable(Animal.select(Animal.c.Legs == 4))) \ +@@ -194,9 +194,9 @@ + assert len(fulltable(Animal.select(Animal.c.Lifespan + > 70))) == 2 + assert len(fulltable(Animal.select(Animal.c.Species. +- startswith(u'L')))) == 2 ++ startswith('L')))) == 2 + assert len(fulltable(Animal.select(Animal.c.Species. +- endswith(u'pede')))) == 2 ++ endswith('pede')))) == 2 + assert len(fulltable(Animal.select(Animal.c.LastEscape + != None))) == 1 + assert len(fulltable(Animal.select(None +@@ -204,10 +204,10 @@ + + # In operator (containedby) + +- assert len(fulltable(Animal.select(Animal.c.Species.like(u'%pede%' ++ assert len(fulltable(Animal.select(Animal.c.Species.like('%pede%' + )))) == 2 +- assert len(fulltable(Animal.select(Animal.c.Species.in_([u'Lion' +- , u'Tiger', u'Bear'])))) == 3 ++ assert len(fulltable(Animal.select(Animal.c.Species.in_(['Lion' ++ , 'Tiger', 'Bear'])))) == 3 + + # Try In with cell references + class thing(object): +@@ -215,20 +215,20 @@ + + + pet, pet2 = thing(), thing() +- pet.Name, pet2.Name = u'Slug', u'Ostrich' ++ pet.Name, pet2.Name = 'Slug', 'Ostrich' + assert len(fulltable(Animal.select(Animal.c.Species.in_([pet.Name, + pet2.Name])))) == 2 + + # logic and other functions + +- assert len(fulltable(Animal.select(Animal.c.Species.like(u'Slug' ++ assert len(fulltable(Animal.select(Animal.c.Species.like('Slug' + )))) == 1 +- assert len(fulltable(Animal.select(Animal.c.Species.like(u'%pede%' ++ assert len(fulltable(Animal.select(Animal.c.Species.like('%pede%' + )))) == 2 +- name = u'Lion' ++ name = 'Lion' + assert len(fulltable(Animal.select(func.length(Animal.c.Species) + == len(name)))) == ITERATIONS + 3 +- assert len(fulltable(Animal.select(Animal.c.Species.like(u'%i%' ++ assert len(fulltable(Animal.select(Animal.c.Species.like('%i%' + )))) == ITERATIONS + 7 + + # Test now(), today(), year(), month(), day() +@@ -250,7 +250,7 @@ + Zoo = metadata.tables['Zoo'] + engine = metadata.bind + +- for x in xrange(ITERATIONS): ++ for x in range(ITERATIONS): + + # views + +@@ -274,7 +274,7 @@ + for species, lifespan in engine.execute(select([Animal.c.Species, + Animal.c.Lifespan])).fetchall(): + assert lifespan == expected[species] +- expected = [u'Montr\xe9al Biod\xf4me', 'Wild Animal Park'] ++ expected = ['Montr\xe9al Biod\xf4me', 'Wild Animal Park'] + e = select([Zoo.c.Name], and_(Zoo.c.Founded != None, + Zoo.c.Founded <= func.current_timestamp(), + Zoo.c.Founded >= datetime.date(1990, 1, 1))) +@@ -290,21 +290,21 @@ + def test_baseline_6_editing(self): + Zoo = metadata.tables['Zoo'] + engine = metadata.bind +- for x in xrange(ITERATIONS): ++ for x in range(ITERATIONS): + + # Edit + +- SDZ = engine.execute(Zoo.select(Zoo.c.Name == u'San Diego Zoo' ++ SDZ = engine.execute(Zoo.select(Zoo.c.Name == 'San Diego Zoo' + )).first() + engine.execute(Zoo.update(Zoo.c.ID == SDZ['ID' +- ]), Name=u'The San Diego Zoo', ++ ]), Name='The San Diego Zoo', + Founded=datetime.date(1900, 1, 1), + Opens=datetime.time(7, 30, 0), + Admission='35.00') + + # Test edits + +- SDZ = engine.execute(Zoo.select(Zoo.c.Name == u'The San Diego Zoo' ++ SDZ = engine.execute(Zoo.select(Zoo.c.Name == 'The San Diego Zoo' + )).first() + assert SDZ['Founded'] == datetime.date(1900, 1, 1), \ + SDZ['Founded'] +@@ -312,14 +312,14 @@ + # Change it back + + engine.execute(Zoo.update(Zoo.c.ID == SDZ['ID' +- ]), Name=u'San Diego Zoo', ++ ]), Name='San Diego Zoo', + Founded=datetime.date(1935, 9, 13), + Opens=datetime.time(9, 0, 0), + Admission='0') + + # Test re-edits + +- SDZ = engine.execute(Zoo.select(Zoo.c.Name == u'San Diego Zoo' ++ SDZ = engine.execute(Zoo.select(Zoo.c.Name == 'San Diego Zoo' + )).first() + assert SDZ['Founded'] == datetime.date(1935, 9, 13) + +@@ -333,14 +333,14 @@ + + return [list(row) for row in engine.execute(select).fetchall()] + +- for x in xrange(ITERATIONS): ++ for x in range(ITERATIONS): + za = fulltable(select([Zoo.c.ID] + list(Animal.c), +- Zoo.c.Name == u'San Diego Zoo', ++ Zoo.c.Name == 'San Diego Zoo', + from_obj=[join(Zoo, Animal)])) +- SDZ = Zoo.select(Zoo.c.Name == u'San Diego Zoo') ++ SDZ = Zoo.select(Zoo.c.Name == 'San Diego Zoo') + e = fulltable(select([Zoo.c.ID, Animal.c.ID], +- and_(Zoo.c.Name == u'San Diego Zoo', +- Animal.c.Species == u'Leopard'), ++ and_(Zoo.c.Name == 'San Diego Zoo', ++ Animal.c.Species == 'Leopard'), + from_obj=[join(Zoo, Animal)])) + + # Now try the same query with INNER, LEFT, and RIGHT JOINs. +diff -r 9d0639b9d3be test/aaa_profiling/test_zoomark_orm.py +--- a/test/aaa_profiling/test_zoomark_orm.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/aaa_profiling/test_zoomark_orm.py Sat Apr 27 19:42:17 2013 -0400 +@@ -75,14 +75,14 @@ + class Zoo(object): + + def __init__(self, **kwargs): +- for k, v in kwargs.iteritems(): ++ for k, v in kwargs.items(): + setattr(self, k, v) + + + class Animal(object): + + def __init__(self, **kwargs): +- for k, v in kwargs.iteritems(): ++ for k, v in kwargs.items(): + setattr(self, k, v) + + +@@ -90,93 +90,93 @@ + mapper(Animal, animal) + + def test_baseline_1a_populate(self): +- wap = Zoo(Name=u'Wild Animal Park', Founded=datetime.date(2000, ++ wap = Zoo(Name='Wild Animal Park', Founded=datetime.date(2000, + 1, 1), Opens=datetime.time(8, 15, 59), + LastEscape=datetime.datetime( 2004, 7, 29, 5, 6, 7, ), + Admission=4.95) + session.add(wap) +- sdz = Zoo(Name=u'San Diego Zoo', Founded=datetime.date(1835, 9, ++ sdz = Zoo(Name='San Diego Zoo', Founded=datetime.date(1835, 9, + 13), Opens=datetime.time(9, 0, 0), Admission=0) + session.add(sdz) +- bio = Zoo(Name=u'Montr\xe9al Biod\xf4me', ++ bio = Zoo(Name='Montr\xe9al Biod\xf4me', + Founded=datetime.date(1992, 6, 19), + Opens=datetime.time(9, 0, 0), Admission=11.75) + session.add(bio) +- seaworld = Zoo(Name=u'Sea_World', Admission=60) ++ seaworld = Zoo(Name='Sea_World', Admission=60) + session.add(seaworld) + + # Let's add a crazy futuristic Zoo to test large date values. + +- lp = Zoo(Name=u'Luna Park', Founded=datetime.date(2072, 7, 17), ++ lp = Zoo(Name='Luna Park', Founded=datetime.date(2072, 7, 17), + Opens=datetime.time(0, 0, 0), Admission=134.95) + session.add(lp) + session.flush() + + # Animals + +- leopard = Animal(Species=u'Leopard', Lifespan=73.5) ++ leopard = Animal(Species='Leopard', Lifespan=73.5) + session.add(leopard) + leopard.ZooID = wap.ID + leopard.LastEscape = \ + datetime.datetime(2004, 12, 21, 8, 15, 0, 999907, ) +- session.add(Animal(Species=u'Lion', ZooID=wap.ID)) +- session.add(Animal(Species=u'Slug', Legs=1, Lifespan=.75)) +- session.add(Animal(Species=u'Tiger', ZooID=sdz.ID)) ++ session.add(Animal(Species='Lion', ZooID=wap.ID)) ++ session.add(Animal(Species='Slug', Legs=1, Lifespan=.75)) ++ session.add(Animal(Species='Tiger', ZooID=sdz.ID)) + + # Override Legs.default with itself just to make sure it works. + +- session.add(Animal(Species=u'Bear', Legs=4)) +- session.add(Animal(Species=u'Ostrich', Legs=2, Lifespan=103.2)) +- session.add(Animal(Species=u'Centipede', Legs=100)) +- session.add(Animal(Species=u'Emperor Penguin', Legs=2, ++ session.add(Animal(Species='Bear', Legs=4)) ++ session.add(Animal(Species='Ostrich', Legs=2, Lifespan=103.2)) ++ session.add(Animal(Species='Centipede', Legs=100)) ++ session.add(Animal(Species='Emperor Penguin', Legs=2, + ZooID=seaworld.ID)) +- session.add(Animal(Species=u'Adelie Penguin', Legs=2, ++ session.add(Animal(Species='Adelie Penguin', Legs=2, + ZooID=seaworld.ID)) +- session.add(Animal(Species=u'Millipede', Legs=1000000, ++ session.add(Animal(Species='Millipede', Legs=1000000, + ZooID=sdz.ID)) + + # Add a mother and child to test relationships + +- bai_yun = Animal(Species=u'Ape', Nameu=u'Bai Yun', Legs=2) ++ bai_yun = Animal(Species='Ape', Nameu='Bai Yun', Legs=2) + session.add(bai_yun) +- session.add(Animal(Species=u'Ape', Name=u'Hua Mei', Legs=2, ++ session.add(Animal(Species='Ape', Name='Hua Mei', Legs=2, + MotherID=bai_yun.ID)) + session.flush() + session.commit() + + def test_baseline_2_insert(self): +- for x in xrange(ITERATIONS): +- session.add(Animal(Species=u'Tick', Name=u'Tick %d' % x, ++ for x in range(ITERATIONS): ++ session.add(Animal(Species='Tick', Name='Tick %d' % x, + Legs=8)) + session.flush() + + def test_baseline_3_properties(self): +- for x in xrange(ITERATIONS): ++ for x in range(ITERATIONS): + + # Zoos + + WAP = list(session.query(Zoo).filter(Zoo.Name +- == u'Wild Animal Park')) ++ == 'Wild Animal Park')) + SDZ = list(session.query(Zoo).filter(Zoo.Founded + == datetime.date(1835, 9, 13))) + Biodome = list(session.query(Zoo).filter(Zoo.Name +- == u'Montr\xe9al Biod\xf4me')) ++ == 'Montr\xe9al Biod\xf4me')) + seaworld = list(session.query(Zoo).filter(Zoo.Admission + == float(60))) + + # Animals + + leopard = list(session.query(Animal).filter(Animal.Species +- == u'Leopard')) ++ == 'Leopard')) + ostrich = list(session.query(Animal).filter(Animal.Species +- == u'Ostrich')) ++ == 'Ostrich')) + millipede = list(session.query(Animal).filter(Animal.Legs + == 1000000)) + ticks = list(session.query(Animal).filter(Animal.Species +- == u'Tick')) ++ == 'Tick')) + + def test_baseline_4_expressions(self): +- for x in xrange(ITERATIONS): ++ for x in range(ITERATIONS): + assert len(list(session.query(Zoo))) == 5 + assert len(list(session.query(Animal))) == ITERATIONS + 12 + assert len(list(session.query(Animal).filter(Animal.Legs +@@ -190,9 +190,9 @@ + assert len(list(session.query(Animal).filter(Animal.Lifespan + > 70))) == 2 + assert len(list(session.query(Animal). +- filter(Animal.Species.like(u'L%')))) == 2 ++ filter(Animal.Species.like('L%')))) == 2 + assert len(list(session.query(Animal). +- filter(Animal.Species.like(u'%pede')))) == 2 ++ filter(Animal.Species.like('%pede')))) == 2 + assert len(list(session.query(Animal).filter(Animal.LastEscape + != None))) == 1 + assert len(list(session.query(Animal).filter(Animal.LastEscape +@@ -201,29 +201,29 @@ + # In operator (containedby) + + assert len(list(session.query(Animal).filter( +- Animal.Species.like(u'%pede%')))) == 2 ++ Animal.Species.like('%pede%')))) == 2 + assert len(list(session.query(Animal). +- filter(Animal.Species.in_((u'Lion' +- , u'Tiger', u'Bear'))))) == 3 ++ filter(Animal.Species.in_(('Lion' ++ , 'Tiger', 'Bear'))))) == 3 + + # Try In with cell references + class thing(object): + pass + + pet, pet2 = thing(), thing() +- pet.Name, pet2.Name = u'Slug', u'Ostrich' ++ pet.Name, pet2.Name = 'Slug', 'Ostrich' + assert len(list(session.query(Animal). + filter(Animal.Species.in_((pet.Name, + pet2.Name))))) == 2 + + # logic and other functions + +- name = u'Lion' ++ name = 'Lion' + assert len(list(session.query(Animal). + filter(func.length(Animal.Species) + == len(name)))) == ITERATIONS + 3 + assert len(list(session.query(Animal). +- filter(Animal.Species.like(u'%i%' ++ filter(Animal.Species.like('%i%' + )))) == ITERATIONS + 7 + + # Test now(), today(), year(), month(), day() +@@ -246,7 +246,7 @@ + + # TODO: convert to ORM + engine = metadata.bind +- for x in xrange(ITERATIONS): ++ for x in range(ITERATIONS): + + # views + +@@ -270,7 +270,7 @@ + for species, lifespan in engine.execute(select([Animal.c.Species, + Animal.c.Lifespan])).fetchall(): + assert lifespan == expected[species] +- expected = [u'Montr\xe9al Biod\xf4me', 'Wild Animal Park'] ++ expected = ['Montr\xe9al Biod\xf4me', 'Wild Animal Park'] + e = select([Zoo.c.Name], and_(Zoo.c.Founded != None, + Zoo.c.Founded <= func.current_timestamp(), + Zoo.c.Founded >= datetime.date(1990, 1, 1))) +@@ -284,13 +284,13 @@ + legs.sort() + + def test_baseline_6_editing(self): +- for x in xrange(ITERATIONS): ++ for x in range(ITERATIONS): + + # Edit + +- SDZ = session.query(Zoo).filter(Zoo.Name == u'San Diego Zoo' ++ SDZ = session.query(Zoo).filter(Zoo.Name == 'San Diego Zoo' + ).one() +- SDZ.Name = u'The San Diego Zoo' ++ SDZ.Name = 'The San Diego Zoo' + SDZ.Founded = datetime.date(1900, 1, 1) + SDZ.Opens = datetime.time(7, 30, 0) + SDZ.Admission = 35.00 +@@ -298,19 +298,19 @@ + # Test edits + + SDZ = session.query(Zoo).filter(Zoo.Name +- == u'The San Diego Zoo').one() ++ == 'The San Diego Zoo').one() + assert SDZ.Founded == datetime.date(1900, 1, 1), SDZ.Founded + + # Change it back + +- SDZ.Name = u'San Diego Zoo' ++ SDZ.Name = 'San Diego Zoo' + SDZ.Founded = datetime.date(1835, 9, 13) + SDZ.Opens = datetime.time(9, 0, 0) + SDZ.Admission = 0 + + # Test re-edits + +- SDZ = session.query(Zoo).filter(Zoo.Name == u'San Diego Zoo' ++ SDZ = session.query(Zoo).filter(Zoo.Name == 'San Diego Zoo' + ).one() + assert SDZ.Founded == datetime.date(1835, 9, 13), \ + SDZ.Founded +diff -r 9d0639b9d3be test/base/test_dependency.py +--- a/test/base/test_dependency.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/base/test_dependency.py Sat Apr 27 19:42:17 2013 -0400 +@@ -82,7 +82,7 @@ + try: + list(topological.sort(tuples, allitems)) + assert False +- except exc.CircularDependencyError, err: ++ except exc.CircularDependencyError as err: + eq_(err.cycles, set(['node1', 'node3', 'node2', 'node5', + 'node4'])) + eq_(err.edges, set([('node3', 'node1'), ('node4', 'node1'), +@@ -105,7 +105,7 @@ + try: + list(topological.sort(tuples, allitems)) + assert False +- except exc.CircularDependencyError, err: ++ except exc.CircularDependencyError as err: + eq_(err.cycles, set(['node1', 'node3', 'node2'])) + eq_(err.edges, set([('node3', 'node1'), ('node2', 'node3'), + ('node3', 'node2'), ('node1', 'node2'), +@@ -271,7 +271,7 @@ + ('node4', 'node17'), ('node2', 'node20'), ('node19', 'node10'), + ('node8', 'node4'), ('node11', 'node3'), ('node6', 'node1') + ] +- allnodes = ['node%d' % i for i in xrange(1, 21)] ++ allnodes = ['node%d' % i for i in range(1, 21)] + eq_( + topological.find_cycles(tuples, allnodes), + set(['node11', 'node10', 'node13', 'node15', 'node14', 'node17', +diff -r 9d0639b9d3be test/base/test_events.py +--- a/test/base/test_events.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/base/test_events.py Sat Apr 27 19:42:17 2013 -0400 +@@ -190,7 +190,7 @@ + def test_lis_subcalss_lis(self): + @event.listens_for(self.TargetOne, "event_one") + def handler1(x, y): +- print 'handler1' ++ print('handler1') + + class SubTarget(self.TargetOne): + pass +@@ -207,7 +207,7 @@ + def test_lis_multisub_lis(self): + @event.listens_for(self.TargetOne, "event_one") + def handler1(x, y): +- print 'handler1' ++ print('handler1') + + class SubTarget(self.TargetOne): + pass +diff -r 9d0639b9d3be test/base/test_except.py +--- a/test/base/test_except.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/base/test_except.py Sat Apr 27 19:42:17 2013 -0400 +@@ -5,14 +5,15 @@ + from sqlalchemy.testing import fixtures + from sqlalchemy.testing import eq_ + +-# Py3K +-#StandardError = BaseException +-# Py2K +-from exceptions import StandardError, KeyboardInterrupt, SystemExit ++# start Py3K ++Exception = BaseException ++# end Py3K ++# start Py2K ++#from exceptions import StandardError, KeyboardInterrupt, SystemExit + # end Py2K + + +-class Error(StandardError): ++class Error(Exception): + """This class will be old-style on <= 2.4 and new-style on >= + 2.5.""" + +@@ -47,7 +48,7 @@ + try: + raise sa_exceptions.DBAPIError.instance('this is a message' + , None, OperationalError(), DatabaseError) +- except sa_exceptions.DBAPIError, exc: ++ except sa_exceptions.DBAPIError as exc: + assert str(exc) \ + == "(OperationalError) 'this is a message' None" + +@@ -58,7 +59,7 @@ + {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': + 8, 'i': 9, 'j': 10, 'k': 11, + }, OperationalError(), DatabaseError) +- except sa_exceptions.DBAPIError, exc: ++ except sa_exceptions.DBAPIError as exc: + assert str(exc).startswith("(OperationalError) 'this is a " + "message' {") + +@@ -67,7 +68,7 @@ + raise sa_exceptions.DBAPIError.instance('this is a message', + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,], + OperationalError(), DatabaseError) +- except sa_exceptions.DBAPIError, exc: ++ except sa_exceptions.DBAPIError as exc: + assert str(exc).startswith("(OperationalError) 'this is a " + "message' [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]") + +@@ -77,7 +78,7 @@ + [{1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, + {1: 1}, {1:1}, {1: 1}, {1: 1},], + OperationalError(), DatabaseError) +- except sa_exceptions.DBAPIError, exc: ++ except sa_exceptions.DBAPIError as exc: + eq_(str(exc) , + "(OperationalError) 'this is a message' [{1: 1}, "\ + "{1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: "\ +@@ -87,7 +88,7 @@ + {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, + {1:1}, {1: 1}, {1: 1}, {1: 1}, + ], OperationalError(), DatabaseError) +- except sa_exceptions.DBAPIError, exc: ++ except sa_exceptions.DBAPIError as exc: + eq_(str(exc) , + "(OperationalError) 'this is a message' [{1: 1}, " + "{1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, " +@@ -100,7 +101,7 @@ + (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), + (1, ), + ], OperationalError(), DatabaseError) +- except sa_exceptions.DBAPIError, exc: ++ except sa_exceptions.DBAPIError as exc: + eq_(str(exc), + "(OperationalError) 'this is a message' [(1,), "\ + "(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,)]") +@@ -109,7 +110,7 @@ + (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), + (1, ), (1, ), + ], OperationalError(), DatabaseError) +- except sa_exceptions.DBAPIError, exc: ++ except sa_exceptions.DBAPIError as exc: + eq_(str(exc), + "(OperationalError) 'this is a message' [(1,), " + "(1,), (1,), (1,), (1,), (1,), (1,), (1,) " +@@ -121,7 +122,7 @@ + try: + raise sa_exceptions.DBAPIError.instance('', [], + ProgrammingError(), DatabaseError) +- except sa_exceptions.DBAPIError, e: ++ except sa_exceptions.DBAPIError as e: + self.assert_(True) + self.assert_('Error in str() of DB-API' in e.args[0]) + +@@ -129,7 +130,7 @@ + try: + raise sa_exceptions.DBAPIError.instance('', [], OutOfSpec(), + DatabaseError) +- except sa_exceptions.DBAPIError, e: ++ except sa_exceptions.DBAPIError as e: + self.assert_(e.__class__ is sa_exceptions.DBAPIError) + except OutOfSpec: + self.assert_(False) +@@ -137,7 +138,7 @@ + try: + raise sa_exceptions.DBAPIError.instance('', [], + sa_exceptions.ArgumentError(), DatabaseError) +- except sa_exceptions.DBAPIError, e: ++ except sa_exceptions.DBAPIError as e: + self.assert_(e.__class__ is sa_exceptions.DBAPIError) + except sa_exceptions.ArgumentError: + self.assert_(False) +diff -r 9d0639b9d3be test/base/test_utils.py +--- a/test/base/test_utils.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/base/test_utils.py Sat Apr 27 19:42:17 2013 -0400 +@@ -16,7 +16,7 @@ + eq_(len(keyed_tuple), 0) + + eq_(keyed_tuple.__dict__, {'_labels': []}) +- eq_(keyed_tuple.keys(), []) ++ eq_(list(keyed_tuple.keys()), []) + eq_(keyed_tuple._fields, ()) + eq_(keyed_tuple._asdict(), {}) + +@@ -27,7 +27,7 @@ + eq_(len(keyed_tuple), 2) + + eq_(keyed_tuple.__dict__, {'_labels': []}) +- eq_(keyed_tuple.keys(), []) ++ eq_(list(keyed_tuple.keys()), []) + eq_(keyed_tuple._fields, ()) + eq_(keyed_tuple._asdict(), {}) + +@@ -37,7 +37,7 @@ + def test_basic_creation(self): + keyed_tuple = util.KeyedTuple([1, 2], ['a', 'b']) + eq_(str(keyed_tuple), '(1, 2)') +- eq_(keyed_tuple.keys(), ['a', 'b']) ++ eq_(list(keyed_tuple.keys()), ['a', 'b']) + eq_(keyed_tuple._fields, ('a', 'b')) + eq_(keyed_tuple._asdict(), {'a': 1, 'b': 2}) + +@@ -66,7 +66,7 @@ + # TODO: consider not allowing None labels + expected = {'a': 1, None: 2, 'b': 3, '_labels': ['a', None, 'b']} + eq_(keyed_tuple.__dict__, expected) +- eq_(keyed_tuple.keys(), ['a', 'b']) ++ eq_(list(keyed_tuple.keys()), ['a', 'b']) + eq_(keyed_tuple._fields, ('a', 'b')) + eq_(keyed_tuple._asdict(), {'a': 1, 'b': 3}) + +@@ -86,7 +86,7 @@ + # TODO: consider not allowing duplicate labels + expected = {'a': 1, 'b': 3, '_labels': ['a', 'b', 'b']} + eq_(keyed_tuple.__dict__, expected) +- eq_(keyed_tuple.keys(), ['a', 'b', 'b']) ++ eq_(list(keyed_tuple.keys()), ['a', 'b', 'b']) + eq_(keyed_tuple._fields, ('a', 'b', 'b')) + eq_(keyed_tuple._asdict(), {'a': 1, 'b': 3}) + +@@ -125,12 +125,12 @@ + o['snack'] = 'attack' + o['c'] = 3 + +- eq_(o.keys(), ['a', 'b', 'snack', 'c']) +- eq_(o.values(), [1, 2, 'attack', 3]) ++ eq_(list(o.keys()), ['a', 'b', 'snack', 'c']) ++ eq_(list(o.values()), [1, 2, 'attack', 3]) + + o.pop('snack') +- eq_(o.keys(), ['a', 'b', 'c']) +- eq_(o.values(), [1, 2, 3]) ++ eq_(list(o.keys()), ['a', 'b', 'c']) ++ eq_(list(o.values()), [1, 2, 3]) + + try: + o.pop('eep') +@@ -146,40 +146,40 @@ + except TypeError: + pass + +- eq_(o.keys(), ['a', 'b', 'c']) +- eq_(o.values(), [1, 2, 3]) ++ eq_(list(o.keys()), ['a', 'b', 'c']) ++ eq_(list(o.values()), [1, 2, 3]) + + o2 = util.OrderedDict(d=4) + o2['e'] = 5 + +- eq_(o2.keys(), ['d', 'e']) +- eq_(o2.values(), [4, 5]) ++ eq_(list(o2.keys()), ['d', 'e']) ++ eq_(list(o2.values()), [4, 5]) + + o.update(o2) +- eq_(o.keys(), ['a', 'b', 'c', 'd', 'e']) +- eq_(o.values(), [1, 2, 3, 4, 5]) ++ eq_(list(o.keys()), ['a', 'b', 'c', 'd', 'e']) ++ eq_(list(o.values()), [1, 2, 3, 4, 5]) + + o.setdefault('c', 'zzz') + o.setdefault('f', 6) +- eq_(o.keys(), ['a', 'b', 'c', 'd', 'e', 'f']) +- eq_(o.values(), [1, 2, 3, 4, 5, 6]) ++ eq_(list(o.keys()), ['a', 'b', 'c', 'd', 'e', 'f']) ++ eq_(list(o.values()), [1, 2, 3, 4, 5, 6]) + + def test_odict_constructor(self): + o = util.OrderedDict([('name', 'jbe'), ('fullname', 'jonathan' + ), ('password', '')]) +- eq_(o.keys(), ['name', 'fullname', 'password']) ++ eq_(list(o.keys()), ['name', 'fullname', 'password']) + + def test_odict_copy(self): + o = util.OrderedDict() + o["zzz"] = 1 + o["aaa"] = 2 +- eq_(o.keys(), ['zzz', 'aaa']) ++ eq_(list(o.keys()), ['zzz', 'aaa']) + + o2 = o.copy() +- eq_(o2.keys(), o.keys()) ++ eq_(list(o2.keys()), list(o.keys())) + + o3 = copy.copy(o) +- eq_(o3.keys(), o.keys()) ++ eq_(list(o3.keys()), list(o.keys())) + + + class OrderedSetTest(fixtures.TestBase): +@@ -198,7 +198,7 @@ + def test_serialize(self): + d = util.immutabledict({1: 2, 3: 4}) + for loads, dumps in picklers(): +- print loads(dumps(d)) ++ print(loads(dumps(d))) + + + class MemoizedAttrTest(fixtures.TestBase): +@@ -252,7 +252,7 @@ + try: + cc['col1'] in cc + assert False +- except exc.ArgumentError, e: ++ except exc.ArgumentError as e: + eq_(str(e), "__contains__ requires a string argument") + + def test_compare(self): +@@ -414,14 +414,14 @@ + for type_ in (object, ImmutableSubclass): + data = [type_(), type_()] + ids = util.IdentitySet() +- for i in range(2) + range(2): ++ for i in list(range(2)) + list(range(2)): + ids.add(data[i]) + self.assert_eq(ids, data) + + for type_ in (EqOverride, HashOverride, HashEqOverride): + data = [type_(1), type_(1), type_(2)] + ids = util.IdentitySet() +- for i in range(3) + range(3): ++ for i in list(range(3)) + list(range(3)): + ids.add(data[i]) + self.assert_eq(ids, data) + +@@ -843,13 +843,14 @@ + return super_, sub_, twin1, twin2, unique1, unique2 + + def _assert_unorderable_types(self, callable_): +- # Py3K +- #assert_raises_message( +- # TypeError, 'unorderable types', callable_) +- # Py2K ++# start Py3K + assert_raises_message( +- TypeError, 'cannot compare sets using cmp()', callable_) +- # end Py2K ++ TypeError, 'unorderable types', callable_) ++# end Py3K ++# start Py2K ++# assert_raises_message( ++# TypeError, 'cannot compare sets using cmp()', callable_) ++# end Py2K + + def test_basic_sanity(self): + IdentitySet = util.IdentitySet +@@ -969,23 +970,23 @@ + d = subdict(a=1, b=2, c=3) + self._ok(d) + +- # Py2K +- def test_UserDict(self): +- import UserDict +- d = UserDict.UserDict(a=1, b=2, c=3) +- self._ok(d) +- # end Py2K ++# start Py2K ++# def test_UserDict(self): ++# import UserDict ++# d = UserDict.UserDict(a=1, b=2, c=3) ++# self._ok(d) ++# end Py2K + + def test_object(self): + self._notok(object()) + +- # Py2K +- def test_duck_1(self): +- class duck1(object): +- def iteritems(duck): +- return iter(self.baseline) +- self._ok(duck1()) +- # end Py2K ++# start Py2K ++# def test_duck_1(self): ++# class duck1(object): ++# def iteritems(duck): ++# return iter(self.baseline) ++# self._ok(duck1()) ++# end Py2K + + def test_duck_2(self): + class duck2(object): +@@ -993,16 +994,16 @@ + return list(self.baseline) + self._ok(duck2()) + +- # Py2K +- def test_duck_3(self): +- class duck3(object): +- def iterkeys(duck): +- return iter(['a', 'b', 'c']) +- +- def __getitem__(duck, key): +- return dict(a=1, b=2, c=3).get(key) +- self._ok(duck3()) +- # end Py2K ++# start Py2K ++# def test_duck_3(self): ++# class duck3(object): ++# def iterkeys(duck): ++# return iter(['a', 'b', 'c']) ++# ++# def __getitem__(duck, key): ++# return dict(a=1, b=2, c=3).get(key) ++# self._ok(duck3()) ++# end Py2K + + def test_duck_4(self): + class duck4(object): +@@ -1029,9 +1030,9 @@ + class DuckTypeCollectionTest(fixtures.TestBase): + + def test_sets(self): +- # Py2K +- import sets +- # end Py2K ++# start Py2K ++# import sets ++# end Py2K + + class SetLike(object): + def add(self): +@@ -1041,9 +1042,9 @@ + __emulates__ = set + + for type_ in (set, +- # Py2K +- sets.Set, +- # end Py2K ++# start Py2K ++# sets.Set, ++# end Py2K + SetLike, + ForcedSet): + eq_(util.duck_type_collection(type_), set) +@@ -1051,9 +1052,9 @@ + eq_(util.duck_type_collection(instance), set) + + for type_ in (frozenset, +- # Py2K +- sets.ImmutableSet +- # end Py2K ++# start Py2K ++# sets.ImmutableSet ++# end Py2K + ): + is_(util.duck_type_collection(type_), None) + instance = type_() +@@ -1175,7 +1176,7 @@ + sym3 = util.pickle.loads(s) + + for protocol in 0, 1, 2: +- print protocol ++ print(protocol) + serial = util.pickle.dumps(sym1) + rt = util.pickle.loads(serial) + assert rt is sym1 +@@ -1550,21 +1551,21 @@ + eq_(set(util.class_hierarchy(A)), set((A, B, C, object))) + eq_(set(util.class_hierarchy(B)), set((A, B, C, object))) + +- # Py2K +- def test_oldstyle_mixin(self): +- class A(object): +- pass +- +- class Mixin: +- pass +- +- class B(A, Mixin): +- pass +- +- eq_(set(util.class_hierarchy(B)), set((A, B, object))) +- eq_(set(util.class_hierarchy(Mixin)), set()) +- eq_(set(util.class_hierarchy(A)), set((A, B, object))) +- # end Py2K ++# start Py2K ++# def test_oldstyle_mixin(self): ++# class A(object): ++# pass ++# ++# class Mixin: ++# pass ++# ++# class B(A, Mixin): ++# pass ++# ++# eq_(set(util.class_hierarchy(B)), set((A, B, object))) ++# eq_(set(util.class_hierarchy(Mixin)), set()) ++# eq_(set(util.class_hierarchy(A)), set((A, B, object))) ++# end Py2K + + + class TestClassProperty(fixtures.TestBase): +diff -r 9d0639b9d3be test/dialect/test_firebird.py +--- a/test/dialect/test_firebird.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/dialect/test_firebird.py Sat Apr 27 19:42:17 2013 -0400 +@@ -28,7 +28,7 @@ + ) + con.execute('CREATE DOMAIN img_domain AS BLOB SUB_TYPE ' + 'BINARY') +- except ProgrammingError, e: ++ except ProgrammingError as e: + if not 'attempt to store duplicate value' in str(e): + raise e + con.execute('''CREATE GENERATOR gen_testtable_id''') +diff -r 9d0639b9d3be test/dialect/test_mssql.py +--- a/test/dialect/test_mssql.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/dialect/test_mssql.py Sat Apr 27 19:42:17 2013 -0400 +@@ -403,7 +403,7 @@ + self.assert_compile( + s, + "SELECT TOP 10 t.x, t.y FROM t WHERE t.x = :x_1 ORDER BY t.y", +- checkparams={u'x_1': 5} ++ checkparams={'x_1': 5} + ) + + def test_limit_zero_using_top(self): +@@ -414,7 +414,7 @@ + self.assert_compile( + s, + "SELECT TOP 0 t.x, t.y FROM t WHERE t.x = :x_1 ORDER BY t.y", +- checkparams={u'x_1': 5} ++ checkparams={'x_1': 5} + ) + + def test_offset_using_window(self): +@@ -424,14 +424,14 @@ + + # test that the select is not altered with subsequent compile + # calls +- for i in xrange(2): ++ for i in range(2): + self.assert_compile( + s, + "SELECT anon_1.x, anon_1.y FROM (SELECT t.x AS x, t.y " + "AS y, ROW_NUMBER() OVER (ORDER BY t.y) AS " + "mssql_rn FROM t WHERE t.x = :x_1) AS " + "anon_1 WHERE mssql_rn > :mssql_rn_1", +- checkparams={u'mssql_rn_1': 20, u'x_1': 5} ++ checkparams={'mssql_rn_1': 20, 'x_1': 5} + ) + + def test_limit_offset_using_window(self): +@@ -447,7 +447,7 @@ + "FROM t " + "WHERE t.x = :x_1) AS anon_1 " + "WHERE mssql_rn > :mssql_rn_1 AND mssql_rn <= :mssql_rn_2", +- checkparams={u'mssql_rn_1': 20, u'mssql_rn_2': 30, u'x_1': 5} ++ checkparams={'mssql_rn_1': 20, 'mssql_rn_2': 30, 'x_1': 5} + ) + + def test_limit_offset_with_correlated_order_by(self): +@@ -468,7 +468,7 @@ + "FROM t1 " + "WHERE t1.x = :x_1) AS anon_1 " + "WHERE mssql_rn > :mssql_rn_1 AND mssql_rn <= :mssql_rn_2", +- checkparams={u'mssql_rn_1': 20, u'mssql_rn_2': 30, u'x_1': 5} ++ checkparams={'mssql_rn_1': 20, 'mssql_rn_2': 30, 'x_1': 5} + ) + + def test_limit_zero_offset_using_window(self): +@@ -482,7 +482,7 @@ + s, + "SELECT TOP 0 t.x, t.y FROM t " + "WHERE t.x = :x_1 ORDER BY t.y", +- checkparams={u'x_1': 5} ++ checkparams={'x_1': 5} + ) + + def test_sequence_start_0(self): +@@ -851,11 +851,11 @@ + # encode in UTF-8 (sting object) because this is the default + # dialect encoding + +- con.execute(u"insert into unitest_table values ('bien u\ ++ con.execute("insert into unitest_table values ('bien u\ + umang\xc3\xa9')".encode('UTF-8')) + try: + r = t1.select().execute().first() +- assert isinstance(r[1], unicode), \ ++ assert isinstance(r[1], str), \ + '%s is %s instead of unicode, working on %s' % (r[1], + type(r[1]), meta.bind) + finally: +@@ -1707,7 +1707,7 @@ + )] + for value in test_items: + float_table.insert().execute(floatcol=value) +- except Exception, e: ++ except Exception as e: + raise e + + +@@ -1953,8 +1953,8 @@ + + def test_unicode(self): + module = __import__('pymssql') +- result = module.Binary(u'foo') +- eq_(result, u'foo') ++ result = module.Binary('foo') ++ eq_(result, 'foo') + + def test_bytes(self): + module = __import__('pymssql') +@@ -2073,7 +2073,7 @@ + + dialect = mssql.dialect() + value = CoerceUnicode().bind_processor(dialect)('a string') +- assert isinstance(value, unicode) ++ assert isinstance(value, str) + + class ReflectHugeViewTest(fixtures.TestBase): + __only_on__ = 'mssql' +@@ -2085,13 +2085,13 @@ + t = Table('base_table', self.metadata, + *[ + Column("long_named_column_number_%d" % i, Integer) +- for i in xrange(self.col_num) ++ for i in range(self.col_num) + ] + ) + self.view_str = view_str = \ + "CREATE VIEW huge_named_view AS SELECT %s FROM base_table" % ( + ",".join("long_named_column_number_%d" % i +- for i in xrange(self.col_num)) ++ for i in range(self.col_num)) + ) + assert len(view_str) > 4000 + +diff -r 9d0639b9d3be test/dialect/test_mysql.py +--- a/test/dialect/test_mysql.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/dialect/test_mysql.py Sat Apr 27 19:42:17 2013 -0400 +@@ -372,9 +372,9 @@ + try: + self.assert_(list(row) == expected) + except: +- print "Storing %s" % store +- print "Expected %s" % expected +- print "Found %s" % list(row) ++ print("Storing %s" % store) ++ print("Expected %s" % expected) ++ print("Found %s" % list(row)) + raise + table.delete().execute().close() + +@@ -684,17 +684,17 @@ + metadata = MetaData(unicode_engine) + t1 = Table('table', metadata, + Column('id', Integer, primary_key=True), +- Column('value', Enum(u'réveillé', u'drôle', u'S’il')), +- Column('value2', mysql.ENUM(u'réveillé', u'drôle', u'S’il')) ++ Column('value', Enum('réveillé', 'drôle', 'S’il')), ++ Column('value2', mysql.ENUM('réveillé', 'drôle', 'S’il')) + ) + metadata.create_all() + try: +- t1.insert().execute(value=u'drôle', value2=u'drôle') +- t1.insert().execute(value=u'réveillé', value2=u'réveillé') +- t1.insert().execute(value=u'S’il', value2=u'S’il') ++ t1.insert().execute(value='drôle', value2='drôle') ++ t1.insert().execute(value='réveillé', value2='réveillé') ++ t1.insert().execute(value='S’il', value2='S’il') + eq_(t1.select().order_by(t1.c.id).execute().fetchall(), +- [(1, u'drôle', u'drôle'), (2, u'réveillé', u'réveillé'), +- (3, u'S’il', u'S’il')] ++ [(1, 'drôle', 'drôle'), (2, 'réveillé', 'réveillé'), ++ (3, 'S’il', 'S’il')] + ) + + # test reflection of the enum labels +@@ -706,10 +706,10 @@ + # latin-1 stuff forcing its way in ? + + assert t2.c.value.type.enums[0:2] == \ +- (u'réveillé', u'drôle') # u'S’il') # eh ? ++ ('réveillé', 'drôle') # u'S’il') # eh ? + + assert t2.c.value2.type.enums[0:2] == \ +- (u'réveillé', u'drôle') # u'S’il') # eh ? ++ ('réveillé', 'drôle') # u'S’il') # eh ? + finally: + metadata.drop_all() + +@@ -877,13 +877,13 @@ + reflected = Table('mysql_case', MetaData(testing.db), + autoload=True, include_columns=['c1', 'C2']) + for t in case_table, reflected: +- assert 'c1' in t.c.keys() +- assert 'C2' in t.c.keys() ++ assert 'c1' in list(t.c.keys()) ++ assert 'C2' in list(t.c.keys()) + reflected2 = Table('mysql_case', MetaData(testing.db), + autoload=True, include_columns=['c1', 'c2']) +- assert 'c1' in reflected2.c.keys() ++ assert 'c1' in list(reflected2.c.keys()) + for c in ['c2', 'C2', 'C3']: +- assert c not in reflected2.c.keys() ++ assert c not in list(reflected2.c.keys()) + finally: + case_table.drop() + +@@ -1370,7 +1370,7 @@ + def _options(self, modes): + def connect(con, record): + cursor = con.cursor() +- print "DOING THiS:", "set sql_mode='%s'" % (",".join(modes)) ++ print("DOING THiS:", "set sql_mode='%s'" % (",".join(modes))) + cursor.execute("set sql_mode='%s'" % (",".join(modes))) + e = engines.testing_engine(options={ + 'pool_events':[ +diff -r 9d0639b9d3be test/dialect/test_oracle.py +--- a/test/dialect/test_oracle.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/dialect/test_oracle.py Sat Apr 27 19:42:17 2013 -0400 +@@ -1,5 +1,5 @@ + # coding: utf-8 +-from __future__ import with_statement ++ + + from sqlalchemy.testing import eq_ + from sqlalchemy import * +@@ -807,7 +807,7 @@ + ) + def test_twophase_prepare_false(self): + conn = self._connection() +- for i in xrange(2): ++ for i in range(2): + trans = conn.begin_twophase() + conn.execute("select 1 from dual") + trans.prepare() +@@ -817,7 +817,7 @@ + + def test_twophase_prepare_true(self): + conn = self._connection() +- for i in xrange(2): ++ for i in range(2): + trans = conn.begin_twophase() + conn.execute("insert into datatable (id, data) " + "values (%s, 'somedata')" % i) +@@ -870,7 +870,7 @@ + b = bindparam("foo", "hello world!") + assert b.type.dialect_impl(dialect).get_dbapi_type(dbapi) == 'STRING' + +- b = bindparam("foo", u"hello world!") ++ b = bindparam("foo", "hello world!") + assert b.type.dialect_impl(dialect).get_dbapi_type(dbapi) == 'STRING' + + def test_long(self): +@@ -1257,7 +1257,7 @@ + autoload=True, oracle_resolve_synonyms=True + ) + for row in types_table.select().execute().fetchall(): +- [row[k] for k in row.keys()] ++ [row[k] for k in list(row.keys())] + + @testing.provide_metadata + def test_raw_roundtrip(self): +@@ -1291,11 +1291,11 @@ + t2.c.data.type.dialect_impl(testing.db.dialect), + cx_oracle._OracleNVarChar) + +- data = u'm’a réveillé.' ++ data = 'm’a réveillé.' + t2.insert().execute(data=data) + res = t2.select().execute().first()['data'] + eq_(res, data) +- assert isinstance(res, unicode) ++ assert isinstance(res, str) + + + def test_char_length(self): +@@ -1426,7 +1426,7 @@ + m = MetaData(testing.db) + m.reflect() + eq_( +- set(t.name for t in m.tables.values()), ++ set(t.name for t in list(m.tables.values())), + set(['admin_docindex']) + ) + +@@ -1641,28 +1641,28 @@ + metadata.create_all() + + table.insert().execute( +- {'_underscorecolumn': u'’é'}, ++ {'_underscorecolumn': '’é'}, + ) + result = testing.db.execute( +- table.select().where(table.c._underscorecolumn==u'’é') ++ table.select().where(table.c._underscorecolumn=='’é') + ).scalar() +- eq_(result, u'’é') ++ eq_(result, '’é') + + @testing.provide_metadata + def test_quoted_column_unicode(self): + metadata = self.metadata + table=Table("atable", metadata, +- Column(u"méil", Unicode(255), primary_key=True), ++ Column("méil", Unicode(255), primary_key=True), + ) + metadata.create_all() + + table.insert().execute( +- {u'méil': u'’é'}, ++ {'méil': '’é'}, + ) + result = testing.db.execute( +- table.select().where(table.c[u'méil']==u'’é') ++ table.select().where(table.c['méil']=='’é') + ).scalar() +- eq_(result, u'’é') ++ eq_(result, '’é') + + + class DBLinkReflectionTest(fixtures.TestBase): +@@ -1702,5 +1702,5 @@ + + t = Table('test_table_syn', m, autoload=True, + autoload_with=testing.db, oracle_resolve_synonyms=True) +- eq_(t.c.keys(), ['id', 'data']) ++ eq_(list(t.c.keys()), ['id', 'data']) + eq_(list(t.primary_key), [t.c.id]) +diff -r 9d0639b9d3be test/dialect/test_postgresql.py +--- a/test/dialect/test_postgresql.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/dialect/test_postgresql.py Sat Apr 27 19:42:17 2013 -0400 +@@ -1,6 +1,6 @@ + # coding: utf-8 + +-from __future__ import with_statement ++ + + from sqlalchemy.testing.assertions import eq_, assert_raises, \ + assert_raises_message, is_, AssertsExecutionResults, \ +@@ -559,21 +559,21 @@ + t1 = Table('table', metadata, + Column('id', Integer, primary_key=True), + Column('value', +- Enum(u'réveillé', u'drôle', u'S’il', ++ Enum('réveillé', 'drôle', 'S’il', + name='onetwothreetype')) + ) + + metadata.create_all() + try: +- t1.insert().execute(value=u'drôle') +- t1.insert().execute(value=u'réveillé') +- t1.insert().execute(value=u'S’il') ++ t1.insert().execute(value='drôle') ++ t1.insert().execute(value='réveillé') ++ t1.insert().execute(value='S’il') + eq_(t1.select().order_by(t1.c.id).execute().fetchall(), +- [(1, u'drôle'), (2, u'réveillé'), (3, u'S’il')] ++ [(1, 'drôle'), (2, 'réveillé'), (3, 'S’il')] + ) + m2 = MetaData(testing.db) + t2 = Table('table', m2, autoload=True) +- assert t2.c.value.type.enums == (u'réveillé', u'drôle', u'S’il') ++ assert t2.c.value.type.enums == ('réveillé', 'drôle', 'S’il') + finally: + metadata.drop_all() + +@@ -1238,7 +1238,7 @@ + : + try: + con.execute(ddl) +- except exc.DBAPIError, e: ++ except exc.DBAPIError as e: + if not 'already exists' in str(e): + raise e + con.execute('CREATE TABLE testtable (question integer, answer ' +@@ -1476,7 +1476,7 @@ + meta1.create_all() + meta2 = MetaData(testing.db) + subject = Table('subject', meta2, autoload=True) +- eq_(subject.primary_key.columns.keys(), [u'p2', u'p1']) ++ eq_(list(subject.primary_key.columns.keys()), ['p2', 'p1']) + + @testing.provide_metadata + def test_pg_weirdchar_reflection(self): +@@ -1749,7 +1749,7 @@ + conn.execute("ALTER TABLE t RENAME COLUMN x to y") + + ind = testing.db.dialect.get_indexes(conn, "t", None) +- eq_(ind, [{'unique': False, 'column_names': [u'y'], 'name': u'idx1'}]) ++ eq_(ind, [{'unique': False, 'column_names': ['y'], 'name': 'idx1'}]) + conn.close() + + class CustomTypeReflectionTest(fixtures.TestBase): +@@ -2174,8 +2174,8 @@ + + def test_insert_array(self): + arrtable = self.tables.arrtable +- arrtable.insert().execute(intarr=[1, 2, 3], strarr=[u'abc', +- u'def']) ++ arrtable.insert().execute(intarr=[1, 2, 3], strarr=['abc', ++ 'def']) + results = arrtable.select().execute().fetchall() + eq_(len(results), 1) + eq_(results[0]['intarr'], [1, 2, 3]) +@@ -2183,9 +2183,9 @@ + + def test_array_where(self): + arrtable = self.tables.arrtable +- arrtable.insert().execute(intarr=[1, 2, 3], strarr=[u'abc', +- u'def']) +- arrtable.insert().execute(intarr=[4, 5, 6], strarr=u'ABC') ++ arrtable.insert().execute(intarr=[1, 2, 3], strarr=['abc', ++ 'def']) ++ arrtable.insert().execute(intarr=[4, 5, 6], strarr='ABC') + results = arrtable.select().where(arrtable.c.intarr == [1, 2, + 3]).execute().fetchall() + eq_(len(results), 1) +@@ -2194,7 +2194,7 @@ + def test_array_concat(self): + arrtable = self.tables.arrtable + arrtable.insert().execute(intarr=[1, 2, 3], +- strarr=[u'abc', u'def']) ++ strarr=['abc', 'def']) + results = select([arrtable.c.intarr + [4, 5, + 6]]).execute().fetchall() + eq_(len(results), 1) +@@ -2203,15 +2203,15 @@ + def test_array_subtype_resultprocessor(self): + arrtable = self.tables.arrtable + arrtable.insert().execute(intarr=[4, 5, 6], +- strarr=[[u'm\xe4\xe4'], [u'm\xf6\xf6' ++ strarr=[['m\xe4\xe4'], ['m\xf6\xf6' + ]]) +- arrtable.insert().execute(intarr=[1, 2, 3], strarr=[u'm\xe4\xe4' +- , u'm\xf6\xf6']) ++ arrtable.insert().execute(intarr=[1, 2, 3], strarr=['m\xe4\xe4' ++ , 'm\xf6\xf6']) + results = \ + arrtable.select(order_by=[arrtable.c.intarr]).execute().fetchall() + eq_(len(results), 2) +- eq_(results[0]['strarr'], [u'm\xe4\xe4', u'm\xf6\xf6']) +- eq_(results[1]['strarr'], [[u'm\xe4\xe4'], [u'm\xf6\xf6']]) ++ eq_(results[0]['strarr'], ['m\xe4\xe4', 'm\xf6\xf6']) ++ eq_(results[1]['strarr'], [['m\xe4\xe4'], ['m\xf6\xf6']]) + + def test_array_literal(self): + eq_( +@@ -2263,7 +2263,7 @@ + testing.db.execute( + arrtable.insert(), + intarr=[4, 5, 6], +- strarr=[u'abc', u'def'] ++ strarr=['abc', 'def'] + ) + eq_( + testing.db.scalar(select([arrtable.c.intarr[2:3]])), +diff -r 9d0639b9d3be test/dialect/test_sqlite.py +--- a/test/dialect/test_sqlite.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/dialect/test_sqlite.py Sat Apr 27 19:42:17 2013 -0400 +@@ -84,7 +84,7 @@ + eq_(row, (1, datetime.date(2010, 5, 10), + datetime.datetime( 2010, 5, 10, 12, 15, 25, ))) + r = engine.execute(func.current_date()).scalar() +- assert isinstance(r, basestring) ++ assert isinstance(r, str) + finally: + t.drop(engine) + engine.dispose() +@@ -104,8 +104,8 @@ + UnicodeText(), + ): + bindproc = t.dialect_impl(dialect).bind_processor(dialect) +- assert not bindproc or isinstance(bindproc(u'some string'), +- unicode) ++ assert not bindproc or isinstance(bindproc('some string'), ++ str) + + @testing.provide_metadata + def test_type_reflection(self): +@@ -566,7 +566,7 @@ + eq_(inspector.get_indexes('foo'), []) + eq_(inspector.get_indexes('foo', + include_auto_indexes=True), [{'unique': 1, 'name' +- : u'sqlite_autoindex_foo_1', 'column_names': [u'bar']}]) ++ : 'sqlite_autoindex_foo_1', 'column_names': ['bar']}]) + finally: + meta.drop_all() + +@@ -602,7 +602,7 @@ + 'dow': '%w', + 'week': '%W', + } +- for field, subst in mapping.items(): ++ for field, subst in list(mapping.items()): + self.assert_compile(select([extract(field, t.c.col1)]), + "SELECT CAST(STRFTIME('%s', t.col1) AS " + "INTEGER) AS anon_1 FROM t" % subst) +diff -r 9d0639b9d3be test/dialect/test_sybase.py +--- a/test/dialect/test_sybase.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/dialect/test_sybase.py Sat Apr 27 19:42:17 2013 -0400 +@@ -19,7 +19,7 @@ + 'year': 'year', + } + +- for field, subst in mapping.items(): ++ for field, subst in list(mapping.items()): + self.assert_compile( + select([extract(field, t.c.col1)]), + 'SELECT DATEPART("%s", t.col1) AS anon_1 FROM t' % subst) +diff -r 9d0639b9d3be test/engine/test_bind.py +--- a/test/engine/test_bind.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/engine/test_bind.py Sat Apr 27 19:42:17 2013 -0400 +@@ -1,6 +1,6 @@ + """tests the "bind" attribute/argument across schema and SQL, + including the deprecated versions of these arguments""" +-from __future__ import with_statement ++ + from sqlalchemy.testing import eq_, assert_raises + from sqlalchemy import engine, exc + from sqlalchemy import MetaData, ThreadLocalMetaData +@@ -61,7 +61,7 @@ + try: + meth() + assert False +- except exc.UnboundExecutionError, e: ++ except exc.UnboundExecutionError as e: + eq_(str(e), + "The MetaData is not bound to an Engine or " + "Connection. Execution can not proceed without a " +@@ -82,7 +82,7 @@ + try: + meth() + assert False +- except exc.UnboundExecutionError, e: ++ except exc.UnboundExecutionError as e: + eq_( + str(e), + "The Table 'test_table' " +diff -r 9d0639b9d3be test/engine/test_ddlemit.py +--- a/test/engine/test_ddlemit.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/engine/test_ddlemit.py Sat Apr 27 19:42:17 2013 -0400 +@@ -47,7 +47,7 @@ + + return (m, ) + tuple( + Table('t%d' % i, m, Column('x', Integer)) +- for i in xrange(1, 6) ++ for i in range(1, 6) + ) + + def _table_seq_fixture(self): +diff -r 9d0639b9d3be test/engine/test_ddlevents.py +--- a/test/engine/test_ddlevents.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/engine/test_ddlevents.py Sat Apr 27 19:42:17 2013 -0400 +@@ -1,4 +1,4 @@ +-from __future__ import with_statement ++ + from sqlalchemy.testing import assert_raises, assert_raises_message + from sqlalchemy.schema import DDL, CheckConstraint, AddConstraint, \ + DropConstraint +diff -r 9d0639b9d3be test/engine/test_execute.py +--- a/test/engine/test_execute.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/engine/test_execute.py Sat Apr 27 19:42:17 2013 -0400 +@@ -1,4 +1,4 @@ +-from __future__ import with_statement ++ + + from sqlalchemy.testing import eq_, assert_raises, assert_raises_message, \ + config, is_ +@@ -18,7 +18,7 @@ + from sqlalchemy.engine import result as _result, default + from sqlalchemy.engine.base import Connection, Engine + from sqlalchemy.testing import fixtures +-import StringIO ++import io + + users, metadata, users_autoinc = None, None, None + class ExecuteTest(fixtures.TestBase): +@@ -256,7 +256,7 @@ + try: + cursor = raw.cursor() + cursor.execute("SELECTINCORRECT") +- except testing.db.dialect.dbapi.DatabaseError, orig: ++ except testing.db.dialect.dbapi.DatabaseError as orig: + # py3k has "orig" in local scope... + the_orig = orig + finally: +@@ -622,7 +622,7 @@ + def test_log_large_dict(self): + self.eng.execute( + "INSERT INTO foo (data) values (:data)", +- [{"data":str(i)} for i in xrange(100)] ++ [{"data":str(i)} for i in range(100)] + ) + eq_( + self.buf.buffer[1].message, +@@ -635,7 +635,7 @@ + def test_log_large_list(self): + self.eng.execute( + "INSERT INTO foo (data) values (?)", +- [(str(i), ) for i in xrange(100)] ++ [(str(i), ) for i in range(100)] + ) + eq_( + self.buf.buffer[1].message, +@@ -654,7 +654,7 @@ + "100 total bound parameter sets ... {'data': '98'}, {'data': '99'}\]", + lambda: self.eng.execute( + "INSERT INTO nonexistent (data) values (:data)", +- [{"data":str(i)} for i in xrange(100)] ++ [{"data":str(i)} for i in range(100)] + ) + ) + +@@ -668,7 +668,7 @@ + "\('98',\), \('99',\)\]", + lambda: self.eng.execute( + "INSERT INTO nonexistent (data) values (?)", +- [(str(i), ) for i in xrange(100)] ++ [(str(i), ) for i in range(100)] + ) + ) + +@@ -834,9 +834,9 @@ + + class MockStrategyTest(fixtures.TestBase): + def _engine_fixture(self): +- buf = StringIO.StringIO() ++ buf = io.StringIO() + def dump(sql, *multiparams, **params): +- buf.write(unicode(sql.compile(dialect=engine.dialect))) ++ buf.write(str(sql.compile(dialect=engine.dialect))) + engine = create_engine('postgresql://', strategy='mock', executor=dump) + return engine, buf + +@@ -939,7 +939,7 @@ + def test_row_c_sequence_check(self): + import csv + import collections +- from StringIO import StringIO ++ from io import StringIO + + metadata = MetaData() + metadata.bind = 'sqlite://' +@@ -1026,7 +1026,7 @@ + ) + m.create_all(engine) + engine.execute(t.insert(), [ +- {'x':i, 'y':"t_%d" % i} for i in xrange(1, 12) ++ {'x':i, 'y':"t_%d" % i} for i in range(1, 12) + ]) + + def _test_proxy(self, cls): +@@ -1039,13 +1039,13 @@ + assert isinstance(r, cls) + for i in range(5): + rows.append(r.fetchone()) +- eq_(rows, [(i, "t_%d" % i) for i in xrange(1, 6)]) ++ eq_(rows, [(i, "t_%d" % i) for i in range(1, 6)]) + + rows = r.fetchmany(3) +- eq_(rows, [(i, "t_%d" % i) for i in xrange(6, 9)]) ++ eq_(rows, [(i, "t_%d" % i) for i in range(6, 9)]) + + rows = r.fetchall() +- eq_(rows, [(i, "t_%d" % i) for i in xrange(9, 12)]) ++ eq_(rows, [(i, "t_%d" % i) for i in range(9, 12)]) + + r = self.engine.execute(select([self.table])) + rows = r.fetchmany(None) +@@ -1059,7 +1059,7 @@ + + r = self.engine.execute(select([self.table]).limit(5)) + rows = r.fetchmany(6) +- eq_(rows, [(i, "t_%d" % i) for i in xrange(1, 6)]) ++ eq_(rows, [(i, "t_%d" % i) for i in range(1, 6)]) + + def test_plain(self): + self._test_proxy(_result.ResultProxy) +@@ -1184,7 +1184,7 @@ + try: + conn.execute("SELECT FOO FROM I_DONT_EXIST") + assert False +- except tsa.exc.DBAPIError, e: ++ except tsa.exc.DBAPIError as e: + assert canary[0][2] is e.orig + assert canary[0][0] == "SELECT FOO FROM I_DONT_EXIST" + +diff -r 9d0639b9d3be test/engine/test_parseconnect.py +--- a/test/engine/test_parseconnect.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/engine/test_parseconnect.py Sat Apr 27 19:42:17 2013 -0400 +@@ -1,6 +1,6 @@ + from sqlalchemy.testing import assert_raises, assert_raises_message, eq_ +-import ConfigParser +-import StringIO ++import configparser ++import io + import sqlalchemy.engine.url as url + from sqlalchemy import create_engine, engine_from_config, exc, pool + from sqlalchemy.engine.util import _coerce_config +@@ -103,8 +103,8 @@ + pool_threadlocal=1 + pool_timeout=10 + """ +- ini = ConfigParser.ConfigParser() +- ini.readfp(StringIO.StringIO(raw)) ++ ini = configparser.ConfigParser() ++ ini.readfp(io.StringIO(raw)) + + expected = { + 'url': 'postgresql://scott:tiger@somehost/test?fooz=somevalue', +@@ -234,7 +234,7 @@ + : True}, convert_unicode=True) + try: + e.connect() +- except tsa.exc.DBAPIError, de: ++ except tsa.exc.DBAPIError as de: + assert not de.connection_invalidated + + def test_ensure_dialect_does_is_disconnect_no_conn(self): +@@ -266,7 +266,7 @@ + try: + create_engine('sqlite://', module=ThrowOnConnect()).connect() + assert False +- except tsa.exc.DBAPIError, de: ++ except tsa.exc.DBAPIError as de: + assert de.connection_invalidated + + def test_urlattr(self): +diff -r 9d0639b9d3be test/engine/test_pool.py +--- a/test/engine/test_pool.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/engine/test_pool.py Sat Apr 27 19:42:17 2013 -0400 +@@ -525,23 +525,23 @@ + self.assert_((item in innerself.checked_out) == in_cout) + self.assert_((item in innerself.checked_in) == in_cin) + def inst_connect(self, con, record): +- print "connect(%s, %s)" % (con, record) ++ print("connect(%s, %s)" % (con, record)) + assert con is not None + assert record is not None + self.connected.append(con) + def inst_first_connect(self, con, record): +- print "first_connect(%s, %s)" % (con, record) ++ print("first_connect(%s, %s)" % (con, record)) + assert con is not None + assert record is not None + self.first_connected.append(con) + def inst_checkout(self, con, record, proxy): +- print "checkout(%s, %s, %s)" % (con, record, proxy) ++ print("checkout(%s, %s, %s)" % (con, record, proxy)) + assert con is not None + assert record is not None + assert proxy is not None + self.checked_out.append(con) + def inst_checkin(self, con, record): +- print "checkin(%s, %s)" % (con, record) ++ print("checkin(%s, %s)" % (con, record)) + # con can be None if invalidated + assert record is not None + self.checked_in.append(con) +@@ -738,8 +738,8 @@ + def status(pool): + tup = pool.size(), pool.checkedin(), pool.overflow(), \ + pool.checkedout() +- print 'Pool size: %d Connections in pool: %d Current '\ +- 'Overflow: %d Current Checked out connections: %d' % tup ++ print('Pool size: %d Connections in pool: %d Current '\ ++ 'Overflow: %d Current Checked out connections: %d' % tup) + return tup + + c1 = p.connect() +@@ -794,7 +794,7 @@ + try: + c4 = p.connect() + assert False +- except tsa.exc.TimeoutError, e: ++ except tsa.exc.TimeoutError as e: + assert int(time.time() - now) == 2 + + def test_timeout_race(self): +@@ -812,18 +812,18 @@ + max_overflow = 1, use_threadlocal = False, timeout=3) + timeouts = [] + def checkout(): +- for x in xrange(1): ++ for x in range(1): + now = time.time() + try: + c1 = p.connect() +- except tsa.exc.TimeoutError, e: ++ except tsa.exc.TimeoutError as e: + timeouts.append(time.time() - now) + continue + time.sleep(4) + c1.close() + + threads = [] +- for i in xrange(10): ++ for i in range(10): + th = threading.Thread(target=checkout) + th.start() + threads.append(th) +@@ -860,7 +860,7 @@ + except tsa.exc.TimeoutError: + pass + threads = [] +- for i in xrange(thread_count): ++ for i in range(thread_count): + th = threading.Thread(target=whammy) + th.start() + threads.append(th) +@@ -1007,8 +1007,8 @@ + strong_refs.add(c.connection) + return c + +- for j in xrange(5): +- conns = [_conn() for i in xrange(4)] ++ for j in range(5): ++ conns = [_conn() for i in range(4)] + for c in conns: + c.close() + +@@ -1152,7 +1152,7 @@ + return p.connect() + + def checkout(): +- for x in xrange(10): ++ for x in range(10): + c = _conn() + assert c + c.cursor() +@@ -1160,7 +1160,7 @@ + time.sleep(.1) + + threads = [] +- for i in xrange(10): ++ for i in range(10): + th = threading.Thread(target=checkout) + th.start() + threads.append(th) +diff -r 9d0639b9d3be test/engine/test_processors.py +--- a/test/engine/test_processors.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/engine/test_processors.py Sat Apr 27 19:42:17 2013 -0400 +@@ -53,7 +53,7 @@ + cls.module = type("util", (object,), + dict( + (k, staticmethod(v)) +- for k, v in processors.py_fallback().items() ++ for k, v in list(processors.py_fallback().items()) + ) + ) + +@@ -156,7 +156,7 @@ + cls.module = type("util", (object,), + dict( + (k, staticmethod(v)) +- for k, v in util.py_fallback().items() ++ for k, v in list(util.py_fallback().items()) + ) + ) + +diff -r 9d0639b9d3be test/engine/test_reconnect.py +--- a/test/engine/test_reconnect.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/engine/test_reconnect.py Sat Apr 27 19:42:17 2013 -0400 +@@ -173,7 +173,7 @@ + try: + trans.commit() + assert False +- except tsa.exc.InvalidRequestError, e: ++ except tsa.exc.InvalidRequestError as e: + assert str(e) \ + == "Can't reconnect until invalid transaction is "\ + "rolled back" +@@ -370,7 +370,7 @@ + try: + conn.execute(select([1])) + assert False +- except tsa.exc.DBAPIError, e: ++ except tsa.exc.DBAPIError as e: + if not e.connection_invalidated: + raise + +@@ -386,7 +386,7 @@ + try: + conn.execute(select([1])) + assert False +- except tsa.exc.DBAPIError, e: ++ except tsa.exc.DBAPIError as e: + if not e.connection_invalidated: + raise + assert conn.invalidated +@@ -407,7 +407,7 @@ + try: + c1.execute(select([1])) + assert False +- except tsa.exc.DBAPIError, e: ++ except tsa.exc.DBAPIError as e: + assert e.connection_invalidated + + p2 = engine.pool +@@ -415,7 +415,7 @@ + try: + c2.execute(select([1])) + assert False +- except tsa.exc.DBAPIError, e: ++ except tsa.exc.DBAPIError as e: + assert e.connection_invalidated + + # pool isn't replaced +@@ -503,7 +503,7 @@ + try: + conn.execute(select([1])) + assert False +- except tsa.exc.DBAPIError, e: ++ except tsa.exc.DBAPIError as e: + if not e.connection_invalidated: + raise + assert not conn.closed +@@ -523,7 +523,7 @@ + try: + conn.execute(select([1])) + assert False +- except tsa.exc.DBAPIError, e: ++ except tsa.exc.DBAPIError as e: + if not e.connection_invalidated: + raise + +@@ -542,7 +542,7 @@ + try: + conn.execute(select([1])) + assert False +- except tsa.exc.DBAPIError, e: ++ except tsa.exc.DBAPIError as e: + if not e.connection_invalidated: + raise + assert not conn.closed +@@ -558,7 +558,7 @@ + try: + trans.commit() + assert False +- except tsa.exc.InvalidRequestError, e: ++ except tsa.exc.InvalidRequestError as e: + assert str(e) \ + == "Can't reconnect until invalid transaction is "\ + "rolled back" +@@ -634,13 +634,13 @@ + def test_invalidate_on_results(self): + conn = engine.connect() + result = conn.execute('select * from sometable') +- for x in xrange(20): ++ for x in range(20): + result.fetchone() + engine.test_shutdown() + try: +- print 'ghost result: %r' % result.fetchone() ++ print('ghost result: %r' % result.fetchone()) + assert False +- except tsa.exc.DBAPIError, e: ++ except tsa.exc.DBAPIError as e: + if not e.connection_invalidated: + raise + assert conn.invalidated +diff -r 9d0639b9d3be test/engine/test_reflection.py +--- a/test/engine/test_reflection.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/engine/test_reflection.py Sat Apr 27 19:42:17 2013 -0400 +@@ -811,7 +811,7 @@ + try: + m4.reflect(only=['rt_a', 'rt_f']) + self.assert_(False) +- except sa.exc.InvalidRequestError, e: ++ except sa.exc.InvalidRequestError as e: + self.assert_(e.args[0].endswith('(rt_f)')) + + m5 = MetaData(testing.db) +@@ -833,7 +833,7 @@ + ) + + if existing: +- print "Other tables present in database, skipping some checks." ++ print("Other tables present in database, skipping some checks.") + else: + baseline.drop_all() + m9 = MetaData(testing.db) +@@ -1041,19 +1041,19 @@ + cls.metadata = metadata = MetaData() + + no_multibyte_period = set([ +- (u'plain', u'col_plain', u'ix_plain') ++ ('plain', 'col_plain', 'ix_plain') + ]) + no_has_table = [ +- (u'no_has_table_1', u'col_Unit\u00e9ble', u'ix_Unit\u00e9ble'), +- (u'no_has_table_2', u'col_\u6e2c\u8a66', u'ix_\u6e2c\u8a66'), ++ ('no_has_table_1', 'col_Unit\u00e9ble', 'ix_Unit\u00e9ble'), ++ ('no_has_table_2', 'col_\u6e2c\u8a66', 'ix_\u6e2c\u8a66'), + ] + no_case_sensitivity = [ +- (u'\u6e2c\u8a66', u'col_\u6e2c\u8a66', u'ix_\u6e2c\u8a66'), +- (u'unit\u00e9ble', u'col_unit\u00e9ble', u'ix_unit\u00e9ble'), ++ ('\u6e2c\u8a66', 'col_\u6e2c\u8a66', 'ix_\u6e2c\u8a66'), ++ ('unit\u00e9ble', 'col_unit\u00e9ble', 'ix_unit\u00e9ble'), + ] + full = [ +- (u'Unit\u00e9ble', u'col_Unit\u00e9ble', u'ix_Unit\u00e9ble'), +- (u'\u6e2c\u8a66', u'col_\u6e2c\u8a66', u'ix_\u6e2c\u8a66'), ++ ('Unit\u00e9ble', 'col_Unit\u00e9ble', 'ix_Unit\u00e9ble'), ++ ('\u6e2c\u8a66', 'col_\u6e2c\u8a66', 'ix_\u6e2c\u8a66'), + ] + + # as you can see, our options for this kind of thing +diff -r 9d0639b9d3be test/engine/test_transaction.py +--- a/test/engine/test_transaction.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/engine/test_transaction.py Sat Apr 27 19:42:17 2013 -0400 +@@ -74,8 +74,8 @@ + connection.execute(users.insert(), user_id=1, user_name='user3') + transaction.commit() + assert False +- except Exception , e: +- print "Exception: ", e ++ except Exception as e: ++ print("Exception: ", e) + transaction.rollback() + + result = connection.execute("select * from query_users") +@@ -121,10 +121,10 @@ + trans2.rollback() + raise + transaction.rollback() +- except Exception, e: ++ except Exception as e: + transaction.rollback() + raise +- except Exception, e: ++ except Exception as e: + try: + assert str(e) == 'uh oh' # and not "This transaction is + # inactive" +@@ -167,7 +167,7 @@ + connection.execute(users.insert(), user_id=2, user_name='user2') + try: + connection.execute(users.insert(), user_id=2, user_name='user2.5') +- except Exception, e: ++ except Exception as e: + trans.__exit__(*sys.exc_info()) + + assert not trans.is_active +@@ -1019,7 +1019,7 @@ + con = testing.db.connect() + sel = counters.select(for_update=update_style, + whereclause=counters.c.counter_id == 1) +- for i in xrange(count): ++ for i in range(count): + trans = con.begin() + try: + existing = con.execute(sel).first() +@@ -1033,7 +1033,7 @@ + raise AssertionError('Got %s post-update, expected ' + '%s' % (readback['counter_value'], incr)) + trans.commit() +- except Exception, e: ++ except Exception as e: + trans.rollback() + errors.append(e) + break +@@ -1057,7 +1057,7 @@ + db.execute(counters.insert(), counter_id=1, counter_value=0) + iterations, thread_count = 10, 5 + threads, errors = [], [] +- for i in xrange(thread_count): ++ for i in range(thread_count): + thrd = threading.Thread(target=self.increment, + args=(iterations, ), + kwargs={'errors': errors, +@@ -1088,7 +1088,7 @@ + rows = con.execute(sel).fetchall() + time.sleep(0.25) + trans.commit() +- except Exception, e: ++ except Exception as e: + trans.rollback() + errors.append(e) + con.close() +@@ -1105,7 +1105,7 @@ + db.execute(counters.insert(), counter_id=cid + 1, + counter_value=0) + errors, threads = [], [] +- for i in xrange(thread_count): ++ for i in range(thread_count): + thrd = threading.Thread(target=self.overlap, + args=(groups.pop(0), errors, + update_style)) +diff -r 9d0639b9d3be test/ext/declarative/test_basic.py +--- a/test/ext/declarative/test_basic.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/ext/declarative/test_basic.py Sat Apr 27 19:42:17 2013 -0400 +@@ -127,14 +127,13 @@ + class BrokenMeta(type): + def __getattribute__(self, attr): + if attr == 'xyzzy': +- raise AttributeError, 'xyzzy' ++ raise AttributeError('xyzzy') + else: + return object.__getattribute__(self,attr) + + # even though this class has an xyzzy attribute, getattr(cls,"xyzzy") + # fails +- class BrokenParent(object): +- __metaclass__ = BrokenMeta ++ class BrokenParent(object, metaclass=BrokenMeta): + xyzzy = "magic" + + # _as_declarative() inspects obj.__class__.__bases__ +@@ -1458,12 +1457,12 @@ + + @classmethod + def insert_data(cls): +- params = [dict(zip(('id', 'name'), column_values)) ++ params = [dict(list(zip(('id', 'name'), column_values))) + for column_values in [(7, 'jack'), (8, 'ed'), (9, + 'fred'), (10, 'chuck')]] + User.__table__.insert().execute(params) +- Address.__table__.insert().execute([dict(zip(('id', +- 'user_id', 'email'), column_values)) ++ Address.__table__.insert().execute([dict(list(zip(('id', ++ 'user_id', 'email'), column_values))) + for column_values in [(1, 7, 'jack@bean.com'), (2, + 8, 'ed@wood.com'), (3, 8, 'ed@bettyboop.com'), (4, + 8, 'ed@lala.com'), (5, 9, 'fred@fred.com')]]) +@@ -1492,6 +1491,6 @@ + for inline in True, False: + for stringbased in True, False: + testclass = _produce_test(inline, stringbased) +- exec '%s = testclass' % testclass.__name__ ++ exec('%s = testclass' % testclass.__name__) + del testclass + +diff -r 9d0639b9d3be test/ext/declarative/test_clsregistry.py +--- a/test/ext/declarative/test_clsregistry.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/ext/declarative/test_clsregistry.py Sat Apr 27 19:42:17 2013 -0400 +@@ -124,7 +124,7 @@ + + base = weakref.WeakValueDictionary() + +- for i in xrange(3): ++ for i in range(3): + f1 = MockClass(base, "foo.bar.Foo") + f2 = MockClass(base, "foo.alt.Foo") + clsregistry.add_class("Foo", f1) +diff -r 9d0639b9d3be test/ext/declarative/test_inheritance.py +--- a/test/ext/declarative/test_inheritance.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/ext/declarative/test_inheritance.py Sat Apr 27 19:42:17 2013 -0400 +@@ -573,7 +573,7 @@ + primary_language = Column(String(50)) + + assert Person.__table__.c.golf_swing is not None +- assert not Person.__table__.c.has_key('primary_language') ++ assert 'primary_language' not in Person.__table__.c + assert Engineer.__table__.c.primary_language is not None + assert Engineer.primary_language is not None + assert Manager.golf_swing is not None +diff -r 9d0639b9d3be test/ext/declarative/test_mixin.py +--- a/test/ext/declarative/test_mixin.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/ext/declarative/test_mixin.py Sat Apr 27 19:42:17 2013 -0400 +@@ -685,7 +685,7 @@ + __mapper_args__ = dict(polymorphic_identity='specific') + + assert Specific.__table__ is Generic.__table__ +- eq_(Generic.__table__.c.keys(), ['id', 'type', 'value']) ++ eq_(list(Generic.__table__.c.keys()), ['id', 'type', 'value']) + assert class_mapper(Specific).polymorphic_on \ + is Generic.__table__.c.type + eq_(class_mapper(Specific).polymorphic_identity, 'specific') +@@ -714,9 +714,9 @@ + + eq_(Generic.__table__.name, 'generic') + eq_(Specific.__table__.name, 'specific') +- eq_(Generic.__table__.c.keys(), ['timestamp', 'id', ++ eq_(list(Generic.__table__.c.keys()), ['timestamp', 'id', + 'python_type']) +- eq_(Specific.__table__.c.keys(), ['id']) ++ eq_(list(Specific.__table__.c.keys()), ['id']) + eq_(Generic.__table__.kwargs, {'mysql_engine': 'InnoDB'}) + eq_(Specific.__table__.kwargs, {'mysql_engine': 'InnoDB'}) + +@@ -749,12 +749,12 @@ + primary_key=True) + + eq_(BaseType.__table__.name, 'basetype') +- eq_(BaseType.__table__.c.keys(), ['timestamp', 'type', 'id', ++ eq_(list(BaseType.__table__.c.keys()), ['timestamp', 'type', 'id', + 'value']) + eq_(BaseType.__table__.kwargs, {'mysql_engine': 'InnoDB'}) + assert Single.__table__ is BaseType.__table__ + eq_(Joined.__table__.name, 'joined') +- eq_(Joined.__table__.c.keys(), ['id']) ++ eq_(list(Joined.__table__.c.keys()), ['id']) + eq_(Joined.__table__.kwargs, {'mysql_engine': 'InnoDB'}) + + def test_col_copy_vs_declared_attr_joined_propagation(self): +@@ -839,7 +839,7 @@ + __mapper_args__ = dict(polymorphic_identity='specific') + + eq_(BaseType.__table__.name, 'basetype') +- eq_(BaseType.__table__.c.keys(), ['type', 'id', 'value']) ++ eq_(list(BaseType.__table__.c.keys()), ['type', 'id', 'value']) + assert Specific.__table__ is BaseType.__table__ + assert class_mapper(Specific).polymorphic_on \ + is BaseType.__table__.c.type +@@ -870,9 +870,9 @@ + primary_key=True) + + eq_(BaseType.__table__.name, 'basetype') +- eq_(BaseType.__table__.c.keys(), ['type', 'id', 'value']) ++ eq_(list(BaseType.__table__.c.keys()), ['type', 'id', 'value']) + eq_(Specific.__table__.name, 'specific') +- eq_(Specific.__table__.c.keys(), ['id']) ++ eq_(list(Specific.__table__.c.keys()), ['id']) + + def test_single_back_propagate(self): + +@@ -891,7 +891,7 @@ + + __mapper_args__ = dict(polymorphic_identity='specific') + +- eq_(BaseType.__table__.c.keys(), ['type', 'id', 'timestamp']) ++ eq_(list(BaseType.__table__.c.keys()), ['type', 'id', 'timestamp']) + + def test_table_in_model_and_same_column_in_mixin(self): + +@@ -987,7 +987,7 @@ + id = Column(Integer, primary_key=True) + __tablename__ = 'model' + +- eq_(Model.__table__.c.keys(), ['col1', 'col3', 'col2', 'col4', ++ eq_(list(Model.__table__.c.keys()), ['col1', 'col3', 'col2', 'col4', + 'id']) + + def test_honor_class_mro_one(self): +@@ -1078,8 +1078,8 @@ + filter_class = FilterB + id = Column(Integer(), primary_key=True) + +- TypeA(filters=[u'foo']) +- TypeB(filters=[u'foo']) ++ TypeA(filters=['foo']) ++ TypeB(filters=['foo']) + + class DeclarativeMixinPropertyTest(DeclarativeTestBase): + +diff -r 9d0639b9d3be test/ext/test_associationproxy.py +--- a/test/ext/test_associationproxy.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/ext/test_associationproxy.py Sat Apr 27 19:42:17 2013 -0400 +@@ -288,7 +288,7 @@ + ch = Child('a', 'regular') + p1._children.append(ch) + +- self.assert_(ch in p1._children.values()) ++ self.assert_(ch in list(p1._children.values())) + self.assert_(len(p1._children) == 1) + + self.assert_(p1.children) +@@ -300,7 +300,7 @@ + + p1.children['b'] = 'proxied' + +- self.assert_('proxied' in p1.children.values()) ++ self.assert_('proxied' in list(p1.children.values())) + self.assert_('b' in p1.children) + self.assert_('proxied' not in p1._children) + self.assert_(len(p1.children) == 2) +@@ -526,9 +526,9 @@ + try: + self.assert_(p.children == control) + except: +- print 'Test %s.%s(%s):' % (set(base), op, other) +- print 'want', repr(control) +- print 'got', repr(p.children) ++ print('Test %s.%s(%s):' % (set(base), op, other)) ++ print('want', repr(control)) ++ print('got', repr(p.children)) + raise + + p = self.roundtrip(p) +@@ -536,9 +536,9 @@ + try: + self.assert_(p.children == control) + except: +- print 'Test %s.%s(%s):' % (base, op, other) +- print 'want', repr(control) +- print 'got', repr(p.children) ++ print('Test %s.%s(%s):' % (base, op, other)) ++ print('want', repr(control)) ++ print('got', repr(p.children)) + raise + + # in-place mutations +@@ -553,15 +553,15 @@ + p.children = base[:] + control = set(base[:]) + +- exec "p.children %s other" % op +- exec "control %s other" % op ++ exec("p.children %s other" % op) ++ exec("control %s other" % op) + + try: + self.assert_(p.children == control) + except: +- print 'Test %s %s %s:' % (set(base), op, other) +- print 'want', repr(control) +- print 'got', repr(p.children) ++ print('Test %s %s %s:' % (set(base), op, other)) ++ print('want', repr(control)) ++ print('got', repr(p.children)) + raise + + p = self.roundtrip(p) +@@ -569,9 +569,9 @@ + try: + self.assert_(p.children == control) + except: +- print 'Test %s %s %s:' % (base, op, other) +- print 'want', repr(control) +- print 'got', repr(p.children) ++ print('Test %s %s %s:' % (base, op, other)) ++ print('want', repr(control)) ++ print('got', repr(p.children)) + raise + + +diff -r 9d0639b9d3be test/ext/test_serializer.py +--- a/test/ext/test_serializer.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/ext/test_serializer.py Sat Apr 27 19:42:17 2013 -0400 +@@ -47,12 +47,12 @@ + + @classmethod + def insert_data(cls): +- params = [dict(zip(('id', 'name'), column_values)) ++ params = [dict(list(zip(('id', 'name'), column_values))) + for column_values in [(7, 'jack'), (8, 'ed'), (9, + 'fred'), (10, 'chuck')]] + users.insert().execute(params) +- addresses.insert().execute([dict(zip(('id', 'user_id', 'email' +- ), column_values)) ++ addresses.insert().execute([dict(list(zip(('id', 'user_id', 'email' ++ ), column_values))) + for column_values in [(1, 7, + 'jack@bean.com'), (2, 8, + 'ed@wood.com'), (3, 8, +@@ -85,8 +85,8 @@ + users.metadata, None) + eq_(str(expr), str(re_expr)) + assert re_expr.bind is testing.db +- eq_(re_expr.execute().fetchall(), [(7, u'jack'), (8, u'ed'), +- (8, u'ed'), (8, u'ed'), (9, u'fred')]) ++ eq_(re_expr.execute().fetchall(), [(7, 'jack'), (8, 'ed'), ++ (8, 'ed'), (8, 'ed'), (9, 'fred')]) + + def test_query_one(self): + q = Session.query(User).\ +@@ -121,7 +121,7 @@ + q2 = serializer.loads(serializer.dumps(q, -1), users.metadata, + Session) + eq_(q2.all(), [User(name='fred')]) +- eq_(list(q2.values(User.id, User.name)), [(9, u'fred')]) ++ eq_(list(q2.values(User.id, User.name)), [(9, 'fred')]) + + def test_query_three(self): + ua = aliased(User) +@@ -134,7 +134,7 @@ + + # try to pull out the aliased entity here... + ua_2 = q2._entities[0].entity_zero.entity +- eq_(list(q2.values(ua_2.id, ua_2.name)), [(9, u'fred')]) ++ eq_(list(q2.values(ua_2.id, ua_2.name)), [(9, 'fred')]) + + def test_orm_join(self): + from sqlalchemy.orm.util import join +diff -r 9d0639b9d3be test/orm/inheritance/test_assorted_poly.py +--- a/test/orm/inheritance/test_assorted_poly.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/inheritance/test_assorted_poly.py Sat Apr 27 19:42:17 2013 -0400 +@@ -18,7 +18,7 @@ + + class AttrSettable(object): + def __init__(self, **kwargs): +- [setattr(self, k, v) for k, v in kwargs.iteritems()] ++ [setattr(self, k, v) for k, v in kwargs.items()] + def __repr__(self): + return self.__class__.__name__ + "(%s)" % (hex(id(self))) + +@@ -386,7 +386,7 @@ + # class definitions + class Person(object): + def __init__(self, **kwargs): +- for key, value in kwargs.iteritems(): ++ for key, value in kwargs.items(): + setattr(self, key, value) + def __repr__(self): + return "Ordinary person %s" % self.name +@@ -400,7 +400,7 @@ + (self.name, self.longer_status) + class Car(object): + def __init__(self, **kwargs): +- for key, value in kwargs.iteritems(): ++ for key, value in kwargs.items(): + setattr(self, key, value) + def __repr__(self): + return "Car number %d" % self.car_id +@@ -512,7 +512,7 @@ + + class Person(object): + def __init__(self, **kwargs): +- for key, value in kwargs.iteritems(): ++ for key, value in kwargs.items(): + setattr(self, key, value) + def __repr__(self): + return "Ordinary person %s" % self.name +@@ -526,7 +526,7 @@ + (self.name, self.longer_status) + class Car(object): + def __init__(self, **kwargs): +- for key, value in kwargs.iteritems(): ++ for key, value in kwargs.items(): + setattr(self, key, value) + def __repr__(self): + return "Car number %d" % self.car_id +@@ -646,7 +646,7 @@ + + class PersistentObject(object): + def __init__(self, **kwargs): +- for key, value in kwargs.iteritems(): ++ for key, value in kwargs.items(): + setattr(self, key, value) + + class Status(PersistentObject): +@@ -838,7 +838,7 @@ + # class definitions + class PersistentObject(object): + def __init__(self, **kwargs): +- for key, value in kwargs.iteritems(): ++ for key, value in kwargs.items(): + setattr(self, key, value) + class Status(PersistentObject): + def __repr__(self): +@@ -968,7 +968,7 @@ + def test_threelevels(self): + class Employee( object): + def set( me, **kargs): +- for k,v in kargs.iteritems(): setattr( me, k, v) ++ for k,v in kargs.items(): setattr( me, k, v) + return me + def __str__(me): + return str(me.__class__.__name__)+':'+str(me.name) +diff -r 9d0639b9d3be test/orm/inheritance/test_basic.py +--- a/test/orm/inheritance/test_basic.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/inheritance/test_basic.py Sat Apr 27 19:42:17 2013 -0400 +@@ -1355,7 +1355,7 @@ + def _do_test(self, j1, j2): + class A(object): + def __init__(self, **kwargs): +- for key, value in kwargs.items(): ++ for key, value in list(kwargs.items()): + setattr(self, key, value) + + class B(A): +@@ -1830,7 +1830,7 @@ + "SELECT sub.counter AS sub_counter, base.counter AS base_counter, " + "sub.counter2 AS sub_counter2 FROM base JOIN sub ON " + "base.id = sub.id WHERE base.id = :param_1", +- lambda ctx:{u'param_1': s1.id} ++ lambda ctx:{'param_1': s1.id} + ), + ) + +@@ -1910,7 +1910,7 @@ + "SELECT subsub.counter2 AS subsub_counter2, " + "sub.counter2 AS sub_counter2 FROM subsub, sub " + "WHERE :param_1 = sub.id AND sub.id = subsub.id", +- lambda ctx:{u'param_1': s1.id} ++ lambda ctx:{'param_1': s1.id} + ), + ) + +@@ -2409,9 +2409,9 @@ + polymorphic_identity='foo') + sess = create_session() + f = Foo() +- f.content_type = u'bar' ++ f.content_type = 'bar' + sess.add(f) + sess.flush() + f_id = f.id + sess.expunge_all() +- assert sess.query(Content).get(f_id).content_type == u'bar' ++ assert sess.query(Content).get(f_id).content_type == 'bar' +diff -r 9d0639b9d3be test/orm/inheritance/test_concrete.py +--- a/test/orm/inheritance/test_concrete.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/inheritance/test_concrete.py Sat Apr 27 19:42:17 2013 -0400 +@@ -722,10 +722,10 @@ + @classmethod + def insert_data(cls): + refugees_table.insert().execute(dict(refugee_fid=1, +- name=u'refugee1'), dict(refugee_fid=2, name=u'refugee2' ++ name='refugee1'), dict(refugee_fid=2, name='refugee2' + )) + offices_table.insert().execute(dict(office_fid=1, +- name=u'office1'), dict(office_fid=2, name=u'office2')) ++ name='office1'), dict(office_fid=2, name='office2')) + + def test_keys(self): + pjoin = polymorphic_union({'refugee': refugees_table, 'office' +diff -r 9d0639b9d3be test/orm/inheritance/test_magazine.py +--- a/test/orm/inheritance/test_magazine.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/inheritance/test_magazine.py Sat Apr 27 19:42:17 2013 -0400 +@@ -8,7 +8,7 @@ + + class BaseObject(object): + def __init__(self, *args, **kwargs): +- for key, value in kwargs.iteritems(): ++ for key, value in kwargs.items(): + setattr(self, key, value) + class Publication(BaseObject): + pass +@@ -200,15 +200,15 @@ + + + session.flush() +- print [x for x in session] ++ print([x for x in session]) + session.expunge_all() + + session.flush() + session.expunge_all() + p = session.query(Publication).filter(Publication.name=="Test").one() + +- print p.issues[0].locations[0].magazine.pages +- print [page, page2, page3] ++ print(p.issues[0].locations[0].magazine.pages) ++ print([page, page2, page3]) + assert repr(p.issues[0].locations[0].magazine.pages) == repr([page, page2, page3]), repr(p.issues[0].locations[0].magazine.pages) + + test_roundtrip = function_named( +diff -r 9d0639b9d3be test/orm/inheritance/test_manytomany.py +--- a/test/orm/inheritance/test_manytomany.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/inheritance/test_manytomany.py Sat Apr 27 19:42:17 2013 -0400 +@@ -42,7 +42,7 @@ + def testbasic(self): + class Principal(object): + def __init__(self, **kwargs): +- for key, value in kwargs.iteritems(): ++ for key, value in kwargs.items(): + setattr(self, key, value) + + class User(Principal): +@@ -94,8 +94,8 @@ + + mapper(Foo, foo) + mapper(Bar, bar, inherits=Foo) +- print foo.join(bar).primary_key +- print class_mapper(Bar).primary_key ++ print(foo.join(bar).primary_key) ++ print(class_mapper(Bar).primary_key) + b = Bar('somedata') + sess = create_session() + sess.add(b) +@@ -133,8 +133,8 @@ + sess.expunge_all() + + l = sess.query(Bar).all() +- print l[0] +- print l[0].foos ++ print(l[0]) ++ print(l[0].foos) + self.assert_unordered_result(l, Bar, + # {'id':1, 'data':'barfoo', 'bid':1, 'foos':(Foo, [{'id':2,'data':'subfoo1'}, {'id':3,'data':'subfoo2'}])}, + {'id':b.id, 'data':'barfoo', 'foos':(Foo, [{'id':f1.id,'data':'subfoo1'}, {'id':f2.id,'data':'subfoo2'}])}, +@@ -197,7 +197,7 @@ + compare = [repr(b)] + sorted([repr(o) for o in b.foos]) + sess.expunge_all() + l = sess.query(Bar).all() +- print repr(l[0]) + repr(l[0].foos) ++ print(repr(l[0]) + repr(l[0].foos)) + found = [repr(l[0])] + sorted([repr(o) for o in l[0].foos]) + eq_(found, compare) + +@@ -239,11 +239,11 @@ + sess.expunge_all() + + l = sess.query(Blub).all() +- print l ++ print(l) + self.assert_(repr(l[0]) == compare) + sess.expunge_all() + x = sess.query(Blub).filter_by(id=blubid).one() +- print x ++ print(x) + self.assert_(repr(x) == compare) + + +diff -r 9d0639b9d3be test/orm/inheritance/test_polymorphic_rel.py +--- a/test/orm/inheritance/test_polymorphic_rel.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/inheritance/test_polymorphic_rel.py Sat Apr 27 19:42:17 2013 -0400 +@@ -7,7 +7,7 @@ + from sqlalchemy import testing + from sqlalchemy.testing import assert_raises, eq_ + +-from _poly_fixtures import Company, Person, Engineer, Manager, Boss, \ ++from ._poly_fixtures import Company, Person, Engineer, Manager, Boss, \ + Machine, Paperwork, _Polymorphic,\ + _PolymorphicPolymorphic, _PolymorphicUnions, _PolymorphicJoins,\ + _PolymorphicAliasedJoins +@@ -118,24 +118,24 @@ + eq_(q.count(), 1) + eq_(q.all(), [ + ( +- Company(company_id=1, name=u'MegaCorp, Inc.'), ++ Company(company_id=1, name='MegaCorp, Inc.'), + Engineer( +- status=u'regular engineer', +- engineer_name=u'dilbert', +- name=u'dilbert', ++ status='regular engineer', ++ engineer_name='dilbert', ++ name='dilbert', + company_id=1, +- primary_language=u'java', ++ primary_language='java', + person_id=1, +- type=u'engineer'), +- Company(company_id=1, name=u'MegaCorp, Inc.'), ++ type='engineer'), ++ Company(company_id=1, name='MegaCorp, Inc.'), + Engineer( +- status=u'regular engineer', +- engineer_name=u'wally', +- name=u'wally', ++ status='regular engineer', ++ engineer_name='wally', ++ name='wally', + company_id=1, +- primary_language=u'c++', ++ primary_language='c++', + person_id=2, +- type=u'engineer') ++ type='engineer') + ) + ]) + +@@ -337,8 +337,8 @@ + sess = create_session() + + expected = [ +- (u'dogbert',), +- (u'pointy haired boss',)] ++ ('dogbert',), ++ ('pointy haired boss',)] + eq_(sess.query(Manager.name) + .order_by(Manager.name).all(), + expected) +@@ -346,9 +346,9 @@ + def test_join_from_columns_or_subclass_two(self): + sess = create_session() + expected = [ +- (u'dogbert',), +- (u'dogbert',), +- (u'pointy haired boss',)] ++ ('dogbert',), ++ ('dogbert',), ++ ('pointy haired boss',)] + eq_(sess.query(Manager.name) + .join(Paperwork, Manager.paperwork) + .order_by(Manager.name).all(), +@@ -357,14 +357,14 @@ + def test_join_from_columns_or_subclass_three(self): + sess = create_session() + expected = [ +- (u'dilbert',), +- (u'dilbert',), +- (u'dogbert',), +- (u'dogbert',), +- (u'pointy haired boss',), +- (u'vlad',), +- (u'wally',), +- (u'wally',)] ++ ('dilbert',), ++ ('dilbert',), ++ ('dogbert',), ++ ('dogbert',), ++ ('pointy haired boss',), ++ ('vlad',), ++ ('wally',), ++ ('wally',)] + eq_(sess.query(Person.name) + .join(Paperwork, Person.paperwork) + .order_by(Person.name).all(), +@@ -375,14 +375,14 @@ + # Load Person.name, joining from Person -> paperwork, get all + # the people. + expected = [ +- (u'dilbert',), +- (u'dilbert',), +- (u'dogbert',), +- (u'dogbert',), +- (u'pointy haired boss',), +- (u'vlad',), +- (u'wally',), +- (u'wally',)] ++ ('dilbert',), ++ ('dilbert',), ++ ('dogbert',), ++ ('dogbert',), ++ ('pointy haired boss',), ++ ('vlad',), ++ ('wally',), ++ ('wally',)] + eq_(sess.query(Person.name) + .join(paperwork, + Person.person_id == paperwork.c.person_id) +@@ -393,9 +393,9 @@ + sess = create_session() + # same, on manager. get only managers. + expected = [ +- (u'dogbert',), +- (u'dogbert',), +- (u'pointy haired boss',)] ++ ('dogbert',), ++ ('dogbert',), ++ ('pointy haired boss',)] + eq_(sess.query(Manager.name) + .join(paperwork, + Manager.person_id == paperwork.c.person_id) +@@ -418,14 +418,14 @@ + # here, it joins to the full result set. This is 0.6's + # behavior and is more or less wrong. + expected = [ +- (u'dilbert',), +- (u'dilbert',), +- (u'dogbert',), +- (u'dogbert',), +- (u'pointy haired boss',), +- (u'vlad',), +- (u'wally',), +- (u'wally',)] ++ ('dilbert',), ++ ('dilbert',), ++ ('dogbert',), ++ ('dogbert',), ++ ('pointy haired boss',), ++ ('vlad',), ++ ('wally',), ++ ('wally',)] + eq_(sess.query(Person.name) + .join(paperwork, + Manager.person_id == paperwork.c.person_id) +@@ -435,9 +435,9 @@ + # when a join is present and managers.person_id is available, + # you get the managers. + expected = [ +- (u'dogbert',), +- (u'dogbert',), +- (u'pointy haired boss',)] ++ ('dogbert',), ++ ('dogbert',), ++ ('pointy haired boss',)] + eq_(sess.query(Person.name) + .join(paperwork, + Manager.person_id == paperwork.c.person_id) +@@ -454,9 +454,9 @@ + def test_join_from_columns_or_subclass_eight(self): + sess = create_session() + expected = [ +- (u'dogbert',), +- (u'dogbert',), +- (u'pointy haired boss',)] ++ ('dogbert',), ++ ('dogbert',), ++ ('pointy haired boss',)] + eq_(sess.query(Manager.name) + .join(paperwork, + Manager.person_id == paperwork.c.person_id) +@@ -474,9 +474,9 @@ + def test_join_from_columns_or_subclass_ten(self): + sess = create_session() + expected = [ +- (u'pointy haired boss', u'review #1'), +- (u'dogbert', u'review #2'), +- (u'dogbert', u'review #3')] ++ ('pointy haired boss', 'review #1'), ++ ('dogbert', 'review #2'), ++ ('dogbert', 'review #3')] + eq_(sess.query(Manager.name, Paperwork.description) + .join(Paperwork, + Manager.person_id == Paperwork.person_id) +@@ -486,9 +486,9 @@ + def test_join_from_columns_or_subclass_eleven(self): + sess = create_session() + expected = [ +- (u'pointy haired boss',), +- (u'dogbert',), +- (u'dogbert',)] ++ ('pointy haired boss',), ++ ('dogbert',), ++ ('dogbert',)] + malias = aliased(Manager) + eq_(sess.query(malias.name) + .join(paperwork, +@@ -977,32 +977,32 @@ + + expected = [ + (Engineer( +- status=u'regular engineer', +- engineer_name=u'dilbert', +- name=u'dilbert', ++ status='regular engineer', ++ engineer_name='dilbert', ++ name='dilbert', + company_id=1, +- primary_language=u'java', ++ primary_language='java', + person_id=1, +- type=u'engineer'), +- u'MegaCorp, Inc.'), ++ type='engineer'), ++ 'MegaCorp, Inc.'), + (Engineer( +- status=u'regular engineer', +- engineer_name=u'wally', +- name=u'wally', ++ status='regular engineer', ++ engineer_name='wally', ++ name='wally', + company_id=1, +- primary_language=u'c++', ++ primary_language='c++', + person_id=2, +- type=u'engineer'), +- u'MegaCorp, Inc.'), ++ type='engineer'), ++ 'MegaCorp, Inc.'), + (Engineer( +- status=u'elbonian engineer', +- engineer_name=u'vlad', +- name=u'vlad', ++ status='elbonian engineer', ++ engineer_name='vlad', ++ name='vlad', + company_id=2, +- primary_language=u'cobol', ++ primary_language='cobol', + person_id=5, +- type=u'engineer'), +- u'Elbonia, Inc.')] ++ type='engineer'), ++ 'Elbonia, Inc.')] + eq_(sess.query(Engineer, Company.name) + .join(Company.employees) + .filter(Person.type == 'engineer').all(), +@@ -1011,9 +1011,9 @@ + def test_mixed_entities_two(self): + sess = create_session() + expected = [ +- (u'java', u'MegaCorp, Inc.'), +- (u'cobol', u'Elbonia, Inc.'), +- (u'c++', u'MegaCorp, Inc.')] ++ ('java', 'MegaCorp, Inc.'), ++ ('cobol', 'Elbonia, Inc.'), ++ ('c++', 'MegaCorp, Inc.')] + eq_(sess.query(Engineer.primary_language, Company.name) + .join(Company.employees) + .filter(Person.type == 'engineer') +@@ -1025,19 +1025,19 @@ + palias = aliased(Person) + expected = [( + Engineer( +- status=u'elbonian engineer', +- engineer_name=u'vlad', +- name=u'vlad', +- primary_language=u'cobol'), +- u'Elbonia, Inc.', ++ status='elbonian engineer', ++ engineer_name='vlad', ++ name='vlad', ++ primary_language='cobol'), ++ 'Elbonia, Inc.', + Engineer( +- status=u'regular engineer', +- engineer_name=u'dilbert', +- name=u'dilbert', ++ status='regular engineer', ++ engineer_name='dilbert', ++ name='dilbert', + company_id=1, +- primary_language=u'java', ++ primary_language='java', + person_id=1, +- type=u'engineer'))] ++ type='engineer'))] + eq_(sess.query(Person, Company.name, palias) + .join(Company.employees) + .filter(Company.name == 'Elbonia, Inc.') +@@ -1049,19 +1049,19 @@ + palias = aliased(Person) + expected = [( + Engineer( +- status=u'regular engineer', +- engineer_name=u'dilbert', +- name=u'dilbert', ++ status='regular engineer', ++ engineer_name='dilbert', ++ name='dilbert', + company_id=1, +- primary_language=u'java', ++ primary_language='java', + person_id=1, +- type=u'engineer'), +- u'Elbonia, Inc.', ++ type='engineer'), ++ 'Elbonia, Inc.', + Engineer( +- status=u'elbonian engineer', +- engineer_name=u'vlad', +- name=u'vlad', +- primary_language=u'cobol'),)] ++ status='elbonian engineer', ++ engineer_name='vlad', ++ name='vlad', ++ primary_language='cobol'),)] + eq_(sess.query(palias, Company.name, Person) + .join(Company.employees) + .filter(Company.name == 'Elbonia, Inc.') +@@ -1071,7 +1071,7 @@ + def test_mixed_entities_five(self): + sess = create_session() + palias = aliased(Person) +- expected = [(u'vlad', u'Elbonia, Inc.', u'dilbert')] ++ expected = [('vlad', 'Elbonia, Inc.', 'dilbert')] + eq_(sess.query(Person.name, Company.name, palias.name) + .join(Company.employees) + .filter(Company.name == 'Elbonia, Inc.') +@@ -1082,9 +1082,9 @@ + sess = create_session() + palias = aliased(Person) + expected = [ +- (u'manager', u'dogbert', u'engineer', u'dilbert'), +- (u'manager', u'dogbert', u'engineer', u'wally'), +- (u'manager', u'dogbert', u'boss', u'pointy haired boss')] ++ ('manager', 'dogbert', 'engineer', 'dilbert'), ++ ('manager', 'dogbert', 'engineer', 'wally'), ++ ('manager', 'dogbert', 'boss', 'pointy haired boss')] + eq_(sess.query(Person.type, Person.name, palias.type, palias.name) + .filter(Person.company_id == palias.company_id) + .filter(Person.name == 'dogbert') +@@ -1095,14 +1095,14 @@ + def test_mixed_entities_seven(self): + sess = create_session() + expected = [ +- (u'dilbert', u'tps report #1'), +- (u'dilbert', u'tps report #2'), +- (u'dogbert', u'review #2'), +- (u'dogbert', u'review #3'), +- (u'pointy haired boss', u'review #1'), +- (u'vlad', u'elbonian missive #3'), +- (u'wally', u'tps report #3'), +- (u'wally', u'tps report #4')] ++ ('dilbert', 'tps report #1'), ++ ('dilbert', 'tps report #2'), ++ ('dogbert', 'review #2'), ++ ('dogbert', 'review #3'), ++ ('pointy haired boss', 'review #1'), ++ ('vlad', 'elbonian missive #3'), ++ ('wally', 'tps report #3'), ++ ('wally', 'tps report #4')] + eq_(sess.query(Person.name, Paperwork.description) + .filter(Person.person_id == Paperwork.person_id) + .order_by(Person.name, Paperwork.description).all(), +@@ -1116,7 +1116,7 @@ + + def test_mixed_entities_nine(self): + sess = create_session() +- expected = [(u'Elbonia, Inc.', 1), (u'MegaCorp, Inc.', 4)] ++ expected = [('Elbonia, Inc.', 1), ('MegaCorp, Inc.', 4)] + eq_(sess.query(Company.name, func.count(Person.person_id)) + .filter(Company.company_id == Person.company_id) + .group_by(Company.name) +@@ -1125,7 +1125,7 @@ + + def test_mixed_entities_ten(self): + sess = create_session() +- expected = [(u'Elbonia, Inc.', 1), (u'MegaCorp, Inc.', 4)] ++ expected = [('Elbonia, Inc.', 1), ('MegaCorp, Inc.', 4)] + eq_(sess.query(Company.name, func.count(Person.person_id)) + .join(Company.employees) + .group_by(Company.name) +@@ -1153,14 +1153,14 @@ + + def test_mixed_entities_eleven(self): + sess = create_session() +- expected = [(u'java',), (u'c++',), (u'cobol',)] ++ expected = [('java',), ('c++',), ('cobol',)] + eq_(sess.query(Engineer.primary_language) + .filter(Person.type == 'engineer').all(), + expected) + + def test_mixed_entities_twelve(self): + sess = create_session() +- expected = [(u'vlad', u'Elbonia, Inc.')] ++ expected = [('vlad', 'Elbonia, Inc.')] + eq_(sess.query(Person.name, Company.name) + .join(Company.employees) + .filter(Company.name == 'Elbonia, Inc.').all(), +@@ -1168,15 +1168,15 @@ + + def test_mixed_entities_thirteen(self): + sess = create_session() +- expected = [(u'pointy haired boss', u'fore')] ++ expected = [('pointy haired boss', 'fore')] + eq_(sess.query(Boss.name, Boss.golf_swing).all(), expected) + + def test_mixed_entities_fourteen(self): + sess = create_session() + expected = [ +- (u'dilbert', u'java'), +- (u'wally', u'c++'), +- (u'vlad', u'cobol')] ++ ('dilbert', 'java'), ++ ('wally', 'c++'), ++ ('vlad', 'cobol')] + eq_(sess.query(Engineer.name, Engineer.primary_language).all(), + expected) + +@@ -1184,12 +1184,12 @@ + sess = create_session() + + expected = [( +- u'Elbonia, Inc.', ++ 'Elbonia, Inc.', + Engineer( +- status=u'elbonian engineer', +- engineer_name=u'vlad', +- name=u'vlad', +- primary_language=u'cobol'))] ++ status='elbonian engineer', ++ engineer_name='vlad', ++ name='vlad', ++ primary_language='cobol'))] + eq_(sess.query(Company.name, Person) + .join(Company.employees) + .filter(Company.name == 'Elbonia, Inc.').all(), +@@ -1199,11 +1199,11 @@ + sess = create_session() + expected = [( + Engineer( +- status=u'elbonian engineer', +- engineer_name=u'vlad', +- name=u'vlad', +- primary_language=u'cobol'), +- u'Elbonia, Inc.')] ++ status='elbonian engineer', ++ engineer_name='vlad', ++ name='vlad', ++ primary_language='cobol'), ++ 'Elbonia, Inc.')] + eq_(sess.query(Person, Company.name) + .join(Company.employees) + .filter(Company.name == 'Elbonia, Inc.').all(), +diff -r 9d0639b9d3be test/orm/inheritance/test_productspec.py +--- a/test/orm/inheritance/test_productspec.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/inheritance/test_productspec.py Sat Apr 27 19:42:17 2013 -0400 +@@ -122,8 +122,8 @@ + + a1 = session.query(Product).filter_by(name='a1').one() + new = repr(a1) +- print orig +- print new ++ print(orig) ++ print(new) + assert orig == new == ' specification=[>, >] documents=None' + + def testtwo(self): +@@ -153,8 +153,8 @@ + session.flush() + session.expunge_all() + new = repr(session.query(SpecLine).all()) +- print orig +- print new ++ print(orig) ++ print(new) + assert orig == new == '[>, >]' + + def testthree(self): +@@ -206,8 +206,8 @@ + + a1 = session.query(Product).filter_by(name='a1').one() + new = repr(a1) +- print orig +- print new ++ print(orig) ++ print(new) + assert orig == new == ' specification=[>] documents=[, ]' + + def testfour(self): +@@ -245,8 +245,8 @@ + + a1 = session.query(Product).filter_by(name='a1').one() + new = repr(a1) +- print orig +- print new ++ print(orig) ++ print(new) + assert orig == new == ' specification=None documents=[]' + + del a1.documents[0] +@@ -312,7 +312,7 @@ + + a1 = session.query(Product).filter_by(name='a1').one() + new = repr(a1) +- print orig +- print new ++ print(orig) ++ print(new) + assert orig == new == ' specification=[>] documents=[, ]' + +diff -r 9d0639b9d3be test/orm/inheritance/test_relationship.py +--- a/test/orm/inheritance/test_relationship.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/inheritance/test_relationship.py Sat Apr 27 19:42:17 2013 -0400 +@@ -287,7 +287,7 @@ + def _five_obj_fixture(self): + sess = Session() + e1, e2, e3, e4, e5 = [ +- Engineer(name='e%d' % (i + 1)) for i in xrange(5) ++ Engineer(name='e%d' % (i + 1)) for i in range(5) + ] + e3.reports_to = e1 + e4.reports_to = e2 +diff -r 9d0639b9d3be test/orm/inheritance/test_with_poly.py +--- a/test/orm/inheritance/test_with_poly.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/inheritance/test_with_poly.py Sat Apr 27 19:42:17 2013 -0400 +@@ -11,7 +11,7 @@ + from sqlalchemy.testing.schema import Table, Column + from sqlalchemy.testing import assert_raises, eq_ + +-from _poly_fixtures import Company, Person, Engineer, Manager, Boss, \ ++from ._poly_fixtures import Company, Person, Engineer, Manager, Boss, \ + Machine, Paperwork, _PolymorphicFixtureBase, _Polymorphic,\ + _PolymorphicPolymorphic, _PolymorphicUnions, _PolymorphicJoins,\ + _PolymorphicAliasedJoins +@@ -37,8 +37,8 @@ + pa.Manager.manager_name=='dogbert')).\ + order_by(pa.Engineer.type).all(), + [ +- (u'dilbert', u'java', None), +- (u'dogbert', None, u'dogbert'), ++ ('dilbert', 'java', None), ++ ('dogbert', None, 'dogbert'), + ] + ) + +@@ -63,10 +63,10 @@ + ) + ).order_by(pa.name, pa_alias.name)], + [ +- (u'dilbert', Engineer, u'dilbert', Engineer), +- (u'dogbert', Manager, u'pointy haired boss', Boss), +- (u'vlad', Engineer, u'vlad', Engineer), +- (u'wally', Engineer, u'wally', Engineer) ++ ('dilbert', Engineer, 'dilbert', Engineer), ++ ('dogbert', Manager, 'pointy haired boss', Boss), ++ ('vlad', Engineer, 'vlad', Engineer), ++ ('wally', Engineer, 'wally', Engineer) + ] + ) + +@@ -91,10 +91,10 @@ + ) + ).order_by(pa.name, pa_alias.name)], + [ +- (u'dilbert', u'java', u'dilbert', u'java'), +- (u'dogbert', None, u'pointy haired boss', None), +- (u'vlad', u'cobol', u'vlad', u'cobol'), +- (u'wally', u'c++', u'wally', u'c++') ++ ('dilbert', 'java', 'dilbert', 'java'), ++ ('dogbert', None, 'pointy haired boss', None), ++ ('vlad', 'cobol', 'vlad', 'cobol'), ++ ('wally', 'c++', 'wally', 'c++') + ] + ) + +diff -r 9d0639b9d3be test/orm/test_assorted_eager.py +--- a/test/orm/test_assorted_eager.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_assorted_eager.py Sat Apr 27 19:42:17 2013 -0400 +@@ -129,7 +129,7 @@ + # 3 " + + # not orm style correct query +- print "Obtaining correct results without orm" ++ print("Obtaining correct results without orm") + result = sa.select( + [tests.c.id,categories.c.name], + sa.and_(tests.c.owner_id == 1, +@@ -140,7 +140,7 @@ + tests.c.id == options.c.test_id, + tests.c.owner_id == options.c.owner_id))] + ).execute().fetchall() +- eq_(result, [(1, u'Some Category'), (3, u'Some Category')]) ++ eq_(result, [(1, 'Some Category'), (3, 'Some Category')]) + + def test_withoutjoinedload(self): + Thing, tests, options = (self.classes.Thing, +@@ -158,7 +158,7 @@ + options.c.someoption==False)))) + + result = ["%d %s" % ( t.id,t.category.name ) for t in l] +- eq_(result, [u'1 Some Category', u'3 Some Category']) ++ eq_(result, ['1 Some Category', '3 Some Category']) + + def test_withjoinedload(self): + """ +@@ -185,7 +185,7 @@ + options.c.someoption==False)))) + + result = ["%d %s" % ( t.id,t.category.name ) for t in l] +- eq_(result, [u'1 Some Category', u'3 Some Category']) ++ eq_(result, ['1 Some Category', '3 Some Category']) + + def test_dslish(self): + """test the same as withjoinedload except using generative""" +@@ -203,7 +203,7 @@ + ).outerjoin('owner_option') + + result = ["%d %s" % ( t.id,t.category.name ) for t in l] +- eq_(result, [u'1 Some Category', u'3 Some Category']) ++ eq_(result, ['1 Some Category', '3 Some Category']) + + @testing.crashes('sybase', 'FIXME: unknown, verify not fails_on') + def test_without_outerjoin_literal(self): +@@ -219,7 +219,7 @@ + join('owner_option')) + + result = ["%d %s" % ( t.id,t.category.name ) for t in l] +- eq_(result, [u'3 Some Category']) ++ eq_(result, ['3 Some Category']) + + def test_withoutouterjoin(self): + Thing, tests, options = (self.classes.Thing, +@@ -234,7 +234,7 @@ + ).join('owner_option') + + result = ["%d %s" % ( t.id,t.category.name ) for t in l] +- eq_(result, [u'3 Some Category']) ++ eq_(result, ['3 Some Category']) + + + class EagerTest2(fixtures.MappedTest): +@@ -764,7 +764,7 @@ + (1,),), + + task=(('title', 'task_type_id', 'status_id', 'prj_id'), +- (u'task 1', 1, 1, 1))) ++ ('task 1', 1, 1, 1))) + + @classmethod + def setup_classes(cls): +@@ -804,7 +804,7 @@ + session = create_session() + + eq_(session.query(Joined).limit(10).offset(0).one(), +- Joined(id=1, title=u'task 1', props_cnt=0)) ++ Joined(id=1, title='task 1', props_cnt=0)) + + + class EagerTest9(fixtures.MappedTest): +diff -r 9d0639b9d3be test/orm/test_attributes.py +--- a/test/orm/test_attributes.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_attributes.py Sat Apr 27 19:42:17 2013 -0400 +@@ -838,7 +838,7 @@ + attributes.register_attribute(Foo, 'collection', + uselist=True, typecallable=dict, useobject=True) + assert False +- except sa_exc.ArgumentError, e: ++ except sa_exc.ArgumentError as e: + assert str(e) \ + == 'Type InstrumentedDict must elect an appender '\ + 'method to be a collection class' +@@ -865,7 +865,7 @@ + attributes.register_attribute(Foo, 'collection', + uselist=True, typecallable=MyColl, useobject=True) + assert False +- except sa_exc.ArgumentError, e: ++ except sa_exc.ArgumentError as e: + assert str(e) \ + == 'Type MyColl must elect an appender method to be a '\ + 'collection class' +@@ -889,7 +889,7 @@ + try: + Foo().collection + assert True +- except sa_exc.ArgumentError, e: ++ except sa_exc.ArgumentError as e: + assert False + + class GetNoValueTest(fixtures.ORMTest): +@@ -1410,7 +1410,7 @@ + class Foo(fixtures.BasicEntity): + pass + class Bar(fixtures.BasicEntity): +- def __nonzero__(self): ++ def __bool__(self): + assert False + + instrumentation.register_class(Foo) +diff -r 9d0639b9d3be test/orm/test_collection.py +--- a/test/orm/test_collection.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_collection.py Sat Apr 27 19:42:17 2013 -0400 +@@ -1106,7 +1106,7 @@ + + @collection.converter + def _convert(self, dictlike): +- for key, value in dictlike.iteritems(): ++ for key, value in dictlike.items(): + yield value + 5 + + class Foo(object): +@@ -1145,12 +1145,12 @@ + def __delitem__(self, key): + del self.data[key] + def values(self): +- return self.data.values() ++ return list(self.data.values()) + def __contains__(self, key): + return key in self.data + @collection.iterator + def itervalues(self): +- return self.data.itervalues() ++ return iter(self.data.values()) + __hash__ = object.__hash__ + def __eq__(self, other): + return self.data == other +@@ -1158,7 +1158,7 @@ + return 'DictLike(%s)' % repr(self.data) + + self._test_adapter(DictLike, self.dictable_entity, +- to_set=lambda c: set(c.itervalues())) ++ to_set=lambda c: set(c.values())) + self._test_dict(DictLike) + self._test_dict_bulk(DictLike) + self.assert_(getattr(DictLike, '_sa_instrumented') == id(DictLike)) +@@ -1185,12 +1185,12 @@ + def __delitem__(self, key): + del self.data[key] + def values(self): +- return self.data.values() ++ return list(self.data.values()) + def __contains__(self, key): + return key in self.data + @collection.iterator + def itervalues(self): +- return self.data.itervalues() ++ return iter(self.data.values()) + __hash__ = object.__hash__ + def __eq__(self, other): + return self.data == other +@@ -1198,7 +1198,7 @@ + return 'DictIsh(%s)' % repr(self.data) + + self._test_adapter(DictIsh, self.dictable_entity, +- to_set=lambda c: set(c.itervalues())) ++ to_set=lambda c: set(c.values())) + self._test_dict(DictIsh) + self._test_dict_bulk(DictIsh) + self.assert_(getattr(DictIsh, '_sa_instrumented') == id(DictIsh)) +@@ -1859,7 +1859,7 @@ + f = sess.query(Foo).get(f.col1) + assert len(list(f.bars)) == 2 + +- existing = set([id(b) for b in f.bars.values()]) ++ existing = set([id(b) for b in list(f.bars.values())]) + + col = collections.collection_adapter(f.bars) + col.append_with_event(Bar('b')) +@@ -1869,7 +1869,7 @@ + f = sess.query(Foo).get(f.col1) + assert len(list(f.bars)) == 2 + +- replaced = set([id(b) for b in f.bars.values()]) ++ replaced = set([id(b) for b in list(f.bars.values())]) + self.assert_(existing != replaced) + + def test_list(self): +diff -r 9d0639b9d3be test/orm/test_composites.py +--- a/test/orm/test_composites.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_composites.py Sat Apr 27 19:42:17 2013 -0400 +@@ -510,11 +510,11 @@ + session.commit() + eq_( + testing.db.execute(descriptions.select()).fetchall(), +- [(1, u'Color', u'Number')] ++ [(1, 'Color', 'Number')] + ) + eq_( + testing.db.execute(values.select()).fetchall(), +- [(1, 1, u'Red', u'5'), (2, 1, u'Blue', u'1')] ++ [(1, 1, 'Red', '5'), (2, 1, 'Blue', '1')] + ) + + class ManyToOneTest(fixtures.MappedTest): +diff -r 9d0639b9d3be test/orm/test_deprecations.py +--- a/test/orm/test_deprecations.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_deprecations.py Sat Apr 27 19:42:17 2013 -0400 +@@ -122,7 +122,7 @@ + session = sessionmaker(query_cls=MyQuery)() + + ad1 = session.query(Address).get(1) +- assert ad1 in cache.values() ++ assert ad1 in list(cache.values()) + + def test_load(self): + """x = session.query(Address).load(1) +diff -r 9d0639b9d3be test/orm/test_dynamic.py +--- a/test/orm/test_dynamic.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_dynamic.py Sat Apr 27 19:42:17 2013 -0400 +@@ -119,9 +119,9 @@ + eq_( + list(u.addresses.order_by(desc(Address.email_address))), + [ +- Address(email_address=u'ed@wood.com'), +- Address(email_address=u'ed@lala.com'), +- Address(email_address=u'ed@bettyboop.com') ++ Address(email_address='ed@wood.com'), ++ Address(email_address='ed@lala.com'), ++ Address(email_address='ed@bettyboop.com') + ] + ) + +@@ -137,9 +137,9 @@ + eq_( + list(u.addresses), + [ +- Address(email_address=u'ed@wood.com'), +- Address(email_address=u'ed@lala.com'), +- Address(email_address=u'ed@bettyboop.com') ++ Address(email_address='ed@wood.com'), ++ Address(email_address='ed@lala.com'), ++ Address(email_address='ed@bettyboop.com') + ] + ) + +@@ -147,9 +147,9 @@ + eq_( + list(u.addresses.order_by(None).order_by(Address.email_address)), + [ +- Address(email_address=u'ed@bettyboop.com'), +- Address(email_address=u'ed@lala.com'), +- Address(email_address=u'ed@wood.com') ++ Address(email_address='ed@bettyboop.com'), ++ Address(email_address='ed@lala.com'), ++ Address(email_address='ed@wood.com') + ] + ) + +@@ -157,9 +157,9 @@ + eq_( + set(u.addresses.order_by(None)), + set([ +- Address(email_address=u'ed@bettyboop.com'), +- Address(email_address=u'ed@lala.com'), +- Address(email_address=u'ed@wood.com') ++ Address(email_address='ed@bettyboop.com'), ++ Address(email_address='ed@lala.com'), ++ Address(email_address='ed@wood.com') + ]) + ) + +@@ -529,12 +529,12 @@ + "SELECT addresses.id AS addresses_id, addresses.email_address " + "AS addresses_email_address FROM addresses " + "WHERE addresses.id = :param_1", +- lambda ctx: [{u'param_1': a2_id}] ++ lambda ctx: [{'param_1': a2_id}] + ), + CompiledSQL( + "UPDATE addresses SET user_id=:user_id WHERE addresses.id = " + ":addresses_id", +- lambda ctx: [{u'addresses_id': a2_id, 'user_id': None}] ++ lambda ctx: [{'addresses_id': a2_id, 'user_id': None}] + ) + ) + +diff -r 9d0639b9d3be test/orm/test_eager_relations.py +--- a/test/orm/test_eager_relations.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_eager_relations.py Sat Apr 27 19:42:17 2013 -0400 +@@ -747,11 +747,11 @@ + + sess = create_session() + eq_(sess.query(User).first(), +- User(name=u'jack',orders=[ +- Order(address_id=1,description=u'order 1',isopen=0,user_id=7,id=1), +- Order(address_id=1,description=u'order 3',isopen=1,user_id=7,id=3), +- Order(address_id=None,description=u'order 5',isopen=0,user_id=7,id=5)], +- email_address=u'jack@bean.com',id=7) ++ User(name='jack',orders=[ ++ Order(address_id=1,description='order 1',isopen=0,user_id=7,id=1), ++ Order(address_id=1,description='order 3',isopen=1,user_id=7,id=3), ++ Order(address_id=None,description='order 5',isopen=0,user_id=7,id=5)], ++ email_address='jack@bean.com',id=7) + ) + + def test_useget_cancels_eager(self): +@@ -2131,15 +2131,15 @@ + }) + + sess = create_session() +- w1 = Widget(name=u'w1') +- w2 = Widget(name=u'w2') ++ w1 = Widget(name='w1') ++ w2 = Widget(name='w2') + w1.children.append(w2) + sess.add(w1) + sess.flush() + sess.expunge_all() + + eq_([Widget(name='w1', children=[Widget(name='w2')])], +- sess.query(Widget).filter(Widget.name==u'w1').all()) ++ sess.query(Widget).filter(Widget.name=='w1').all()) + + class MixedEntitiesTest(_fixtures.FixtureTest, testing.AssertsCompiledSQL): + run_setup_mappers = 'once' +@@ -2223,24 +2223,24 @@ + eq_( + [ + ( +- User(addresses=[Address(email_address=u'fred@fred.com')], name=u'fred'), +- Order(description=u'order 2', isopen=0, items=[Item(description=u'item 1'), Item(description=u'item 2'), Item(description=u'item 3')]), +- User(addresses=[Address(email_address=u'jack@bean.com')], name=u'jack'), +- Order(description=u'order 3', isopen=1, items=[Item(description=u'item 3'), Item(description=u'item 4'), Item(description=u'item 5')]) ++ User(addresses=[Address(email_address='fred@fred.com')], name='fred'), ++ Order(description='order 2', isopen=0, items=[Item(description='item 1'), Item(description='item 2'), Item(description='item 3')]), ++ User(addresses=[Address(email_address='jack@bean.com')], name='jack'), ++ Order(description='order 3', isopen=1, items=[Item(description='item 3'), Item(description='item 4'), Item(description='item 5')]) + ), + + ( +- User(addresses=[Address(email_address=u'fred@fred.com')], name=u'fred'), +- Order(description=u'order 2', isopen=0, items=[Item(description=u'item 1'), Item(description=u'item 2'), Item(description=u'item 3')]), +- User(addresses=[Address(email_address=u'jack@bean.com')], name=u'jack'), +- Order(address_id=None, description=u'order 5', isopen=0, items=[Item(description=u'item 5')]) ++ User(addresses=[Address(email_address='fred@fred.com')], name='fred'), ++ Order(description='order 2', isopen=0, items=[Item(description='item 1'), Item(description='item 2'), Item(description='item 3')]), ++ User(addresses=[Address(email_address='jack@bean.com')], name='jack'), ++ Order(address_id=None, description='order 5', isopen=0, items=[Item(description='item 5')]) + ), + + ( +- User(addresses=[Address(email_address=u'fred@fred.com')], name=u'fred'), +- Order(description=u'order 4', isopen=1, items=[Item(description=u'item 1'), Item(description=u'item 5')]), +- User(addresses=[Address(email_address=u'jack@bean.com')], name=u'jack'), +- Order(address_id=None, description=u'order 5', isopen=0, items=[Item(description=u'item 5')]) ++ User(addresses=[Address(email_address='fred@fred.com')], name='fred'), ++ Order(description='order 4', isopen=1, items=[Item(description='item 1'), Item(description='item 5')]), ++ User(addresses=[Address(email_address='jack@bean.com')], name='jack'), ++ Order(address_id=None, description='order 5', isopen=0, items=[Item(description='item 5')]) + ), + ], + sess.query(User, Order, u1, o1).\ +@@ -2651,9 +2651,9 @@ + Movie = self.classes.Movie + + session = Session(testing.db) +- rscott = Director(name=u"Ridley Scott") +- alien = Movie(title=u"Alien") +- brunner = Movie(title=u"Blade Runner") ++ rscott = Director(name="Ridley Scott") ++ alien = Movie(title="Alien") ++ brunner = Movie(title="Blade Runner") + rscott.movies.append(brunner) + rscott.movies.append(alien) + session.add_all([rscott, alien, brunner]) +diff -r 9d0639b9d3be test/orm/test_expire.py +--- a/test/orm/test_expire.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_expire.py Sat Apr 27 19:42:17 2013 -0400 +@@ -850,7 +850,7 @@ + assert len(u.addresses) == 3 + sess.expire(u) + assert 'addresses' not in u.__dict__ +- print "-------------------------------------------" ++ print("-------------------------------------------") + sess.query(User).filter_by(id=8).all() + assert 'addresses' in u.__dict__ + assert len(u.addresses) == 3 +diff -r 9d0639b9d3be test/orm/test_froms.py +--- a/test/orm/test_froms.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_froms.py Sat Apr 27 19:42:17 2013 -0400 +@@ -315,12 +315,12 @@ + from_self(User.name, ualias.name). + order_by(User.name, ualias.name).all(), + [ +- (u'chuck', u'ed'), +- (u'chuck', u'fred'), +- (u'chuck', u'jack'), +- (u'ed', u'jack'), +- (u'fred', u'ed'), +- (u'fred', u'jack') ++ ('chuck', 'ed'), ++ ('chuck', 'fred'), ++ ('chuck', 'jack'), ++ ('ed', 'jack'), ++ ('fred', 'ed'), ++ ('fred', 'jack') + ] + ) + +@@ -330,7 +330,7 @@ + from_self(User.name, ualias.name). + filter(ualias.name=='ed')\ + .order_by(User.name, ualias.name).all(), +- [(u'chuck', u'ed'), (u'fred', u'ed')] ++ [('chuck', 'ed'), ('fred', 'ed')] + ) + + eq_( +@@ -340,11 +340,11 @@ + join(ualias.addresses). + order_by(ualias.name, Address.email_address).all(), + [ +- (u'ed', u'fred@fred.com'), +- (u'jack', u'ed@bettyboop.com'), +- (u'jack', u'ed@lala.com'), +- (u'jack', u'ed@wood.com'), +- (u'jack', u'fred@fred.com')] ++ ('ed', 'fred@fred.com'), ++ ('jack', 'ed@bettyboop.com'), ++ ('jack', 'ed@lala.com'), ++ ('jack', 'ed@wood.com'), ++ ('jack', 'fred@fred.com')] + ) + + +@@ -629,8 +629,8 @@ + eq_( + q.all(), + [( +- A(bid=2, id=1, name=u'a1', type=u'a'), +- C(age=3, id=2, name=u'c1', type=u'c') ++ A(bid=2, id=1, name='a1', type='a'), ++ C(age=3, id=2, name='c1', type='c') + )] + ) + +@@ -642,8 +642,8 @@ + eq_( + q.all(), + [( +- C(age=3, id=2, name=u'c1', type=u'c'), +- A(bid=2, id=1, name=u'a1', type=u'a') ++ C(age=3, id=2, name='c1', type='c'), ++ A(bid=2, id=1, name='a1', type='a') + )] + ) + +@@ -929,12 +929,12 @@ + # have a Dingaling here due to using the inner + # join for the eager load + [ +- User(name=u'ed', addresses=[ +- Address(email_address=u'ed@wood.com', ++ User(name='ed', addresses=[ ++ Address(email_address='ed@wood.com', + dingaling=Dingaling(data='ding 1/2')), + ]), +- User(name=u'fred', addresses=[ +- Address(email_address=u'fred@fred.com', ++ User(name='fred', addresses=[ ++ Address(email_address='fred@fred.com', + dingaling=Dingaling(data='ding 2/5')) + ]) + ] +@@ -965,12 +965,12 @@ + # have a Dingaling here due to using the inner + # join for the eager load + [ +- User(name=u'ed', addresses=[ +- Address(email_address=u'ed@wood.com', ++ User(name='ed', addresses=[ ++ Address(email_address='ed@wood.com', + dingaling=Dingaling(data='ding 1/2')), + ]), +- User(name=u'fred', addresses=[ +- Address(email_address=u'fred@fred.com', ++ User(name='fred', addresses=[ ++ Address(email_address='fred@fred.com', + dingaling=Dingaling(data='ding 2/5')) + ]) + ] +@@ -998,11 +998,11 @@ + contains_eager(User.orders)).order_by(User.id, + Order.id).offset(1).limit(2).all() + eq_(l, [User(id=7, +- addresses=[Address(email_address=u'jack@bean.com', +- user_id=7, id=1)], name=u'jack', ++ addresses=[Address(email_address='jack@bean.com', ++ user_id=7, id=1)], name='jack', + orders=[Order(address_id=1, user_id=7, +- description=u'order 3', isopen=1, id=3), +- Order(address_id=None, user_id=7, description=u'order 5' ++ description='order 3', isopen=1, id=3), ++ Order(address_id=None, user_id=7, description='order 5' + , isopen=0, id=5)])]) + + self.assert_sql_count(testing.db, go, 1) +@@ -1020,11 +1020,11 @@ + order_by(User.id, oalias.id).\ + offset(1).limit(2).all() + eq_(l, [User(id=7, +- addresses=[Address(email_address=u'jack@bean.com', +- user_id=7, id=1)], name=u'jack', ++ addresses=[Address(email_address='jack@bean.com', ++ user_id=7, id=1)], name='jack', + orders=[Order(address_id=1, user_id=7, +- description=u'order 3', isopen=1, id=3), +- Order(address_id=None, user_id=7, description=u'order 5' ++ description='order 3', isopen=1, id=3), ++ Order(address_id=None, user_id=7, description='order 5' + , isopen=0, id=5)])]) + + self.assert_sql_count(testing.db, go, 1) +@@ -1045,15 +1045,15 @@ + sel = users.select(User.id.in_([7, 8])).alias() + q = sess.query(User) + q2 = q.select_from(sel).values(User.name) +- eq_(list(q2), [(u'jack',), (u'ed',)]) ++ eq_(list(q2), [('jack',), ('ed',)]) + + q = sess.query(User) + q2 = q.order_by(User.id).\ + values(User.name, User.name + " " + cast(User.id, String(50))) + eq_( + list(q2), +- [(u'jack', u'jack 7'), (u'ed', u'ed 8'), +- (u'fred', u'fred 9'), (u'chuck', u'chuck 10')] ++ [('jack', 'jack 7'), ('ed', 'ed 8'), ++ ('fred', 'fred 9'), ('chuck', 'chuck 10')] + ) + + q2 = q.join('addresses').\ +@@ -1061,27 +1061,27 @@ + order_by(User.id, Address.id).\ + values(User.name, Address.email_address) + eq_(list(q2), +- [(u'ed', u'ed@wood.com'), (u'ed', u'ed@bettyboop.com'), +- (u'ed', u'ed@lala.com'), (u'fred', u'fred@fred.com')]) ++ [('ed', 'ed@wood.com'), ('ed', 'ed@bettyboop.com'), ++ ('ed', 'ed@lala.com'), ('fred', 'fred@fred.com')]) + + q2 = q.join('addresses').\ + filter(User.name.like('%e%')).\ + order_by(desc(Address.email_address)).\ + slice(1, 3).values(User.name, Address.email_address) +- eq_(list(q2), [(u'ed', u'ed@wood.com'), (u'ed', u'ed@lala.com')]) ++ eq_(list(q2), [('ed', 'ed@wood.com'), ('ed', 'ed@lala.com')]) + + adalias = aliased(Address) + q2 = q.join(adalias, 'addresses').\ + filter(User.name.like('%e%')).order_by(adalias.email_address).\ + values(User.name, adalias.email_address) +- eq_(list(q2), [(u'ed', u'ed@bettyboop.com'), (u'ed', u'ed@lala.com'), +- (u'ed', u'ed@wood.com'), (u'fred', u'fred@fred.com')]) ++ eq_(list(q2), [('ed', 'ed@bettyboop.com'), ('ed', 'ed@lala.com'), ++ ('ed', 'ed@wood.com'), ('fred', 'fred@fred.com')]) + + q2 = q.values(func.count(User.name)) +- assert q2.next() == (4,) ++ assert next(q2) == (4,) + + q2 = q.select_from(sel).filter(User.id==8).values(User.name, sel.c.name, User.name) +- eq_(list(q2), [(u'ed', u'ed', u'ed')]) ++ eq_(list(q2), [('ed', 'ed', 'ed')]) + + # using User.xxx is alised against "sel", so this query returns nothing + q2 = q.select_from(sel).\ +@@ -1093,7 +1093,7 @@ + q2 = q.select_from(sel).\ + filter(users.c.id==8).\ + filter(users.c.id>sel.c.id).values(users.c.name, sel.c.name, User.name) +- eq_(list(q2), [(u'ed', u'jack', u'jack')]) ++ eq_(list(q2), [('ed', 'jack', 'jack')]) + + def test_alias_naming(self): + User = self.classes.User +@@ -1123,10 +1123,10 @@ + filter(u2.id>1).\ + order_by(User.id, sel.c.id, u2.id).\ + values(User.name, sel.c.name, u2.name) +- eq_(list(q2), [(u'jack', u'jack', u'jack'), (u'jack', u'jack', u'ed'), +- (u'jack', u'jack', u'fred'), (u'jack', u'jack', u'chuck'), +- (u'ed', u'ed', u'jack'), (u'ed', u'ed', u'ed'), +- (u'ed', u'ed', u'fred'), (u'ed', u'ed', u'chuck')]) ++ eq_(list(q2), [('jack', 'jack', 'jack'), ('jack', 'jack', 'ed'), ++ ('jack', 'jack', 'fred'), ('jack', 'jack', 'chuck'), ++ ('ed', 'ed', 'jack'), ('ed', 'ed', 'ed'), ++ ('ed', 'ed', 'fred'), ('ed', 'ed', 'chuck')]) + + @testing.fails_on('mssql', 'FIXME: unknown') + @testing.fails_on('oracle', +@@ -1177,8 +1177,8 @@ + # we don't want Address to be outside of the subquery here + eq_( + list(sess.query(User, subq)[0:3]), +- [(User(id=7,name=u'jack'), 1), (User(id=8,name=u'ed'), 3), +- (User(id=9,name=u'fred'), 1)] ++ [(User(id=7,name='jack'), 1), (User(id=8,name='ed'), 3), ++ (User(id=9,name='fred'), 1)] + ) + + # same thing without the correlate, as it should +@@ -1190,8 +1190,8 @@ + # we don't want Address to be outside of the subquery here + eq_( + list(sess.query(User, subq)[0:3]), +- [(User(id=7,name=u'jack'), 1), (User(id=8,name=u'ed'), 3), +- (User(id=9,name=u'fred'), 1)] ++ [(User(id=7,name='jack'), 1), (User(id=8,name='ed'), 3), ++ (User(id=9,name='fred'), 1)] + ) + + +@@ -1202,23 +1202,23 @@ + + sess = create_session() + +- eq_(sess.query(User.name).all(), [(u'jack',), (u'ed',), (u'fred',), (u'chuck',)]) ++ eq_(sess.query(User.name).all(), [('jack',), ('ed',), ('fred',), ('chuck',)]) + + sel = users.select(User.id.in_([7, 8])).alias() + q = sess.query(User.name) + q2 = q.select_from(sel).all() +- eq_(list(q2), [(u'jack',), (u'ed',)]) ++ eq_(list(q2), [('jack',), ('ed',)]) + + eq_(sess.query(User.name, Address.email_address).filter(User.id==Address.user_id).all(), [ +- (u'jack', u'jack@bean.com'), (u'ed', u'ed@wood.com'), +- (u'ed', u'ed@bettyboop.com'), (u'ed', u'ed@lala.com'), +- (u'fred', u'fred@fred.com') ++ ('jack', 'jack@bean.com'), ('ed', 'ed@wood.com'), ++ ('ed', 'ed@bettyboop.com'), ('ed', 'ed@lala.com'), ++ ('fred', 'fred@fred.com') + ]) + + eq_(sess.query(User.name, func.count(Address.email_address)).\ + outerjoin(User.addresses).group_by(User.id, User.name).\ + order_by(User.id).all(), +- [(u'jack', 1), (u'ed', 3), (u'fred', 1), (u'chuck', 0)] ++ [('jack', 1), ('ed', 3), ('fred', 1), ('chuck', 0)] + ) + + eq_(sess.query(User, func.count(Address.email_address)).\ +@@ -1246,8 +1246,8 @@ + eq_(sess.query(func.count(adalias.email_address), User).\ + outerjoin(adalias, User.addresses).group_by(User).\ + order_by(User.id).all(), +- [(1, User(name=u'jack',id=7)), (3, User(name=u'ed',id=8)), +- (1, User(name=u'fred',id=9)), (0, User(name=u'chuck',id=10))] ++ [(1, User(name='jack',id=7)), (3, User(name='ed',id=8)), ++ (1, User(name='fred',id=9)), (0, User(name='chuck',id=10))] + ) + + # select from aliasing + explicit aliasing +@@ -1257,12 +1257,12 @@ + from_self(User, adalias.email_address).\ + order_by(User.id, adalias.id).all(), + [ +- (User(name=u'jack',id=7), u'jack@bean.com'), +- (User(name=u'ed',id=8), u'ed@wood.com'), +- (User(name=u'ed',id=8), u'ed@bettyboop.com'), +- (User(name=u'ed',id=8), u'ed@lala.com'), +- (User(name=u'fred',id=9), u'fred@fred.com'), +- (User(name=u'chuck',id=10), None) ++ (User(name='jack',id=7), 'jack@bean.com'), ++ (User(name='ed',id=8), 'ed@wood.com'), ++ (User(name='ed',id=8), 'ed@bettyboop.com'), ++ (User(name='ed',id=8), 'ed@lala.com'), ++ (User(name='fred',id=9), 'fred@fred.com'), ++ (User(name='chuck',id=10), None) + ] + ) + +@@ -1272,8 +1272,8 @@ + filter(Address.email_address.like('%ed%')).\ + from_self().all(), + [ +- User(name=u'ed',id=8), +- User(name=u'fred',id=9), ++ User(name='ed',id=8), ++ User(name='fred',id=9), + ] + ) + +@@ -1293,27 +1293,27 @@ + + q.all(), + [(User(addresses=[ +- Address(user_id=7,email_address=u'jack@bean.com',id=1)], +- name=u'jack',id=7), u'jack@bean.com'), ++ Address(user_id=7,email_address='jack@bean.com',id=1)], ++ name='jack',id=7), 'jack@bean.com'), + (User(addresses=[ +- Address(user_id=8,email_address=u'ed@wood.com',id=2), +- Address(user_id=8,email_address=u'ed@bettyboop.com',id=3), +- Address(user_id=8,email_address=u'ed@lala.com',id=4)], +- name=u'ed',id=8), u'ed@wood.com'), ++ Address(user_id=8,email_address='ed@wood.com',id=2), ++ Address(user_id=8,email_address='ed@bettyboop.com',id=3), ++ Address(user_id=8,email_address='ed@lala.com',id=4)], ++ name='ed',id=8), 'ed@wood.com'), + (User(addresses=[ +- Address(user_id=8,email_address=u'ed@wood.com',id=2), +- Address(user_id=8,email_address=u'ed@bettyboop.com',id=3), +- Address(user_id=8,email_address=u'ed@lala.com',id=4)],name=u'ed',id=8), +- u'ed@bettyboop.com'), ++ Address(user_id=8,email_address='ed@wood.com',id=2), ++ Address(user_id=8,email_address='ed@bettyboop.com',id=3), ++ Address(user_id=8,email_address='ed@lala.com',id=4)],name='ed',id=8), ++ 'ed@bettyboop.com'), + (User(addresses=[ +- Address(user_id=8,email_address=u'ed@wood.com',id=2), +- Address(user_id=8,email_address=u'ed@bettyboop.com',id=3), +- Address(user_id=8,email_address=u'ed@lala.com',id=4)],name=u'ed',id=8), +- u'ed@lala.com'), +- (User(addresses=[Address(user_id=9,email_address=u'fred@fred.com',id=5)],name=u'fred',id=9), +- u'fred@fred.com'), ++ Address(user_id=8,email_address='ed@wood.com',id=2), ++ Address(user_id=8,email_address='ed@bettyboop.com',id=3), ++ Address(user_id=8,email_address='ed@lala.com',id=4)],name='ed',id=8), ++ 'ed@lala.com'), ++ (User(addresses=[Address(user_id=9,email_address='fred@fred.com',id=5)],name='fred',id=9), ++ 'fred@fred.com'), + +- (User(addresses=[],name=u'chuck',id=10), None)] ++ (User(addresses=[],name='chuck',id=10), None)] + ) + + def test_column_from_limited_joinedload(self): +@@ -1367,19 +1367,19 @@ + eq_( + q.all(), + [ +- (Order(address_id=1,description=u'order 3',isopen=1,user_id=7,id=3), +- Order(address_id=1,description=u'order 1',isopen=0,user_id=7,id=1)), +- (Order(address_id=None,description=u'order 5',isopen=0,user_id=7,id=5), +- Order(address_id=1,description=u'order 1',isopen=0,user_id=7,id=1)), +- (Order(address_id=None,description=u'order 5',isopen=0,user_id=7,id=5), +- Order(address_id=1,description=u'order 3',isopen=1,user_id=7,id=3)) ++ (Order(address_id=1,description='order 3',isopen=1,user_id=7,id=3), ++ Order(address_id=1,description='order 1',isopen=0,user_id=7,id=1)), ++ (Order(address_id=None,description='order 5',isopen=0,user_id=7,id=5), ++ Order(address_id=1,description='order 1',isopen=0,user_id=7,id=1)), ++ (Order(address_id=None,description='order 5',isopen=0,user_id=7,id=5), ++ Order(address_id=1,description='order 3',isopen=1,user_id=7,id=3)) + ] + ) + + + # ensure column expressions are taken from inside the subquery, not restated at the top + q = sess.query(Order.id, Order.description, literal_column("'q'").label('foo')).\ +- filter(Order.description == u'order 3').from_self() ++ filter(Order.description == 'order 3').from_self() + self.assert_compile(q, + "SELECT anon_1.orders_id AS " + "anon_1_orders_id, anon_1.orders_descriptio" +@@ -1392,7 +1392,7 @@ + "anon_1") + eq_( + q.all(), +- [(3, u'order 3', 'q')] ++ [(3, 'order 3', 'q')] + ) + + +@@ -1518,7 +1518,7 @@ + + eq_( + sess.query(User.id).add_column(users).all(), +- [(7, 7, u'jack'), (8, 8, u'ed'), (9, 9, u'fred'), (10, 10, u'chuck')] ++ [(7, 7, 'jack'), (8, 8, 'ed'), (9, 9, 'fred'), (10, 10, 'chuck')] + ) + + def test_multi_columns_2(self): +@@ -1936,7 +1936,7 @@ + filter(Keyword.name.in_(['red', 'big', 'round'])).\ + all(), + [ +- User(name=u'jack',id=7) ++ User(name='jack',id=7) + ]) + + eq_(sess.query(User).select_from(sel).\ +@@ -1944,7 +1944,7 @@ + filter(Keyword.name.in_(['red', 'big', 'round'])).\ + all(), + [ +- User(name=u'jack',id=7) ++ User(name='jack',id=7) + ]) + + def go(): +@@ -1955,39 +1955,39 @@ + filter(Keyword.name.in_(['red', 'big', 'round'])).\ + all(), + [ +- User(name=u'jack',orders=[ +- Order(description=u'order 1',items=[ +- Item(description=u'item 1', ++ User(name='jack',orders=[ ++ Order(description='order 1',items=[ ++ Item(description='item 1', + keywords=[ +- Keyword(name=u'red'), +- Keyword(name=u'big'), +- Keyword(name=u'round') ++ Keyword(name='red'), ++ Keyword(name='big'), ++ Keyword(name='round') + ]), +- Item(description=u'item 2', ++ Item(description='item 2', + keywords=[ +- Keyword(name=u'red',id=2), +- Keyword(name=u'small',id=5), +- Keyword(name=u'square') ++ Keyword(name='red',id=2), ++ Keyword(name='small',id=5), ++ Keyword(name='square') + ]), +- Item(description=u'item 3', ++ Item(description='item 3', + keywords=[ +- Keyword(name=u'green',id=3), +- Keyword(name=u'big',id=4), +- Keyword(name=u'round',id=6)]) ++ Keyword(name='green',id=3), ++ Keyword(name='big',id=4), ++ Keyword(name='round',id=6)]) + ]), +- Order(description=u'order 3',items=[ +- Item(description=u'item 3', ++ Order(description='order 3',items=[ ++ Item(description='item 3', + keywords=[ +- Keyword(name=u'green',id=3), +- Keyword(name=u'big',id=4), +- Keyword(name=u'round',id=6) ++ Keyword(name='green',id=3), ++ Keyword(name='big',id=4), ++ Keyword(name='round',id=6) + ]), +- Item(description=u'item 4',keywords=[],id=4), +- Item(description=u'item 5',keywords=[],id=5) ++ Item(description='item 4',keywords=[],id=4), ++ Item(description='item 5',keywords=[],id=5) + ]), +- Order(description=u'order 5', ++ Order(description='order 5', + items=[ +- Item(description=u'item 5',keywords=[])]) ++ Item(description='item 5',keywords=[])]) + ]) + ]) + self.assert_sql_count(testing.db, go, 1) +@@ -1998,15 +1998,15 @@ + join('items', 'keywords').\ + filter(Keyword.name == 'red').\ + order_by(Order.id).all(), [ +- Order(description=u'order 1',id=1), +- Order(description=u'order 2',id=2), ++ Order(description='order 1',id=1), ++ Order(description='order 2',id=2), + ]) + eq_(sess.query(Order).select_from(sel2).\ + join('items', 'keywords', aliased=True).\ + filter(Keyword.name == 'red').\ + order_by(Order.id).all(), [ +- Order(description=u'order 1',id=1), +- Order(description=u'order 2',id=2), ++ Order(description='order 1',id=1), ++ Order(description='order 2',id=2), + ]) + + +diff -r 9d0639b9d3be test/orm/test_generative.py +--- a/test/orm/test_generative.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_generative.py Sat Apr 27 19:42:17 2013 -0400 +@@ -78,13 +78,14 @@ + assert sess.query(func.min(foo.c.bar)).filter(foo.c.bar<30).one() == (0,) + + assert sess.query(func.max(foo.c.bar)).filter(foo.c.bar<30).one() == (29,) +- # Py3K +- #assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).__next__()[0] == 29 +- #assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).__next__()[0] == 29 +- # Py2K +- assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).next()[0] == 29 +- assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).next()[0] == 29 +- # end Py2K ++# start Py3K ++ assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).__next__()[0] == 29 ++ assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).__next__()[0] == 29 ++# end Py3K ++# start Py2K ++# assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).next()[0] == 29 ++# assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).next()[0] == 29 ++# end Py2K + + @testing.fails_if(lambda:testing.against('mysql+mysqldb') and + testing.db.dialect.dbapi.version_info[:4] == (1, 2, 1, 'gamma'), +@@ -111,18 +112,20 @@ + + query = create_session().query(Foo) + +- # Py3K +- #avg_f = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).__next__()[0] +- # Py2K +- avg_f = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).next()[0] +- # end Py2K ++# start Py3K ++ avg_f = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).__next__()[0] ++# end Py3K ++# start Py2K ++# avg_f = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).next()[0] ++# end Py2K + assert float(round(avg_f, 1)) == 14.5 + +- # Py3K +- #avg_o = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).__next__()[0] +- # Py2K +- avg_o = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).next()[0] +- # end Py2K ++# start Py3K ++ avg_o = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).__next__()[0] ++# end Py3K ++# start Py2K ++# avg_o = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).next()[0] ++# end Py2K + assert float(round(avg_o, 1)) == 14.5 + + def test_filter(self): +diff -r 9d0639b9d3be test/orm/test_inspect.py +--- a/test/orm/test_inspect.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_inspect.py Sat Apr 27 19:42:17 2013 -0400 +@@ -142,7 +142,7 @@ + [insp.get_property('id'), insp.get_property('name')] + ) + eq_( +- insp.column_attrs.keys(), ++ list(insp.column_attrs.keys()), + ['id', 'name'] + ) + is_( +@@ -274,7 +274,7 @@ + insp = inspect(SomeSubClass) + eq_( + dict((k, v.extension_type) +- for k, v in insp.all_orm_descriptors.items() ++ for k, v in list(insp.all_orm_descriptors.items()) + ), + { + 'id': NOT_EXTENSION, +diff -r 9d0639b9d3be test/orm/test_instrumentation.py +--- a/test/orm/test_instrumentation.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_instrumentation.py Sat Apr 27 19:42:17 2013 -0400 +@@ -522,30 +522,31 @@ + class Py3KFunctionInstTest(fixtures.ORMTest): + __requires__ = ("python3", ) + +- # Py3K +- #def _kw_only_fixture(self): +- # class A(object): +- # def __init__(self, a, *, b, c): +- # self.a = a +- # self.b = b +- # self.c = c +- # return self._instrument(A) +- # +- #def _kw_plus_posn_fixture(self): +- # class A(object): +- # def __init__(self, a, *args, b, c): +- # self.a = a +- # self.b = b +- # self.c = c +- # return self._instrument(A) +- # +- #def _kw_opt_fixture(self): +- # class A(object): +- # def __init__(self, a, *, b, c="c"): +- # self.a = a +- # self.b = b +- # self.c = c +- # return self._instrument(A) ++# start Py3K ++ def _kw_only_fixture(self): ++ class A(object): ++ def __init__(self, a, *, b, c): ++ self.a = a ++ self.b = b ++ self.c = c ++ return self._instrument(A) ++ ++ def _kw_plus_posn_fixture(self): ++ class A(object): ++ def __init__(self, a, *args, b, c): ++ self.a = a ++ self.b = b ++ self.c = c ++ return self._instrument(A) ++ ++ def _kw_opt_fixture(self): ++ class A(object): ++ def __init__(self, a, *, b, c="c"): ++ self.a = a ++ self.b = b ++ self.c = c ++ return self._instrument(A) ++# end Py3K + + def _instrument(self, cls): + manager = instrumentation.register_class(cls) +diff -r 9d0639b9d3be test/orm/test_joins.py +--- a/test/orm/test_joins.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_joins.py Sat Apr 27 19:42:17 2013 -0400 +@@ -774,14 +774,14 @@ + eq_( + sess.query(User).join(Address.user).\ + filter(Address.email_address=='ed@wood.com').all(), +- [User(id=8,name=u'ed')] ++ [User(id=8,name='ed')] + ) + + # its actually not so controversial if you view it in terms + # of multiple entities. + eq_( + sess.query(User, Address).join(Address.user).filter(Address.email_address=='ed@wood.com').all(), +- [(User(id=8,name=u'ed'), Address(email_address='ed@wood.com'))] ++ [(User(id=8,name='ed'), Address(email_address='ed@wood.com'))] + ) + + # this was the controversial part. now, raise an error if the feature is abused. +@@ -1162,9 +1162,9 @@ + sess.query(OrderAlias).join('items').filter_by(description='item 3').\ + order_by(OrderAlias.id).all(), + [ +- Order(address_id=1,description=u'order 1',isopen=0,user_id=7,id=1), +- Order(address_id=4,description=u'order 2',isopen=0,user_id=9,id=2), +- Order(address_id=1,description=u'order 3',isopen=1,user_id=7,id=3) ++ Order(address_id=1,description='order 1',isopen=0,user_id=7,id=1), ++ Order(address_id=4,description='order 2',isopen=0,user_id=9,id=2), ++ Order(address_id=1,description='order 3',isopen=1,user_id=7,id=3) + ] + ) + +@@ -1175,9 +1175,9 @@ + filter_by(description='item 3').\ + order_by(User.id, OrderAlias.id).all(), + [ +- (User(name=u'jack',id=7), Order(address_id=1,description=u'order 1',isopen=0,user_id=7,id=1), u'item 3'), +- (User(name=u'jack',id=7), Order(address_id=1,description=u'order 3',isopen=1,user_id=7,id=3), u'item 3'), +- (User(name=u'fred',id=9), Order(address_id=4,description=u'order 2',isopen=0,user_id=9,id=2), u'item 3') ++ (User(name='jack',id=7), Order(address_id=1,description='order 1',isopen=0,user_id=7,id=1), 'item 3'), ++ (User(name='jack',id=7), Order(address_id=1,description='order 3',isopen=1,user_id=7,id=3), 'item 3'), ++ (User(name='fred',id=9), Order(address_id=4,description='order 2',isopen=0,user_id=9,id=2), 'item 3') + ] + ) + +@@ -1334,12 +1334,12 @@ + eq_( + sess.query(User, ualias).filter(User.id > ualias.id).order_by(desc(ualias.id), User.name).all(), + [ +- (User(id=10,name=u'chuck'), User(id=9,name=u'fred')), +- (User(id=10,name=u'chuck'), User(id=8,name=u'ed')), +- (User(id=9,name=u'fred'), User(id=8,name=u'ed')), +- (User(id=10,name=u'chuck'), User(id=7,name=u'jack')), +- (User(id=8,name=u'ed'), User(id=7,name=u'jack')), +- (User(id=9,name=u'fred'), User(id=7,name=u'jack')) ++ (User(id=10,name='chuck'), User(id=9,name='fred')), ++ (User(id=10,name='chuck'), User(id=8,name='ed')), ++ (User(id=9,name='fred'), User(id=8,name='ed')), ++ (User(id=10,name='chuck'), User(id=7,name='jack')), ++ (User(id=8,name='ed'), User(id=7,name='jack')), ++ (User(id=9,name='fred'), User(id=7,name='jack')) + ] + ) + +@@ -1351,7 +1351,7 @@ + + eq_( + sess.query(User.name).join(addresses, User.id==addresses.c.user_id).order_by(User.id).all(), +- [(u'jack',), (u'ed',), (u'ed',), (u'ed',), (u'fred',)] ++ [('jack',), ('ed',), ('ed',), ('ed',), ('fred',)] + ) + + def test_no_joinpoint_expr(self): +@@ -2066,13 +2066,13 @@ + # using 'n1.parent' implicitly joins to unaliased Node + eq_( + sess.query(n1).join(n1.parent).filter(Node.data=='n1').all(), +- [Node(parent_id=1,data=u'n11',id=2), Node(parent_id=1,data=u'n12',id=3), Node(parent_id=1,data=u'n13',id=4)] ++ [Node(parent_id=1,data='n11',id=2), Node(parent_id=1,data='n12',id=3), Node(parent_id=1,data='n13',id=4)] + ) + + # explicit (new syntax) + eq_( + sess.query(n1).join(Node, n1.parent).filter(Node.data=='n1').all(), +- [Node(parent_id=1,data=u'n11',id=2), Node(parent_id=1,data=u'n12',id=3), Node(parent_id=1,data=u'n13',id=4)] ++ [Node(parent_id=1,data='n11',id=2), Node(parent_id=1,data='n12',id=3), Node(parent_id=1,data='n13',id=4)] + ) + + +diff -r 9d0639b9d3be test/orm/test_loading.py +--- a/test/orm/test_loading.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_loading.py Sat Apr 27 19:42:17 2013 -0400 +@@ -73,7 +73,7 @@ + [(x.id, y) for x, y in it], + [(1, 1), (2, 2), (7, 7), (8, 8)] + ) +- eq_(it[0].keys(), ['User', 'id']) ++ eq_(list(it[0].keys()), ['User', 'id']) + + def test_entity_col_mix_keyed_tuple(self): + s, (u1, u2, u3, u4) = self._fixture() +@@ -91,7 +91,7 @@ + [(x.id, y) for x, y in it], + [(1, 1), (2, 2), (7, 7), (8, 8)] + ) +- eq_(it[0].keys(), ['User', 'id']) ++ eq_(list(it[0].keys()), ['User', 'id']) + + def test_none_entity(self): + s, (u1, u2, u3, u4) = self._fixture() +diff -r 9d0639b9d3be test/orm/test_mapper.py +--- a/test/orm/test_mapper.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_mapper.py Sat Apr 27 19:42:17 2013 -0400 +@@ -272,13 +272,14 @@ + ) + m = mapper(Foo, foo_t) + class DontCompareMeToString(int): +- # Py3K +- # pass +- # Py2K +- def __lt__(self, other): +- assert not isinstance(other, basestring) +- return int(self) < other +- # end Py2K ++# start Py3K ++ pass ++# end Py3K ++# start Py2K ++# def __lt__(self, other): ++# assert not isinstance(other, basestring) ++# return int(self) < other ++# end Py2K + foos = [Foo(id='f%d' % i) for i in range(5)] + states = [attributes.instance_state(f) for f in foos] + +@@ -847,7 +848,7 @@ + + def test_we_dont_call_bool(self): + class NoBoolAllowed(object): +- def __nonzero__(self): ++ def __bool__(self): + raise Exception("nope") + mapper(NoBoolAllowed, self.tables.users) + u1 = NoBoolAllowed() +@@ -1057,12 +1058,12 @@ + + eq_( + create_session().query(User).all(), +- [User(id=7, name=u'jack'), User(id=9, name=u'fred'), User(id=8, name=u'ed'), User(id=10, name=u'chuck')] ++ [User(id=7, name='jack'), User(id=9, name='fred'), User(id=8, name='ed'), User(id=10, name='chuck')] + ) + + eq_( + create_session().query(User).order_by(User.name).all(), +- [User(id=10, name=u'chuck'), User(id=8, name=u'ed'), User(id=9, name=u'fred'), User(id=7, name=u'jack')] ++ [User(id=10, name='chuck'), User(id=8, name='ed'), User(id=9, name='fred'), User(id=7, name='jack')] + ) + + # 'Raises a "expression evaluation not supported" error at prepare time +@@ -2123,7 +2124,7 @@ + mapper(Address, addresses) + + eq_( +- dict((k, v[0].__name__) for k, v in u_m.validators.items()), ++ dict((k, v[0].__name__) for k, v in list(u_m.validators.items())), + {'name':'validate_name', + 'addresses':'validate_address'} + ) +@@ -2992,29 +2993,29 @@ + Column('ht1b_id', Integer, ForeignKey('ht1.id'), primary_key=True), + Column('value', String(10))) + +- # Py2K +- def test_baseclass(self): +- ht1 = self.tables.ht1 +- +- class OldStyle: +- pass +- +- assert_raises(sa.exc.ArgumentError, mapper, OldStyle, ht1) +- +- assert_raises(sa.exc.ArgumentError, mapper, 123) +- +- class NoWeakrefSupport(str): +- pass +- +- # TODO: is weakref support detectable without an instance? +- #self.assertRaises(sa.exc.ArgumentError, mapper, NoWeakrefSupport, t2) +- # end Py2K ++# start Py2K ++# def test_baseclass(self): ++# ht1 = self.tables.ht1 ++# ++# class OldStyle: ++# pass ++# ++# assert_raises(sa.exc.ArgumentError, mapper, OldStyle, ht1) ++# ++# assert_raises(sa.exc.ArgumentError, mapper, 123) ++# ++# class NoWeakrefSupport(str): ++# pass ++# ++# # TODO: is weakref support detectable without an instance? ++# #self.assertRaises(sa.exc.ArgumentError, mapper, NoWeakrefSupport, t2) ++# end Py2K + + class _ValueBase(object): + def __init__(self, value='abc', id=None): + self.id = id + self.value = value +- def __nonzero__(self): ++ def __bool__(self): + return False + def __hash__(self): + return hash(self.value) +@@ -3173,7 +3174,7 @@ + return self.value + + class H2(object): +- def __nonzero__(self): ++ def __bool__(self): + return bool(self.get_value()) + + def get_value(self): +@@ -3224,7 +3225,7 @@ + self._test("someprop") + + def test_unicode(self): +- self._test(u"someprop") ++ self._test("someprop") + + def test_int(self): + self._test(5) +diff -r 9d0639b9d3be test/orm/test_merge.py +--- a/test/orm/test_merge.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_merge.py Sat Apr 27 19:42:17 2013 -0400 +@@ -346,7 +346,7 @@ + sess = create_session() + sess.merge(u1) + sess.flush() +- assert u1.addresses.keys() == ['foo@bar.com'] ++ assert list(u1.addresses.keys()) == ['foo@bar.com'] + + def test_attribute_cascade(self): + """Merge of a persistent entity with two child +@@ -803,7 +803,7 @@ + try: + sess2.merge(u, load=False) + assert False +- except sa.exc.InvalidRequestError, e: ++ except sa.exc.InvalidRequestError as e: + assert "merge() with load=False option does not support "\ + "objects marked as 'dirty'. flush() all changes on "\ + "mapped instances before merging with load=False." \ +@@ -924,7 +924,7 @@ + sess2.expunge_all() + eq_(sess2.query(User).get(u2.id).addresses[0].email_address, + 'somenewaddress') +- except sa.exc.InvalidRequestError, e: ++ except sa.exc.InvalidRequestError as e: + assert "load=False option does not support" in str(e) + + def test_synonym_comparable(self): +diff -r 9d0639b9d3be test/orm/test_naturalpks.py +--- a/test/orm/test_naturalpks.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_naturalpks.py Sat Apr 27 19:42:17 2013 -0400 +@@ -2,7 +2,7 @@ + Primary key changing capabilities and passive/non-passive cascading updates. + + """ +-from __future__ import with_statement ++ + from sqlalchemy.testing import eq_, ne_, \ + assert_raises, assert_raises_message + import sqlalchemy as sa +@@ -519,11 +519,11 @@ + + session = sa.orm.sessionmaker()() + +- a_published = User(1, PUBLISHED, u'a') ++ a_published = User(1, PUBLISHED, 'a') + session.add(a_published) + session.commit() + +- a_editable = User(1, EDITABLE, u'a') ++ a_editable = User(1, EDITABLE, 'a') + + session.add(a_editable) + session.commit() +diff -r 9d0639b9d3be test/orm/test_pickled.py +--- a/test/orm/test_pickled.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_pickled.py Sat Apr 27 19:42:17 2013 -0400 +@@ -443,21 +443,21 @@ + if pickled is not False: + row = pickle.loads(pickle.dumps(row, pickled)) + +- eq_(row.keys(), ['User', 'Address']) ++ eq_(list(row.keys()), ['User', 'Address']) + eq_(row.User, row[0]) + eq_(row.Address, row[1]) + + for row in sess.query(User.name, User.id.label('foobar')): + if pickled is not False: + row = pickle.loads(pickle.dumps(row, pickled)) +- eq_(row.keys(), ['name', 'foobar']) ++ eq_(list(row.keys()), ['name', 'foobar']) + eq_(row.name, row[0]) + eq_(row.foobar, row[1]) + + for row in sess.query(User).values(User.name, User.id.label('foobar')): + if pickled is not False: + row = pickle.loads(pickle.dumps(row, pickled)) +- eq_(row.keys(), ['name', 'foobar']) ++ eq_(list(row.keys()), ['name', 'foobar']) + eq_(row.name, row[0]) + eq_(row.foobar, row[1]) + +@@ -465,21 +465,21 @@ + for row in sess.query(User, oalias).join(User.orders).all(): + if pickled is not False: + row = pickle.loads(pickle.dumps(row, pickled)) +- eq_(row.keys(), ['User']) ++ eq_(list(row.keys()), ['User']) + eq_(row.User, row[0]) + + oalias = aliased(Order, name='orders') + for row in sess.query(User, oalias).join(oalias, User.orders).all(): + if pickled is not False: + row = pickle.loads(pickle.dumps(row, pickled)) +- eq_(row.keys(), ['User', 'orders']) ++ eq_(list(row.keys()), ['User', 'orders']) + eq_(row.User, row[0]) + eq_(row.orders, row[1]) + + # test here that first col is not labeled, only + # one name in keys, matches correctly + for row in sess.query(User.name + 'hoho', User.name): +- eq_(row.keys(), ['name']) ++ eq_(list(row.keys()), ['name']) + eq_(row[0], row.name + 'hoho') + + if pickled is not False: +diff -r 9d0639b9d3be test/orm/test_query.py +--- a/test/orm/test_query.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_query.py Sat Apr 27 19:42:17 2013 -0400 +@@ -407,11 +407,12 @@ + Column('data', Unicode(40))) + try: + metadata.create_all() +- # Py3K +- #ustring = b'petit voix m\xe2\x80\x99a'.decode('utf-8') +- # Py2K +- ustring = 'petit voix m\xe2\x80\x99a'.decode('utf-8') +- # end Py2K ++# start Py3K ++ ustring = b'petit voix m\xe2\x80\x99a'.decode('utf-8') ++# end Py3K ++# start Py2K ++# ustring = 'petit voix m\xe2\x80\x99a'.decode('utf-8') ++# end Py2K + + table.insert().execute(id=ustring, data=ustring) + class LocalFoo(self.classes.Base): +@@ -637,9 +638,9 @@ + (operator.sub, '-'), + # Py3k + #(operator.truediv, '/'), +- # Py2K +- (operator.div, '/'), +- # end Py2K ++# start Py2K ++# (operator.div, '/'), ++# end Py2K + ): + for (lhs, rhs, res) in ( + (5, User.id, ':id_1 %s users.id'), +@@ -1047,7 +1048,7 @@ + adalias = aliased(Address, q1.subquery()) + eq_( + s.query(User, adalias).join(adalias, User.id==adalias.user_id).all(), +- [(User(id=7,name=u'jack'), Address(email_address=u'jack@bean.com',user_id=7,id=1))] ++ [(User(id=7,name='jack'), Address(email_address='jack@bean.com',user_id=7,id=1))] + ) + + # more slice tests are available in test/orm/generative.py +@@ -1196,7 +1197,7 @@ + "users.name AS users_name FROM users WHERE users.id = :param_1 " + "UNION SELECT users.id AS users_id, users.name AS users_name " + "FROM users WHERE users.id = :param_2) AS anon_1", +- checkparams = {u'param_1': 7, u'param_2': 8} ++ checkparams = {'param_1': 7, 'param_2': 8} + ) + + def test_any(self): +@@ -1319,7 +1320,7 @@ + "FROM users JOIN addresses ON users.id = addresses.user_id " + "WHERE users.name = :name_1 AND " + "addresses.email_address = :email_address_1", +- checkparams={u'email_address_1': 'ed@ed.com', u'name_1': 'ed'} ++ checkparams={'email_address_1': 'ed@ed.com', 'name_1': 'ed'} + ) + + def test_filter_by_no_property(self): +@@ -1468,14 +1469,14 @@ + for q in (q3.order_by(User.id, "anon_1_param_1"), q6.order_by(User.id, "foo")): + eq_(q.all(), + [ +- (User(id=7, name=u'jack'), u'x'), +- (User(id=7, name=u'jack'), u'y'), +- (User(id=8, name=u'ed'), u'x'), +- (User(id=8, name=u'ed'), u'y'), +- (User(id=9, name=u'fred'), u'x'), +- (User(id=9, name=u'fred'), u'y'), +- (User(id=10, name=u'chuck'), u'x'), +- (User(id=10, name=u'chuck'), u'y') ++ (User(id=7, name='jack'), 'x'), ++ (User(id=7, name='jack'), 'y'), ++ (User(id=8, name='ed'), 'x'), ++ (User(id=8, name='ed'), 'y'), ++ (User(id=9, name='fred'), 'x'), ++ (User(id=9, name='fred'), 'y'), ++ (User(id=10, name='chuck'), 'x'), ++ (User(id=10, name='chuck'), 'y') + ] + ) + +@@ -1603,7 +1604,7 @@ + + sess = create_session() + orders = sess.query(Order).filter(Order.id.in_([2, 3, 4])) +- eq_(orders.values(func.sum(Order.user_id * Order.address_id)).next(), (79,)) ++ eq_(next(orders.values(func.sum(Order.user_id * Order.address_id))), (79,)) + eq_(orders.value(func.sum(Order.user_id * Order.address_id)), 79) + + def test_apply(self): +@@ -1616,9 +1617,9 @@ + User, Address = self.classes.User, self.classes.Address + + sess = create_session() +- assert [User(name=u'ed',id=8)] == sess.query(User).order_by(User.id).group_by(User).join('addresses').having(func.count(Address.id)> 2).all() +- +- assert [User(name=u'jack',id=7), User(name=u'fred',id=9)] == sess.query(User).order_by(User.id).group_by(User).join('addresses').having(func.count(Address.id)< 2).all() ++ assert [User(name='ed',id=8)] == sess.query(User).order_by(User.id).group_by(User).join('addresses').having(func.count(Address.id)> 2).all() ++ ++ assert [User(name='jack',id=7), User(name='fred',id=9)] == sess.query(User).order_by(User.id).group_by(User).join('addresses').having(func.count(Address.id)< 2).all() + + + class ExistsTest(QueryTest, AssertsCompiledSQL): +@@ -1798,14 +1799,14 @@ + + ret = [] + eq_(len(sess.identity_map), 0) +- ret.append(q.next()) +- ret.append(q.next()) ++ ret.append(next(q)) ++ ret.append(next(q)) + eq_(len(sess.identity_map), 2) +- ret.append(q.next()) +- ret.append(q.next()) ++ ret.append(next(q)) ++ ret.append(next(q)) + eq_(len(sess.identity_map), 4) + try: +- q.next() ++ next(q) + assert False + except StopIteration: + pass +@@ -1915,7 +1916,7 @@ + User.id, text("users.name")) + + eq_(s.query(User.id, "name").order_by(User.id).all(), +- [(7, u'jack'), (8, u'ed'), (9, u'fred'), (10, u'chuck')]) ++ [(7, 'jack'), (8, 'ed'), (9, 'fred'), (10, 'chuck')]) + + def test_via_select(self): + User = self.classes.User +@@ -1973,7 +1974,7 @@ + try: + q = sess.query(Item).with_parent(u1) + assert False +- except sa_exc.InvalidRequestError, e: ++ except sa_exc.InvalidRequestError as e: + assert str(e) \ + == "Could not locate a property which relates "\ + "instances of class 'Item' to instances of class 'User'" +@@ -2058,7 +2059,7 @@ + "addresses.id AS addresses_id, addresses.user_id AS " + "addresses_user_id, addresses.email_address AS addresses_email_address " + "FROM addresses WHERE :param_2 = addresses.user_id) AS anon_1", +- checkparams={u'param_1': 7, u'param_2': 8}, ++ checkparams={'param_1': 7, 'param_2': 8}, + ) + + def test_unique_binds_or(self): +@@ -2075,7 +2076,7 @@ + "addresses_user_id, addresses.email_address AS " + "addresses_email_address FROM addresses WHERE " + ":param_1 = addresses.user_id OR :param_2 = addresses.user_id", +- checkparams={u'param_1': 7, u'param_2': 8}, ++ checkparams={'param_1': 7, 'param_2': 8}, + ) + + class SynonymTest(QueryTest): +@@ -2117,9 +2118,9 @@ + options(joinedload(User.orders_syn)).all() + eq_(result, [ + User(id=7, name='jack', orders=[ +- Order(description=u'order 1'), +- Order(description=u'order 3'), +- Order(description=u'order 5') ++ Order(description='order 1'), ++ Order(description='order 3'), ++ Order(description='order 5') + ]) + ]) + self.assert_sql_count(testing.db, go, 1) +@@ -2133,9 +2134,9 @@ + options(joinedload(User.orders_syn_2)).all() + eq_(result, [ + User(id=7, name='jack', orders=[ +- Order(description=u'order 1'), +- Order(description=u'order 3'), +- Order(description=u'order 5') ++ Order(description='order 1'), ++ Order(description='order 3'), ++ Order(description='order 5') + ]) + ]) + self.assert_sql_count(testing.db, go, 1) +@@ -2149,9 +2150,9 @@ + options(joinedload('orders_syn_2')).all() + eq_(result, [ + User(id=7, name='jack', orders=[ +- Order(description=u'order 1'), +- Order(description=u'order 3'), +- Order(description=u'order 5') ++ Order(description='order 1'), ++ Order(description='order 3'), ++ Order(description='order 5') + ]) + ]) + self.assert_sql_count(testing.db, go, 1) +@@ -2355,7 +2356,7 @@ + if isinstance(item, type): + item = class_mapper(item) + else: +- if isinstance(item, basestring): ++ if isinstance(item, str): + item = inspect(r[-1]).mapper.attrs[item] + r.append(item) + return tuple(r) +diff -r 9d0639b9d3be test/orm/test_relationships.py +--- a/test/orm/test_relationships.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_relationships.py Sat Apr 27 19:42:17 2013 -0400 +@@ -426,13 +426,13 @@ + c1 = Company('c1') + c2 = Company('c2') + +- e1 = Employee(u'emp1', c1, 1) +- e2 = Employee(u'emp2', c1, 2, e1) +- e3 = Employee(u'emp3', c1, 3, e1) +- e4 = Employee(u'emp4', c1, 4, e3) +- e5 = Employee(u'emp5', c2, 1) +- e6 = Employee(u'emp6', c2, 2, e5) +- e7 = Employee(u'emp7', c2, 3, e5) ++ e1 = Employee('emp1', c1, 1) ++ e2 = Employee('emp2', c1, 2, e1) ++ e3 = Employee('emp3', c1, 3, e1) ++ e4 = Employee('emp4', c1, 4, e3) ++ e5 = Employee('emp5', c2, 1) ++ e6 = Employee('emp6', c2, 2, e5) ++ e7 = Employee('emp7', c2, 3, e5) + + sess.add_all((c1, c2)) + sess.commit() +@@ -642,7 +642,7 @@ + try: + sess.flush() + assert False +- except AssertionError, e: ++ except AssertionError as e: + startswith_(str(e), + "Dependency rule tried to blank-out " + "primary key column 'tableB.id' on instance ") +@@ -667,7 +667,7 @@ + try: + sess.flush() + assert False +- except AssertionError, e: ++ except AssertionError as e: + startswith_(str(e), + "Dependency rule tried to blank-out " + "primary key column 'tableB.id' on instance ") +@@ -1106,9 +1106,9 @@ + eq_( + sess.query(Subscriber).order_by(Subscriber.type).all(), + [ +- Subscriber(id=1, type=u'A'), +- Subscriber(id=2, type=u'B'), +- Subscriber(id=2, type=u'C') ++ Subscriber(id=1, type='A'), ++ Subscriber(id=2, type='B'), ++ Subscriber(id=2, type='C') + ] + ) + +@@ -1365,7 +1365,7 @@ + try: + sess.add(a1) + assert False +- except AssertionError, err: ++ except AssertionError as err: + eq_(str(err), + "Attribute 'bs' on class '%s' doesn't handle " + "objects of type '%s'" % (A, C)) +diff -r 9d0639b9d3be test/orm/test_session.py +--- a/test/orm/test_session.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_session.py Sat Apr 27 19:42:17 2013 -0400 +@@ -232,7 +232,7 @@ + # use :bindparam style + eq_(sess.execute("select * from users where id=:id", + {'id': 7}).fetchall(), +- [(7, u'jack')]) ++ [(7, 'jack')]) + + + # use :bindparam style +@@ -733,7 +733,7 @@ + # withstand a change? should this be + # more directly attempting to manipulate the identity_map ? + u1, u2, u3 = sess.query(User).all() +- for i, (key, value) in enumerate(sess.identity_map.iteritems()): ++ for i, (key, value) in enumerate(iter(sess.identity_map.items())): + if i == 2: + del u3 + gc_collect() +@@ -747,7 +747,7 @@ + @event.listens_for(m, "after_update") + def e(mapper, conn, target): + sess = object_session(target) +- for entry in sess.identity_map.values(): ++ for entry in list(sess.identity_map.values()): + entry.name = "5" + + a1, a2 = User(name="1"), User(name="2") +@@ -845,7 +845,7 @@ + u = session.query(User).filter_by(id=7).one() + + # get everything to load in both directions +- print [a.user for a in u.addresses] ++ print([a.user for a in u.addresses]) + + # then see if expunge fails + session.expunge(u) +@@ -1187,7 +1187,7 @@ + s.flush() + user = s.query(User).one() + user = None +- print s.identity_map ++ print(s.identity_map) + gc_collect() + assert len(s.identity_map) == 1 + +@@ -1207,7 +1207,7 @@ + s = create_session(weak_identity_map=False) + mapper(User, users) + +- for o in [User(name='u%s' % x) for x in xrange(10)]: ++ for o in [User(name='u%s' % x) for x in range(10)]: + s.add(o) + # o is still live after this loop... + +diff -r 9d0639b9d3be test/orm/test_subquery_relations.py +--- a/test/orm/test_subquery_relations.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_subquery_relations.py Sat Apr 27 19:42:17 2013 -0400 +@@ -1552,9 +1552,9 @@ + Movie = self.classes.Movie + + session = Session(testing.db) +- rscott = Director(name=u"Ridley Scott") +- alien = Movie(title=u"Alien") +- brunner = Movie(title=u"Blade Runner") ++ rscott = Director(name="Ridley Scott") ++ alien = Movie(title="Alien") ++ brunner = Movie(title="Blade Runner") + rscott.movies.append(brunner) + rscott.movies.append(alien) + session.add_all([rscott, alien, brunner]) +diff -r 9d0639b9d3be test/orm/test_unitofwork.py +--- a/test/orm/test_unitofwork.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_unitofwork.py Sat Apr 27 19:42:17 2013 -0400 +@@ -87,7 +87,7 @@ + + mapper(Test, uni_t1) + +- txt = u"\u0160\u0110\u0106\u010c\u017d" ++ txt = "\u0160\u0110\u0106\u010c\u017d" + t1 = Test(id=1, txt=txt) + self.assert_(t1.txt == txt) + +@@ -107,7 +107,7 @@ + 't2s': relationship(Test2)}) + mapper(Test2, uni_t2) + +- txt = u"\u0160\u0110\u0106\u010c\u017d" ++ txt = "\u0160\u0110\u0106\u010c\u017d" + t1 = Test(txt=txt) + t1.t2s.append(Test2()) + t1.t2s.append(Test2()) +@@ -132,16 +132,16 @@ + @classmethod + def define_tables(cls, metadata): + t1 = Table('unitable1', metadata, +- Column(u'méil', Integer, primary_key=True, key='a', test_needs_autoincrement=True), +- Column(u'\u6e2c\u8a66', Integer, key='b'), ++ Column('méil', Integer, primary_key=True, key='a', test_needs_autoincrement=True), ++ Column('\u6e2c\u8a66', Integer, key='b'), + Column('type', String(20)), + test_needs_fk=True, + test_needs_autoincrement=True) +- t2 = Table(u'Unitéble2', metadata, +- Column(u'méil', Integer, primary_key=True, key="cc", test_needs_autoincrement=True), +- Column(u'\u6e2c\u8a66', Integer, +- ForeignKey(u'unitable1.a'), key="d"), +- Column(u'\u6e2c\u8a66_2', Integer, key="e"), ++ t2 = Table('Unitéble2', metadata, ++ Column('méil', Integer, primary_key=True, key="cc", test_needs_autoincrement=True), ++ Column('\u6e2c\u8a66', Integer, ++ ForeignKey('unitable1.a'), key="d"), ++ Column('\u6e2c\u8a66_2', Integer, key="e"), + test_needs_fk=True, + test_needs_autoincrement=True) + +@@ -238,11 +238,12 @@ + Foo, t1 = self.classes.Foo, self.tables.t1 + + +- # Py3K +- #data = b"this is some data" +- # Py2K +- data = "this is some data" +- # end Py2K ++# start Py3K ++ data = b"this is some data" ++# end Py3K ++# start Py2K ++# data = "this is some data" ++# end Py2K + + mapper(Foo, t1) + +@@ -1054,13 +1055,13 @@ + session.flush() + + user_rows = users.select(users.c.id.in_([u.id])).execute().fetchall() +- eq_(user_rows[0].values(), [u.id, 'one2manytester']) ++ eq_(list(user_rows[0].values()), [u.id, 'one2manytester']) + + address_rows = addresses.select( + addresses.c.id.in_([a.id, a2.id]), + order_by=[addresses.c.email_address]).execute().fetchall() +- eq_(address_rows[0].values(), [a2.id, u.id, 'lala@test.org']) +- eq_(address_rows[1].values(), [a.id, u.id, 'one2many@test.org']) ++ eq_(list(address_rows[0].values()), [a2.id, u.id, 'lala@test.org']) ++ eq_(list(address_rows[1].values()), [a.id, u.id, 'one2many@test.org']) + + userid = u.id + addressid = a2.id +@@ -1071,7 +1072,7 @@ + + address_rows = addresses.select( + addresses.c.id == addressid).execute().fetchall() +- eq_(address_rows[0].values(), ++ eq_(list(address_rows[0].values()), + [addressid, userid, 'somethingnew@foo.com']) + self.assert_(u.id == userid and a2.id == addressid) + +@@ -1501,18 +1502,18 @@ + assert u.name == 'multitester' + + user_rows = users.select(users.c.id.in_([u.foo_id])).execute().fetchall() +- eq_(user_rows[0].values(), [u.foo_id, 'multitester']) ++ eq_(list(user_rows[0].values()), [u.foo_id, 'multitester']) + address_rows = addresses.select(addresses.c.id.in_([u.id])).execute().fetchall() +- eq_(address_rows[0].values(), [u.id, u.foo_id, 'multi@test.org']) ++ eq_(list(address_rows[0].values()), [u.id, u.foo_id, 'multi@test.org']) + + u.email = 'lala@hey.com' + u.name = 'imnew' + session.flush() + + user_rows = users.select(users.c.id.in_([u.foo_id])).execute().fetchall() +- eq_(user_rows[0].values(), [u.foo_id, 'imnew']) ++ eq_(list(user_rows[0].values()), [u.foo_id, 'imnew']) + address_rows = addresses.select(addresses.c.id.in_([u.id])).execute().fetchall() +- eq_(address_rows[0].values(), [u.id, u.foo_id, 'lala@hey.com']) ++ eq_(list(address_rows[0].values()), [u.id, u.foo_id, 'lala@hey.com']) + + session.expunge_all() + u = session.query(User).get(id) +@@ -1650,7 +1651,7 @@ + l = sa.select([users, addresses], + sa.and_(users.c.id==addresses.c.user_id, + addresses.c.id==a.id)).execute() +- eq_(l.first().values(), ++ eq_(list(l.first().values()), + [a.user.id, 'asdf8d', a.id, a.user_id, 'theater@foo.com']) + + def test_many_to_one_1(self): +@@ -2127,7 +2128,7 @@ + + assert assoc.count().scalar() == 2 + i.keywords = [] +- print i.keywords ++ print(i.keywords) + session.flush() + assert assoc.count().scalar() == 0 + +diff -r 9d0639b9d3be test/orm/test_unitofworkv2.py +--- a/test/orm/test_unitofworkv2.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_unitofworkv2.py Sat Apr 27 19:42:17 2013 -0400 +@@ -26,7 +26,7 @@ + def _assert_uow_size(self, session, expected ): + uow = self._get_test_uow(session) + postsort_actions = uow._generate_actions() +- print postsort_actions ++ print(postsort_actions) + eq_(len(postsort_actions), expected, postsort_actions) + + class UOWTest(_fixtures.FixtureTest, +@@ -125,12 +125,12 @@ + CompiledSQL( + "UPDATE addresses SET user_id=:user_id WHERE " + "addresses.id = :addresses_id", +- lambda ctx: [{u'addresses_id': a1.id, 'user_id': None}] ++ lambda ctx: [{'addresses_id': a1.id, 'user_id': None}] + ), + CompiledSQL( + "UPDATE addresses SET user_id=:user_id WHERE " + "addresses.id = :addresses_id", +- lambda ctx: [{u'addresses_id': a2.id, 'user_id': None}] ++ lambda ctx: [{'addresses_id': a2.id, 'user_id': None}] + ), + CompiledSQL( + "DELETE FROM users WHERE users.id = :id", +@@ -235,12 +235,12 @@ + CompiledSQL( + "UPDATE addresses SET user_id=:user_id WHERE " + "addresses.id = :addresses_id", +- lambda ctx: [{u'addresses_id': a1.id, 'user_id': None}] ++ lambda ctx: [{'addresses_id': a1.id, 'user_id': None}] + ), + CompiledSQL( + "UPDATE addresses SET user_id=:user_id WHERE " + "addresses.id = :addresses_id", +- lambda ctx: [{u'addresses_id': a2.id, 'user_id': None}] ++ lambda ctx: [{'addresses_id': a2.id, 'user_id': None}] + ), + CompiledSQL( + "DELETE FROM users WHERE users.id = :id", +@@ -1149,7 +1149,7 @@ + "nodes, node_to_nodes WHERE :param_1 = " + "node_to_nodes.right_node_id AND nodes.id = " + "node_to_nodes.left_node_id" , +- lambda ctx:{u'param_1': n1.id}, ++ lambda ctx:{'param_1': n1.id}, + ), + CompiledSQL( + "DELETE FROM node_to_nodes WHERE " +diff -r 9d0639b9d3be test/orm/test_update_delete.py +--- a/test/orm/test_update_delete.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_update_delete.py Sat Apr 27 19:42:17 2013 -0400 +@@ -188,22 +188,22 @@ + update({'age': User.age - 10}, synchronize_session='evaluate') + + eq_([john.age, jack.age, jill.age, jane.age], [25,37,29,27]) +- eq_(sess.query(User.age).order_by(User.id).all(), zip([25,37,29,27])) ++ eq_(sess.query(User.age).order_by(User.id).all(), list(zip([25,37,29,27]))) + + sess.query(User).filter(User.age > 29).\ + update({User.age: User.age - 10}, synchronize_session='evaluate') + eq_([john.age, jack.age, jill.age, jane.age], [25,27,29,27]) +- eq_(sess.query(User.age).order_by(User.id).all(), zip([25,27,29,27])) ++ eq_(sess.query(User.age).order_by(User.id).all(), list(zip([25,27,29,27]))) + + sess.query(User).filter(User.age > 27).\ + update({users.c.age: User.age - 10}, synchronize_session='evaluate') + eq_([john.age, jack.age, jill.age, jane.age], [25,27,19,27]) +- eq_(sess.query(User.age).order_by(User.id).all(), zip([25,27,19,27])) ++ eq_(sess.query(User.age).order_by(User.id).all(), list(zip([25,27,19,27]))) + + sess.query(User).filter(User.age == 25).\ + update({User.age: User.age - 10}, synchronize_session='fetch') + eq_([john.age, jack.age, jill.age, jane.age], [15,27,19,27]) +- eq_(sess.query(User.age).order_by(User.id).all(), zip([15,27,19,27])) ++ eq_(sess.query(User.age).order_by(User.id).all(), list(zip([15,27,19,27]))) + + def test_update_against_metadata(self): + User, users = self.classes.User, self.tables.users +@@ -211,7 +211,7 @@ + sess = Session() + + sess.query(users).update({users.c.age: 29}, synchronize_session=False) +- eq_(sess.query(User.age).order_by(User.id).all(), zip([29,29,29,29])) ++ eq_(sess.query(User.age).order_by(User.id).all(), list(zip([29,29,29,29]))) + + def test_update_with_bindparams(self): + User = self.classes.User +@@ -224,7 +224,7 @@ + update({'age': User.age - 10}, synchronize_session='fetch') + + eq_([john.age, jack.age, jill.age, jane.age], [25,37,29,27]) +- eq_(sess.query(User.age).order_by(User.id).all(), zip([25,37,29,27])) ++ eq_(sess.query(User.age).order_by(User.id).all(), list(zip([25,37,29,27]))) + + def test_update_without_load(self): + User = self.classes.User +@@ -233,7 +233,7 @@ + + sess.query(User).filter(User.id == 3).\ + update({'age': 44}, synchronize_session='fetch') +- eq_(sess.query(User.age).order_by(User.id).all(), zip([25,47,44,37])) ++ eq_(sess.query(User.age).order_by(User.id).all(), list(zip([25,47,44,37]))) + + def test_update_changes_resets_dirty(self): + User = self.classes.User +@@ -300,7 +300,7 @@ + update({'age': User.age - 10}, synchronize_session='fetch') + + eq_([john.age, jack.age, jill.age, jane.age], [25,37,29,27]) +- eq_(sess.query(User.age).order_by(User.id).all(), zip([25,37,29,27])) ++ eq_(sess.query(User.age).order_by(User.id).all(), list(zip([25,37,29,27]))) + + @testing.fails_if(lambda: not testing.db.dialect.supports_sane_rowcount) + def test_update_returns_rowcount(self): +@@ -334,7 +334,7 @@ + sess.query(User).update({'age': 42}, synchronize_session='evaluate') + + eq_([john.age, jack.age, jill.age, jane.age], [42,42,42,42]) +- eq_(sess.query(User.age).order_by(User.id).all(), zip([42,42,42,42])) ++ eq_(sess.query(User.age).order_by(User.id).all(), list(zip([42,42,42,42]))) + + def test_delete_all(self): + User = self.classes.User +@@ -516,7 +516,7 @@ + + eq_([foo.title, bar.title, baz.title], ['foofoo','barbar', 'baz']) + eq_(sess.query(Document.title).order_by(Document.id).all(), +- zip(['foofoo','barbar', 'baz'])) ++ list(zip(['foofoo','barbar', 'baz']))) + + def test_update_with_explicit_joinedload(self): + User = self.classes.User +@@ -528,7 +528,7 @@ + update({'age': User.age - 10}, synchronize_session='fetch') + + eq_([john.age, jack.age, jill.age, jane.age], [25,37,29,27]) +- eq_(sess.query(User.age).order_by(User.id).all(), zip([25,37,29,27])) ++ eq_(sess.query(User.age).order_by(User.id).all(), list(zip([25,37,29,27]))) + + def test_delete_with_eager_relationships(self): + Document = self.classes.Document +@@ -538,7 +538,7 @@ + sess.query(Document).filter(Document.user_id == 1).\ + delete(synchronize_session=False) + +- eq_(sess.query(Document.title).all(), zip(['baz'])) ++ eq_(sess.query(Document.title).all(), list(zip(['baz']))) + + class UpdateDeleteFromTest(fixtures.MappedTest): + @classmethod +diff -r 9d0639b9d3be test/orm/test_utils.py +--- a/test/orm/test_utils.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/orm/test_utils.py Sat Apr 27 19:42:17 2013 -0400 +@@ -52,10 +52,10 @@ + alias = aliased(Point) + + assert Point.zero +- # Py2K +- # TODO: what is this testing ?? +- assert not getattr(alias, 'zero') +- # end Py2K ++# start Py2K ++# # TODO: what is this testing ?? ++# assert not getattr(alias, 'zero') ++# end Py2K + + def test_classmethods(self): + class Point(object): +@@ -123,17 +123,19 @@ + self.func = func + def __get__(self, instance, owner): + if instance is None: +- # Py3K +- #args = (self.func, owner) +- # Py2K +- args = (self.func, owner, owner.__class__) +- # end Py2K ++# start Py3K ++ args = (self.func, owner) ++# end Py3K ++# start Py2K ++# args = (self.func, owner, owner.__class__) ++# end Py2K + else: +- # Py3K +- #args = (self.func, instance) +- # Py2K +- args = (self.func, instance, owner) +- # end Py2K ++# start Py3K ++ args = (self.func, instance) ++# end Py3K ++# start Py2K ++# args = (self.func, instance, owner) ++# end Py2K + return types.MethodType(*args) + + class PropertyDescriptor(object): +diff -r 9d0639b9d3be test/perf/insertspeed.py +--- a/test/perf/insertspeed.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/perf/insertspeed.py Sat Apr 27 19:42:17 2013 -0400 +@@ -13,18 +13,18 @@ + + def sa_unprofiled_insertmany(n): + i = Person_table.insert() +- i.execute([{'name':'John Doe','sex':1,'age':35} for j in xrange(n)]) ++ i.execute([{'name':'John Doe','sex':1,'age':35} for j in range(n)]) + + def sqlite_unprofiled_insertmany(n): + conn = db.connect().connection + c = conn.cursor() +- persons = [('john doe', 1, 35) for i in xrange(n)] ++ persons = [('john doe', 1, 35) for i in range(n)] + c.executemany("insert into Person(name, sex, age) values (?,?,?)", persons) + + @profiling.profiled('sa_profiled_insert_many', always=True) + def sa_profiled_insert_many(n): + i = Person_table.insert() +- i.execute([{'name':'John Doe','sex':1,'age':35} for j in xrange(n)]) ++ i.execute([{'name':'John Doe','sex':1,'age':35} for j in range(n)]) + s = Person_table.select() + r = s.execute() + res = [[value for value in row] for row in r.fetchall()] +@@ -32,7 +32,7 @@ + def sqlite_unprofiled_insert(n): + conn = db.connect().connection + c = conn.cursor() +- for j in xrange(n): ++ for j in range(n): + c.execute("insert into Person(name, sex, age) values (?,?,?)", + ('john doe', 1, 35)) + +@@ -40,13 +40,13 @@ + # Another option is to build Person_table.insert() outside of the + # loop. But it doesn't make much of a difference, so might as well + # use the worst-case/naive version here. +- for j in xrange(n): ++ for j in range(n): + Person_table.insert().execute({'name':'John Doe','sex':1,'age':35}) + + @profiling.profiled('sa_profiled_insert', always=True) + def sa_profiled_insert(n): + i = Person_table.insert() +- for j in xrange(n): ++ for j in range(n): + i.execute({'name':'John Doe','sex':1,'age':35}) + s = Person_table.select() + r = s.execute() +@@ -69,12 +69,12 @@ + metadata.drop_all() + metadata.create_all() + +- print "%s (%s)" % (label, ', '.join([str(a) for a in args])) ++ print("%s (%s)" % (label, ', '.join([str(a) for a in args]))) + fn(*args, **kw) + + def all(): + try: +- print "Bulk INSERTS via executemany():\n" ++ print("Bulk INSERTS via executemany():\n") + + run_timed(sqlite_unprofiled_insertmany, + 'pysqlite bulk insert', +@@ -88,7 +88,7 @@ + 'SQLAlchemy bulk insert/select, profiled', + 50000) + +- print "\nIndividual INSERTS via execute():\n" ++ print("\nIndividual INSERTS via execute():\n") + + run_timed(sqlite_unprofiled_insert, + "pysqlite individual insert", +diff -r 9d0639b9d3be test/perf/objselectspeed.py +--- a/test/perf/objselectspeed.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/perf/objselectspeed.py Sat Apr 27 19:42:17 2013 -0400 +@@ -36,7 +36,7 @@ + metadata.create_all() + i = Person_table.insert() + data = [{'name':'John Doe','sex':1,'age':35, 'type':'employee'}] * 100 +- for j in xrange(500): ++ for j in range(500): + i.execute(data) + + # note we arent fetching from employee_table, +@@ -46,7 +46,7 @@ + #for j in xrange(500): + # i.execute(data) + +- print "Inserted 50,000 rows" ++ print("Inserted 50,000 rows") + + def sqlite_select(entity_cls): + conn = db.connect().connection +@@ -89,10 +89,10 @@ + t, t2 = 0, 0 + def usage(label): + now = resource.getrusage(resource.RUSAGE_SELF) +- print "%s: %0.3fs real, %0.3fs user, %0.3fs sys" % ( ++ print("%s: %0.3fs real, %0.3fs user, %0.3fs sys" % ( + label, t2 - t, + now.ru_utime - usage.last.ru_utime, +- now.ru_stime - usage.last.ru_stime) ++ now.ru_stime - usage.last.ru_stime)) + usage.snap(now) + usage.snap = lambda stats=None: setattr( + usage, 'last', stats or resource.getrusage(resource.RUSAGE_SELF)) +diff -r 9d0639b9d3be test/perf/objupdatespeed.py +--- a/test/perf/objupdatespeed.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/perf/objupdatespeed.py Sat Apr 27 19:42:17 2013 -0400 +@@ -39,12 +39,12 @@ + i.execute(data) + + i = Email_table.insert() +- for j in xrange(1, NUM + 1): ++ for j in range(1, NUM + 1): + i.execute(address='foo@bar', person_id=j) + if j % 2: + i.execute(address='baz@quux', person_id=j) + +- print "Inserted %d rows." % (NUM + NUM + (NUM // 2)) ++ print("Inserted %d rows." % (NUM + NUM + (NUM // 2))) + + def orm_select(session): + return session.query(Person).all() +@@ -63,10 +63,10 @@ + t, t2 = 0, 0 + def usage(label): + now = resource.getrusage(resource.RUSAGE_SELF) +- print "%s: %0.3fs real, %0.3fs user, %0.3fs sys" % ( ++ print("%s: %0.3fs real, %0.3fs user, %0.3fs sys" % ( + label, t2 - t, + now.ru_utime - usage.last.ru_utime, +- now.ru_stime - usage.last.ru_stime) ++ now.ru_stime - usage.last.ru_stime)) + usage.snap(now) + usage.snap = lambda stats=None: setattr( + usage, 'last', stats or resource.getrusage(resource.RUSAGE_SELF)) +diff -r 9d0639b9d3be test/perf/orm2010.py +--- a/test/perf/orm2010.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/perf/orm2010.py Sat Apr 27 19:42:17 2013 -0400 +@@ -95,7 +95,7 @@ + name="Boss %d" % i, + golf_average=Decimal(random.randint(40, 150)) + ) +- for i in xrange(1000) ++ for i in range(1000) + ] + + sess.add_all(bosses) +@@ -107,7 +107,7 @@ + name="Grunt %d" % i, + savings=Decimal(random.randint(5000000, 15000000) / 100) + ) +- for i in xrange(10000) ++ for i in range(10000) + ] + + # Assign each Grunt a Boss. Look them up in the DB +@@ -149,15 +149,15 @@ + + counts_by_methname = dict((key[2], stats.stats[key][0]) for key in stats.stats) + +-print "SQLA Version: %s" % __version__ +-print "Total calls %d" % stats.total_calls +-print "Total cpu seconds: %.2f" % stats.total_tt +-print 'Total execute calls: %d' \ ++print("SQLA Version: %s" % __version__) ++print("Total calls %d" % stats.total_calls) ++print("Total cpu seconds: %.2f" % stats.total_tt) ++print('Total execute calls: %d' \ + % counts_by_methname[""] +-print 'Total executemany calls: %d' \ ++ "objects>"]) ++print('Total executemany calls: %d' \ + % counts_by_methname.get("", 0) ++ "objects>", 0)) + + #stats.sort_stats('time', 'calls') + #stats.print_stats() +diff -r 9d0639b9d3be test/perf/ormsession.py +--- a/test/perf/ormsession.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/perf/ormsession.py Sat Apr 27 19:42:17 2013 -0400 +@@ -81,9 +81,9 @@ + + transaction = con.begin() + data, subdata = [], [] +- for item_id in xrange(1, q_items + 1): ++ for item_id in range(1, q_items + 1): + data.append({'name': "item number %s" % item_id}) +- for subitem_id in xrange(1, (item_id % q_sub_per_item) + 1): ++ for subitem_id in range(1, (item_id % q_sub_per_item) + 1): + subdata.append({'item_id': item_id, + 'name': "subitem number %s" % subitem_id}) + if item_id % 100 == 0: +@@ -99,7 +99,7 @@ + + transaction = con.begin() + data = [] +- for customer_id in xrange(1, q_customers): ++ for customer_id in range(1, q_customers): + data.append({'name': "customer number %s" % customer_id}) + if customer_id % 100 == 0: + customers.insert().execute(*data) +@@ -111,7 +111,7 @@ + transaction = con.begin() + data, subdata = [], [] + order_t = int(time.time()) - (5000 * 5 * 60) +- current = xrange(1, q_customers) ++ current = range(1, q_customers) + step, purchase_id = 1, 0 + while current: + next = [] +diff -r 9d0639b9d3be test/perf/stress_all.py +--- a/test/perf/stress_all.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/perf/stress_all.py Sat Apr 27 19:42:17 2013 -0400 +@@ -2,7 +2,7 @@ + from datetime import * + import decimal + #from fastdec import mpd as Decimal +-from cPickle import dumps, loads ++from pickle import dumps, loads + + #from sqlalchemy.dialects.postgresql.base import ARRAY + +@@ -42,9 +42,9 @@ + + def getitem_long_results(raw_results): + return [ +- (r[0L], +- r[1L], r[2L], r[3L], r[4L], r[5L], +- r[6L], r[7L], r[8L], r[9L], r[10L]) ++ (r[0], ++ r[1], r[2], r[3], r[4], r[5], ++ r[6], r[7], r[8], r[9], r[10]) + for r in raw_results] + + def getitem_obj_results(raw_results): +@@ -128,7 +128,7 @@ + + # Unicode + def genunicodevalue(rnum, fnum): +- return (rnum % 4) and (u"value%d" % fnum) or None ++ return (rnum % 4) and ("value%d" % fnum) or None + unicodetest = (Unicode(20, ), genunicodevalue, + dict(num_records=100000)) + # dict(engineurl='mysql:///test', freshdata=False)) +@@ -139,10 +139,10 @@ + pickletypetest, typedecoratortest, unicodetest] + for engineurl in ('postgresql://scott:tiger@localhost/test', + 'sqlite://', 'mysql://scott:tiger@localhost/test'): +- print "\n%s\n" % engineurl ++ print("\n%s\n" % engineurl) + for datatype, genvalue, kwargs in tests: +- print "%s:" % getattr(datatype, '__name__', +- datatype.__class__.__name__), ++ print("%s:" % getattr(datatype, '__name__', ++ datatype.__class__.__name__), end=' ') + profile_and_time_dbfunc(iter_results, datatype, genvalue, + profile=False, engineurl=engineurl, + verbose=verbose, **kwargs) +@@ -158,13 +158,13 @@ + slice_results] + for engineurl in ('postgresql://scott:tiger@localhost/test', + 'sqlite://', 'mysql://scott:tiger@localhost/test'): +- print "\n%s\n" % engineurl ++ print("\n%s\n" % engineurl) + test_table = prepare(Unicode(20,), + genunicodevalue, + num_fields=10, num_records=100000, + verbose=verbose, engineurl=engineurl) + for method in methods: +- print "%s:" % method.__name__, ++ print("%s:" % method.__name__, end=' ') + time_dbfunc(test_table, method, genunicodevalue, + num_fields=10, num_records=100000, profile=False, + verbose=verbose) +@@ -174,9 +174,9 @@ + # -------------------------------- + + def pickletofile_results(raw_results): +- from cPickle import dump, load ++ from pickle import dump, load + for protocol in (0, 1, 2): +- print "dumping protocol %d..." % protocol ++ print("dumping protocol %d..." % protocol) + f = file('noext.pickle%d' % protocol, 'wb') + dump(raw_results, f, protocol) + f.close() +@@ -198,7 +198,7 @@ + num_fields=10, num_records=10000) + funcs = [pickle_rows, pickle_results] + for func in funcs: +- print "%s:" % func.__name__, ++ print("%s:" % func.__name__, end=' ') + time_dbfunc(test_table, func, genunicodevalue, + num_records=10000, profile=False, verbose=verbose) + +@@ -217,9 +217,9 @@ + + def get_results(): + return session.query(Test).all() +- print "ORM:", ++ print("ORM:", end=' ') + for engineurl in ('postgresql:///test', 'sqlite://', 'mysql:///test'): +- print "\n%s\n" % engineurl ++ print("\n%s\n" % engineurl) + profile_and_time_dbfunc(getattr_results, Unicode(20), genunicodevalue, + class_=Test, getresults_func=get_results, + engineurl=engineurl, #freshdata=False, +diff -r 9d0639b9d3be test/perf/stresstest.py +--- a/test/perf/stresstest.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/perf/stresstest.py Sat Apr 27 19:42:17 2013 -0400 +@@ -17,13 +17,13 @@ + + def insert(test_table, num_fields, num_records, genvalue, verbose=True): + if verbose: +- print "building insert values...", ++ print("building insert values...", end=' ') + sys.stdout.flush() + values = [dict(("field%d" % fnum, genvalue(rnum, fnum)) + for fnum in range(num_fields)) + for rnum in range(num_records)] + if verbose: +- print "inserting...", ++ print("inserting...", end=' ') + sys.stdout.flush() + def db_insert(): + test_table.insert().execute(values) +@@ -32,11 +32,11 @@ + "from __main__ import db_insert", + number=1) + if verbose: +- print "%s" % round(timing, 3) ++ print("%s" % round(timing, 3)) + + def check_result(results, num_fields, genvalue, verbose=True): + if verbose: +- print "checking...", ++ print("checking...", end=' ') + sys.stdout.flush() + for rnum, row in enumerate(results): + expected = tuple([rnum + 1] + +@@ -49,28 +49,28 @@ + + def nicer_res(values, printvalues=False): + if printvalues: +- print values ++ print(values) + min_time = min(values) + return round(min_time, 3), round(avgdev(values, min_time), 2) + + def profile_func(func_name, verbose=True): + if verbose: +- print "profiling...", ++ print("profiling...", end=' ') + sys.stdout.flush() + cProfile.run('%s()' % func_name, 'prof') + + def time_func(func_name, num_tests=1, verbose=True): + if verbose: +- print "timing...", ++ print("timing...", end=' ') + sys.stdout.flush() + timings = timeit.repeat('%s()' % func_name, + "from __main__ import %s" % func_name, + number=num_tests, repeat=5) + avg, dev = nicer_res(timings) + if verbose: +- print "%s (%s)" % (avg, dev) ++ print("%s (%s)" % (avg, dev)) + else: +- print avg ++ print(avg) + + def profile_and_time(func_name, num_tests=1): + profile_func(func_name) +@@ -121,7 +121,7 @@ + check_results=check_result, profile=True, + check_leaks=True, print_leaks=False, verbose=True): + if verbose: +- print "testing '%s'..." % test_func.__name__, ++ print("testing '%s'..." % test_func.__name__, end=' ') + sys.stdout.flush() + if class_ is not None: + clear_mappers() +@@ -148,12 +148,12 @@ + diff = hashable_objects_after - hashable_objects_before + ldiff = len(diff) + if print_leaks and ldiff < num_records: +- print "\n*** hashable objects leaked (%d) ***" % ldiff +- print '\n'.join(map(str, diff)) +- print "***\n" ++ print("\n*** hashable objects leaked (%d) ***" % ldiff) ++ print('\n'.join(map(str, diff))) ++ print("***\n") + + if num_leaks > num_records: +- print "(leaked: %d !)" % num_leaks, ++ print("(leaked: %d !)" % num_leaks, end=' ') + if profile: + profile_func('test', verbose) + time_func('test', num_tests, verbose) +diff -r 9d0639b9d3be test/perf/threaded_compile.py +--- a/test/perf/threaded_compile.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/perf/threaded_compile.py Sat Apr 27 19:42:17 2013 -0400 +@@ -4,7 +4,7 @@ + + from sqlalchemy import * + from sqlalchemy.orm import * +-import thread, time ++import _thread, time + from sqlalchemy.orm import mapperlib + + +@@ -42,20 +42,20 @@ + + def run1(): + for i in range(50): +- print "T1", thread.get_ident() ++ print("T1", _thread.get_ident()) + class_mapper(T1) + time.sleep(.05) + + def run2(): + for i in range(50): +- print "T2", thread.get_ident() ++ print("T2", _thread.get_ident()) + class_mapper(T2) + time.sleep(.057) + + def run3(): + for i in range(50): + def foo(): +- print "FOO", thread.get_ident() ++ print("FOO", _thread.get_ident()) + class Foo(object):pass + mapper(Foo, t3) + class_mapper(Foo).compile() +@@ -64,12 +64,12 @@ + + mapper(T1, t1, properties={'t2':relationship(T2, backref="t1")}) + mapper(T2, t2) +-print "START" ++print("START") + for j in range(0, 5): +- thread.start_new_thread(run1, ()) +- thread.start_new_thread(run2, ()) +- thread.start_new_thread(run3, ()) +- thread.start_new_thread(run3, ()) +- thread.start_new_thread(run3, ()) +-print "WAIT" ++ _thread.start_new_thread(run1, ()) ++ _thread.start_new_thread(run2, ()) ++ _thread.start_new_thread(run3, ()) ++ _thread.start_new_thread(run3, ()) ++ _thread.start_new_thread(run3, ()) ++print("WAIT") + time.sleep(5) +diff -r 9d0639b9d3be test/sql/test_compiler.py +--- a/test/sql/test_compiler.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/sql/test_compiler.py Sat Apr 27 19:42:17 2013 -0400 +@@ -661,13 +661,13 @@ + s = select([table1.c.myid]).as_scalar() + try: + s.c.foo +- except exc.InvalidRequestError, err: ++ except exc.InvalidRequestError as err: + assert str(err) \ + == 'Scalar Select expression has no columns; use this '\ + 'object directly within a column-level expression.' + try: + s.columns.foo +- except exc.InvalidRequestError, err: ++ except exc.InvalidRequestError as err: + assert str(err) \ + == 'Scalar Select expression has no columns; use this '\ + 'object directly within a column-level expression.' +@@ -1116,9 +1116,9 @@ + + # test unicode + self.assert_compile(select( +- [u"foobar(a)", u"pk_foo_bar(syslaal)"], +- u"a = 12", +- from_obj=[u"foobar left outer join lala on foobar.foo = lala.foo"] ++ ["foobar(a)", "pk_foo_bar(syslaal)"], ++ "a = 12", ++ from_obj=["foobar left outer join lala on foobar.foo = lala.foo"] + ), + "SELECT foobar(a), pk_foo_bar(syslaal) FROM foobar " + "left outer join lala on foobar.foo = lala.foo WHERE a = 12" +@@ -2245,7 +2245,7 @@ + func.lala(table1.c.name).label('gg')]) + + eq_( +- s1.c.keys(), ++ list(s1.c.keys()), + ['myid', 'foobar', str(f1), 'gg'] + ) + +@@ -2273,7 +2273,7 @@ + t = table1 + + s1 = select([col], from_obj=t) +- assert s1.c.keys() == [key], s1.c.keys() ++ assert list(s1.c.keys()) == [key], list(s1.c.keys()) + + if label: + self.assert_compile(s1, +@@ -2679,11 +2679,11 @@ + def test_reraise_of_column_spec_issue_unicode(self): + MyType = self._illegal_type_fixture() + t1 = Table('t', MetaData(), +- Column(u'méil', MyType()) ++ Column('méil', MyType()) + ) + assert_raises_message( + exc.CompileError, +- ur"\(in table 't', column 'méil'\): Couldn't compile type", ++ r"\(in table 't', column 'méil'\): Couldn't compile type", + schema.CreateTable(t1).compile + ) + +diff -r 9d0639b9d3be test/sql/test_defaults.py +--- a/test/sql/test_defaults.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/sql/test_defaults.py Sat Apr 27 19:42:17 2013 -0400 +@@ -600,7 +600,7 @@ + nonai.insert().execute(data='row 1') + nonai.insert().execute(data='row 2') + assert False +- except sa.exc.DBAPIError, e: ++ except sa.exc.DBAPIError as e: + assert True + + nonai.insert().execute(id=1, data='row 1') +@@ -649,7 +649,7 @@ + def _assert_seq_result(self, ret): + """asserts return of next_value is an int""" + +- assert isinstance(ret, (int, long)) ++ assert isinstance(ret, int) + assert ret > 0 + + def test_implicit_connectionless(self): +@@ -781,7 +781,7 @@ + ] + start = seq.start or 1 + inc = seq.increment or 1 +- assert values == list(xrange(start, start + inc * 3, inc)) ++ assert values == list(range(start, start + inc * 3, inc)) + + finally: + seq.drop(testing.db) +@@ -1156,20 +1156,22 @@ + c = Column(Unicode(32)) + + def test_unicode_default(self): +- # Py3K +- #default = 'foo' +- # Py2K +- default = u'foo' +- # end Py2K ++# start Py3K ++ default = 'foo' ++# end Py3K ++# start Py2K ++# default = u'foo' ++# end Py2K + c = Column(Unicode(32), default=default) + + + def test_nonunicode_default(self): +- # Py3K +- #default = b'foo' +- # Py2K +- default = 'foo' +- # end Py2K ++# start Py3K ++ default = b'foo' ++# end Py3K ++# start Py2K ++# default = 'foo' ++# end Py2K + assert_raises_message( + sa.exc.SAWarning, + "Unicode column received non-unicode default value.", +diff -r 9d0639b9d3be test/sql/test_functions.py +--- a/test/sql/test_functions.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/sql/test_functions.py Sat Apr 27 19:42:17 2013 -0400 +@@ -381,7 +381,7 @@ + assert t.select(t.c.id == id).execute().first()['value'] == 9 + t.update(values={t.c.value: func.length("asdf")}).execute() + assert t.select().execute().first()['value'] == 4 +- print "--------------------------" ++ print("--------------------------") + t2.insert().execute() + t2.insert(values=dict(value=func.length("one"))).execute() + t2.insert(values=dict(value=func.length("asfda") + -19)).\ +@@ -409,7 +409,7 @@ + + t2.update(values={t2.c.value: func.length("asfdaasdf"), + t2.c.stuff: "foo"}).execute() +- print "HI", select([t2.c.value, t2.c.stuff]).execute().first() ++ print("HI", select([t2.c.value, t2.c.stuff]).execute().first()) + eq_(select([t2.c.value, t2.c.stuff]).execute().first(), + (9, "foo") + ) +diff -r 9d0639b9d3be test/sql/test_generative.py +--- a/test/sql/test_generative.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/sql/test_generative.py Sat Apr 27 19:42:17 2013 -0400 +@@ -176,7 +176,7 @@ + canary = [] + def visit(binary, l, r): + canary.append((binary.operator, l, r)) +- print binary.operator, l, r ++ print(binary.operator, l, r) + sql_util.visit_binary_product(visit, expr) + eq_( + canary, expected +@@ -433,7 +433,7 @@ + clause2 = Vis().traverse(clause) + assert c1 == str(clause) + assert str(clause2) == c1 + " SOME MODIFIER=:lala" +- assert clause.bindparams.keys() == ['bar'] ++ assert list(clause.bindparams.keys()) == ['bar'] + assert set(clause2.bindparams.keys()) == set(['bar', 'lala']) + + def test_select(self): +@@ -446,8 +446,8 @@ + s3 = Vis().traverse(s2) + assert str(s3) == s3_assert + assert str(s2) == s2_assert +- print str(s2) +- print str(s3) ++ print(str(s2)) ++ print(str(s3)) + class Vis(ClauseVisitor): + def visit_select(self, select): + select.append_whereclause(t1.c.col2 == 7) +@@ -459,8 +459,8 @@ + def visit_select(self, select): + select.append_whereclause(t1.c.col3 == 9) + s4 = Vis().traverse(s3) +- print str(s3) +- print str(s4) ++ print(str(s3)) ++ print(str(s4)) + assert str(s4) == s4_assert + assert str(s3) == s3_assert + +@@ -471,8 +471,8 @@ + binary.left = t1.c.col1 + binary.right = bindparam("col1", unique=True) + s5 = Vis().traverse(s4) +- print str(s4) +- print str(s5) ++ print(str(s4)) ++ print(str(s5)) + assert str(s5) == s5_assert + assert str(s4) == s4_assert + +diff -r 9d0639b9d3be test/sql/test_metadata.py +--- a/test/sql/test_metadata.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/sql/test_metadata.py Sat Apr 27 19:42:17 2013 -0400 +@@ -89,7 +89,7 @@ + msgs.append("attach %s.%s" % (t.name, c.name)) + c1 = Column('foo', String()) + m = MetaData() +- for i in xrange(3): ++ for i in range(3): + cx = c1.copy() + # as of 0.7, these events no longer copy. its expected + # that listeners will be re-established from the +@@ -511,7 +511,7 @@ + def _get_key(i): + return [i.name, i.unique] + \ + sorted(i.kwargs.items()) + \ +- i.columns.keys() ++ list(i.columns.keys()) + + eq_( + sorted([_get_key(i) for i in table.indexes]), +diff -r 9d0639b9d3be test/sql/test_query.py +--- a/test/sql/test_query.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/sql/test_query.py Sat Apr 27 19:42:17 2013 -0400 +@@ -367,10 +367,10 @@ + ) + if use_labels: + eq_(result[0]['query_users_user_id'], 7) +- eq_(result[0].keys(), ["query_users_user_id", "query_users_user_name"]) ++ eq_(list(result[0].keys()), ["query_users_user_id", "query_users_user_name"]) + else: + eq_(result[0]['user_id'], 7) +- eq_(result[0].keys(), ["user_id", "user_name"]) ++ eq_(list(result[0].keys()), ["user_id", "user_name"]) + + eq_(result[0][0], 7) + eq_(result[0][users.c.user_id], 7) +@@ -523,13 +523,13 @@ + + def a_eq(got, wanted): + if got != wanted: +- print "Wanted %s" % wanted +- print "Received %s" % got ++ print("Wanted %s" % wanted) ++ print("Received %s" % got) + self.assert_(got == wanted, got) + + a_eq(prep('select foo'), 'select foo') + a_eq(prep("time='12:30:00'"), "time='12:30:00'") +- a_eq(prep(u"time='12:30:00'"), u"time='12:30:00'") ++ a_eq(prep("time='12:30:00'"), "time='12:30:00'") + a_eq(prep(":this:that"), ":this:that") + a_eq(prep(":this :that"), "? ?") + a_eq(prep("(:this),(:that :other)"), "(?),(? ?)") +@@ -769,7 +769,7 @@ + ).first() + eq_(r['user_id'], 1) + eq_(r['user_name'], "john") +- eq_(r.keys(), ["user_id", "user_name"]) ++ eq_(list(r.keys()), ["user_id", "user_name"]) + + @testing.only_on("sqlite", "sqlite specific feature") + def test_column_accessor_sqlite_raw(self): +@@ -784,7 +784,7 @@ + assert 'user_name' not in r + eq_(r['query_users.user_id'], 1) + eq_(r['query_users.user_name'], "john") +- eq_(r.keys(), ["query_users.user_id", "query_users.user_name"]) ++ eq_(list(r.keys()), ["query_users.user_id", "query_users.user_name"]) + + @testing.only_on("sqlite", "sqlite specific feature") + def test_column_accessor_sqlite_translated(self): +@@ -799,7 +799,7 @@ + eq_(r['user_name'], "john") + eq_(r['query_users.user_id'], 1) + eq_(r['query_users.user_name'], "john") +- eq_(r.keys(), ["user_id", "user_name"]) ++ eq_(list(r.keys()), ["user_id", "user_name"]) + + def test_column_accessor_labels_w_dots(self): + users.insert().execute( +@@ -812,7 +812,7 @@ + eq_(r['query_users.user_id'], 1) + eq_(r['query_users.user_name'], "john") + assert "user_name" not in r +- eq_(r.keys(), ["query_users.user_id", "query_users.user_name"]) ++ eq_(list(r.keys()), ["query_users.user_id", "query_users.user_name"]) + + def test_column_accessor_unary(self): + users.insert().execute( +@@ -889,7 +889,7 @@ + ]) + ).first() + +- eq_(row.keys(), ["case_insensitive", "CaseSensitive"]) ++ eq_(list(row.keys()), ["case_insensitive", "CaseSensitive"]) + eq_(row["case_insensitive"], 1) + eq_(row["CaseSensitive"], 2) + +@@ -911,7 +911,7 @@ + ]) + ).first() + +- eq_(row.keys(), ["case_insensitive", "CaseSensitive"]) ++ eq_(list(row.keys()), ["case_insensitive", "CaseSensitive"]) + eq_(row["case_insensitive"], 1) + eq_(row["CaseSensitive"], 2) + eq_(row["Case_insensitive"],1) +@@ -1072,14 +1072,14 @@ + def test_keys(self): + users.insert().execute(user_id=1, user_name='foo') + r = users.select().execute() +- eq_([x.lower() for x in r.keys()], ['user_id', 'user_name']) ++ eq_([x.lower() for x in list(r.keys())], ['user_id', 'user_name']) + r = r.first() +- eq_([x.lower() for x in r.keys()], ['user_id', 'user_name']) ++ eq_([x.lower() for x in list(r.keys())], ['user_id', 'user_name']) + + def test_items(self): + users.insert().execute(user_id=1, user_name='foo') + r = users.select().execute().first() +- eq_([(x[0].lower(), x[1]) for x in r.items()], [('user_id', 1), ('user_name', 'foo')]) ++ eq_([(x[0].lower(), x[1]) for x in list(r.items())], [('user_id', 1), ('user_name', 'foo')]) + + def test_len(self): + users.insert().execute(user_id=1, user_name='foo') +@@ -1098,8 +1098,8 @@ + r = users.select(users.c.user_id==1).execute().first() + eq_(r[0], 1) + eq_(r[1], 'foo') +- eq_([x.lower() for x in r.keys()], ['user_id', 'user_name']) +- eq_(r.values(), [1, 'foo']) ++ eq_([x.lower() for x in list(r.keys())], ['user_id', 'user_name']) ++ eq_(list(r.values()), [1, 'foo']) + + def test_column_order_with_text_query(self): + # should return values in query order +@@ -1107,8 +1107,8 @@ + r = testing.db.execute('select user_name, user_id from query_users').first() + eq_(r[0], 'foo') + eq_(r[1], 1) +- eq_([x.lower() for x in r.keys()], ['user_name', 'user_id']) +- eq_(r.values(), ['foo', 1]) ++ eq_([x.lower() for x in list(r.keys())], ['user_name', 'user_id']) ++ eq_(list(r.values()), ['foo', 1]) + + @testing.crashes('oracle', 'FIXME: unknown, varify not fails_on()') + @testing.crashes('firebird', 'An identifier must begin with a letter') +@@ -1137,7 +1137,7 @@ + self.assert_(r['_parent'] == 'Hidden parent') + self.assert_(r['_row'] == 'Hidden row') + try: +- print r._parent, r._row ++ print(r._parent, r._row) + self.fail('Should not allow access to private attributes') + except AttributeError: + pass # expected +@@ -2334,7 +2334,7 @@ + expr = select( + [t1.c.t1_id, t2.c.t2_id, t3.c.t3_id], + from_obj=[(t1.join(t2).outerjoin(t3, criteria))]) +- print expr ++ print(expr) + self.assertRows(expr, [(10, 20, 30), (11, 21, None)]) + + def test_mixed_where(self): +@@ -2416,7 +2416,7 @@ + select([ + flds.c.intcol, func.row_number().over(order_by=flds.c.strcol) + ]).execute().fetchall(), +- [(13, 1L), (5, 2L)] ++ [(13, 1), (5, 2)] + ) + + +diff -r 9d0639b9d3be test/sql/test_quote.py +--- a/test/sql/test_quote.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/sql/test_quote.py Sat Apr 27 19:42:17 2013 -0400 +@@ -552,8 +552,8 @@ + + def a_eq(have, want): + if have != want: +- print "Wanted %s" % want +- print "Received %s" % have ++ print("Wanted %s" % want) ++ print("Received %s" % have) + self.assert_(have == want) + + a_eq(unformat('foo'), ['foo']) +@@ -584,13 +584,13 @@ + + def a_eq(have, want): + if have != want: +- print "Wanted %s" % want +- print "Received %s" % have ++ print("Wanted %s" % want) ++ print("Received %s" % have) + self.assert_(have == want) + + a_eq(unformat('foo'), ['foo']) + a_eq(unformat('`foo`'), ['foo']) +- a_eq(unformat(`'foo'`), ["'foo'"]) ++ a_eq(unformat(repr('foo')), ["'foo'"]) + a_eq(unformat('foo.bar'), ['foo', 'bar']) + a_eq(unformat('`foo`.`bar`'), ['foo', 'bar']) + a_eq(unformat('foo.`bar`'), ['foo', 'bar']) +diff -r 9d0639b9d3be test/sql/test_rowcount.py +--- a/test/sql/test_rowcount.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/sql/test_rowcount.py Sat Apr 27 19:42:17 2013 -0400 +@@ -53,20 +53,20 @@ + # WHERE matches 3, 3 rows changed + department = employees_table.c.department + r = employees_table.update(department=='C').execute(department='Z') +- print "expecting 3, dialect reports %s" % r.rowcount ++ print("expecting 3, dialect reports %s" % r.rowcount) + assert r.rowcount == 3 + + def test_update_rowcount2(self): + # WHERE matches 3, 0 rows changed + department = employees_table.c.department + r = employees_table.update(department=='C').execute(department='C') +- print "expecting 3, dialect reports %s" % r.rowcount ++ print("expecting 3, dialect reports %s" % r.rowcount) + assert r.rowcount == 3 + + def test_delete_rowcount(self): + # WHERE matches 3, 3 rows deleted + department = employees_table.c.department + r = employees_table.delete(department=='C').execute() +- print "expecting 3, dialect reports %s" % r.rowcount ++ print("expecting 3, dialect reports %s" % r.rowcount) + assert r.rowcount == 3 + +diff -r 9d0639b9d3be test/sql/test_selectable.py +--- a/test/sql/test_selectable.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/sql/test_selectable.py Sat Apr 27 19:42:17 2013 -0400 +@@ -174,11 +174,11 @@ + + def test_clone_append_column(self): + sel = select([literal_column('1').label('a')]) +- eq_(sel.c.keys(), ['a']) ++ eq_(list(sel.c.keys()), ['a']) + cloned = visitors.ReplacingCloningVisitor().traverse(sel) + cloned.append_column(literal_column('2').label('b')) + cloned.append_column(func.foo()) +- eq_(cloned.c.keys(), ['a', 'b', 'foo()']) ++ eq_(list(cloned.c.keys()), ['a', 'b', 'foo()']) + + def test_append_column_after_replace_selectable(self): + basesel = select([literal_column('1').label('a')]) +@@ -362,10 +362,10 @@ + + def test_join(self): + a = join(table1, table2) +- print str(a.select(use_labels=True)) ++ print(str(a.select(use_labels=True))) + b = table2.alias('b') + j = join(a, b) +- print str(j) ++ print(str(j)) + criterion = a.c.table1_col1 == b.c.col2 + self.assert_(criterion.compare(j.onclause)) + +@@ -949,7 +949,7 @@ + primary_key=True), Column('x', Integer)) + d = Table('d', meta, Column('id', Integer, ForeignKey('c.id'), + primary_key=True), Column('x', Integer)) +- print list(a.join(b, a.c.x == b.c.id).primary_key) ++ print(list(a.join(b, a.c.x == b.c.id).primary_key)) + assert list(a.join(b, a.c.x == b.c.id).primary_key) == [a.c.id] + assert list(b.join(c, b.c.x == c.c.id).primary_key) == [b.c.id] + assert list(a.join(b).join(c, c.c.id == b.c.x).primary_key) \ +@@ -1618,7 +1618,7 @@ + def test_names_overlap_label(self): + sel = self._names_overlap().apply_labels() + eq_( +- sel.c.keys(), ++ list(sel.c.keys()), + ['t1_x', 't2_x'] + ) + self._assert_result_keys(sel, ['t1_x', 't2_x']) +@@ -1632,7 +1632,7 @@ + def test_names_overlap_keys_dont_nolabel(self): + sel = self._names_overlap_keys_dont() + eq_( +- sel.c.keys(), ++ list(sel.c.keys()), + ['a', 'b'] + ) + self._assert_result_keys(sel, ['x']) +@@ -1640,7 +1640,7 @@ + def test_names_overlap_keys_dont_label(self): + sel = self._names_overlap_keys_dont().apply_labels() + eq_( +- sel.c.keys(), ++ list(sel.c.keys()), + ['t1_a', 't2_b'] + ) + self._assert_result_keys(sel, ['t1_x', 't2_x']) +@@ -1654,7 +1654,7 @@ + def test_labels_overlap_nolabel(self): + sel = self._labels_overlap() + eq_( +- sel.c.keys(), ++ list(sel.c.keys()), + ['x_id', 'id'] + ) + self._assert_result_keys(sel, ['x_id', 'id']) +@@ -1663,7 +1663,7 @@ + sel = self._labels_overlap().apply_labels() + t2 = sel.froms[1] + eq_( +- sel.c.keys(), ++ list(sel.c.keys()), + ['t_x_id', t2.c.id.anon_label] + ) + self._assert_result_keys(sel, ['t_x_id', 'id_1']) +@@ -1677,12 +1677,12 @@ + + def test_labels_overlap_keylabels_dont_nolabel(self): + sel = self._labels_overlap_keylabels_dont() +- eq_(sel.c.keys(), ['a', 'b']) ++ eq_(list(sel.c.keys()), ['a', 'b']) + self._assert_result_keys(sel, ['x_id', 'id']) + + def test_labels_overlap_keylabels_dont_label(self): + sel = self._labels_overlap_keylabels_dont().apply_labels() +- eq_(sel.c.keys(), ['t_a', 't_x_b']) ++ eq_(list(sel.c.keys()), ['t_a', 't_x_b']) + self._assert_result_keys(sel, ['t_x_id', 'id_1']) + + def _keylabels_overlap_labels_dont(self): +@@ -1693,13 +1693,13 @@ + + def test_keylabels_overlap_labels_dont_nolabel(self): + sel = self._keylabels_overlap_labels_dont() +- eq_(sel.c.keys(), ['x_id', 'id']) ++ eq_(list(sel.c.keys()), ['x_id', 'id']) + self._assert_result_keys(sel, ['a', 'b']) + + def test_keylabels_overlap_labels_dont_label(self): + sel = self._keylabels_overlap_labels_dont().apply_labels() + t2 = sel.froms[1] +- eq_(sel.c.keys(), ['t_x_id', t2.c.id.anon_label]) ++ eq_(list(sel.c.keys()), ['t_x_id', t2.c.id.anon_label]) + self._assert_result_keys(sel, ['t_a', 't_x_b']) + self._assert_subq_result_keys(sel, ['t_a', 't_x_b']) + +@@ -1711,14 +1711,14 @@ + + def test_keylabels_overlap_labels_overlap_nolabel(self): + sel = self._keylabels_overlap_labels_overlap() +- eq_(sel.c.keys(), ['x_a', 'a']) ++ eq_(list(sel.c.keys()), ['x_a', 'a']) + self._assert_result_keys(sel, ['x_id', 'id']) + self._assert_subq_result_keys(sel, ['x_id', 'id']) + + def test_keylabels_overlap_labels_overlap_label(self): + sel = self._keylabels_overlap_labels_overlap().apply_labels() + t2 = sel.froms[1] +- eq_(sel.c.keys(), ['t_x_a', t2.c.a.anon_label]) ++ eq_(list(sel.c.keys()), ['t_x_a', t2.c.a.anon_label]) + self._assert_result_keys(sel, ['t_x_id', 'id_1']) + self._assert_subq_result_keys(sel, ['t_x_id', 'id_1']) + +@@ -1736,7 +1736,7 @@ + def test_keys_overlap_names_dont_label(self): + sel = self._keys_overlap_names_dont().apply_labels() + eq_( +- sel.c.keys(), ++ list(sel.c.keys()), + ['t1_x', 't2_x'] + ) + self._assert_result_keys(sel, ['t1_a', 't2_b']) +diff -r 9d0639b9d3be test/sql/test_types.py +--- a/test/sql/test_types.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/sql/test_types.py Sat Apr 27 19:42:17 2013 -0400 +@@ -141,22 +141,24 @@ + eq_(types.Integer().python_type, int) + eq_(types.Numeric().python_type, decimal.Decimal) + eq_(types.Numeric(asdecimal=False).python_type, float) +- # Py3K +- #eq_(types.LargeBinary().python_type, bytes) +- # Py2K +- eq_(types.LargeBinary().python_type, str) +- # end Py2K ++# start Py3K ++ eq_(types.LargeBinary().python_type, bytes) ++# end Py3K ++# start Py2K ++# eq_(types.LargeBinary().python_type, str) ++# end Py2K + eq_(types.Float().python_type, float) + eq_(types.Interval().python_type, datetime.timedelta) + eq_(types.Date().python_type, datetime.date) + eq_(types.DateTime().python_type, datetime.datetime) +- # Py3K +- #eq_(types.String().python_type, unicode) +- # Py2K ++# start Py3K + eq_(types.String().python_type, str) +- # end Py2K +- eq_(types.Unicode().python_type, unicode) +- eq_(types.String(convert_unicode=True).python_type, unicode) ++# end Py3K ++# start Py2K ++# eq_(types.String().python_type, str) ++# end Py2K ++ eq_(types.Unicode().python_type, str) ++ eq_(types.String(convert_unicode=True).python_type, str) + + assert_raises( + NotImplementedError, +@@ -257,14 +259,14 @@ + def test_processing(self): + users = self.tables.users + users.insert().execute( +- user_id=2, goofy='jack', goofy2='jack', goofy4=u'jack', +- goofy7=u'jack', goofy8=12, goofy9=12) ++ user_id=2, goofy='jack', goofy2='jack', goofy4='jack', ++ goofy7='jack', goofy8=12, goofy9=12) + users.insert().execute( +- user_id=3, goofy='lala', goofy2='lala', goofy4=u'lala', +- goofy7=u'lala', goofy8=15, goofy9=15) ++ user_id=3, goofy='lala', goofy2='lala', goofy4='lala', ++ goofy7='lala', goofy8=15, goofy9=15) + users.insert().execute( +- user_id=4, goofy='fred', goofy2='fred', goofy4=u'fred', +- goofy7=u'fred', goofy8=9, goofy9=9) ++ user_id=4, goofy='fred', goofy2='fred', goofy4='fred', ++ goofy7='fred', goofy8=9, goofy9=9) + + l = users.select().order_by(users.c.user_id).execute().fetchall() + for assertstr, assertint, assertint2, row in zip( +@@ -278,7 +280,7 @@ + eq_(row[5], assertint) + eq_(row[6], assertint2) + for col in row[3], row[4]: +- assert isinstance(col, unicode) ++ assert isinstance(col, str) + + def test_typedecorator_impl(self): + for impl_, exp, kw in [ +@@ -715,9 +717,9 @@ + expected + ) + +- data = u"Alors vous imaginez ma surprise, au lever du jour, quand "\ +- u"une drôle de petite voix m’a réveillé. "\ +- u"Elle disait: « S’il vous plaît… dessine-moi un mouton! »" ++ data = "Alors vous imaginez ma surprise, au lever du jour, quand "\ ++ "une drôle de petite voix m’a réveillé. "\ ++ "Elle disait: « S’il vous plaît… dessine-moi un mouton! »" + + def test_unicode_warnings_typelevel_native_unicode(self): + +@@ -726,13 +728,14 @@ + dialect = default.DefaultDialect() + dialect.supports_unicode_binds = True + uni = u.dialect_impl(dialect).bind_processor(dialect) +- # Py3K +- #assert_raises(exc.SAWarning, uni, b'x') +- #assert isinstance(uni(unicodedata), str) +- # Py2K +- assert_raises(exc.SAWarning, uni, 'x') +- assert isinstance(uni(unicodedata), unicode) +- # end Py2K ++# start Py3K ++ assert_raises(exc.SAWarning, uni, b'x') ++ assert isinstance(uni(unicodedata), str) ++# end Py3K ++# start Py2K ++# assert_raises(exc.SAWarning, uni, 'x') ++# assert isinstance(uni(unicodedata), unicode) ++# end Py2K + + def test_unicode_warnings_typelevel_sqla_unicode(self): + unicodedata = self.data +@@ -740,13 +743,14 @@ + dialect = default.DefaultDialect() + dialect.supports_unicode_binds = False + uni = u.dialect_impl(dialect).bind_processor(dialect) +- # Py3K +- #assert_raises(exc.SAWarning, uni, b'x') +- #assert isinstance(uni(unicodedata), bytes) +- # Py2K +- assert_raises(exc.SAWarning, uni, 'x') +- assert isinstance(uni(unicodedata), str) +- # end Py2K ++# start Py3K ++ assert_raises(exc.SAWarning, uni, b'x') ++ assert isinstance(uni(unicodedata), bytes) ++# end Py3K ++# start Py2K ++# assert_raises(exc.SAWarning, uni, 'x') ++# assert isinstance(uni(unicodedata), str) ++# end Py2K + + eq_(uni(unicodedata), unicodedata.encode('utf-8')) + +@@ -760,13 +764,14 @@ + s = String() + uni = s.dialect_impl(dialect).bind_processor(dialect) + # this is not the unicode type - no warning +- # Py3K +- #uni(b'x') +- #assert isinstance(uni(unicodedata), bytes) +- # Py2K +- uni('x') +- assert isinstance(uni(unicodedata), str) +- # end Py2K ++# start Py3K ++ uni(b'x') ++ assert isinstance(uni(unicodedata), bytes) ++# end Py3K ++# start Py2K ++# uni('x') ++# assert isinstance(uni(unicodedata), str) ++# end Py2K + + eq_(uni(unicodedata), unicodedata.encode('utf-8')) + +@@ -1366,7 +1371,7 @@ + metadata = self.metadata + t = self._fixture(metadata, Integer, 45) + val = testing.db.execute("select val from t").scalar() +- assert isinstance(val, (int, long)) ++ assert isinstance(val, int) + eq_(val, 45) + + @testing.provide_metadata +diff -r 9d0639b9d3be test/sql/test_unicode.py +--- a/test/sql/test_unicode.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/sql/test_unicode.py Sat Apr 27 19:42:17 2013 -0400 +@@ -19,13 +19,13 @@ + + metadata = MetaData(unicode_bind) + t1 = Table('unitable1', metadata, +- Column(u'méil', Integer, primary_key=True), +- Column(u'\u6e2c\u8a66', Integer), ++ Column('méil', Integer, primary_key=True), ++ Column('\u6e2c\u8a66', Integer), + test_needs_fk=True, + ) +- t2 = Table(u'Unitéble2', metadata, +- Column(u'méil', Integer, primary_key=True, key="a"), +- Column(u'\u6e2c\u8a66', Integer, ForeignKey(u'unitable1.méil'), ++ t2 = Table('Unitéble2', metadata, ++ Column('méil', Integer, primary_key=True, key="a"), ++ Column('\u6e2c\u8a66', Integer, ForeignKey('unitable1.méil'), + key="b" + ), + test_needs_fk=True, +@@ -33,27 +33,27 @@ + + # Few DBs support Unicode foreign keys + if testing.against('sqlite'): +- t3 = Table(u'\u6e2c\u8a66', metadata, +- Column(u'\u6e2c\u8a66_id', Integer, primary_key=True, ++ t3 = Table('\u6e2c\u8a66', metadata, ++ Column('\u6e2c\u8a66_id', Integer, primary_key=True, + autoincrement=False), +- Column(u'unitable1_\u6e2c\u8a66', Integer, +- ForeignKey(u'unitable1.\u6e2c\u8a66') ++ Column('unitable1_\u6e2c\u8a66', Integer, ++ ForeignKey('unitable1.\u6e2c\u8a66') + ), +- Column(u'Unitéble2_b', Integer, +- ForeignKey(u'Unitéble2.b') ++ Column('Unitéble2_b', Integer, ++ ForeignKey('Unitéble2.b') + ), +- Column(u'\u6e2c\u8a66_self', Integer, +- ForeignKey(u'\u6e2c\u8a66.\u6e2c\u8a66_id') ++ Column('\u6e2c\u8a66_self', Integer, ++ ForeignKey('\u6e2c\u8a66.\u6e2c\u8a66_id') + ), + test_needs_fk=True, + ) + else: +- t3 = Table(u'\u6e2c\u8a66', metadata, +- Column(u'\u6e2c\u8a66_id', Integer, primary_key=True, ++ t3 = Table('\u6e2c\u8a66', metadata, ++ Column('\u6e2c\u8a66_id', Integer, primary_key=True, + autoincrement=False), +- Column(u'unitable1_\u6e2c\u8a66', Integer), +- Column(u'Unitéble2_b', Integer), +- Column(u'\u6e2c\u8a66_self', Integer), ++ Column('unitable1_\u6e2c\u8a66', Integer), ++ Column('Unitéble2_b', Integer), ++ Column('\u6e2c\u8a66_self', Integer), + test_needs_fk=True, + ) + metadata.create_all() +@@ -72,42 +72,42 @@ + del unicode_bind + + def test_insert(self): +- t1.insert().execute({u'méil':1, u'\u6e2c\u8a66':5}) ++ t1.insert().execute({'méil':1, '\u6e2c\u8a66':5}) + t2.insert().execute({'a':1, 'b':1}) +- t3.insert().execute({u'\u6e2c\u8a66_id': 1, +- u'unitable1_\u6e2c\u8a66': 5, +- u'Unitéble2_b': 1, +- u'\u6e2c\u8a66_self': 1}) ++ t3.insert().execute({'\u6e2c\u8a66_id': 1, ++ 'unitable1_\u6e2c\u8a66': 5, ++ 'Unitéble2_b': 1, ++ '\u6e2c\u8a66_self': 1}) + + assert t1.select().execute().fetchall() == [(1, 5)] + assert t2.select().execute().fetchall() == [(1, 1)] + assert t3.select().execute().fetchall() == [(1, 5, 1, 1)] + + def test_reflect(self): +- t1.insert().execute({u'méil':2, u'\u6e2c\u8a66':7}) ++ t1.insert().execute({'méil':2, '\u6e2c\u8a66':7}) + t2.insert().execute({'a':2, 'b':2}) +- t3.insert().execute({u'\u6e2c\u8a66_id': 2, +- u'unitable1_\u6e2c\u8a66': 7, +- u'Unitéble2_b': 2, +- u'\u6e2c\u8a66_self': 2}) ++ t3.insert().execute({'\u6e2c\u8a66_id': 2, ++ 'unitable1_\u6e2c\u8a66': 7, ++ 'Unitéble2_b': 2, ++ '\u6e2c\u8a66_self': 2}) + + meta = MetaData(unicode_bind) + tt1 = Table(t1.name, meta, autoload=True) + tt2 = Table(t2.name, meta, autoload=True) + tt3 = Table(t3.name, meta, autoload=True) + +- tt1.insert().execute({u'méil':1, u'\u6e2c\u8a66':5}) +- tt2.insert().execute({u'méil':1, u'\u6e2c\u8a66':1}) +- tt3.insert().execute({u'\u6e2c\u8a66_id': 1, +- u'unitable1_\u6e2c\u8a66': 5, +- u'Unitéble2_b': 1, +- u'\u6e2c\u8a66_self': 1}) ++ tt1.insert().execute({'méil':1, '\u6e2c\u8a66':5}) ++ tt2.insert().execute({'méil':1, '\u6e2c\u8a66':1}) ++ tt3.insert().execute({'\u6e2c\u8a66_id': 1, ++ 'unitable1_\u6e2c\u8a66': 5, ++ 'Unitéble2_b': 1, ++ '\u6e2c\u8a66_self': 1}) + +- self.assert_(tt1.select(order_by=desc(u'méil')).execute().fetchall() == ++ self.assert_(tt1.select(order_by=desc('méil')).execute().fetchall() == + [(2, 7), (1, 5)]) +- self.assert_(tt2.select(order_by=desc(u'méil')).execute().fetchall() == ++ self.assert_(tt2.select(order_by=desc('méil')).execute().fetchall() == + [(2, 2), (1, 1)]) +- self.assert_(tt3.select(order_by=desc(u'\u6e2c\u8a66_id')). ++ self.assert_(tt3.select(order_by=desc('\u6e2c\u8a66_id')). + execute().fetchall() == + [(2, 7, 2, 2), (1, 5, 1, 1)]) + meta.drop_all() +@@ -117,7 +117,7 @@ + def test_default_exec(self): + metadata = MetaData(testing.db) + t1 = Table('t1', metadata, +- Column(u'special_col', Integer, Sequence('special_col'), primary_key=True), ++ Column('special_col', Integer, Sequence('special_col'), primary_key=True), + Column('data', String(50)) # to appease SQLite without DEFAULT VALUES + ) + metadata.create_all() +@@ -128,8 +128,8 @@ + # reset the identifier preparer, so that we can force it to cache + # a unicode identifier + engine.dialect.identifier_preparer = engine.dialect.preparer(engine.dialect) +- select([column(u'special_col')]).select_from(t1).execute().close() +- assert isinstance(engine.dialect.identifier_preparer.format_sequence(Sequence('special_col')), unicode) ++ select([column('special_col')]).select_from(t1).execute().close() ++ assert isinstance(engine.dialect.identifier_preparer.format_sequence(Sequence('special_col')), str) + + # now execute, run the sequence. it should run in u"Special_col.nextid" or similar as + # a unicode object; cx_oracle asserts that this is None or a String (postgresql lets it pass thru). +diff -r 9d0639b9d3be test/sql/test_update.py +--- a/test/sql/test_update.py Sat Apr 27 17:51:52 2013 -0400 ++++ b/test/sql/test_update.py Sat Apr 27 19:42:17 2013 -0400 +@@ -242,7 +242,7 @@ + 'WHERE ' + 'users.id = addresses.user_id AND ' + 'addresses.email_address = :email_address_1', +- checkparams={u'email_address_1': 'e1', 'name': 'newname'}) ++ checkparams={'email_address_1': 'e1', 'name': 'newname'}) + + def test_render_multi_table(self): + users = self.tables.users +@@ -250,8 +250,8 @@ + dingalings = self.tables.dingalings + + checkparams = { +- u'email_address_1': 'e1', +- u'id_1': 2, ++ 'email_address_1': 'e1', ++ 'id_1': 2, + 'name': 'newname' + } + +@@ -285,15 +285,15 @@ + 'WHERE ' + 'users.id = addresses.user_id AND ' + 'addresses.email_address = %s', +- checkparams={u'email_address_1': 'e1', 'name': 'newname'}, ++ checkparams={'email_address_1': 'e1', 'name': 'newname'}, + dialect=mysql.dialect()) + + def test_render_subquery(self): + users, addresses = self.tables.users, self.tables.addresses + + checkparams = { +- u'email_address_1': 'e1', +- u'id_1': 7, ++ 'email_address_1': 'e1', ++ 'id_1': 7, + 'name': 'newname' + } + diff --git a/examples/adjacency_list/adjacency_list.py b/examples/adjacency_list/adjacency_list.py index 1020cc57d..a0683ea0c 100644 --- a/examples/adjacency_list/adjacency_list.py +++ b/examples/adjacency_list/adjacency_list.py @@ -55,9 +55,9 @@ if __name__ == '__main__': def msg(msg, *args): msg = msg % args - print "\n\n\n" + "-" * len(msg.split("\n")[0]) - print msg - print "-" * len(msg.split("\n")[0]) + print("\n\n\n" + "-" * len(msg.split("\n")[0])) + print(msg) + print("-" * len(msg.split("\n")[0])) msg("Creating Tree Table:") diff --git a/examples/association/basic_association.py b/examples/association/basic_association.py index 29a473fce..a175b1b89 100644 --- a/examples/association/basic_association.py +++ b/examples/association/basic_association.py @@ -83,12 +83,12 @@ 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) - for order_item in order.order_items] + print([(order_item.item.description, order_item.price) + for order_item in order.order_items]) # print customers who bought 'MySQL Crowbar' on sale q = session.query(Order).join('order_items', 'item') q = q.filter(and_(Item.description == 'MySQL Crowbar', Item.price > OrderItem.price)) - print [order.customer_name for order in q] + print([order.customer_name for order in q]) diff --git a/examples/association/dict_of_sets_with_default.py b/examples/association/dict_of_sets_with_default.py index 9a43e300c..f541727e7 100644 --- a/examples/association/dict_of_sets_with_default.py +++ b/examples/association/dict_of_sets_with_default.py @@ -75,13 +75,13 @@ if __name__ == '__main__': session.commit() a1 = session.query(A).first() - print a1.collections["1"] + print(a1.collections["1"]) a1.collections["1"].add(4) session.commit() a1.collections["2"].update([7, 8, 9]) session.commit() - print a1.collections["2"] + print(a1.collections["2"]) diff --git a/examples/association/proxied_association.py b/examples/association/proxied_association.py index 7f4d611a7..4cf1c51be 100644 --- a/examples/association/proxied_association.py +++ b/examples/association/proxied_association.py @@ -86,16 +86,16 @@ if __name__ == '__main__': order = session.query(Order).filter_by(customer_name='john smith').one() # print items based on the OrderItem collection directly - print [(assoc.item.description, assoc.price, assoc.item.price) - for assoc in order.order_items] + print([(assoc.item.description, assoc.price, assoc.item.price) + for assoc in order.order_items]) # print items based on the "proxied" items collection - print [(item.description, item.price) - for item in order.items] + print([(item.description, item.price) + for item in order.items]) # print customers who bought 'MySQL Crowbar' on sale orders = session.query(Order).\ join('order_items', 'item').\ filter(Item.description == 'MySQL Crowbar').\ filter(Item.price > OrderItem.price) - print [o.customer_name for o in orders] + print([o.customer_name for o in orders]) diff --git a/examples/custom_attributes/listen_for_events.py b/examples/custom_attributes/listen_for_events.py index 4cdf4b056..82bc860fa 100644 --- a/examples/custom_attributes/listen_for_events.py +++ b/examples/custom_attributes/listen_for_events.py @@ -34,7 +34,7 @@ if __name__ == '__main__': if oldvalue: s += "which replaced the value '%s', " % oldvalue s += "on object %s" % self - print s + print(s) Base = declarative_base(cls=Base) 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')) diff --git a/examples/dynamic_dict/dynamic_dict.py b/examples/dynamic_dict/dynamic_dict.py index ec7c8e918..530674f2e 100644 --- a/examples/dynamic_dict/dynamic_dict.py +++ b/examples/dynamic_dict/dynamic_dict.py @@ -1,88 +1,88 @@ -class ProxyDict(object): - def __init__(self, parent, collection_name, childclass, keyname): - self.parent = parent - self.collection_name = collection_name - self.childclass = childclass - self.keyname = keyname - - @property - def collection(self): - return getattr(self.parent, self.collection_name) - - def keys(self): - descriptor = getattr(self.childclass, self.keyname) - return [x[0] for x in self.collection.values(descriptor)] - - def __getitem__(self, key): - x = self.collection.filter_by(**{self.keyname:key}).first() - if x: - return x - else: - raise KeyError(key) - - def __setitem__(self, key, value): - try: - existing = self[key] - self.collection.remove(existing) - except KeyError: - pass - self.collection.append(value) - -from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy import create_engine, Column, Integer, String, ForeignKey -from sqlalchemy.orm import sessionmaker, relationship - -engine = create_engine('sqlite://', echo=True) -Base = declarative_base(engine) - -class Parent(Base): - __tablename__ = 'parent' - id = Column(Integer, primary_key=True) - name = Column(String(50)) - _collection = relationship("Child", lazy="dynamic", - cascade="all, delete-orphan") - - @property - def child_map(self): - return ProxyDict(self, '_collection', Child, 'key') - -class Child(Base): - __tablename__ = 'child' - id = Column(Integer, primary_key=True) - key = Column(String(50)) - parent_id = Column(Integer, ForeignKey('parent.id')) - - def __repr__(self): - return "Child(key=%r)" % self.key - -Base.metadata.create_all() - -sess = sessionmaker()() - -p1 = Parent(name='p1') -sess.add(p1) - -print "\n---------begin setting nodes, autoflush occurs\n" -p1.child_map['k1'] = Child(key='k1') -p1.child_map['k2'] = Child(key='k2') - -# this will autoflush the current map. -# ['k1', 'k2'] -print "\n---------print keys - flushes first\n" -print p1.child_map.keys() - -# k1 -print "\n---------print 'k1' node\n" -print p1.child_map['k1'] - -print "\n---------update 'k2' node - must find existing, and replace\n" -p1.child_map['k2'] = Child(key='k2') - -print "\n---------print 'k2' key - flushes first\n" -# k2 -print p1.child_map['k2'] - -print "\n---------print all child nodes\n" -# [k1, k2b] -print sess.query(Child).all() - +class ProxyDict(object): + def __init__(self, parent, collection_name, childclass, keyname): + self.parent = parent + self.collection_name = collection_name + self.childclass = childclass + self.keyname = keyname + + @property + def collection(self): + return getattr(self.parent, self.collection_name) + + def keys(self): + descriptor = getattr(self.childclass, self.keyname) + return [x[0] for x in self.collection.values(descriptor)] + + def __getitem__(self, key): + x = self.collection.filter_by(**{self.keyname:key}).first() + if x: + return x + else: + raise KeyError(key) + + def __setitem__(self, key, value): + try: + existing = self[key] + self.collection.remove(existing) + except KeyError: + pass + self.collection.append(value) + +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy import create_engine, Column, Integer, String, ForeignKey +from sqlalchemy.orm import sessionmaker, relationship + +engine = create_engine('sqlite://', echo=True) +Base = declarative_base(engine) + +class Parent(Base): + __tablename__ = 'parent' + id = Column(Integer, primary_key=True) + name = Column(String(50)) + _collection = relationship("Child", lazy="dynamic", + cascade="all, delete-orphan") + + @property + def child_map(self): + return ProxyDict(self, '_collection', Child, 'key') + +class Child(Base): + __tablename__ = 'child' + id = Column(Integer, primary_key=True) + key = Column(String(50)) + parent_id = Column(Integer, ForeignKey('parent.id')) + + def __repr__(self): + return "Child(key=%r)" % self.key + +Base.metadata.create_all() + +sess = sessionmaker()() + +p1 = Parent(name='p1') +sess.add(p1) + +print("\n---------begin setting nodes, autoflush occurs\n") +p1.child_map['k1'] = Child(key='k1') +p1.child_map['k2'] = Child(key='k2') + +# this will autoflush the current map. +# ['k1', 'k2'] +print("\n---------print keys - flushes first\n") +print(list(p1.child_map.keys())) + +# k1 +print("\n---------print 'k1' node\n") +print(p1.child_map['k1']) + +print("\n---------update 'k2' node - must find existing, and replace\n") +p1.child_map['k2'] = Child(key='k2') + +print("\n---------print 'k2' key - flushes first\n") +# k2 +print(p1.child_map['k2']) + +print("\n---------print all child nodes\n") +# [k1, k2b] +print(sess.query(Child).all()) + diff --git a/examples/elementtree/adjacency_list.py b/examples/elementtree/adjacency_list.py index 3b9e4c523..a3ad42778 100644 --- a/examples/elementtree/adjacency_list.py +++ b/examples/elementtree/adjacency_list.py @@ -11,7 +11,7 @@ from sqlalchemy import (MetaData, Table, Column, Integer, String, ForeignKey, Unicode, and_, create_engine) from sqlalchemy.orm import mapper, relationship, Session, lazyload -import sys, os, StringIO, re +import sys, os, io, re from xml.etree import ElementTree @@ -56,7 +56,7 @@ class Document(object): self.element = element def __str__(self): - buf = StringIO.StringIO() + buf = io.StringIO() self.element.write(buf) return buf.getvalue() @@ -120,11 +120,11 @@ class ElementTreeMarshal(object): def __set__(self, document, element): def traverse(node): n = _Node() - n.tag = unicode(node.tag) - n.text = unicode(node.text) - n.tail = unicode(node.tail) + n.tag = str(node.tag) + n.text = str(node.text) + n.tail = str(node.tail) n.children = [traverse(n2) for n2 in node] - n.attributes = [_Attribute(unicode(k), unicode(v)) for k, v in node.attrib.iteritems()] + n.attributes = [_Attribute(str(k), str(v)) for k, v in node.attrib.items()] return n document._root = traverse(element.getroot()) @@ -150,23 +150,23 @@ for file in ('test.xml', 'test2.xml', 'test3.xml'): doc = ElementTree.parse(filename) session.add(Document(file, doc)) -print "\nSaving three documents...", line +print("\nSaving three documents...", line) session.commit() -print "Done." +print("Done.") -print "\nFull text of document 'text.xml':", line +print("\nFull text of document 'text.xml':", line) document = session.query(Document).filter_by(filename="test.xml").first() -print document +print(document) ############################################ PART VI - Searching for Paths ######################### # manually search for a document which contains "/somefile/header/field1:hi" -d = session.query(Document).join('_root', aliased=True).filter(_Node.tag==u'somefile').\ - join('children', aliased=True, from_joinpoint=True).filter(_Node.tag==u'header').\ +d = session.query(Document).join('_root', aliased=True).filter(_Node.tag=='somefile').\ + join('children', aliased=True, from_joinpoint=True).filter(_Node.tag=='header').\ join('children', aliased=True, from_joinpoint=True).filter( - and_(_Node.tag==u'field1', _Node.text==u'hi')).one() -print d + and_(_Node.tag=='field1', _Node.text=='hi')).one() +print(d) # generalize the above approach into an extremely impoverished xpath function: def find_document(path, compareto): @@ -188,11 +188,11 @@ def find_document(path, compareto): return query.options(lazyload('_root')).filter(_Node.text==compareto).all() for path, compareto in ( - (u'/somefile/header/field1', u'hi'), - (u'/somefile/field1', u'hi'), - (u'/somefile/header/field2', u'there'), - (u'/somefile/header/field2[@attr=foo]', u'there') + ('/somefile/header/field1', 'hi'), + ('/somefile/field1', 'hi'), + ('/somefile/header/field2', 'there'), + ('/somefile/header/field2[@attr=foo]', 'there') ): - print "\nDocuments containing '%s=%s':" % (path, compareto), line - print [d.filename for d in find_document(path, compareto)] + print("\nDocuments containing '%s=%s':" % (path, compareto), line) + print([d.filename for d in find_document(path, compareto)]) diff --git a/examples/elementtree/optimized_al.py b/examples/elementtree/optimized_al.py index 1cec61366..1dbad0943 100644 --- a/examples/elementtree/optimized_al.py +++ b/examples/elementtree/optimized_al.py @@ -10,7 +10,7 @@ from sqlalchemy import (MetaData, Table, Column, Integer, String, ForeignKey, Unicode, and_, create_engine) from sqlalchemy.orm import mapper, relationship, Session, lazyload -import sys, os, StringIO, re +import sys, os, io, re from xml.etree import ElementTree @@ -55,7 +55,7 @@ class Document(object): self.element = element def __str__(self): - buf = StringIO.StringIO() + buf = io.StringIO() self.element.write(buf) return buf.getvalue() @@ -127,12 +127,12 @@ class ElementTreeMarshal(object): def __set__(self, document, element): def traverse(node): n = _Node() - n.tag = unicode(node.tag) - n.text = unicode(node.text) - n.tail = unicode(node.tail) + n.tag = str(node.tag) + n.text = str(node.text) + n.tail = str(node.tail) document._nodes.append(n) n.children = [traverse(n2) for n2 in node] - n.attributes = [_Attribute(unicode(k), unicode(v)) for k, v in node.attrib.iteritems()] + n.attributes = [_Attribute(str(k), str(v)) for k, v in node.attrib.items()] return n traverse(element.getroot()) @@ -158,27 +158,27 @@ for file in ('test.xml', 'test2.xml', 'test3.xml'): doc = ElementTree.parse(filename) session.add(Document(file, doc)) -print "\nSaving three documents...", line +print("\nSaving three documents...", line) session.commit() -print "Done." +print("Done.") -print "\nFull text of document 'text.xml':", line +print("\nFull text of document 'text.xml':", line) document = session.query(Document).filter_by(filename="test.xml").first() -print document +print(document) ######################## PART VI - Searching for Paths ####################### # manually search for a document which contains "/somefile/header/field1:hi" -print "\nManual search for /somefile/header/field1=='hi':", line +print("\nManual search for /somefile/header/field1=='hi':", line) d = session.query(Document).join('_nodes', aliased=True).\ - filter(and_(_Node.parent_id==None, _Node.tag==u'somefile')).\ + filter(and_(_Node.parent_id==None, _Node.tag=='somefile')).\ join('children', aliased=True, from_joinpoint=True).\ - filter(_Node.tag==u'header').\ + filter(_Node.tag=='header').\ join('children', aliased=True, from_joinpoint=True).\ - filter(and_(_Node.tag==u'field1', _Node.text==u'hi')).\ + filter(and_(_Node.tag=='field1', _Node.text=='hi')).\ one() -print d +print(d) # generalize the above approach into an extremely impoverished xpath function: def find_document(path, compareto): @@ -203,11 +203,11 @@ def find_document(path, compareto): return query.options(lazyload('_nodes')).filter(_Node.text==compareto).all() for path, compareto in ( - (u'/somefile/header/field1', u'hi'), - (u'/somefile/field1', u'hi'), - (u'/somefile/header/field2', u'there'), - (u'/somefile/header/field2[@attr=foo]', u'there') + ('/somefile/header/field1', 'hi'), + ('/somefile/field1', 'hi'), + ('/somefile/header/field2', 'there'), + ('/somefile/header/field2[@attr=foo]', 'there') ): - print "\nDocuments containing '%s=%s':" % (path, compareto), line - print [d.filename for d in find_document(path, compareto)] + print("\nDocuments containing '%s=%s':" % (path, compareto), line) + print([d.filename for d in find_document(path, compareto)]) diff --git a/examples/generic_associations/discriminator_on_association.py b/examples/generic_associations/discriminator_on_association.py index 3c170d5c8..7b4565a85 100644 --- a/examples/generic_associations/discriminator_on_association.py +++ b/examples/generic_associations/discriminator_on_association.py @@ -144,5 +144,5 @@ session.commit() for customer in session.query(Customer): for address in customer.addresses: - print address - print address.parent \ No newline at end of file + print(address) + print(address.parent) \ No newline at end of file diff --git a/examples/generic_associations/table_per_association.py b/examples/generic_associations/table_per_association.py index e1ff2be5b..84e85de2f 100644 --- a/examples/generic_associations/table_per_association.py +++ b/examples/generic_associations/table_per_association.py @@ -102,5 +102,5 @@ session.commit() for customer in session.query(Customer): for address in customer.addresses: - print address + print(address) # no parent here \ No newline at end of file diff --git a/examples/generic_associations/table_per_related.py b/examples/generic_associations/table_per_related.py index 693908189..0ec5f29b0 100644 --- a/examples/generic_associations/table_per_related.py +++ b/examples/generic_associations/table_per_related.py @@ -103,5 +103,5 @@ session.commit() for customer in session.query(Customer): for address in customer.addresses: - print address - print address.parent \ No newline at end of file + print(address) + print(address.parent) \ No newline at end of file diff --git a/examples/inheritance/concrete.py b/examples/inheritance/concrete.py index 75741df6d..b05afa5ea 100644 --- a/examples/inheritance/concrete.py +++ b/examples/inheritance/concrete.py @@ -68,5 +68,5 @@ session.add(e1) session.add(e2) session.commit() -print session.query(Employee).all() +print(session.query(Employee).all()) diff --git a/examples/inheritance/joined.py b/examples/inheritance/joined.py index 4d3dc08d0..c6ce37146 100644 --- a/examples/inheritance/joined.py +++ b/examples/inheritance/joined.py @@ -92,10 +92,10 @@ session.commit() c = session.query(Company).get(1) for e in c.employees: - print e, inspect(e).key, e.company + print(e, inspect(e).key, e.company) assert set([e.name for e in c.employees]) == set(['pointy haired boss', 'dilbert', 'joesmith', 'wally', 'jsmith']) -print "\n" +print("\n") dilbert = session.query(Person).filter_by(name='dilbert').one() dilbert2 = session.query(Engineer).filter_by(name='dilbert').one() @@ -107,29 +107,29 @@ session.commit() c = session.query(Company).get(1) for e in c.employees: - print e + print(e) # query using with_polymorphic. eng_manager = with_polymorphic(Person, [Engineer, Manager], aliased=True) -print session.query(eng_manager).\ +print(session.query(eng_manager).\ filter( or_(eng_manager.Engineer.engineer_name=='engineer1', eng_manager.Manager.manager_name=='manager2' ) - ).all() + ).all()) # illustrate join from Company, # We use aliased=True # to help when the selectable is used as the target of a join. eng_manager = with_polymorphic(Person, [Engineer, Manager], aliased=True) -print session.query(Company).\ +print(session.query(Company).\ join( eng_manager, Company.employees ).filter( or_(eng_manager.Engineer.engineer_name=='engineer1', eng_manager.Manager.manager_name=='manager2') - ).all() + ).all()) session.commit() diff --git a/examples/inheritance/single.py b/examples/inheritance/single.py index b2f934120..b445f74a6 100644 --- a/examples/inheritance/single.py +++ b/examples/inheritance/single.py @@ -23,7 +23,7 @@ employees_table = Table('employees', metadata, class Person(object): def __init__(self, **kwargs): - for key, value in kwargs.iteritems(): + for key, value in kwargs.items(): setattr(self, key, value) def __repr__(self): return "Ordinary person %s" % self.name @@ -39,7 +39,7 @@ class Manager(Person): (self.name, self.status, self.manager_name) class Company(object): def __init__(self, **kwargs): - for key, value in kwargs.iteritems(): + for key, value in kwargs.items(): setattr(self, key, value) def __repr__(self): return "Company %s" % self.name @@ -79,9 +79,9 @@ session.commit() c = session.query(Company).get(1) for e in c.employees: - print e, e.company + print(e, e.company) -print "\n" +print("\n") dilbert = session.query(Person).filter_by(name='dilbert').one() dilbert2 = session.query(Engineer).filter_by(name='dilbert').one() @@ -94,7 +94,7 @@ session.expunge_all() c = session.query(Company).get(1) for e in c.employees: - print e + print(e) session.delete(c) session.commit() diff --git a/examples/large_collection/large_collection.py b/examples/large_collection/large_collection.py index 3e386ae64..82d2e554b 100644 --- a/examples/large_collection/large_collection.py +++ b/examples/large_collection/large_collection.py @@ -63,14 +63,14 @@ if __name__ == '__main__': sess.add(org) - print "-------------------------\nflush one - save org + 3 members\n" + print("-------------------------\nflush one - save org + 3 members\n") sess.commit() # the 'members' collection is a Query. it issues # SQL as needed to load subsets of the collection. - print "-------------------------\nload subset of members\n" + print("-------------------------\nload subset of members\n") members = org.members.filter(member_table.c.name.like('%member t%')).all() - print members + print(members) # new Members can be appended without any # SQL being emitted to load the full collection @@ -78,19 +78,19 @@ if __name__ == '__main__': org.members.append(Member('member five')) org.members.append(Member('member six')) - print "-------------------------\nflush two - save 3 more members\n" + print("-------------------------\nflush two - save 3 more members\n") sess.commit() # delete the object. Using ON DELETE CASCADE # SQL is only emitted for the head row - the Member rows # disappear automatically without the need for additional SQL. sess.delete(org) - print "-------------------------\nflush three - delete org, delete members in one statement\n" + print("-------------------------\nflush three - delete org, delete members in one statement\n") sess.commit() - print "-------------------------\nno Member rows should remain:\n" - print sess.query(Member).count() + print("-------------------------\nno Member rows should remain:\n") + print(sess.query(Member).count()) sess.close() - print "------------------------\ndone. dropping tables." + print("------------------------\ndone. dropping tables.") meta.drop_all(engine) \ No newline at end of file diff --git a/examples/postgis/postgis.py b/examples/postgis/postgis.py index 0b86ad323..01671c5c4 100644 --- a/examples/postgis/postgis.py +++ b/examples/postgis/postgis.py @@ -251,7 +251,7 @@ if __name__ == '__main__': road_table = Road.__table__ stmt = select([road_table]).where(road_table.c.road_geom.intersects(r1.road_geom)) - print session.execute(stmt).fetchall() + print(session.execute(stmt).fetchall()) # TODO: for some reason the auto-generated labels have the internal replacement # strings exposed, even though PG doesn't complain diff --git a/examples/versioning/_lib.py b/examples/versioning/_lib.py index ec0da4709..9132f9b35 100644 --- a/examples/versioning/_lib.py +++ b/examples/versioning/_lib.py @@ -17,7 +17,7 @@ def eq_(a, b, msg=None): _repr_stack = set() class BasicEntity(object): def __init__(self, **kw): - for key, value in kw.iteritems(): + for key, value in kw.items(): setattr(self, key, value) def __repr__(self): diff --git a/examples/versioning/history_meta.py b/examples/versioning/history_meta.py index 533599394..45f1c8369 100644 --- a/examples/versioning/history_meta.py +++ b/examples/versioning/history_meta.py @@ -166,7 +166,7 @@ def create_version(obj, session, deleted = False): attr['version'] = obj.version hist = history_cls() - for key, value in attr.iteritems(): + for key, value in attr.items(): setattr(hist, key, value) session.add(hist) obj.version += 1 diff --git a/examples/versioning/test_versioning.py b/examples/versioning/test_versioning.py index 43e2b0ae1..5b57ecaa2 100644 --- a/examples/versioning/test_versioning.py +++ b/examples/versioning/test_versioning.py @@ -1,9 +1,9 @@ from unittest import TestCase from sqlalchemy.ext.declarative import declarative_base -from history_meta import Versioned, versioned_session +from .history_meta import Versioned, versioned_session from sqlalchemy import create_engine, Column, Integer, String, ForeignKey from sqlalchemy.orm import clear_mappers, sessionmaker, deferred, relationship -from _lib import ComparableEntity, eq_ +from ._lib import ComparableEntity, eq_ engine = Session = None @@ -188,9 +188,9 @@ 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), - SubClassSamePkHistory(id=3, name=u'same1', type=u'same', version=1) + SubClassSeparatePkHistory(id=1, name='sep1', type='sep', version=1), + BaseClassHistory(id=2, name='base1', type='base', version=1), + SubClassSamePkHistory(id=3, name='same1', type='same', version=1) ] ) @@ -199,10 +199,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), - SubClassSamePkHistory(id=3, name=u'same1', type=u'same', version=1), - SubClassSamePkHistory(id=3, name=u'same1', type=u'same', version=2) + SubClassSeparatePkHistory(id=1, name='sep1', type='sep', version=1), + BaseClassHistory(id=2, name='base1', type='base', version=1), + SubClassSamePkHistory(id=3, name='same1', type='same', version=1), + SubClassSamePkHistory(id=3, name='same1', type='same', version=2) ] ) @@ -210,11 +210,11 @@ 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), - SubClassSamePkHistory(id=3, name=u'same1', type=u'same', version=2) + SubClassSeparatePkHistory(id=1, name='sep1', type='sep', version=1), + BaseClassHistory(id=2, name='base1', type='base', version=1), + BaseClassHistory(id=2, name='base1mod', type='base', version=2), + SubClassSamePkHistory(id=3, name='same1', type='same', version=1), + SubClassSamePkHistory(id=3, name='same1', type='same', version=2) ] ) @@ -249,7 +249,7 @@ class TestVersioning(TestCase): eq_( sess.query(BaseClassHistory).order_by(BaseClassHistory.id, BaseClassHistory.version).all(), - [BaseClassHistory(id=1, name=u'b1', type=u'base', version=1)] + [BaseClassHistory(id=1, name='b1', type='base', version=1)] ) sc.name ='s1modified' @@ -258,9 +258,9 @@ class TestVersioning(TestCase): eq_( sess.query(BaseClassHistory).order_by(BaseClassHistory.id, BaseClassHistory.version).all(), [ - BaseClassHistory(id=1, name=u'b1', type=u'base', version=1), - BaseClassHistory(id=1, name=u'b1modified', type=u'base', version=2), - SubClassHistory(id=2, name=u's1', type=u'sub', version=1) + BaseClassHistory(id=1, name='b1', type='base', version=1), + BaseClassHistory(id=1, name='b1modified', type='base', version=2), + SubClassHistory(id=2, name='s1', type='sub', version=1) ] ) diff --git a/examples/vertical/dictlike-polymorphic.py b/examples/vertical/dictlike-polymorphic.py index f800eea73..872a7c52e 100644 --- a/examples/vertical/dictlike-polymorphic.py +++ b/examples/vertical/dictlike-polymorphic.py @@ -33,7 +33,7 @@ from sqlalchemy.orm import comparable_property from sqlalchemy.ext.hybrid import hybrid_property # Using the VerticalPropertyDictMixin from the base example -from dictlike import VerticalPropertyDictMixin +from .dictlike import VerticalPropertyDictMixin class PolymorphicVerticalProperty(object): """A key/value pair with polymorphic value storage. @@ -150,9 +150,9 @@ if __name__ == '__main__': class AnimalFact(PolymorphicVerticalProperty): type_map = { - int: (u'integer', 'int_value'), - unicode: (u'char', 'char_value'), - bool: (u'boolean', 'boolean_value'), + int: ('integer', 'int_value'), + str: ('char', 'char_value'), + bool: ('boolean', 'boolean_value'), type(None): (None, None), } @@ -190,42 +190,42 @@ if __name__ == '__main__': metadata.create_all(engine) session = Session(engine) - stoat = Animal(u'stoat') - stoat[u'color'] = u'red' - stoat[u'cuteness'] = 7 - stoat[u'weasel-like'] = True + stoat = Animal('stoat') + stoat['color'] = 'red' + stoat['cuteness'] = 7 + stoat['weasel-like'] = True session.add(stoat) session.commit() - critter = session.query(Animal).filter(Animal.name == u'stoat').one() - print critter[u'color'] - print critter[u'cuteness'] + critter = session.query(Animal).filter(Animal.name == 'stoat').one() + print(critter['color']) + print(critter['cuteness']) - print "changing cuteness value and type:" - critter[u'cuteness'] = u'very cute' + print("changing cuteness value and type:") + critter['cuteness'] = 'very cute' session.commit() - marten = Animal(u'marten') - marten[u'cuteness'] = 5 - marten[u'weasel-like'] = True - marten[u'poisonous'] = False + marten = Animal('marten') + marten['cuteness'] = 5 + marten['weasel-like'] = True + marten['poisonous'] = False session.add(marten) - shrew = Animal(u'shrew') - shrew[u'cuteness'] = 5 - shrew[u'weasel-like'] = False - shrew[u'poisonous'] = True + shrew = Animal('shrew') + shrew['cuteness'] = 5 + shrew['weasel-like'] = False + shrew['poisonous'] = True session.add(shrew) session.commit() q = (session.query(Animal). filter(Animal.facts.any( - and_(AnimalFact.key == u'weasel-like', + and_(AnimalFact.key == 'weasel-like', AnimalFact.value == True)))) - print 'weasel-like animals', q.all() + print('weasel-like animals', q.all()) # Save some typing by wrapping that up in a function: with_characteristic = lambda key, value: and_(AnimalFact.key == key, @@ -233,24 +233,24 @@ if __name__ == '__main__': q = (session.query(Animal). filter(Animal.facts.any( - with_characteristic(u'weasel-like', True)))) - print 'weasel-like animals again', q.all() + with_characteristic('weasel-like', True)))) + print('weasel-like animals again', q.all()) q = (session.query(Animal). - filter(Animal.facts.any(with_characteristic(u'poisonous', False)))) - print 'animals with poisonous=False', q.all() + filter(Animal.facts.any(with_characteristic('poisonous', False)))) + print('animals with poisonous=False', q.all()) q = (session.query(Animal). filter(or_(Animal.facts.any( - with_characteristic(u'poisonous', False)), - not_(Animal.facts.any(AnimalFact.key == u'poisonous'))))) - print 'non-poisonous animals', q.all() + with_characteristic('poisonous', False)), + not_(Animal.facts.any(AnimalFact.key == 'poisonous'))))) + print('non-poisonous animals', q.all()) q = (session.query(Animal). filter(Animal.facts.any(AnimalFact.value == 5))) - print 'any animal with a .value of 5', q.all() + print('any animal with a .value of 5', q.all()) # Facts can be queried as well. q = (session.query(AnimalFact). - filter(with_characteristic(u'cuteness', u'very cute'))) - print q.all() + filter(with_characteristic('cuteness', 'very cute'))) + print(q.all()) diff --git a/examples/vertical/dictlike.py b/examples/vertical/dictlike.py index 71ab77342..f17d1acc8 100644 --- a/examples/vertical/dictlike.py +++ b/examples/vertical/dictlike.py @@ -176,49 +176,49 @@ if __name__ == '__main__': metadata.create_all(engine) session = Session(bind=engine) - stoat = Animal(u'stoat') - stoat[u'color'] = u'reddish' - stoat[u'cuteness'] = u'somewhat' + stoat = Animal('stoat') + stoat['color'] = 'reddish' + stoat['cuteness'] = 'somewhat' # dict-like assignment transparently creates entries in the # stoat.facts collection: - print stoat.facts[u'color'] + print(stoat.facts['color']) session.add(stoat) session.commit() - critter = session.query(Animal).filter(Animal.name == u'stoat').one() - print critter[u'color'] - print critter[u'cuteness'] + critter = session.query(Animal).filter(Animal.name == 'stoat').one() + print(critter['color']) + print(critter['cuteness']) - critter[u'cuteness'] = u'very' + critter['cuteness'] = 'very' - print 'changing cuteness:' + print('changing cuteness:') engine.echo = True session.commit() engine.echo = False - marten = Animal(u'marten') - marten[u'color'] = u'brown' - marten[u'cuteness'] = u'somewhat' + marten = Animal('marten') + marten['color'] = 'brown' + marten['cuteness'] = 'somewhat' session.add(marten) - shrew = Animal(u'shrew') - shrew[u'cuteness'] = u'somewhat' - shrew[u'poisonous-part'] = u'saliva' + shrew = Animal('shrew') + shrew['cuteness'] = 'somewhat' + shrew['poisonous-part'] = 'saliva' session.add(shrew) - loris = Animal(u'slow loris') - loris[u'cuteness'] = u'fairly' - loris[u'poisonous-part'] = u'elbows' + loris = Animal('slow loris') + loris['cuteness'] = 'fairly' + loris['poisonous-part'] = 'elbows' session.add(loris) session.commit() q = (session.query(Animal). filter(Animal.facts.any( - and_(AnimalFact.key == u'color', - AnimalFact.value == u'reddish')))) - print 'reddish animals', q.all() + and_(AnimalFact.key == 'color', + AnimalFact.value == 'reddish')))) + print('reddish animals', q.all()) # Save some typing by wrapping that up in a function: with_characteristic = lambda key, value: and_(AnimalFact.key == key, @@ -226,21 +226,21 @@ if __name__ == '__main__': q = (session.query(Animal). filter(Animal.facts.any( - with_characteristic(u'color', u'brown')))) - print 'brown animals', q.all() + with_characteristic('color', 'brown')))) + print('brown animals', q.all()) q = (session.query(Animal). filter(not_(Animal.facts.any( - with_characteristic(u'poisonous-part', u'elbows'))))) - print 'animals without poisonous-part == elbows', q.all() + with_characteristic('poisonous-part', 'elbows'))))) + print('animals without poisonous-part == elbows', q.all()) q = (session.query(Animal). - filter(Animal.facts.any(AnimalFact.value == u'somewhat'))) - print 'any animal with any .value of "somewhat"', q.all() + filter(Animal.facts.any(AnimalFact.value == 'somewhat'))) + print('any animal with any .value of "somewhat"', q.all()) # Facts can be queried as well. q = (session.query(AnimalFact). - filter(with_characteristic(u'cuteness', u'very'))) - print 'just the facts', q.all() + filter(with_characteristic('cuteness', 'very'))) + print('just the facts', q.all()) diff --git a/lib/sqlalchemy/__init__.py b/lib/sqlalchemy/__init__.py index 6e924ea9d..d92b81eac 100644 --- a/lib/sqlalchemy/__init__.py +++ b/lib/sqlalchemy/__init__.py @@ -117,7 +117,7 @@ from .inspection import inspect from .engine import create_engine, engine_from_config -__all__ = sorted(name for name, obj in locals().items() +__all__ = sorted(name for name, obj in list(locals().items()) if not (name.startswith('_') or _inspect.ismodule(obj))) __version__ = '0.8.1' diff --git a/lib/sqlalchemy/connectors/mxodbc.py b/lib/sqlalchemy/connectors/mxodbc.py index db297c9ab..ebdcd2758 100644 --- a/lib/sqlalchemy/connectors/mxodbc.py +++ b/lib/sqlalchemy/connectors/mxodbc.py @@ -82,7 +82,7 @@ class MxODBCConnector(Connector): category=errorclass, stacklevel=2) else: - raise errorclass, errorvalue + raise errorclass(errorvalue) return error_handler def create_connect_args(self, url): diff --git a/lib/sqlalchemy/connectors/pyodbc.py b/lib/sqlalchemy/connectors/pyodbc.py index f1a979286..504414b0f 100644 --- a/lib/sqlalchemy/connectors/pyodbc.py +++ b/lib/sqlalchemy/connectors/pyodbc.py @@ -9,7 +9,7 @@ from ..util import asbool import sys import re -import urllib +import urllib.request, urllib.parse, urllib.error class PyODBCConnector(Connector): @@ -59,7 +59,7 @@ class PyODBCConnector(Connector): connect_args[param] = asbool(keys.pop(param)) if 'odbc_connect' in keys: - connectors = [urllib.unquote_plus(keys.pop('odbc_connect'))] + connectors = [urllib.parse.unquote_plus(keys.pop('odbc_connect'))] else: dsn_connection = 'dsn' in keys or \ ('host' in keys and 'database' not in keys) @@ -91,7 +91,7 @@ class PyODBCConnector(Connector): connectors.append("AutoTranslate=%s" % keys.pop("odbc_autotranslate")) - connectors.extend(['%s=%s' % (k, v) for k, v in keys.iteritems()]) + connectors.extend(['%s=%s' % (k, v) for k, v in keys.items()]) return [[";".join(connectors)], connect_args] def is_disconnect(self, e, connection, cursor): @@ -123,16 +123,16 @@ class PyODBCConnector(Connector): # the "Py2K only" part here is theoretical. # have not tried pyodbc + python3.1 yet. - # Py2K - self.supports_unicode_statements = ( - not self.freetds and not self.easysoft) - if self._user_supports_unicode_binds is not None: - self.supports_unicode_binds = self._user_supports_unicode_binds - else: - self.supports_unicode_binds = ( - not self.freetds or self.freetds_driver_version >= '0.91' - ) and not self.easysoft - # end Py2K +# start Py2K +# self.supports_unicode_statements = ( +# not self.freetds and not self.easysoft) +# if self._user_supports_unicode_binds is not None: +# self.supports_unicode_binds = self._user_supports_unicode_binds +# else: +# self.supports_unicode_binds = ( +# not self.freetds or self.freetds_driver_version >= '0.91' +# ) and not self.easysoft +# end Py2K # run other initialization which asks for user name, etc. super(PyODBCConnector, self).initialize(connection) diff --git a/lib/sqlalchemy/dialects/firebird/base.py b/lib/sqlalchemy/dialects/firebird/base.py index 95196f44c..bb60a591e 100644 --- a/lib/sqlalchemy/dialects/firebird/base.py +++ b/lib/sqlalchemy/dialects/firebird/base.py @@ -685,7 +685,7 @@ class FBDialect(default.DefaultDialect): self.normalize_name(row['fname'])) fk['referred_columns'].append( self.normalize_name(row['targetfname'])) - return fks.values() + return list(fks.values()) @reflection.cache def get_indexes(self, connection, table_name, schema=None, **kw): @@ -716,7 +716,7 @@ class FBDialect(default.DefaultDialect): indexrec['column_names'].append( self.normalize_name(row['field_name'])) - return indexes.values() + return list(indexes.values()) def do_execute(self, cursor, statement, parameters, context=None): # kinterbase does not accept a None, but wants an empty list diff --git a/lib/sqlalchemy/dialects/informix/base.py b/lib/sqlalchemy/dialects/informix/base.py index 77361a5d0..691400e05 100644 --- a/lib/sqlalchemy/dialects/informix/base.py +++ b/lib/sqlalchemy/dialects/informix/base.py @@ -24,6 +24,7 @@ from sqlalchemy import sql, schema, exc, pool, util from sqlalchemy.sql import compiler, text from sqlalchemy.engine import default, reflection from sqlalchemy import types as sqltypes +from functools import reduce RESERVED_WORDS = set( ["abs", "absolute", "access", "access_method", "acos", "active", "add", @@ -298,7 +299,7 @@ class InfoDDLCompiler(compiler.DDLCompiler): def get_column_default_string(self, column): if (isinstance(column.server_default, schema.DefaultClause) and - isinstance(column.server_default.arg, basestring)): + isinstance(column.server_default.arg, str)): if isinstance(column.type, (sqltypes.Integer, sqltypes.Numeric)): return self.sql_compiler.process(text(column.server_default.arg)) @@ -322,10 +323,10 @@ class InfoDDLCompiler(compiler.DDLCompiler): remote_table = list(constraint._elements.values())[0].column.table text = "FOREIGN KEY (%s) REFERENCES %s (%s)" % ( ', '.join(preparer.quote(f.parent.name, f.parent.quote) - for f in constraint._elements.values()), + for f in list(constraint._elements.values())), preparer.format_table(remote_table), ', '.join(preparer.quote(f.column.name, f.column.quote) - for f in constraint._elements.values()) + for f in list(constraint._elements.values())) ) text += self.define_constraint_cascades(constraint) text += self.define_constraint_deferrability(constraint) @@ -506,7 +507,7 @@ class InformixDialect(default.DefaultDialect): if remote_column not in remote_cols: remote_cols.append(remote_column) - return fkeys.values() + return list(fkeys.values()) @reflection.cache def get_pk_constraint(self, connection, table_name, schema=None, **kw): diff --git a/lib/sqlalchemy/dialects/mssql/adodbapi.py b/lib/sqlalchemy/dialects/mssql/adodbapi.py index 167b4e807..080382d55 100644 --- a/lib/sqlalchemy/dialects/mssql/adodbapi.py +++ b/lib/sqlalchemy/dialects/mssql/adodbapi.py @@ -44,7 +44,7 @@ class MSDialect_adodbapi(MSDialect): @classmethod def import_dbapi(cls): - import adodbapi as module + from . import adodbapi as module return module colspecs = util.update_copy( diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index 70ffcb8cd..827cf0186 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -295,7 +295,7 @@ class _MSDate(sqltypes.Date): def process(value): if isinstance(value, datetime.datetime): return value.date() - elif isinstance(value, basestring): + elif isinstance(value, str): return datetime.date(*[ int(x or 0) for x in self._reg.match(value).groups() @@ -328,7 +328,7 @@ class TIME(sqltypes.TIME): def process(value): if isinstance(value, datetime.datetime): return value.time() - elif isinstance(value, basestring): + elif isinstance(value, str): return datetime.time(*[ int(x or 0) for x in self._reg.match(value).groups()]) @@ -1002,7 +1002,7 @@ class MSDDLCompiler(compiler.DDLCompiler): # handle other included columns if index.kwargs.get("mssql_include"): inclusions = [index.table.c[col] - if isinstance(col, basestring) else col + if isinstance(col, str) else col for col in index.kwargs["mssql_include"]] text += " INCLUDE (%s)" \ @@ -1103,7 +1103,7 @@ class MSDialect(default.DefaultDialect): query_timeout=None, use_scope_identity=True, max_identifier_length=None, - schema_name=u"dbo", **opts): + schema_name="dbo", **opts): self.query_timeout = int(query_timeout or 0) self.schema_name = schema_name @@ -1123,7 +1123,7 @@ class MSDialect(default.DefaultDialect): def initialize(self, connection): super(MSDialect, self).initialize(connection) - if self.server_version_info[0] not in range(8, 17): + if self.server_version_info[0] not in list(range(8, 17)): # FreeTDS with version 4.2 seems to report here # a number like "95.10.255". Don't know what # that is. So emit warning. @@ -1150,7 +1150,7 @@ class MSDialect(default.DefaultDialect): try: default_schema_name = connection.scalar(query, name=user_name) if default_schema_name is not None: - return unicode(default_schema_name) + return str(default_schema_name) except: pass return self.schema_name @@ -1188,7 +1188,7 @@ class MSDialect(default.DefaultDialect): s = sql.select([tables.c.table_name], sql.and_( tables.c.table_schema == owner, - tables.c.table_type == u'BASE TABLE' + tables.c.table_type == 'BASE TABLE' ), order_by=[tables.c.table_name] ) @@ -1202,7 +1202,7 @@ class MSDialect(default.DefaultDialect): s = sql.select([tables.c.table_name], sql.and_( tables.c.table_schema == owner, - tables.c.table_type == u'VIEW' + tables.c.table_type == 'VIEW' ), order_by=[tables.c.table_name] ) @@ -1267,7 +1267,7 @@ class MSDialect(default.DefaultDialect): if row['index_id'] in indexes: indexes[row['index_id']]['column_names'].append(row['name']) - return indexes.values() + return list(indexes.values()) @reflection.cache @_db_plus_owner @@ -1474,4 +1474,4 @@ class MSDialect(default.DefaultDialect): local_cols.append(scol) remote_cols.append(rcol) - return fkeys.values() + return list(fkeys.values()) diff --git a/lib/sqlalchemy/dialects/mssql/information_schema.py b/lib/sqlalchemy/dialects/mssql/information_schema.py index 80e59d323..61403271f 100644 --- a/lib/sqlalchemy/dialects/mssql/information_schema.py +++ b/lib/sqlalchemy/dialects/mssql/information_schema.py @@ -17,10 +17,10 @@ class CoerceUnicode(TypeDecorator): impl = Unicode def process_bind_param(self, value, dialect): - # Py2K - if isinstance(value, str): - value = value.decode(dialect.encoding) - # end Py2K +# start Py2K +# if isinstance(value, str): +# value = value.decode(dialect.encoding) +# end Py2K return value def bind_expression(self, bindvalue): diff --git a/lib/sqlalchemy/dialects/mssql/pyodbc.py b/lib/sqlalchemy/dialects/mssql/pyodbc.py index beb6066f5..5a359d179 100644 --- a/lib/sqlalchemy/dialects/mssql/pyodbc.py +++ b/lib/sqlalchemy/dialects/mssql/pyodbc.py @@ -219,7 +219,7 @@ class MSExecutionContext_pyodbc(MSExecutionContext): # without closing it (FreeTDS particularly) row = self.cursor.fetchall()[0] break - except self.dialect.dbapi.Error, e: + except self.dialect.dbapi.Error as e: # no way around this - nextset() consumes the previous set # so we need to just keep flipping self.cursor.nextset() diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index 38c86b116..c0497b14f 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -652,7 +652,7 @@ class BIT(sqltypes.TypeEngine): def process(value): if value is not None: - v = 0L + v = 0 for i in map(ord, value): v = v << 8 | i return v @@ -1171,7 +1171,7 @@ class SET(_StringType): super_convert = super(SET, self).bind_processor(dialect) def process(value): - if value is None or isinstance(value, (int, long, basestring)): + if value is None or isinstance(value, (int, str)): pass else: if None in value: @@ -1352,7 +1352,7 @@ class MySQLCompiler(compiler.SQLCompiler): of a SELECT. """ - if isinstance(select._distinct, basestring): + if isinstance(select._distinct, str): return select._distinct.upper() + " " elif select._distinct: return "DISTINCT " @@ -1441,7 +1441,7 @@ class MySQLDDLCompiler(compiler.DDLCompiler): MySQLDDLCompiler, self).create_table_constraints(table) engine_key = '%s_engine' % self.dialect.name - is_innodb = table.kwargs.has_key(engine_key) and \ + is_innodb = engine_key in table.kwargs and \ table.kwargs[engine_key].lower() == 'innodb' auto_inc_column = table._autoincrement_column @@ -1494,7 +1494,7 @@ class MySQLDDLCompiler(compiler.DDLCompiler): k[len(self.dialect.name) + 1:].upper(), v ) - for k, v in table.kwargs.items() + for k, v in list(table.kwargs.items()) if k.startswith('%s_' % self.dialect.name) ) @@ -2045,7 +2045,7 @@ class MySQLDialect(default.DefaultDialect): have = rs.fetchone() is not None rs.close() return have - except exc.DBAPIError, e: + except exc.DBAPIError as e: if self._extract_error_code(e.orig) == 1146: return False raise @@ -2328,7 +2328,7 @@ class MySQLDialect(default.DefaultDialect): rp = None try: rp = connection.execute(st) - except exc.DBAPIError, e: + except exc.DBAPIError as e: if self._extract_error_code(e.orig) == 1146: raise exc.NoSuchTableError(full_name) else: @@ -2352,7 +2352,7 @@ class MySQLDialect(default.DefaultDialect): try: try: rp = connection.execute(st) - except exc.DBAPIError, e: + except exc.DBAPIError as e: if self._extract_error_code(e.orig) == 1146: raise exc.NoSuchTableError(full_name) else: @@ -2485,7 +2485,7 @@ class MySQLTableDefinitionParser(object): for nope in ('auto_increment', 'data directory', 'index directory'): options.pop(nope, None) - for opt, val in options.items(): + for opt, val in list(options.items()): state.table_options['%s_%s' % (self.dialect.name, opt)] = val def _parse_column(self, line, state): @@ -2626,11 +2626,11 @@ class MySQLTableDefinitionParser(object): _final = self.preparer.final_quote - quotes = dict(zip(('iq', 'fq', 'esc_fq'), + quotes = dict(list(zip(('iq', 'fq', 'esc_fq'), [re.escape(s) for s in (self.preparer.initial_quote, _final, - self.preparer._escape_identifier(_final))])) + self.preparer._escape_identifier(_final))]))) self._pr_name = _pr_compile( r'^CREATE (?:\w+ +)?TABLE +' @@ -2802,11 +2802,12 @@ class _DecodingRowProxy(object): item = self.rowproxy[index] if isinstance(item, _array): item = item.tostring() - # Py2K - if self.charset and isinstance(item, str): - # end Py2K - # Py3K - #if self.charset and isinstance(item, bytes): +# start Py2K +# if self.charset and isinstance(item, str): +# end Py2K +# start Py3K + if self.charset and isinstance(item, bytes): +# end Py3K return item.decode(self.charset) else: return item @@ -2815,11 +2816,12 @@ class _DecodingRowProxy(object): item = getattr(self.rowproxy, attr) if isinstance(item, _array): item = item.tostring() - # Py2K - if self.charset and isinstance(item, str): - # end Py2K - # Py3K - #if self.charset and isinstance(item, bytes): +# start Py2K +# if self.charset and isinstance(item, str): +# end Py2K +# start Py3K + if self.charset and isinstance(item, bytes): +# end Py3K return item.decode(self.charset) else: return item diff --git a/lib/sqlalchemy/dialects/mysql/cymysql.py b/lib/sqlalchemy/dialects/mysql/cymysql.py index 0806f63b4..6fcbc2307 100644 --- a/lib/sqlalchemy/dialects/mysql/cymysql.py +++ b/lib/sqlalchemy/dialects/mysql/cymysql.py @@ -25,15 +25,16 @@ class _cymysqlBIT(BIT): def process(value): if value is not None: - # Py2K - v = 0L - for i in map(ord, value): +# start Py2K +# v = 0L +# for i in map(ord, value): +# v = v << 8 | i +# end Py2K +# start Py3K + v = 0 + for i in value: v = v << 8 | i - # end Py2K - # Py3K - #v = 0 - #for i in value: - # v = v << 8 | i +# end Py3K return v return value return process diff --git a/lib/sqlalchemy/dialects/mysql/oursql.py b/lib/sqlalchemy/dialects/mysql/oursql.py index db24adf03..b97afe933 100644 --- a/lib/sqlalchemy/dialects/mysql/oursql.py +++ b/lib/sqlalchemy/dialects/mysql/oursql.py @@ -55,9 +55,9 @@ class MySQLExecutionContext_oursql(MySQLExecutionContext): class MySQLDialect_oursql(MySQLDialect): driver = 'oursql' -# Py2K - supports_unicode_binds = True - supports_unicode_statements = True +# start Py2K +# supports_unicode_binds = True +# supports_unicode_statements = True # end Py2K supports_native_decimal = True @@ -90,12 +90,13 @@ class MySQLDialect_oursql(MySQLDialect): connection.cursor().execute('BEGIN', plain_query=True) def _xa_query(self, connection, query, xid): -# Py2K - arg = connection.connection._escape_string(xid) +# start Py2K +# arg = connection.connection._escape_string(xid) # end Py2K -# Py3K -# charset = self._connection_charset -# arg = connection.connection._escape_string(xid.encode(charset)).decode(charset) +# start Py3K + charset = self._connection_charset + arg = connection.connection._escape_string(xid.encode(charset)).decode(charset) +# end Py3K arg = "'%s'" % arg connection.execution_options(_oursql_plain_query=True).execute(query % arg) diff --git a/lib/sqlalchemy/dialects/mysql/zxjdbc.py b/lib/sqlalchemy/dialects/mysql/zxjdbc.py index ea01da21c..20f2e7359 100644 --- a/lib/sqlalchemy/dialects/mysql/zxjdbc.py +++ b/lib/sqlalchemy/dialects/mysql/zxjdbc.py @@ -37,7 +37,7 @@ class _ZxJDBCBit(BIT): return value if isinstance(value, bool): return int(value) - v = 0L + v = 0 for i in value: v = v << 8 | (i & 0xff) value = v diff --git a/lib/sqlalchemy/dialects/oracle/base.py b/lib/sqlalchemy/dialects/oracle/base.py index 831ba5f1b..a45793367 100644 --- a/lib/sqlalchemy/dialects/oracle/base.py +++ b/lib/sqlalchemy/dialects/oracle/base.py @@ -437,7 +437,7 @@ class OracleCompiler(compiler.SQLCompiler): def get_select_hint_text(self, byfroms): return " ".join( - "/*+ %s */" % text for table, text in byfroms.items() + "/*+ %s */" % text for table, text in list(byfroms.items()) ) def function_argspec(self, fn, **kw): @@ -654,14 +654,14 @@ class OracleDDLCompiler(compiler.DDLCompiler): class OracleIdentifierPreparer(compiler.IdentifierPreparer): reserved_words = set([x.lower() for x in RESERVED_WORDS]) - illegal_initial_characters = set(xrange(0, 10)).union(["_", "$"]) + illegal_initial_characters = set(range(0, 10)).union(["_", "$"]) def _bindparam_requires_quotes(self, value): """Return True if the given identifier requires quoting.""" lc_value = value.lower() return (lc_value in self.reserved_words or value[0] in self.illegal_initial_characters - or not self.legal_characters.match(unicode(value)) + or not self.legal_characters.match(str(value)) ) def format_savepoint(self, savepoint): @@ -765,10 +765,10 @@ class OracleDialect(default.DefaultDialect): def normalize_name(self, name): if name is None: return None - # Py2K - if isinstance(name, str): - name = name.decode(self.encoding) - # end Py2K +# start Py2K +# if isinstance(name, str): +# name = name.decode(self.encoding) +# end Py2K if name.upper() == name and \ not self.identifier_preparer._requires_quotes(name.lower()): return name.lower() @@ -780,16 +780,16 @@ class OracleDialect(default.DefaultDialect): return None elif name.lower() == name and not self.identifier_preparer._requires_quotes(name.lower()): name = name.upper() - # Py2K - if not self.supports_unicode_binds: - name = name.encode(self.encoding) - else: - name = unicode(name) - # end Py2K +# start Py2K +# if not self.supports_unicode_binds: +# name = name.encode(self.encoding) +# else: +# name = unicode(name) +# end Py2K return name def _get_default_schema_name(self, connection): - return self.normalize_name(connection.execute(u'SELECT USER FROM DUAL').scalar()) + return self.normalize_name(connection.execute('SELECT USER FROM DUAL').scalar()) def _resolve_synonym(self, connection, desired_owner=None, desired_synonym=None, desired_table=None): """search for a local synonym matching the given desired owner/name. @@ -1167,7 +1167,7 @@ class OracleDialect(default.DefaultDialect): local_cols.append(local_column) remote_cols.append(remote_column) - return fkeys.values() + return list(fkeys.values()) @reflection.cache def get_view_definition(self, connection, view_name, schema=None, diff --git a/lib/sqlalchemy/dialects/oracle/cx_oracle.py b/lib/sqlalchemy/dialects/oracle/cx_oracle.py index b8f7439f5..10ec20dee 100644 --- a/lib/sqlalchemy/dialects/oracle/cx_oracle.py +++ b/lib/sqlalchemy/dialects/oracle/cx_oracle.py @@ -182,7 +182,7 @@ a period "." as the decimal character. """ -from __future__ import absolute_import + from .base import OracleCompiler, OracleDialect, OracleExecutionContext from . import base as oracle @@ -268,20 +268,21 @@ class _LOBMixin(object): class _NativeUnicodeMixin(object): - # Py3K - #pass - # Py2K - def bind_processor(self, dialect): - if dialect._cx_oracle_with_unicode: - def process(value): - if value is None: - return value - else: - return unicode(value) - return process - else: - return super(_NativeUnicodeMixin, self).bind_processor(dialect) - # end Py2K +# start Py3K + pass +# end Py3K +# start Py2K +# def bind_processor(self, dialect): +# if dialect._cx_oracle_with_unicode: +# def process(value): +# if value is None: +# return value +# else: +# return unicode(value) +# return process +# else: +# return super(_NativeUnicodeMixin, self).bind_processor(dialect) +# end Py2K # we apply a connection output handler that returns # unicode in all cases, so the "native_unicode" flag @@ -391,10 +392,10 @@ class OracleExecutionContext_cx_oracle(OracleExecutionContext): (fromname.encode(self.dialect.encoding), toname.encode(self.dialect.encoding)) for fromname, toname in - quoted_bind_names.items() + list(quoted_bind_names.items()) ) for param in self.parameters: - for fromname, toname in quoted_bind_names.items(): + for fromname, toname in list(quoted_bind_names.items()): param[toname] = param[fromname] del param[fromname] @@ -408,7 +409,7 @@ class OracleExecutionContext_cx_oracle(OracleExecutionContext): # if a single execute, check for outparams if len(self.compiled_parameters) == 1: - for bindparam in self.compiled.binds.values(): + for bindparam in list(self.compiled.binds.values()): if bindparam.isoutparam: dbtype = bindparam.type.dialect_impl(self.dialect).\ get_dbapi_type(self.dialect.dbapi) @@ -437,7 +438,7 @@ class OracleExecutionContext_cx_oracle(OracleExecutionContext): if hasattr(self, 'out_parameters') and self.compiled.returning: returning_params = dict( (k, v.getvalue()) - for k, v in self.out_parameters.items() + for k, v in list(self.out_parameters.items()) ) return ReturningResultProxy(self, returning_params) @@ -456,7 +457,7 @@ class OracleExecutionContext_cx_oracle(OracleExecutionContext): len(self.compiled_parameters) == 1: result.out_parameters = out_parameters = {} - for bind, name in self.compiled.bind_names.items(): + for bind, name in list(self.compiled.bind_names.items()): if name in self.out_parameters: type = bind.type impl_type = type.dialect_impl(self.dialect) @@ -472,7 +473,7 @@ class OracleExecutionContext_cx_oracle(OracleExecutionContext): else: result.out_parameters = dict( (k, v.getvalue()) - for k, v in self.out_parameters.items() + for k, v in list(self.out_parameters.items()) ) return result @@ -493,11 +494,11 @@ class OracleExecutionContext_cx_oracle_with_unicode(OracleExecutionContext_cx_or """ def __init__(self, *arg, **kw): OracleExecutionContext_cx_oracle.__init__(self, *arg, **kw) - self.statement = unicode(self.statement) + self.statement = str(self.statement) def _execute_scalar(self, stmt): return super(OracleExecutionContext_cx_oracle_with_unicode, self).\ - _execute_scalar(unicode(stmt)) + _execute_scalar(str(stmt)) class ReturningResultProxy(_result.FullyBufferedResultProxy): @@ -607,19 +608,19 @@ class OracleDialect_cx_oracle(OracleDialect): self.supports_unicode_statements = True self.supports_unicode_binds = True self._cx_oracle_with_unicode = True - # Py2K - # There's really no reason to run with WITH_UNICODE under Python 2.x. - # Give the user a hint. - util.warn("cx_Oracle is compiled under Python 2.xx using the " - "WITH_UNICODE flag. Consider recompiling cx_Oracle without " - "this flag, which is in no way necessary for full support of Unicode. " - "Otherwise, all string-holding bind parameters must " - "be explicitly typed using SQLAlchemy's String type or one of its subtypes," - "or otherwise be passed as Python unicode. Plain Python strings " - "passed as bind parameters will be silently corrupted by cx_Oracle." - ) - self.execution_ctx_cls = OracleExecutionContext_cx_oracle_with_unicode - # end Py2K +# start Py2K +# # There's really no reason to run with WITH_UNICODE under Python 2.x. +# # Give the user a hint. +# util.warn("cx_Oracle is compiled under Python 2.xx using the " +# "WITH_UNICODE flag. Consider recompiling cx_Oracle without " +# "this flag, which is in no way necessary for full support of Unicode. " +# "Otherwise, all string-holding bind parameters must " +# "be explicitly typed using SQLAlchemy's String type or one of its subtypes," +# "or otherwise be passed as Python unicode. Plain Python strings " +# "passed as bind parameters will be silently corrupted by cx_Oracle." +# ) +# self.execution_ctx_cls = OracleExecutionContext_cx_oracle_with_unicode +# end Py2K else: self._cx_oracle_with_unicode = False @@ -731,7 +732,7 @@ class OracleDialect_cx_oracle(OracleDialect): arraysize=cursor.arraysize) # allow all strings to come back natively as Unicode elif defaultType in (cx_Oracle.STRING, cx_Oracle.FIXED_CHAR): - return cursor.var(unicode, size, cursor.arraysize) + return cursor.var(str, size, cursor.arraysize) def on_connect(conn): conn.outputtypehandler = output_type_handler @@ -766,20 +767,20 @@ class OracleDialect_cx_oracle(OracleDialect): twophase=self.allow_twophase, ) - # Py2K - if self._cx_oracle_with_unicode: - for k, v in opts.items(): - if isinstance(v, str): - opts[k] = unicode(v) - else: - for k, v in opts.items(): - if isinstance(v, unicode): - opts[k] = str(v) - # end Py2K +# start Py2K +# if self._cx_oracle_with_unicode: +# for k, v in opts.items(): +# if isinstance(v, str): +# opts[k] = unicode(v) +# else: +# for k, v in opts.items(): +# if isinstance(v, unicode): +# opts[k] = str(v) +# end Py2K if 'mode' in url.query: opts['mode'] = url.query['mode'] - if isinstance(opts['mode'], basestring): + if isinstance(opts['mode'], str): mode = opts['mode'].upper() if mode == 'SYSDBA': opts['mode'] = self.dbapi.SYSDBA diff --git a/lib/sqlalchemy/dialects/oracle/zxjdbc.py b/lib/sqlalchemy/dialects/oracle/zxjdbc.py index d74f21aca..ad53b89a1 100644 --- a/lib/sqlalchemy/dialects/oracle/zxjdbc.py +++ b/lib/sqlalchemy/dialects/oracle/zxjdbc.py @@ -95,8 +95,8 @@ class OracleExecutionContext_zxjdbc(OracleExecutionContext): try: try: rrs = self.statement.__statement__.getReturnResultSet() - rrs.next() - except SQLException, sqle: + next(rrs) + except SQLException as sqle: msg = '%s [SQLCode: %d]' % (sqle.getMessage(), sqle.getErrorCode()) if sqle.getSQLState() is not None: msg += ' [SQLState: %s]' % sqle.getSQLState() diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 1acdb57b9..992995434 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -1419,7 +1419,7 @@ class PGDialect(default.DefaultDialect): query, bindparams=[ sql.bindparam( - 'schema', unicode(schema.lower()), + 'schema', str(schema.lower()), type_=sqltypes.Unicode)] ) ) @@ -1435,7 +1435,7 @@ class PGDialect(default.DefaultDialect): "n.oid=c.relnamespace where n.nspname=current_schema() and " "relname=:name", bindparams=[ - sql.bindparam('name', unicode(table_name), + sql.bindparam('name', str(table_name), type_=sqltypes.Unicode)] ) ) @@ -1447,9 +1447,9 @@ class PGDialect(default.DefaultDialect): "relname=:name", bindparams=[ sql.bindparam('name', - unicode(table_name), type_=sqltypes.Unicode), + str(table_name), type_=sqltypes.Unicode), sql.bindparam('schema', - unicode(schema), type_=sqltypes.Unicode)] + str(schema), type_=sqltypes.Unicode)] ) ) return bool(cursor.first()) @@ -1463,7 +1463,7 @@ class PGDialect(default.DefaultDialect): "n.nspname=current_schema() " "and relname=:name", bindparams=[ - sql.bindparam('name', unicode(sequence_name), + sql.bindparam('name', str(sequence_name), type_=sqltypes.Unicode) ] ) @@ -1475,10 +1475,10 @@ class PGDialect(default.DefaultDialect): "n.oid=c.relnamespace where relkind='S' and " "n.nspname=:schema and relname=:name", bindparams=[ - sql.bindparam('name', unicode(sequence_name), + sql.bindparam('name', str(sequence_name), type_=sqltypes.Unicode), sql.bindparam('schema', - unicode(schema), type_=sqltypes.Unicode) + str(schema), type_=sqltypes.Unicode) ] ) ) @@ -1488,9 +1488,9 @@ class PGDialect(default.DefaultDialect): def has_type(self, connection, type_name, schema=None): bindparams = [ sql.bindparam('typname', - unicode(type_name), type_=sqltypes.Unicode), + str(type_name), type_=sqltypes.Unicode), sql.bindparam('nspname', - unicode(schema), type_=sqltypes.Unicode), + str(schema), type_=sqltypes.Unicode), ] if schema is not None: query = """ @@ -1546,9 +1546,9 @@ class PGDialect(default.DefaultDialect): """ % schema_where_clause # Since we're binding to unicode, table_name and schema_name must be # unicode. - table_name = unicode(table_name) + table_name = str(table_name) if schema is not None: - schema = unicode(schema) + schema = str(schema) s = sql.text(query, bindparams=[ sql.bindparam('table_name', type_=sqltypes.Unicode), sql.bindparam('schema', type_=sqltypes.Unicode) @@ -1570,13 +1570,14 @@ class PGDialect(default.DefaultDialect): """ rp = connection.execute(s) # what about system tables? - # Py3K - #schema_names = [row[0] for row in rp \ - # if not row[0].startswith('pg_')] - # Py2K - schema_names = [row[0].decode(self.encoding) for row in rp \ +# start Py3K + schema_names = [row[0] for row in rp \ if not row[0].startswith('pg_')] - # end Py2K +# end Py3K +# start Py2K +# schema_names = [row[0].decode(self.encoding) for row in rp \ +# if not row[0].startswith('pg_')] +# end Py2K return schema_names @reflection.cache @@ -1587,7 +1588,7 @@ class PGDialect(default.DefaultDialect): current_schema = self.default_schema_name result = connection.execute( - sql.text(u"SELECT relname FROM pg_class c " + sql.text("SELECT relname FROM pg_class c " "WHERE relkind = 'r' " "AND '%s' = (select nspname from pg_namespace n " "where n.oid = c.relnamespace) " % @@ -1610,12 +1611,13 @@ class PGDialect(default.DefaultDialect): AND '%(schema)s' = (select nspname from pg_namespace n where n.oid = c.relnamespace) """ % dict(schema=current_schema) - # Py3K - #view_names = [row[0] for row in connection.execute(s)] - # Py2K - view_names = [row[0].decode(self.encoding) - for row in connection.execute(s)] - # end Py2K +# start Py3K + view_names = [row[0] for row in connection.execute(s)] +# end Py3K +# start Py2K +# view_names = [row[0].decode(self.encoding) +# for row in connection.execute(s)] +# end Py2K return view_names @reflection.cache @@ -1632,11 +1634,12 @@ class PGDialect(default.DefaultDialect): rp = connection.execute(sql.text(s), view_name=view_name, schema=current_schema) if rp: - # Py3K - #view_def = rp.scalar() - # Py2K - view_def = rp.scalar().decode(self.encoding) - # end Py2K +# start Py3K + view_def = rp.scalar() +# end Py3K +# start Py2K +# view_def = rp.scalar().decode(self.encoding) +# end Py2K return view_def @reflection.cache diff --git a/lib/sqlalchemy/dialects/postgresql/hstore.py b/lib/sqlalchemy/dialects/postgresql/hstore.py index e555a1afd..d7fd34d05 100644 --- a/lib/sqlalchemy/dialects/postgresql/hstore.py +++ b/lib/sqlalchemy/dialects/postgresql/hstore.py @@ -96,14 +96,14 @@ def _serialize_hstore(val): def esc(s, position): if position == 'value' and s is None: return 'NULL' - elif isinstance(s, basestring): + elif isinstance(s, str): return '"%s"' % s.replace('"', r'\"') else: raise ValueError("%r in %s position is not a string." % (s, position)) return ', '.join('%s=>%s' % (esc(k, 'key'), esc(v, 'value')) - for k, v in val.iteritems()) + for k, v in val.items()) class HSTORE(sqltypes.Concatenable, sqltypes.TypeEngine): diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index 805fc72af..2893a3872 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -142,7 +142,7 @@ type. This replaces SQLAlchemy's pure-Python HSTORE coercion which takes effect for other DBAPIs. """ -from __future__ import absolute_import + import re import logging @@ -190,22 +190,22 @@ class _PGNumeric(sqltypes.Numeric): class _PGEnum(ENUM): def __init__(self, *arg, **kw): super(_PGEnum, self).__init__(*arg, **kw) - # Py2K - if self.convert_unicode: - self.convert_unicode = "force" - # end Py2K +# start Py2K +# if self.convert_unicode: +# self.convert_unicode = "force" +# end Py2K class _PGArray(ARRAY): def __init__(self, *arg, **kw): super(_PGArray, self).__init__(*arg, **kw) - # Py2K - # FIXME: this check won't work for setups that - # have convert_unicode only on their create_engine(). - if isinstance(self.item_type, sqltypes.String) and \ - self.item_type.convert_unicode: - self.item_type.convert_unicode = "force" - # end Py2K +# start Py2K +# # FIXME: this check won't work for setups that +# # have convert_unicode only on their create_engine(). +# if isinstance(self.item_type, sqltypes.String) and \ +# self.item_type.convert_unicode: +# self.item_type.convert_unicode = "force" +# end Py2K class _PGHStore(HSTORE): @@ -294,9 +294,9 @@ class PGIdentifierPreparer_psycopg2(PGIdentifierPreparer): class PGDialect_psycopg2(PGDialect): driver = 'psycopg2' - # Py2K - supports_unicode_statements = False - # end Py2K +# start Py2K +# supports_unicode_statements = False +# end Py2K default_paramstyle = 'pyformat' supports_sane_multi_rowcount = False execution_ctx_cls = PGExecutionContext_psycopg2 diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index f21a81d0c..d742a71b5 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -508,7 +508,7 @@ class SQLiteDDLCompiler(compiler.DDLCompiler): def visit_foreign_key_constraint(self, constraint): - local_table = constraint._elements.values()[0].parent.table + local_table = list(constraint._elements.values())[0].parent.table remote_table = list(constraint._elements.values())[0].column.table if local_table.schema != remote_table.schema: @@ -812,7 +812,7 @@ class SQLiteDialect(default.DefaultDialect): coltype = sqltypes.NullType() if default is not None: - default = unicode(default) + default = str(default) return { 'name': name, diff --git a/lib/sqlalchemy/dialects/sqlite/pysqlite.py b/lib/sqlalchemy/dialects/sqlite/pysqlite.py index d827607ba..4a86d38d2 100644 --- a/lib/sqlalchemy/dialects/sqlite/pysqlite.py +++ b/lib/sqlalchemy/dialects/sqlite/pysqlite.py @@ -267,8 +267,9 @@ class SQLiteDialect_pysqlite(SQLiteDialect): } ) - # Py3K - #description_encoding = None +# start Py3K + description_encoding = None +# end Py3K driver = 'pysqlite' @@ -288,7 +289,7 @@ class SQLiteDialect_pysqlite(SQLiteDialect): def dbapi(cls): try: from pysqlite2 import dbapi2 as sqlite - except ImportError, e: + except ImportError as e: try: from sqlite3 import dbapi2 as sqlite # try 2.5+ stdlib name. except ImportError: diff --git a/lib/sqlalchemy/dialects/sybase/__init__.py b/lib/sqlalchemy/dialects/sybase/__init__.py index 7d504e54e..f61352ceb 100644 --- a/lib/sqlalchemy/dialects/sybase/__init__.py +++ b/lib/sqlalchemy/dialects/sybase/__init__.py @@ -9,7 +9,7 @@ from sqlalchemy.dialects.sybase import base, pysybase, pyodbc # default dialect base.dialect = pyodbc.dialect -from base import CHAR, VARCHAR, TIME, NCHAR, NVARCHAR,\ +from .base import CHAR, VARCHAR, TIME, NCHAR, NVARCHAR,\ TEXT, DATE, DATETIME, FLOAT, NUMERIC,\ BIGINT, INT, INTEGER, SMALLINT, BINARY,\ VARBINARY, UNITEXT, UNICHAR, UNIVARCHAR,\ diff --git a/lib/sqlalchemy/dialects/sybase/base.py b/lib/sqlalchemy/dialects/sybase/base.py index a9e5c5fda..6770ed8e7 100644 --- a/lib/sqlalchemy/dialects/sybase/base.py +++ b/lib/sqlalchemy/dialects/sybase/base.py @@ -475,12 +475,12 @@ class SybaseDialect(default.DefaultDialect): AND o.type in ('U', 'V') """) - # Py2K - if isinstance(schema, unicode): - schema = schema.encode("ascii") - if isinstance(table_name, unicode): - table_name = table_name.encode("ascii") - # end Py2K +# start Py2K +# if isinstance(schema, unicode): +# schema = schema.encode("ascii") +# if isinstance(table_name, unicode): +# table_name = table_name.encode("ascii") +# end Py2K result = connection.execute(TABLEID_SQL, schema_name=schema, table_name=table_name) @@ -759,10 +759,10 @@ class SybaseDialect(default.DefaultDialect): AND o.type = 'U' """) - # Py2K - if isinstance(schema, unicode): - schema = schema.encode("ascii") - # end Py2K +# start Py2K +# if isinstance(schema, unicode): +# schema = schema.encode("ascii") +# end Py2K tables = connection.execute(TABLE_SQL, schema_name=schema) return [t["name"] for t in tables] @@ -779,10 +779,10 @@ class SybaseDialect(default.DefaultDialect): AND o.type = 'V' """) - # Py2K - if isinstance(view_name, unicode): - view_name = view_name.encode("ascii") - # end Py2K +# start Py2K +# if isinstance(view_name, unicode): +# view_name = view_name.encode("ascii") +# end Py2K view = connection.execute(VIEW_DEF_SQL, view_name=view_name) return view.scalar() @@ -799,10 +799,10 @@ class SybaseDialect(default.DefaultDialect): AND o.type = 'V' """) - # Py2K - if isinstance(schema, unicode): - schema = schema.encode("ascii") - # end Py2K +# start Py2K +# if isinstance(schema, unicode): +# schema = schema.encode("ascii") +# end Py2K views = connection.execute(VIEW_SQL, schema_name=schema) return [v["name"] for v in views] diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index b4c9b1e1c..9eb3d6128 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -9,7 +9,7 @@ """ -from __future__ import with_statement + import sys from .. import exc, schema, util, log, interfaces from ..sql import expression, util as sql_util @@ -460,7 +460,7 @@ class Connection(Connectable): try: self.engine.dialect.do_begin(self.connection) - except Exception, e: + except Exception as e: self._handle_dbapi_exception(e, None, None, None, None) def _rollback_impl(self): @@ -473,7 +473,7 @@ class Connection(Connectable): try: self.engine.dialect.do_rollback(self.connection) self.__transaction = None - except Exception, e: + except Exception as e: self._handle_dbapi_exception(e, None, None, None, None) else: self.__transaction = None @@ -487,7 +487,7 @@ class Connection(Connectable): try: self.engine.dialect.do_commit(self.connection) self.__transaction = None - except Exception, e: + except Exception as e: self._handle_dbapi_exception(e, None, None, None, None) def _savepoint_impl(self, name=None): @@ -688,7 +688,7 @@ class Connection(Connectable): dialect = self.dialect ctx = dialect.execution_ctx_cls._init_default( dialect, self, conn) - except Exception, e: + except Exception as e: self._handle_dbapi_exception(e, None, None, None, None) ret = ctx._exec_default(default, None) @@ -734,7 +734,7 @@ class Connection(Connectable): distilled_params = _distill_params(multiparams, params) if distilled_params: - keys = distilled_params[0].keys() + keys = list(distilled_params[0].keys()) else: keys = [] @@ -822,7 +822,7 @@ class Connection(Connectable): conn = self._revalidate_connection() context = constructor(dialect, self, conn, *args) - except Exception, e: + except Exception as e: self._handle_dbapi_exception(e, str(statement), parameters, None, None) @@ -865,7 +865,7 @@ class Connection(Connectable): statement, parameters, context) - except Exception, e: + except Exception as e: self._handle_dbapi_exception( e, statement, @@ -939,7 +939,7 @@ class Connection(Connectable): cursor, statement, parameters) - except Exception, e: + except Exception as e: self._handle_dbapi_exception( e, statement, @@ -954,7 +954,7 @@ class Connection(Connectable): """ try: cursor.close() - except Exception, e: + except Exception as e: try: ex_text = str(e) except TypeError: @@ -1045,7 +1045,7 @@ class Connection(Connectable): Compiled: _execute_compiled, schema.SchemaItem: _execute_default, schema.DDLElement: _execute_ddl, - basestring: _execute_text + str: _execute_text } def default_schema_name(self): diff --git a/lib/sqlalchemy/engine/ddl.py b/lib/sqlalchemy/engine/ddl.py index c61a9d59c..56f475e30 100644 --- a/lib/sqlalchemy/engine/ddl.py +++ b/lib/sqlalchemy/engine/ddl.py @@ -52,10 +52,10 @@ class SchemaGenerator(DDLBase): if self.tables is not None: tables = self.tables else: - tables = metadata.tables.values() + tables = list(metadata.tables.values()) collection = [t for t in sql_util.sort_tables(tables) if self._can_create_table(t)] - seq_coll = [s for s in metadata._sequences.values() + seq_coll = [s for s in list(metadata._sequences.values()) if s.column is None and self._can_create_sequence(s)] metadata.dispatch.before_create(metadata, self.connection, @@ -120,7 +120,7 @@ class SchemaDropper(DDLBase): if self.tables is not None: tables = self.tables else: - tables = metadata.tables.values() + tables = list(metadata.tables.values()) collection = [ t @@ -130,7 +130,7 @@ class SchemaDropper(DDLBase): seq_coll = [ s - for s in metadata._sequences.values() + for s in list(metadata._sequences.values()) if s.column is None and self._can_drop_sequence(s) ] diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index daa9fe085..9dda6d81e 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -57,17 +57,18 @@ class DefaultDialect(interfaces.Dialect): # *not* the FLOAT type however. supports_native_decimal = False - # Py3K - #supports_unicode_statements = True - #supports_unicode_binds = True - #returns_unicode_strings = True - #description_encoding = None - # Py2K - supports_unicode_statements = False - supports_unicode_binds = False - returns_unicode_strings = False - description_encoding = 'use_encoding' - # end Py2K +# start Py3K + supports_unicode_statements = True + supports_unicode_binds = True + returns_unicode_strings = True + description_encoding = None +# end Py3K +# start Py2K +# supports_unicode_statements = False +# supports_unicode_binds = False +# returns_unicode_strings = False +# description_encoding = 'use_encoding' +# end Py2K name = 'default' @@ -201,14 +202,15 @@ class DefaultDialect(interfaces.Dialect): return None def _check_unicode_returns(self, connection): - # Py2K - if self.supports_unicode_statements: - cast_to = unicode - else: - cast_to = str - # end Py2K - # Py3K - #cast_to = str +# start Py2K +# if self.supports_unicode_statements: +# cast_to = unicode +# else: +# cast_to = str +# end Py2K +# start Py3K + cast_to = str +# end Py3K def check_unicode(formatstr, type_): cursor = connection.connection.cursor() @@ -226,8 +228,8 @@ class DefaultDialect(interfaces.Dialect): ) row = cursor.fetchone() - return isinstance(row[0], unicode) - except self.dbapi.Error, de: + return isinstance(row[0], str) + except self.dbapi.Error as de: util.warn("Exception attempting to " "detect unicode returns: %r" % de) return False @@ -373,10 +375,10 @@ class DefaultExecutionContext(interfaces.ExecutionContext): self.execution_options.update(connection._execution_options) if not dialect.supports_unicode_statements: - self.unicode_statement = unicode(compiled) + self.unicode_statement = str(compiled) self.statement = dialect._encoder(self.unicode_statement)[0] else: - self.statement = self.unicode_statement = unicode(compiled) + self.statement = self.unicode_statement = str(compiled) self.cursor = self.create_cursor() self.compiled_parameters = [] @@ -414,7 +416,7 @@ class DefaultExecutionContext(interfaces.ExecutionContext): self.result_map = compiled.result_map - self.unicode_statement = unicode(compiled) + self.unicode_statement = str(compiled) if not dialect.supports_unicode_statements: self.statement = self.unicode_statement.encode( self.dialect.encoding) @@ -519,7 +521,7 @@ class DefaultExecutionContext(interfaces.ExecutionContext): self.executemany = len(parameters) > 1 if not dialect.supports_unicode_statements and \ - isinstance(statement, unicode): + isinstance(statement, str): self.unicode_statement = statement self.statement = dialect._encoder(statement)[0] else: @@ -573,7 +575,7 @@ class DefaultExecutionContext(interfaces.ExecutionContext): """ conn = self.root_connection - if isinstance(stmt, unicode) and \ + if isinstance(stmt, str) and \ not self.dialect.supports_unicode_statements: stmt = self.dialect._encoder(stmt)[0] @@ -734,12 +736,12 @@ class DefaultExecutionContext(interfaces.ExecutionContext): inputsizes.append(dbtype) try: self.cursor.setinputsizes(*inputsizes) - except Exception, e: + except Exception as e: self.root_connection._handle_dbapi_exception( e, None, None, None, self) else: inputsizes = {} - for key in self.compiled.bind_names.values(): + for key in list(self.compiled.bind_names.values()): typeengine = types[key] dbtype = typeengine.dialect_impl(self.dialect).\ get_dbapi_type(self.dialect.dbapi) @@ -752,7 +754,7 @@ class DefaultExecutionContext(interfaces.ExecutionContext): inputsizes[key] = dbtype try: self.cursor.setinputsizes(**inputsizes) - except Exception, e: + except Exception as e: self.root_connection._handle_dbapi_exception( e, None, None, None, self) diff --git a/lib/sqlalchemy/engine/reflection.py b/lib/sqlalchemy/engine/reflection.py index 90f21db09..cf4a1d532 100644 --- a/lib/sqlalchemy/engine/reflection.py +++ b/lib/sqlalchemy/engine/reflection.py @@ -41,8 +41,8 @@ def cache(fn, self, con, *args, **kw): return fn(self, con, *args, **kw) key = ( fn.__name__, - tuple(a for a in args if isinstance(a, basestring)), - tuple((k, v) for k, v in kw.iteritems() if isinstance(v, (basestring, int, float))) + tuple(a for a in args if isinstance(a, str)), + tuple((k, v) for k, v in kw.items() if isinstance(v, (str, int, float))) ) ret = info_cache.get(key) if ret is None: @@ -381,16 +381,16 @@ class Inspector(object): # table.kwargs will need to be passed to each reflection method. Make # sure keywords are strings. tblkw = table.kwargs.copy() - for (k, v) in tblkw.items(): + for (k, v) in list(tblkw.items()): del tblkw[k] tblkw[str(k)] = v - # Py2K - if isinstance(schema, str): - schema = schema.decode(dialect.encoding) - if isinstance(table_name, str): - table_name = table_name.decode(dialect.encoding) - # end Py2K +# start Py2K +# if isinstance(schema, str): +# schema = schema.decode(dialect.encoding) +# if isinstance(table_name, str): +# table_name = table_name.decode(dialect.encoding) +# end Py2K # columns found_table = False diff --git a/lib/sqlalchemy/engine/result.py b/lib/sqlalchemy/engine/result.py index 88930081e..0bd501423 100644 --- a/lib/sqlalchemy/engine/result.py +++ b/lib/sqlalchemy/engine/result.py @@ -8,7 +8,7 @@ and :class:`.RowProxy.""" -from itertools import izip + from .. import exc, types, util from ..sql import expression import collections @@ -55,7 +55,7 @@ except ImportError: return list(self) def __iter__(self): - for processor, value in izip(self._processors, self._row): + for processor, value in zip(self._processors, self._row): if processor is None: yield value else: @@ -72,7 +72,7 @@ except ImportError: except TypeError: if isinstance(key, slice): l = [] - for processor, value in izip(self._processors[key], + for processor, value in zip(self._processors[key], self._row[key]): if processor is None: l.append(value) @@ -93,7 +93,7 @@ except ImportError: def __getattr__(self, name): try: return self[name] - except KeyError, e: + except KeyError as e: raise AttributeError(e.args[0]) @@ -142,7 +142,7 @@ class RowProxy(BaseRowProxy): def items(self): """Return a list of tuples, each tuple containing a key/value pair.""" # TODO: no coverage here - return [(key, self[key]) for key in self.iterkeys()] + return [(key, self[key]) for key in self.keys()] def keys(self): """Return the list of keys as strings represented by this RowProxy.""" @@ -274,7 +274,7 @@ class ResultMetaData(object): def _key_fallback(self, key, raiseerr=True): map = self._keymap result = None - if isinstance(key, basestring): + if isinstance(key, str): result = map.get(key if self.case_sensitive else key.lower()) # fallback for targeting a ColumnElement to a textual expression # this is a rare use case which only occurs when matching text() @@ -328,8 +328,8 @@ class ResultMetaData(object): return { '_pickled_keymap': dict( (key, index) - for key, (processor, obj, index) in self._keymap.iteritems() - if isinstance(key, (basestring, int)) + for key, (processor, obj, index) in self._keymap.items() + if isinstance(key, (str, int)) ), 'keys': self.keys, "case_sensitive": self.case_sensitive, @@ -338,9 +338,9 @@ class ResultMetaData(object): def __setstate__(self, state): # the row has been processed at pickling time so we don't need any # processor anymore - self._processors = [None for _ in xrange(len(state['keys']))] + self._processors = [None for _ in range(len(state['keys']))] self._keymap = keymap = {} - for key, index in state['_pickled_keymap'].iteritems(): + for key, index in state['_pickled_keymap'].items(): # not preserving "obj" here, unfortunately our # proxy comparison fails with the unpickle keymap[key] = (None, None, index) @@ -440,7 +440,7 @@ class ResultProxy(object): """ try: return self.context.rowcount - except Exception, e: + except Exception as e: self.connection._handle_dbapi_exception( e, None, None, self.cursor, self.context) @@ -462,7 +462,7 @@ class ResultProxy(object): """ try: return self._saved_cursor.lastrowid - except Exception, e: + except Exception as e: self.connection._handle_dbapi_exception( e, None, None, self._saved_cursor, self.context) @@ -746,7 +746,7 @@ class ResultProxy(object): l = self.process_rows(self._fetchall_impl()) self.close() return l - except Exception, e: + except Exception as e: self.connection._handle_dbapi_exception( e, None, None, self.cursor, self.context) @@ -765,7 +765,7 @@ class ResultProxy(object): if len(l) == 0: self.close() return l - except Exception, e: + except Exception as e: self.connection._handle_dbapi_exception( e, None, None, self.cursor, self.context) @@ -784,7 +784,7 @@ class ResultProxy(object): else: self.close() return None - except Exception, e: + except Exception as e: self.connection._handle_dbapi_exception( e, None, None, self.cursor, self.context) @@ -800,7 +800,7 @@ class ResultProxy(object): try: row = self._fetchone_impl() - except Exception, e: + except Exception as e: self.connection._handle_dbapi_exception( e, None, None, self.cursor, self.context) @@ -966,9 +966,9 @@ class BufferedColumnResultProxy(ResultProxy): # constructed. metadata._orig_processors = metadata._processors # replace the all type processors by None processors. - metadata._processors = [None for _ in xrange(len(metadata.keys))] + metadata._processors = [None for _ in range(len(metadata.keys))] keymap = {} - for k, (func, obj, index) in metadata._keymap.iteritems(): + for k, (func, obj, index) in metadata._keymap.items(): keymap[k] = (None, obj, index) self._metadata._keymap = keymap @@ -989,7 +989,7 @@ class BufferedColumnResultProxy(ResultProxy): if size is None: return self.fetchall() l = [] - for i in xrange(size): + for i in range(size): row = self.fetchone() if row is None: break diff --git a/lib/sqlalchemy/engine/strategies.py b/lib/sqlalchemy/engine/strategies.py index 4c81df8f0..bed14c671 100644 --- a/lib/sqlalchemy/engine/strategies.py +++ b/lib/sqlalchemy/engine/strategies.py @@ -78,20 +78,21 @@ class DefaultEngineStrategy(EngineStrategy): def connect(): try: return dialect.connect(*cargs, **cparams) - except Exception, e: + except Exception as e: invalidated = dialect.is_disconnect(e, None, None) - # Py3K - #raise exc.DBAPIError.instance(None, None, - # e, dialect.dbapi.Error, - # connection_invalidated=invalidated - #) from e - # Py2K - import sys - raise exc.DBAPIError.instance( - None, None, e, dialect.dbapi.Error, +# start Py3K + raise exc.DBAPIError.instance(None, None, + e, dialect.dbapi.Error, connection_invalidated=invalidated - ), None, sys.exc_info()[2] - # end Py2K + ) from e +# end Py3K +# start Py2K +# import sys +# raise exc.DBAPIError.instance( +# None, None, e, dialect.dbapi.Error, +# connection_invalidated=invalidated +# ), None, sys.exc_info()[2] +# end Py2K creator = kwargs.pop('creator', connect) diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py index c4931b48c..45768c5dc 100644 --- a/lib/sqlalchemy/engine/url.py +++ b/lib/sqlalchemy/engine/url.py @@ -14,7 +14,7 @@ be used directly and is also accepted directly by ``create_engine()``. """ import re -import urllib +import urllib.request, urllib.parse, urllib.error from .. import exc, util from . import Dialect @@ -67,7 +67,7 @@ class URL(object): if self.username is not None: s += self.username if self.password is not None: - s += ':' + urllib.quote_plus(self.password) + s += ':' + urllib.parse.quote_plus(self.password) s += "@" if self.host is not None: s += self.host @@ -76,7 +76,7 @@ class URL(object): if self.database is not None: s += '/' + self.database if self.query: - keys = self.query.keys() + keys = list(self.query.keys()) keys.sort() s += '?' + "&".join("%s=%s" % (k, self.query[k]) for k in keys) return s @@ -150,7 +150,7 @@ def make_url(name_or_url): existing URL object is passed, just returns the object. """ - if isinstance(name_or_url, basestring): + if isinstance(name_or_url, str): return _parse_rfc1738_args(name_or_url) else: return name_or_url @@ -177,17 +177,17 @@ def _parse_rfc1738_args(name): tokens = components['database'].split('?', 2) components['database'] = tokens[0] query = (len(tokens) > 1 and dict(util.parse_qsl(tokens[1]))) or None - # Py2K - if query is not None: - query = dict((k.encode('ascii'), query[k]) for k in query) - # end Py2K +# start Py2K +# if query is not None: +# query = dict((k.encode('ascii'), query[k]) for k in query) +# end Py2K else: query = None components['query'] = query if components['password'] is not None: components['password'] = \ - urllib.unquote_plus(components['password']) + urllib.parse.unquote_plus(components['password']) name = components.pop('name') return URL(name, **components) diff --git a/lib/sqlalchemy/event.py b/lib/sqlalchemy/event.py index f28f19ee9..de054b0fd 100644 --- a/lib/sqlalchemy/event.py +++ b/lib/sqlalchemy/event.py @@ -201,11 +201,9 @@ def _remove_dispatcher(cls): del _registrars[k] -class Events(object): +class Events(object, metaclass=_EventMeta): """Define event listening functions for a particular target type.""" - __metaclass__ = _EventMeta - @classmethod def _accept_with(cls, target): # Mapper, ClassManager, Session override this to @@ -302,7 +300,7 @@ class _DispatchDescriptor(object): def clear(self): """Clear all class level listeners""" - for dispatcher in self._clslevel.values(): + for dispatcher in list(self._clslevel.values()): dispatcher[:] = [] def for_modify(self, obj): @@ -377,7 +375,7 @@ class _EmptyListener(object): def __iter__(self): return iter(self.parent_listeners) - def __nonzero__(self): + def __bool__(self): return bool(self.parent_listeners) @@ -414,7 +412,7 @@ class _CompoundListener(object): def __iter__(self): return chain(self.parent_listeners, self.listeners) - def __nonzero__(self): + def __bool__(self): return bool(self.listeners or self.parent_listeners) diff --git a/lib/sqlalchemy/exc.py b/lib/sqlalchemy/exc.py index 0ce5393be..f5dc1119d 100644 --- a/lib/sqlalchemy/exc.py +++ b/lib/sqlalchemy/exc.py @@ -285,7 +285,7 @@ class DBAPIError(StatementError): text = str(orig) except (KeyboardInterrupt, SystemExit): raise - except Exception, e: + except Exception as e: text = 'Error in str() of DB-API-generated exception: ' + str(e) StatementError.__init__( self, diff --git a/lib/sqlalchemy/ext/associationproxy.py b/lib/sqlalchemy/ext/associationproxy.py index 252efcb42..ad09db831 100644 --- a/lib/sqlalchemy/ext/associationproxy.py +++ b/lib/sqlalchemy/ext/associationproxy.py @@ -475,7 +475,7 @@ class _AssociationCollection(object): def __len__(self): return len(self.col) - def __nonzero__(self): + def __bool__(self): return bool(self.col) def __getstate__(self): @@ -514,7 +514,7 @@ class _AssociationList(_AssociationCollection): stop = index.stop step = index.step or 1 - rng = range(index.start or 0, stop, step) + rng = list(range(index.start or 0, stop, step)) if step == 1: for i in rng: del self[index.start] @@ -569,7 +569,7 @@ class _AssociationList(_AssociationCollection): def count(self, value): return sum([1 for _ in - itertools.ifilter(lambda v: v == value, iter(self))]) + filter(lambda v: v == value, iter(self))]) def extend(self, values): for v in values: @@ -668,8 +668,8 @@ class _AssociationList(_AssociationCollection): def __hash__(self): raise TypeError("%s objects are unhashable" % type(self).__name__) - for func_name, func in locals().items(): - if (util.callable(func) and func.func_name == func_name and + for func_name, func in list(locals().items()): + if (util.callable(func) and func.__name__ == func_name and not func.__doc__ and hasattr(list, func_name)): func.__doc__ = getattr(list, func_name).__doc__ del func_name, func @@ -711,7 +711,7 @@ class _AssociationDict(_AssociationCollection): return key in self.col def __iter__(self): - return self.col.iterkeys() + return iter(self.col.keys()) def clear(self): self.col.clear() @@ -738,7 +738,7 @@ class _AssociationDict(_AssociationCollection): return cmp(dict(self), other) def __repr__(self): - return repr(dict(self.items())) + return repr(dict(list(self.items()))) def get(self, key, default=None): try: @@ -754,13 +754,13 @@ class _AssociationDict(_AssociationCollection): return self[key] def keys(self): - return self.col.keys() + return list(self.col.keys()) def iterkeys(self): - return self.col.iterkeys() + return iter(self.col.keys()) def values(self): - return [self._get(member) for member in self.col.values()] + return [self._get(member) for member in list(self.col.values())] def itervalues(self): for key in self.col: @@ -811,13 +811,13 @@ class _AssociationDict(_AssociationCollection): self[key] = value def copy(self): - return dict(self.items()) + return dict(list(self.items())) def __hash__(self): raise TypeError("%s objects are unhashable" % type(self).__name__) - for func_name, func in locals().items(): - if (util.callable(func) and func.func_name == func_name and + for func_name, func in list(locals().items()): + if (util.callable(func) and func.__name__ == func_name and not func.__doc__ and hasattr(dict, func_name)): func.__doc__ = getattr(dict, func_name).__doc__ del func_name, func @@ -838,7 +838,7 @@ class _AssociationSet(_AssociationCollection): def __len__(self): return len(self.col) - def __nonzero__(self): + def __bool__(self): if self.col: return True else: @@ -1014,8 +1014,8 @@ class _AssociationSet(_AssociationCollection): def __hash__(self): raise TypeError("%s objects are unhashable" % type(self).__name__) - for func_name, func in locals().items(): - if (util.callable(func) and func.func_name == func_name and + for func_name, func in list(locals().items()): + if (util.callable(func) and func.__name__ == func_name and not func.__doc__ and hasattr(set, func_name)): func.__doc__ = getattr(set, func_name).__doc__ del func_name, func diff --git a/lib/sqlalchemy/ext/declarative/api.py b/lib/sqlalchemy/ext/declarative/api.py index 6f3ffddc7..21fac8534 100644 --- a/lib/sqlalchemy/ext/declarative/api.py +++ b/lib/sqlalchemy/ext/declarative/api.py @@ -424,7 +424,7 @@ class DeferredReflection(object): def prepare(cls, engine): """Reflect all :class:`.Table` objects for all current :class:`.DeferredReflection` subclasses""" - to_map = [m for m in _MapperConfig.configs.values() + to_map = [m for m in list(_MapperConfig.configs.values()) if issubclass(m.cls, cls)] for thingy in to_map: cls._sa_decl_prepare(thingy.local_table, engine) diff --git a/lib/sqlalchemy/ext/declarative/base.py b/lib/sqlalchemy/ext/declarative/base.py index ee2f0134a..2099f9eb0 100644 --- a/lib/sqlalchemy/ext/declarative/base.py +++ b/lib/sqlalchemy/ext/declarative/base.py @@ -57,7 +57,7 @@ def _as_declarative(cls, classname, dict_): class_mapped = _declared_mapping_info(base) is not None - for name, obj in vars(base).items(): + for name, obj in list(vars(base).items()): if name == '__mapper_args__': if not mapper_args_fn and ( not class_mapped or @@ -129,7 +129,7 @@ def _as_declarative(cls, classname, dict_): ret.doc = obj.__doc__ # apply inherited columns as we should - for k, v in potential_columns.items(): + for k, v in list(potential_columns.items()): dict_[k] = v if inherited_table_args and not tablename: @@ -173,7 +173,7 @@ def _as_declarative(cls, classname, dict_): # extract columns from the class dict declared_columns = set() - for key, c in our_stuff.iteritems(): + for key, c in our_stuff.items(): if isinstance(c, (ColumnProperty, CompositeProperty)): for col in c.columns: if isinstance(col, Column) and \ @@ -354,7 +354,7 @@ class _MapperConfig(object): # in which case the mapper makes this combination). # See if the superclass has a similar column property. # If so, join them together. - for k, col in properties.items(): + for k, col in list(properties.items()): if not isinstance(col, expression.ColumnElement): continue if k in inherited_mapper._props: diff --git a/lib/sqlalchemy/ext/declarative/clsregistry.py b/lib/sqlalchemy/ext/declarative/clsregistry.py index 89975716d..95aba93fa 100644 --- a/lib/sqlalchemy/ext/declarative/clsregistry.py +++ b/lib/sqlalchemy/ext/declarative/clsregistry.py @@ -255,7 +255,7 @@ def _resolver(cls, prop): return x.cls else: return x - except NameError, n: + except NameError as n: raise exc.InvalidRequestError( "When initializing mapper %s, expression %r failed to " "locate a name (%r). If this is a class name, consider " @@ -275,14 +275,14 @@ def _deferred_relationship(cls, prop): for attr in ('argument', 'order_by', 'primaryjoin', 'secondaryjoin', 'secondary', '_user_defined_foreign_keys', 'remote_side'): v = getattr(prop, attr) - if isinstance(v, basestring): + if isinstance(v, str): setattr(prop, attr, resolve_arg(v)) if prop.backref and isinstance(prop.backref, tuple): key, kwargs = prop.backref for attr in ('primaryjoin', 'secondaryjoin', 'secondary', 'foreign_keys', 'remote_side', 'order_by'): - if attr in kwargs and isinstance(kwargs[attr], basestring): + if attr in kwargs and isinstance(kwargs[attr], str): kwargs[attr] = resolve_arg(kwargs[attr]) return prop diff --git a/lib/sqlalchemy/ext/mutable.py b/lib/sqlalchemy/ext/mutable.py index b1b851f72..08c0bdf13 100644 --- a/lib/sqlalchemy/ext/mutable.py +++ b/lib/sqlalchemy/ext/mutable.py @@ -485,7 +485,7 @@ class Mutable(MutableBase): def changed(self): """Subclasses should call this method whenever change events occur.""" - for parent, key in self._parents.items(): + for parent, key in list(self._parents.items()): flag_modified(parent, key) @classmethod @@ -579,7 +579,7 @@ class MutableComposite(MutableBase): def changed(self): """Subclasses should call this method whenever change events occur.""" - for parent, key in self._parents.items(): + for parent, key in list(self._parents.items()): prop = object_mapper(parent).get_property(key) for value, attr_name in zip( diff --git a/lib/sqlalchemy/ext/orderinglist.py b/lib/sqlalchemy/ext/orderinglist.py index ffdd971a0..930464d7b 100644 --- a/lib/sqlalchemy/ext/orderinglist.py +++ b/lib/sqlalchemy/ext/orderinglist.py @@ -324,7 +324,7 @@ class OrderingList(list): if stop < 0: stop += len(self) - for i in xrange(start, stop, step): + for i in range(start, stop, step): self.__setitem__(i, entity[i]) else: self._order_entity(index, entity, True) @@ -334,21 +334,21 @@ class OrderingList(list): super(OrderingList, self).__delitem__(index) self._reorder() - # Py2K - def __setslice__(self, start, end, values): - super(OrderingList, self).__setslice__(start, end, values) - self._reorder() - - def __delslice__(self, start, end): - super(OrderingList, self).__delslice__(start, end) - self._reorder() - # end Py2K +# start Py2K +# def __setslice__(self, start, end, values): +# super(OrderingList, self).__setslice__(start, end, values) +# self._reorder() +# +# def __delslice__(self, start, end): +# super(OrderingList, self).__delslice__(start, end) +# self._reorder() +# end Py2K def __reduce__(self): return _reconstitute, (self.__class__, self.__dict__, list(self)) - for func_name, func in locals().items(): - if (util.callable(func) and func.func_name == func_name and + for func_name, func in list(locals().items()): + if (util.callable(func) and func.__name__ == func_name and not func.__doc__ and hasattr(list, func_name)): func.__doc__ = getattr(list, func_name).__doc__ del func_name, func diff --git a/lib/sqlalchemy/ext/serializer.py b/lib/sqlalchemy/ext/serializer.py index 5a3fb5937..759652014 100644 --- a/lib/sqlalchemy/ext/serializer.py +++ b/lib/sqlalchemy/ext/serializer.py @@ -61,20 +61,22 @@ from ..engine import Engine from ..util import pickle import re import base64 -# Py3K -#from io import BytesIO as byte_buffer -# Py2K -from cStringIO import StringIO as byte_buffer +# start Py3K +from io import BytesIO as byte_buffer +# end Py3K +# start Py2K +#from cStringIO import StringIO as byte_buffer # end Py2K -# Py3K -#def b64encode(x): -# return base64.b64encode(x).decode('ascii') -#def b64decode(x): -# return base64.b64decode(x.encode('ascii')) -# Py2K -b64encode = base64.b64encode -b64decode = base64.b64decode +# start Py3K +def b64encode(x): + return base64.b64encode(x).decode('ascii') +def b64decode(x): + return base64.b64decode(x.encode('ascii')) +# end Py3K +# start Py2K +#b64encode = base64.b64encode +#b64decode = base64.b64decode # end Py2K __all__ = ['Serializer', 'Deserializer', 'dumps', 'loads'] diff --git a/lib/sqlalchemy/orm/__init__.py b/lib/sqlalchemy/orm/__init__.py index 0132bb389..07927890e 100644 --- a/lib/sqlalchemy/orm/__init__.py +++ b/lib/sqlalchemy/orm/__init__.py @@ -1628,7 +1628,7 @@ def contains_eager(*keys, **kwargs): alias = kwargs.pop('alias', None) if kwargs: raise exc.ArgumentError( - 'Invalid kwargs for contains_eager: %r' % kwargs.keys()) + 'Invalid kwargs for contains_eager: %r' % list(kwargs.keys())) return strategies.EagerLazyOption(keys, lazy='joined', propagate_to_loaders=False, chained=True), \ strategies.LoadEagerFromAliasOption(keys, alias=alias, chained=True) diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index 3eda127fd..691904bb3 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -1214,7 +1214,7 @@ class History(History): """ - def __nonzero__(self): + def __bool__(self): return self != HISTORY_BLANK def empty(self): diff --git a/lib/sqlalchemy/orm/collections.py b/lib/sqlalchemy/orm/collections.py index 5691acfff..0a11b83c6 100644 --- a/lib/sqlalchemy/orm/collections.py +++ b/lib/sqlalchemy/orm/collections.py @@ -657,11 +657,12 @@ class CollectionAdapter(object): if getattr(obj, '_sa_adapter', None) is not None: return getattr(obj, '_sa_adapter') elif setting_type == dict: - # Py3K - #return obj.values() - # Py2K - return getattr(obj, 'itervalues', getattr(obj, 'values'))() - # end Py2K +# start Py3K + return list(obj.values()) +# end Py3K +# start Py2K +# return getattr(obj, 'itervalues', getattr(obj, 'values'))() +# end Py2K else: return iter(obj) @@ -705,14 +706,15 @@ class CollectionAdapter(object): def __iter__(self): """Iterate over entities in the collection.""" - # Py3K requires iter() here +# start Py3K +# end Py3K return iter(getattr(self._data(), '_sa_iterator')()) def __len__(self): """Count entities in the collection.""" return len(list(getattr(self._data(), '_sa_iterator')())) - def __nonzero__(self): + def __bool__(self): return True def fire_append_event(self, item, initiator=None): @@ -883,7 +885,7 @@ def _instrument_class(cls): # search for _sa_instrument_role-decorated methods in # method resolution order, assign to roles for supercls in cls.__mro__: - for name, method in vars(supercls).items(): + for name, method in list(vars(supercls).items()): if not util.callable(method): continue @@ -917,11 +919,11 @@ def _instrument_class(cls): collection_type = util.duck_type_collection(cls) if collection_type in __interfaces: canned_roles, decorators = __interfaces[collection_type] - for role, name in canned_roles.items(): + for role, name in list(canned_roles.items()): roles.setdefault(role, name) # apply ABC auto-decoration to methods that need it - for method, decorator in decorators.items(): + for method, decorator in list(decorators.items()): fn = getattr(cls, method, None) if (fn and method not in methods and not hasattr(fn, '_sa_instrumented')): @@ -952,12 +954,12 @@ def _instrument_class(cls): # apply ad-hoc instrumentation from decorators, class-level defaults # and implicit role declarations - for method_name, (before, argument, after) in methods.items(): + for method_name, (before, argument, after) in list(methods.items()): setattr(cls, method_name, _instrument_membership_mutator(getattr(cls, method_name), before, argument, after)) # intern the role map - for role, method_name in roles.items(): + for role, method_name in list(roles.items()): setattr(cls, '_sa_%s' % role, getattr(cls, method_name)) setattr(cls, '_sa_instrumented', id(cls)) @@ -1094,14 +1096,14 @@ def _list_decorators(): stop += len(self) if step == 1: - for i in xrange(start, stop, step): + for i in range(start, stop, step): if len(self) > start: del self[start] for i, item in enumerate(value): self.insert(i + start, item) else: - rng = range(start, stop, step) + rng = list(range(start, stop, step)) if len(value) != len(rng): raise ValueError( "attempt to assign sequence of size %s to " @@ -1128,24 +1130,24 @@ def _list_decorators(): _tidy(__delitem__) return __delitem__ - # Py2K - def __setslice__(fn): - def __setslice__(self, start, end, values): - for value in self[start:end]: - __del(self, value) - values = [__set(self, value) for value in values] - fn(self, start, end, values) - _tidy(__setslice__) - return __setslice__ - - def __delslice__(fn): - def __delslice__(self, start, end): - for value in self[start:end]: - __del(self, value) - fn(self, start, end) - _tidy(__delslice__) - return __delslice__ - # end Py2K +# start Py2K +# def __setslice__(fn): +# def __setslice__(self, start, end, values): +# for value in self[start:end]: +# __del(self, value) +# values = [__set(self, value) for value in values] +# fn(self, start, end, values) +# _tidy(__setslice__) +# return __setslice__ +# +# def __delslice__(fn): +# def __delslice__(self, start, end): +# for value in self[start:end]: +# __del(self, value) +# fn(self, start, end) +# _tidy(__delslice__) +# return __delslice__ +# end Py2K def extend(fn): def extend(self, iterable): @@ -1251,7 +1253,7 @@ def _dict_decorators(): def update(self, __other=Unspecified, **kw): if __other is not Unspecified: if hasattr(__other, 'keys'): - for key in __other.keys(): + for key in list(__other.keys()): if (key not in self or self[key] is not __other[key]): self[key] = __other[key] @@ -1467,11 +1469,12 @@ __interfaces = { ), # decorators are required for dicts and object collections. - # Py3K - #dict: ({'iterator': 'values'}, _dict_decorators()), - # Py2K - dict: ({'iterator': 'itervalues'}, _dict_decorators()), - # end Py2K +# start Py3K + dict: ({'iterator': 'values'}, _dict_decorators()), +# end Py3K +# start Py2K +# dict: ({'iterator': 'itervalues'}, _dict_decorators()), +# end Py2K } diff --git a/lib/sqlalchemy/orm/descriptor_props.py b/lib/sqlalchemy/orm/descriptor_props.py index 1969bd03b..86b445bb6 100644 --- a/lib/sqlalchemy/orm/descriptor_props.py +++ b/lib/sqlalchemy/orm/descriptor_props.py @@ -184,7 +184,7 @@ class CompositeProperty(DescriptorProperty): def _init_props(self): self.props = props = [] for attr in self.attrs: - if isinstance(attr, basestring): + if isinstance(attr, str): prop = self.parent.get_property(attr) elif isinstance(attr, schema.Column): prop = self.parent._columntoproperty[attr] diff --git a/lib/sqlalchemy/orm/evaluator.py b/lib/sqlalchemy/orm/evaluator.py index 0844e2f72..e8433290c 100644 --- a/lib/sqlalchemy/orm/evaluator.py +++ b/lib/sqlalchemy/orm/evaluator.py @@ -13,9 +13,9 @@ class UnevaluatableError(Exception): _straight_ops = set(getattr(operators, op) for op in ('add', 'mul', 'sub', - # Py2K - 'div', - # end Py2K +# start Py2K +# 'div', +# end Py2K 'mod', 'truediv', 'lt', 'le', 'ne', 'gt', 'ge', 'eq')) @@ -50,7 +50,7 @@ class EvaluatorCompiler(object): return lambda obj: get_corresponding_attr(obj) def visit_clauselist(self, clause): - evaluators = map(self.process, clause.clauses) + evaluators = list(map(self.process, clause.clauses)) if clause.operator is operators.or_: def evaluate(obj): has_null = False @@ -79,8 +79,8 @@ class EvaluatorCompiler(object): return evaluate def visit_binary(self, clause): - eval_left, eval_right = map(self.process, - [clause.left, clause.right]) + eval_left, eval_right = list(map(self.process, + [clause.left, clause.right])) operator = clause.operator if operator is operators.is_: def evaluate(obj): diff --git a/lib/sqlalchemy/orm/identity.py b/lib/sqlalchemy/orm/identity.py index 01d34428e..f010a7699 100644 --- a/lib/sqlalchemy/orm/identity.py +++ b/lib/sqlalchemy/orm/identity.py @@ -75,7 +75,7 @@ class WeakInstanceDict(IdentityMap): state = dict.__getitem__(self, key) o = state.obj() if o is None: - raise KeyError, key + raise KeyError(key) return o def __contains__(self, key): @@ -152,30 +152,32 @@ class WeakInstanceDict(IdentityMap): return result - # Py3K - #def items(self): - # return iter(self._items()) - # - #def values(self): - # return iter(self._values()) - # Py2K - items = _items - - def iteritems(self): - return iter(self.items()) - - values = _values - - def itervalues(self): - return iter(self.values()) - # end Py2K +# start Py3K + def items(self): + return iter(self._items()) + + def values(self): + return iter(self._values()) +# end Py3K +# start Py2K +# items = _items +# +# def iteritems(self): +# return iter(self.items()) +# +# values = _values +# +# def itervalues(self): +# return iter(self.values()) +# end Py2K def all_states(self): - # Py3K - # return list(dict.values(self)) - # Py2K - return dict.values(self) - # end Py2K +# start Py3K + return list(dict.values(self)) +# end Py3K +# start Py2K +# return dict.values(self) +# end Py2K def discard(self, state): st = dict.get(self, state.key, None) @@ -189,7 +191,7 @@ class WeakInstanceDict(IdentityMap): class StrongInstanceDict(IdentityMap): def all_states(self): - return [attributes.instance_state(o) for o in self.itervalues()] + return [attributes.instance_state(o) for o in self.values()] def contains_state(self, state): return ( diff --git a/lib/sqlalchemy/orm/instrumentation.py b/lib/sqlalchemy/orm/instrumentation.py index 0e71494c4..ce12acf20 100644 --- a/lib/sqlalchemy/orm/instrumentation.py +++ b/lib/sqlalchemy/orm/instrumentation.py @@ -279,7 +279,7 @@ class ClassManager(dict): @property def attributes(self): - return self.itervalues() + return iter(self.values()) ## InstanceState management @@ -325,7 +325,7 @@ class ClassManager(dict): """TODO""" return self.get_impl(key).hasparent(state, optimistic=optimistic) - def __nonzero__(self): + def __bool__(self): """All ClassManagers are non-zero regardless of attribute state.""" return True @@ -444,21 +444,23 @@ def __init__(%(apply_pos)s): func_vars = util.format_argspec_init(original__init__, grouped=False) func_text = func_body % func_vars - # Py3K - #func_defaults = getattr(original__init__, '__defaults__', None) - #func_kw_defaults = getattr(original__init__, '__kwdefaults__', None) - # Py2K - func = getattr(original__init__, 'im_func', original__init__) - func_defaults = getattr(func, 'func_defaults', None) - # end Py2K +# start Py3K + func_defaults = getattr(original__init__, '__defaults__', None) + func_kw_defaults = getattr(original__init__, '__kwdefaults__', None) +# end Py3K +# start Py2K +# func = getattr(original__init__, 'im_func', original__init__) +# func_defaults = getattr(func, 'func_defaults', None) +# end Py2K env = locals().copy() - exec func_text in env + exec(func_text, env) __init__ = env['__init__'] __init__.__doc__ = original__init__.__doc__ if func_defaults: - __init__.func_defaults = func_defaults - # Py3K - #if func_kw_defaults: - # __init__.__kwdefaults__ = func_kw_defaults + __init__.__defaults__ = func_defaults +# start Py3K + if func_kw_defaults: + __init__.__kwdefaults__ = func_kw_defaults +# end Py3K return __init__ diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py index 70743624c..f14c8ca47 100644 --- a/lib/sqlalchemy/orm/interfaces.py +++ b/lib/sqlalchemy/orm/interfaces.py @@ -15,7 +15,7 @@ Other than the deprecated extensions, this module and the classes within should be considered mostly private. """ -from __future__ import absolute_import + from .. import exc as sa_exc, util, inspect from ..sql import operators @@ -659,7 +659,7 @@ class PropertyOption(MapperOption): tokens = deque(self.key) while tokens: token = tokens.popleft() - if isinstance(token, basestring): + if isinstance(token, str): # wildcard token if token.endswith(':*'): return [path.token(token)] diff --git a/lib/sqlalchemy/orm/loading.py b/lib/sqlalchemy/orm/loading.py index 5937197fd..e1f4d1b7c 100644 --- a/lib/sqlalchemy/orm/loading.py +++ b/lib/sqlalchemy/orm/loading.py @@ -11,7 +11,7 @@ the functions here are called primarily by Query, Mapper, as well as some of the attribute loading strategies. """ -from __future__ import absolute_import + from .. import util from . import attributes, exc as orm_exc, state as statelib @@ -47,11 +47,11 @@ def instances(query, cursor, context): query._entities[0].mapper.dispatch.append_result (process, labels) = \ - zip(*[ + list(zip(*[ query_entity.row_processor(query, context, custom_rows) for query_entity in query._entities - ]) + ])) while True: context.progress = {} @@ -84,11 +84,11 @@ def instances(query, cursor, context): context.progress.pop(context.refresh_state) statelib.InstanceState._commit_all_states( - context.progress.items(), + list(context.progress.items()), session.identity_map ) - for state, (dict_, attrs) in context.partials.iteritems(): + for state, (dict_, attrs) in context.partials.items(): state._commit(dict_, attrs) for row in rows: @@ -507,7 +507,7 @@ def _populators(mapper, context, path, row, adapter, pops = (new_populators, existing_populators, delayed_populators, eager_populators) - for prop in mapper._props.itervalues(): + for prop in mapper._props.values(): for i, pop in enumerate(prop.create_row_processor( context, diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index c08d91b57..91c678547 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -13,7 +13,7 @@ This is a semi-private module; the main configurational API of the ORM is available in :class:`~sqlalchemy.orm.`. """ -from __future__ import absolute_import + import types import weakref from itertools import chain @@ -581,7 +581,7 @@ class Mapper(_InspectionAttr): if with_polymorphic == '*': self.with_polymorphic = ('*', None) elif isinstance(with_polymorphic, (tuple, list)): - if isinstance(with_polymorphic[0], (basestring, tuple, list)): + if isinstance(with_polymorphic[0], (str, tuple, list)): self.with_polymorphic = with_polymorphic else: self.with_polymorphic = (with_polymorphic, None) @@ -626,7 +626,7 @@ class Mapper(_InspectionAttr): self.inherits._inheriting_mappers.add(self) self.passive_updates = self.inherits.passive_updates self._all_tables = self.inherits._all_tables - for key, prop in mapper._props.iteritems(): + for key, prop in mapper._props.items(): if key not in self._props and \ not self._should_exclude(key, key, local=False, column=None): @@ -866,12 +866,12 @@ class Mapper(_InspectionAttr): # load custom properties if self._init_properties: - for key, prop in self._init_properties.iteritems(): + for key, prop in self._init_properties.items(): self._configure_property(key, prop, False) # pull properties from the inherited mapper if any. if self.inherits: - for key, prop in self.inherits._props.iteritems(): + for key, prop in self.inherits._props.items(): if key not in self._props and \ not self._should_exclude(key, key, local=False, column=None): @@ -919,7 +919,7 @@ class Mapper(_InspectionAttr): if self.polymorphic_on is not None: setter = True - if isinstance(self.polymorphic_on, basestring): + if isinstance(self.polymorphic_on, str): # polymorphic_on specified as as string - link # it to mapped ColumnProperty try: @@ -1235,7 +1235,7 @@ class Mapper(_InspectionAttr): """ self._log("_post_configure_properties() started") - l = [(key, prop) for key, prop in self._props.iteritems()] + l = [(key, prop) for key, prop in self._props.items()] for key, prop in l: self._log("initialize prop %s", key) @@ -1253,7 +1253,7 @@ class Mapper(_InspectionAttr): using `add_property`. """ - for key, value in dict_of_properties.iteritems(): + for key, value in dict_of_properties.items(): self.add_property(key, value) def add_property(self, key, prop): @@ -1350,7 +1350,7 @@ class Mapper(_InspectionAttr): """return an iterator of all MapperProperty objects.""" if _new_mappers: configure_mappers() - return self._props.itervalues() + return iter(self._props.values()) def _mappers_from_spec(self, spec, selectable): """given a with_polymorphic() argument, return the set of mappers it @@ -1623,7 +1623,7 @@ class Mapper(_InspectionAttr): if _new_mappers: configure_mappers() return util.ImmutableProperties(util.OrderedDict( - (k, v) for k, v in self._props.iteritems() + (k, v) for k, v in self._props.items() if isinstance(v, type_) )) @@ -1972,7 +1972,7 @@ class Mapper(_InspectionAttr): visited_states = set() prp, mpp = object(), object() - visitables = deque([(deque(self._props.values()), prp, + visitables = deque([(deque(list(self._props.values())), prp, state, state.dict)]) while visitables: @@ -1994,7 +1994,7 @@ class Mapper(_InspectionAttr): corresponding_dict = iterator.popleft() yield instance, instance_mapper, \ corresponding_state, corresponding_dict - visitables.append((deque(instance_mapper._props.values()), + visitables.append((deque(list(instance_mapper._props.values())), prp, corresponding_state, corresponding_dict)) @@ -2011,7 +2011,7 @@ class Mapper(_InspectionAttr): table_to_mapper.setdefault(t, mapper) extra_dependencies = [] - for table, mapper in table_to_mapper.items(): + for table, mapper in list(table_to_mapper.items()): super_ = mapper.inherits if super_: extra_dependencies.extend([ @@ -2040,7 +2040,7 @@ class Mapper(_InspectionAttr): return fk.parent not in cols return False - sorted_ = sql_util.sort_tables(table_to_mapper.iterkeys(), + sorted_ = sql_util.sort_tables(iter(table_to_mapper.keys()), skip_fn=skip, extra_dependencies=extra_dependencies) diff --git a/lib/sqlalchemy/orm/persistence.py b/lib/sqlalchemy/orm/persistence.py index e225a7c83..0eedea793 100644 --- a/lib/sqlalchemy/orm/persistence.py +++ b/lib/sqlalchemy/orm/persistence.py @@ -45,7 +45,7 @@ def save_obj(base_mapper, states, uowtransaction, single=False): cached_connections = _cached_connection_dict(base_mapper) - for table, mapper in base_mapper._sorted_tables.iteritems(): + for table, mapper in base_mapper._sorted_tables.items(): insert = _collect_insert_commands(base_mapper, uowtransaction, table, states_to_insert) @@ -77,7 +77,7 @@ def post_update(base_mapper, states, uowtransaction, post_update_cols): base_mapper, states, uowtransaction) - for table, mapper in base_mapper._sorted_tables.iteritems(): + for table, mapper in base_mapper._sorted_tables.items(): update = _collect_post_update_commands(base_mapper, uowtransaction, table, states_to_update, post_update_cols) @@ -105,7 +105,7 @@ def delete_obj(base_mapper, states, uowtransaction): table_to_mapper = base_mapper._sorted_tables - for table in reversed(table_to_mapper.keys()): + for table in reversed(list(table_to_mapper.keys())): delete = _collect_delete_commands(base_mapper, uowtransaction, table, states_to_delete) @@ -318,7 +318,7 @@ def _collect_update_commands(base_mapper, uowtransaction, # history is only # in a different table than the one # where the version_id_col is. - for prop in mapper._columntoproperty.itervalues(): + for prop in mapper._columntoproperty.values(): history = attributes.get_state_history( state, prop.key, attributes.PASSIVE_NO_INITIALIZE) @@ -526,7 +526,7 @@ def _emit_insert_statements(base_mapper, uowtransaction, for (connection, pkeys, hasvalue, has_all_pks), \ records in groupby(insert, lambda rec: (rec[4], - rec[2].keys(), + list(rec[2].keys()), bool(rec[5]), rec[6]) ): @@ -612,7 +612,7 @@ def _emit_post_update_statements(base_mapper, uowtransaction, # also group them into common (connection, cols) sets # to support executemany(). for key, grouper in groupby( - update, lambda rec: (rec[4], rec[2].keys()) + update, lambda rec: (rec[4], list(rec[2].keys())) ): connection = key[0] multiparams = [params for state, state_dict, @@ -646,7 +646,7 @@ def _emit_delete_statements(base_mapper, uowtransaction, cached_connections, return table.delete(clause) - for connection, del_objects in delete.iteritems(): + for connection, del_objects in delete.items(): statement = base_mapper._memo(('delete', table), delete_stmt) connection = cached_connections[connection] @@ -803,7 +803,7 @@ class BulkUD(object): raise sa_exc.ArgumentError( "Valid strategies for session synchronization " "are %s" % (", ".join(sorted(repr(x) - for x in lookup.keys())))) + for x in list(lookup.keys()))))) else: return klass(*arg) @@ -868,7 +868,7 @@ class BulkEvaluate(BulkUD): #TODO: detect when the where clause is a trivial primary key match self.matched_objects = [ obj for (cls, pk), obj in - query.session.identity_map.iteritems() + query.session.identity_map.items() if issubclass(cls, target_cls) and eval_condition(obj)] @@ -951,7 +951,7 @@ class BulkUpdateEvaluate(BulkEvaluate, BulkUpdate): def _additional_evaluators(self, evaluator_compiler): self.value_evaluators = {} - for key, value in self.values.iteritems(): + for key, value in self.values.items(): key = _attr_as_key(key) self.value_evaluators[key] = evaluator_compiler.process( expression._literal_as_binds(value)) @@ -959,7 +959,7 @@ class BulkUpdateEvaluate(BulkEvaluate, BulkUpdate): def _do_post_synchronize(self): session = self.query.session states = set() - evaluated_keys = self.value_evaluators.keys() + evaluated_keys = list(self.value_evaluators.keys()) for obj in self.matched_objects: state, dict_ = attributes.instance_state(obj),\ attributes.instance_dict(obj) diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py index 9f8721de9..8c0576527 100644 --- a/lib/sqlalchemy/orm/properties.py +++ b/lib/sqlalchemy/orm/properties.py @@ -27,7 +27,7 @@ from .interfaces import MANYTOMANY, MANYTOONE, ONETOMANY,\ mapperlib = util.importlater("sqlalchemy.orm", "mapperlib") NoneType = type(None) -from descriptor_props import CompositeProperty, SynonymProperty, \ +from .descriptor_props import CompositeProperty, SynonymProperty, \ ComparableProperty, ConcreteInheritedProperty __all__ = ['ColumnProperty', 'CompositeProperty', 'SynonymProperty', @@ -1204,7 +1204,7 @@ class RelationshipProperty(StrategizedProperty): if not self.is_primary(): return if self.backref is not None and not self.back_populates: - if isinstance(self.backref, basestring): + if isinstance(self.backref, str): backref_key, kwargs = self.backref, {} else: backref_key, kwargs = self.backref diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index c9f3a2699..80441b976 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -47,7 +47,7 @@ def _generative(*assertions): def generate(fn, *args, **kw): self = args[0]._clone() for assertion in assertions: - assertion(self, fn.func_name) + assertion(self, fn.__name__) fn(self, *args[1:], **kw) return self return generate @@ -981,11 +981,12 @@ class Query(object): """Return a scalar result corresponding to the given column expression.""" try: - # Py3K - #return self.values(column).__next__()[0] - # Py2K - return self.values(column).next()[0] - # end Py2K +# start Py3K + return self.values(column).__next__()[0] +# end Py3K +# start Py2K +# return self.values(column).next()[0] +# end Py2K except StopIteration: return None @@ -1231,7 +1232,7 @@ class Query(object): """ clauses = [_entity_descriptor(self._joinpoint_zero(), key) == value - for key, value in kwargs.iteritems()] + for key, value in kwargs.items()] return self.filter(sql.and_(*clauses)) @_generative(_no_statement_condition, _no_limit_offset) @@ -1296,7 +1297,7 @@ class Query(object): """ - if isinstance(criterion, basestring): + if isinstance(criterion, str): criterion = sql.text(criterion) if criterion is not None and \ @@ -1655,7 +1656,7 @@ class Query(object): kwargs.pop('from_joinpoint', False) if kwargs: raise TypeError("unknown arguments: %s" % - ','.join(kwargs.iterkeys())) + ','.join(iter(kwargs.keys()))) return self._join(props, outerjoin=False, create_aliases=aliased, from_joinpoint=from_joinpoint) @@ -1671,7 +1672,7 @@ class Query(object): kwargs.pop('from_joinpoint', False) if kwargs: raise TypeError("unknown arguments: %s" % - ','.join(kwargs.iterkeys())) + ','.join(iter(kwargs.keys()))) return self._join(props, outerjoin=True, create_aliases=aliased, from_joinpoint=from_joinpoint) @@ -1701,7 +1702,7 @@ class Query(object): if len(keys) == 2 and \ isinstance(keys[0], (expression.FromClause, type, AliasedClass)) and \ - isinstance(keys[1], (basestring, expression.ClauseElement, + isinstance(keys[1], (str, expression.ClauseElement, interfaces.PropComparator)): # detect 2-arg form of join and # convert to a tuple. @@ -1721,14 +1722,14 @@ class Query(object): # is a little bit of legacy behavior still at work here # which means they might be in either order. may possibly # lock this down to (right_entity, onclause) in 0.6. - if isinstance(arg1, (interfaces.PropComparator, basestring)): + if isinstance(arg1, (interfaces.PropComparator, str)): right_entity, onclause = arg2, arg1 else: right_entity, onclause = arg1, arg2 left_entity = prop = None - if isinstance(onclause, basestring): + if isinstance(onclause, str): left_entity = self._joinpoint_zero() descriptor = _entity_descriptor(left_entity, onclause) @@ -1922,7 +1923,7 @@ class Query(object): clause = orm_join(clause, right, onclause, isouter=outerjoin) - except sa_exc.ArgumentError, ae: + except sa_exc.ArgumentError as ae: raise sa_exc.InvalidRequestError( "Could not find a FROM clause to join from. " "Tried joining to %s, but got: %s" % (right, ae)) @@ -1947,7 +1948,7 @@ class Query(object): try: clause = orm_join(clause, right, onclause, isouter=outerjoin) - except sa_exc.ArgumentError, ae: + except sa_exc.ArgumentError as ae: raise sa_exc.InvalidRequestError( "Could not find a FROM clause to join from. " "Tried joining to %s, but got: %s" % (right, ae)) @@ -2115,7 +2116,7 @@ class Query(object): appropriate to the entity class represented by this ``Query``. """ - if isinstance(statement, basestring): + if isinstance(statement, str): statement = sql.text(statement) if not isinstance(statement, @@ -2609,7 +2610,7 @@ class Query(object): use_labels=context.labels) from_clause = inner - for eager_join in context.eager_joins.values(): + for eager_join in list(context.eager_joins.values()): # EagerLoader places a 'stop_on' attribute on the join, # giving us a marker as to where the "splice point" of # the join should be @@ -2674,7 +2675,7 @@ class Query(object): subtypes are selected from the total results. """ - for (ext_info, adapter) in self._mapper_adapter_map.values(): + for (ext_info, adapter) in list(self._mapper_adapter_map.values()): if ext_info in self._join_entities: continue single_crit = ext_info.mapper._single_table_criterion @@ -2697,7 +2698,7 @@ class _QueryEntity(object): def __new__(cls, *args, **kwargs): if cls is _QueryEntity: entity = args[1] - if not isinstance(entity, basestring) and \ + if not isinstance(entity, str) and \ _is_mapped_class(entity): cls = _MapperEntity else: @@ -2905,7 +2906,7 @@ class _ColumnEntity(_QueryEntity): self.expr = column self.namespace = namespace - if isinstance(column, basestring): + if isinstance(column, str): column = sql.literal_column(column) self._label_name = column.name elif isinstance(column, ( @@ -3080,7 +3081,7 @@ class AliasOption(interfaces.MapperOption): self.alias = alias def process_query(self, query): - if isinstance(self.alias, basestring): + if isinstance(self.alias, str): alias = query._mapper_zero().mapped_table.alias(self.alias) else: alias = self.alias diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index f7a5558f1..3d5f94246 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -5,7 +5,7 @@ # the MIT License: http://www.opensource.org/licenses/mit-license.php """Provides the Session class and related utilities.""" -from __future__ import with_statement + import weakref from .. import util, sql, engine, exc as sa_exc, event @@ -35,7 +35,7 @@ class _SessionClassMethods(object): def close_all(cls): """Close *all* sessions in memory.""" - for sess in _sessions.values(): + for sess in list(_sessions.values()): sess.close() @classmethod @@ -249,7 +249,7 @@ class SessionTransaction(object): if s.key: del s.key - for s, (oldkey, newkey) in self._key_switches.items(): + for s, (oldkey, newkey) in list(self._key_switches.items()): self.session.identity_map.discard(s) s.key = oldkey self.session.identity_map.replace(s) @@ -327,7 +327,7 @@ class SessionTransaction(object): subtransaction.commit() if not self.session._flushing: - for _flush_guard in xrange(100): + for _flush_guard in range(100): if self.session._is_clean(): break self.session.flush() @@ -604,7 +604,7 @@ class Session(_SessionClassMethods): SessionExtension._adapt_listener(self, ext) if binds is not None: - for mapperortable, bind in binds.iteritems(): + for mapperortable, bind in binds.items(): if isinstance(mapperortable, (type, Mapper)): self.bind_mapper(mapperortable, bind) else: @@ -1775,7 +1775,7 @@ class Session(_SessionClassMethods): Session. """ - return iter(list(self._new.values()) + self.identity_map.values()) + return iter(list(self._new.values()) + list(self.identity_map.values())) def _contains_state(self, state): return state in self._new or self.identity_map.contains_state(state) @@ -2138,13 +2138,13 @@ class Session(_SessionClassMethods): def deleted(self): "The set of all instances marked as 'deleted' within this ``Session``" - return util.IdentitySet(self._deleted.values()) + return util.IdentitySet(list(self._deleted.values())) @property def new(self): "The set of all instances marked as 'new' within this ``Session``." - return util.IdentitySet(self._new.values()) + return util.IdentitySet(list(self._new.values())) class sessionmaker(_SessionClassMethods): @@ -2236,7 +2236,7 @@ class sessionmaker(_SessionClassMethods): session = Session() # invokes sessionmaker.__call__() """ - for k, v in self.kw.items(): + for k, v in list(self.kw.items()): local_kw.setdefault(k, v) return self.class_(**local_kw) @@ -2255,7 +2255,7 @@ class sessionmaker(_SessionClassMethods): return "%s(class_=%r%s)" % ( self.__class__.__name__, self.class_.__name__, - ", ".join("%s=%r" % (k, v) for k, v in self.kw.items()) + ", ".join("%s=%r" % (k, v) for k, v in list(self.kw.items())) ) _sessions = weakref.WeakValueDictionary() diff --git a/lib/sqlalchemy/orm/state.py b/lib/sqlalchemy/orm/state.py index 6ade91b3e..8fe37e41c 100644 --- a/lib/sqlalchemy/orm/state.py +++ b/lib/sqlalchemy/orm/state.py @@ -417,7 +417,7 @@ class InstanceState(interfaces._InspectionAttr): against this set when a refresh operation occurs. """ - return set([k for k, v in self.callables.items() if v is self]) + return set([k for k, v in list(self.callables.items()) if v is self]) def _instance_dict(self): return None diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py index 6660a39ef..e80745c79 100644 --- a/lib/sqlalchemy/orm/strategies.py +++ b/lib/sqlalchemy/orm/strategies.py @@ -359,7 +359,7 @@ class LazyLoader(AbstractRelationshipLoader): ) if self.use_get: - for col in self._equated_columns.keys(): + for col in list(self._equated_columns.keys()): if col in self.mapper._equivalent_columns: for c in self.mapper._equivalent_columns[col]: self._equated_columns[c] = self._equated_columns[col] @@ -1332,7 +1332,7 @@ class EagerLazyOption(StrategizedOption): def __init__(self, key, lazy=True, chained=False, propagate_to_loaders=True ): - if isinstance(key[0], basestring) and key[0] == '*': + if isinstance(key[0], str) and key[0] == '*': if len(key) != 1: raise sa_exc.ArgumentError( "Wildcard identifier '*' must " @@ -1384,7 +1384,7 @@ class LoadEagerFromAliasOption(PropertyOption): def __init__(self, key, alias=None, chained=False): super(LoadEagerFromAliasOption, self).__init__(key) if alias is not None: - if not isinstance(alias, basestring): + if not isinstance(alias, str): info = inspect(alias) alias = info.selectable self.alias = alias @@ -1401,7 +1401,7 @@ class LoadEagerFromAliasOption(PropertyOption): root_mapper, prop = paths[-1].path[-2:] if self.alias is not None: - if isinstance(self.alias, basestring): + if isinstance(self.alias, str): self.alias = prop.target.alias(self.alias) paths[-1].set(query, "user_defined_eager_row_processor", sql_util.ColumnAdapter(self.alias, diff --git a/lib/sqlalchemy/orm/unitofwork.py b/lib/sqlalchemy/orm/unitofwork.py index 1f5115c41..54b0ebf72 100644 --- a/lib/sqlalchemy/orm/unitofwork.py +++ b/lib/sqlalchemy/orm/unitofwork.py @@ -315,7 +315,7 @@ class UOWTransaction(object): # see if the graph of mapper dependencies has cycles. self.cycles = cycles = topological.find_cycles( self.dependencies, - self.postsort_actions.values()) + list(self.postsort_actions.values())) if cycles: # if yes, break the per-mapper actions into @@ -342,7 +342,7 @@ class UOWTransaction(object): for dep in convert[edge[1]]: self.dependencies.add((edge[0], dep)) - return set([a for a in self.postsort_actions.values() + return set([a for a in list(self.postsort_actions.values()) if not a.disabled ] ).difference(cycles) @@ -381,7 +381,7 @@ class UOWTransaction(object): """ states = set(self.states) isdel = set( - s for (s, (isdelete, listonly)) in self.states.iteritems() + s for (s, (isdelete, listonly)) in self.states.items() if isdelete ) other = states.difference(isdel) @@ -461,7 +461,7 @@ class PostSortRec(object): def __repr__(self): return "%s(%s)" % ( self.__class__.__name__, - ",".join(str(x) for x in self.__dict__.values()) + ",".join(str(x) for x in list(self.__dict__.values())) ) diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index 35cb0bdf5..30a8a8084 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -120,7 +120,7 @@ def polymorphic_union(table_map, typecolname, colnames = util.OrderedSet() colnamemaps = {} types = {} - for key in table_map.keys(): + for key in list(table_map.keys()): table = table_map[key] # mysql doesnt like selecting from a select; @@ -146,7 +146,7 @@ def polymorphic_union(table_map, typecolname, return sql.type_coerce(sql.null(), types[name]).label(name) result = [] - for type, table in table_map.iteritems(): + for type, table in table_map.items(): if typecolname is not None: result.append( sql.select([col(name, table) for name in colnames] + @@ -203,7 +203,7 @@ def identity_key(*args, **kwargs): "positional arguments, got %s" % len(args)) if kwargs: raise sa_exc.ArgumentError("unknown keyword arguments: %s" - % ", ".join(kwargs.keys())) + % ", ".join(list(kwargs.keys()))) mapper = class_mapper(class_) if "ident" in locals(): return mapper.identity_key_from_primary_key(util.to_list(ident)) @@ -211,7 +211,7 @@ def identity_key(*args, **kwargs): instance = kwargs.pop("instance") if kwargs: raise sa_exc.ArgumentError("unknown keyword arguments: %s" - % ", ".join(kwargs.keys())) + % ", ".join(list(kwargs.keys()))) mapper = object_mapper(instance) return mapper.identity_key_from_instance(instance) @@ -300,7 +300,7 @@ class PathRegistry(object): def pairs(self): path = self.path - for i in xrange(0, len(path), 2): + for i in range(0, len(path), 2): yield path[i], path[i + 1] def contains_mapper(self, mapper): @@ -314,10 +314,10 @@ class PathRegistry(object): def serialize(self): path = self.path - return zip( + return list(zip( [m.class_ for m in [path[i] for i in range(0, len(path), 2)]], [path[i].key for i in range(1, len(path), 2)] + [None] - ) + )) @classmethod def deserialize(cls, path): @@ -411,7 +411,7 @@ class EntityRegistry(PathRegistry, dict): self.path = parent.path + (entity,) - def __nonzero__(self): + def __bool__(self): return True def __getitem__(self, entity): @@ -589,8 +589,8 @@ class AliasedClass(object): return self.__adapt_prop(attr, key) elif hasattr(attr, 'func_code'): is_method = getattr(self.__target, key, None) - if is_method and is_method.im_self is not None: - return util.types.MethodType(attr.im_func, self, self) + if is_method and is_method.__self__ is not None: + return util.types.MethodType(attr.__func__, self, self) else: return None elif hasattr(attr, '__get__'): @@ -880,7 +880,7 @@ class _ORMJoin(expression.Join): self._joined_from_info = right_info - if isinstance(onclause, basestring): + if isinstance(onclause, str): onclause = getattr(left_orm_info.entity, onclause) if isinstance(onclause, attributes.QueryableAttribute): @@ -1001,7 +1001,7 @@ def with_parent(instance, prop): parent/child relationship. """ - if isinstance(prop, basestring): + if isinstance(prop, str): mapper = object_mapper(instance) prop = getattr(mapper.class_, prop).property elif isinstance(prop, attributes.QueryableAttribute): diff --git a/lib/sqlalchemy/pool.py b/lib/sqlalchemy/pool.py index 501b6d2a0..562a76163 100644 --- a/lib/sqlalchemy/pool.py +++ b/lib/sqlalchemy/pool.py @@ -57,7 +57,7 @@ def clear_managers(): All pools and connections are disposed. """ - for manager in proxies.itervalues(): + for manager in proxies.values(): manager.close() proxies.clear() @@ -368,7 +368,7 @@ class _ConnectionRecord(object): connection = self.__pool._creator() self.__pool.logger.debug("Created new connection %r", connection) return connection - except Exception, e: + except Exception as e: self.__pool.logger.debug("Error on connect(): %s", e) raise @@ -391,7 +391,7 @@ def _finalize_fairy(connection, connection_record, pool, ref, echo): # Immediately close detached instances if connection_record is None: pool._close_connection(connection) - except Exception, e: + except Exception as e: if connection_record is not None: connection_record.invalidate(e=e) if isinstance(e, (SystemExit, KeyboardInterrupt)): @@ -499,7 +499,7 @@ class _ConnectionFairy(object): self._connection_record, self) return self - except exc.DisconnectionError, e: + except exc.DisconnectionError as e: self._pool.logger.info( "Disconnection detected on checkout: %s", e) self._connection_record.invalidate(e) @@ -755,7 +755,7 @@ class QueuePool(Pool): wait = self._max_overflow > -1 and \ self._overflow >= self._max_overflow return self._pool.get(wait, self._timeout) - except sqla_queue.SAAbort, aborted: + except sqla_queue.SAAbort as aborted: return aborted.context._do_get() except sqla_queue.Empty: if self._max_overflow > -1 and \ @@ -1004,7 +1004,7 @@ class _DBProxy(object): self._create_pool_mutex = threading.Lock() def close(self): - for key in self.pools.keys(): + for key in list(self.pools.keys()): del self.pools[key] def __del__(self): diff --git a/lib/sqlalchemy/processors.py b/lib/sqlalchemy/processors.py index 9963ca9a3..bf95d146b 100644 --- a/lib/sqlalchemy/processors.py +++ b/lib/sqlalchemy/processors.py @@ -38,10 +38,10 @@ def str_to_datetime_processor_factory(regexp, type_): "'%s'" % (type_.__name__, value)) if has_named_groups: groups = m.groupdict(0) - return type_(**dict(zip(groups.iterkeys(), - map(int, groups.itervalues())))) + return type_(**dict(list(zip(iter(groups.keys()), + list(map(int, iter(groups.values()))))))) else: - return type_(*map(int, m.groups(0))) + return type_(*list(map(int, m.groups(0)))) return process diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index 9a07b9de4..030c400a7 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -27,7 +27,7 @@ Since these objects are part of the SQL expression language, they are usable as components in SQL expressions. """ -from __future__ import with_statement + import re import inspect from . import exc, util, dialects, event, events, inspection @@ -683,7 +683,7 @@ class Table(SchemaItem, expression.TableClause): continue Index(index.name, unique=index.unique, - *[table.c[col] for col in index.columns.keys()], + *[table.c[col] for col in list(index.columns.keys())], **index.kwargs) table.dispatch._update(self.dispatch) return table @@ -898,7 +898,7 @@ class Column(SchemaItem, expression.ColumnClause): type_ = kwargs.pop('type_', None) args = list(args) if args: - if isinstance(args[0], basestring): + if isinstance(args[0], str): if name is not None: raise exc.ArgumentError( "May not pass name positionally and as a keyword.") @@ -944,11 +944,12 @@ class Column(SchemaItem, expression.ColumnClause): args.append(self.default) else: if getattr(self.type, '_warn_on_bytestring', False): - # Py3K - #if isinstance(self.default, bytes): - # Py2K - if isinstance(self.default, str): - # end Py2K +# start Py3K + if isinstance(self.default, bytes): +# end Py3K +# start Py2K +# if isinstance(self.default, str): +# end Py2K util.warn("Unicode column received non-unicode " "default value.") args.append(ColumnDefault(self.default)) @@ -983,7 +984,7 @@ class Column(SchemaItem, expression.ColumnClause): if kwargs: raise exc.ArgumentError( - "Unknown arguments passed to Column: " + repr(kwargs.keys())) + "Unknown arguments passed to Column: " + repr(list(kwargs.keys()))) def __str__(self): if self.name is None: @@ -1069,7 +1070,7 @@ class Column(SchemaItem, expression.ColumnClause): self.table = table if self.index: - if isinstance(self.index, basestring): + if isinstance(self.index, str): raise exc.ArgumentError( "The 'index' keyword argument on Column is boolean only. " "To create indexes with a specific name, create an " @@ -1077,7 +1078,7 @@ class Column(SchemaItem, expression.ColumnClause): Index(expression._truncated_label('ix_%s' % self._label), self, unique=self.unique) elif self.unique: - if isinstance(self.unique, basestring): + if isinstance(self.unique, str): raise exc.ArgumentError( "The 'unique' keyword argument on Column is boolean " "only. To create unique constraints or indexes with a " @@ -1153,23 +1154,24 @@ class Column(SchemaItem, expression.ColumnClause): nullable=self.nullable, quote=self.quote, _proxies=[self], *fk) - except TypeError, e: - # Py3K - #raise TypeError( - # "Could not create a copy of this %r object. " - # "Ensure the class includes a _constructor() " - # "attribute or method which accepts the " - # "standard Column constructor arguments, or " - # "references the Column class itself." % self.__class__) from e - # Py2K + except TypeError as e: +# start Py3K raise TypeError( "Could not create a copy of this %r object. " "Ensure the class includes a _constructor() " "attribute or method which accepts the " "standard Column constructor arguments, or " - "references the Column class itself. " - "Original error: %s" % (self.__class__, e)) - # end Py2K + "references the Column class itself." % self.__class__) from e +# end Py3K +# start Py2K +# raise TypeError( +# "Could not create a copy of this %r object. " +# "Ensure the class includes a _constructor() " +# "attribute or method which accepts the " +# "standard Column constructor arguments, or " +# "references the Column class itself. " +# "Original error: %s" % (self.__class__, e)) +# end Py2K c.table = selectable selectable._columns.add(c) @@ -1345,7 +1347,7 @@ class ForeignKey(SchemaItem): if schema: return schema + "." + self.column.table.name + \ "." + self.column.key - elif isinstance(self._colspec, basestring): + elif isinstance(self._colspec, str): return self._colspec elif hasattr(self._colspec, '__clause_element__'): _column = self._colspec.__clause_element__() @@ -1390,7 +1392,7 @@ class ForeignKey(SchemaItem): """ # ForeignKey inits its remote column as late as possible, so tables # can be defined without dependencies - if isinstance(self._colspec, basestring): + if isinstance(self._colspec, str): # locate the parent table this foreign key is attached to. we # use the "original" column which our parent column represents # (its a list of columns/other ColumnElements if the parent @@ -1657,7 +1659,8 @@ class ColumnDefault(DefaultGenerator): defaulted = argspec[3] is not None and len(argspec[3]) or 0 positionals = len(argspec[0]) - defaulted - # Py3K compat - no unbound methods +# start Py3K +# end Py3K if inspect.ismethod(inspectable) or inspect.isclass(fn): positionals -= 1 @@ -1919,7 +1922,7 @@ class DefaultClause(FetchedValue): has_argument = True def __init__(self, arg, for_update=False, _reflected=False): - util.assert_arg_type(arg, (basestring, + util.assert_arg_type(arg, (str, expression.ClauseElement, expression.TextClause), 'arg') super(DefaultClause, self).__init__(for_update) @@ -2029,7 +2032,7 @@ class ColumnCollectionMixin(object): def _set_parent(self, table): for col in self._pending_colargs: - if isinstance(col, basestring): + if isinstance(col, str): col = table.c[col] self.columns.add(col) @@ -2066,7 +2069,7 @@ class ColumnCollectionConstraint(ColumnCollectionMixin, Constraint): def copy(self, **kw): c = self.__class__(name=self.name, deferrable=self.deferrable, - initially=self.initially, *self.columns.keys()) + initially=self.initially, *list(self.columns.keys())) c.dispatch._update(self.dispatch) return c @@ -2256,19 +2259,19 @@ class ForeignKeyConstraint(Constraint): @property def columns(self): - return self._elements.keys() + return list(self._elements.keys()) @property def elements(self): - return self._elements.values() + return list(self._elements.values()) def _set_parent(self, table): super(ForeignKeyConstraint, self)._set_parent(table) - for col, fk in self._elements.iteritems(): + for col, fk in self._elements.items(): # string-specified column names now get # resolved to Column objects - if isinstance(col, basestring): + if isinstance(col, str): try: col = table.c[col] except KeyError: @@ -2293,8 +2296,8 @@ class ForeignKeyConstraint(Constraint): def copy(self, schema=None, **kw): fkc = ForeignKeyConstraint( - [x.parent.key for x in self._elements.values()], - [x._get_colspec(schema=schema) for x in self._elements.values()], + [x.parent.key for x in list(self._elements.values())], + [x._get_colspec(schema=schema) for x in list(self._elements.values())], name=self.name, onupdate=self.onupdate, ondelete=self.ondelete, @@ -2569,7 +2572,7 @@ class MetaData(SchemaItem): return 'MetaData(bind=%r)' % self.bind def __contains__(self, table_or_key): - if not isinstance(table_or_key, basestring): + if not isinstance(table_or_key, str): table_or_key = table_or_key.key return table_or_key in self.tables @@ -2584,7 +2587,7 @@ class MetaData(SchemaItem): dict.pop(self.tables, key, None) if self._schemas: self._schemas = set([t.schema - for t in self.tables.values() + for t in list(self.tables.values()) if t.schema is not None]) def __getstate__(self): @@ -2629,7 +2632,7 @@ class MetaData(SchemaItem): def _bind_to(self, bind): """Bind this MetaData to an Engine, Connection, string or URL.""" - if isinstance(bind, (basestring, url.URL)): + if isinstance(bind, (str, url.URL)): from sqlalchemy import create_engine self._bind = create_engine(bind) else: @@ -2662,7 +2665,7 @@ class MetaData(SchemaItem): :meth:`.Inspector.sorted_tables` """ - return sqlutil.sort_tables(self.tables.itervalues()) + return sqlutil.sort_tables(iter(self.tables.values())) def reflect(self, bind=None, schema=None, views=False, only=None): """Load all available table definitions from the database. @@ -2723,7 +2726,7 @@ class MetaData(SchemaItem): bind.dialect.get_view_names(conn, schema) ) - current = set(self.tables.iterkeys()) + current = set(self.tables.keys()) if only is None: load = [name for name in available if name not in current] @@ -2845,7 +2848,7 @@ class ThreadLocalMetaData(MetaData): def _bind_to(self, bind): """Bind to a Connectable in the caller's thread.""" - if isinstance(bind, (basestring, url.URL)): + if isinstance(bind, (str, url.URL)): try: self.context._engine = self.__engines[bind] except KeyError: @@ -2870,7 +2873,7 @@ class ThreadLocalMetaData(MetaData): def dispose(self): """Dispose all bound engines, in all thread contexts.""" - for e in self.__engines.itervalues(): + for e in self.__engines.values(): if hasattr(e, 'dispose'): e.dispose() @@ -3075,7 +3078,7 @@ class DDLElement(expression.Executable, _DDLCompiles): not self._should_execute_deprecated(None, target, bind, **kw): return False - if isinstance(self.dialect, basestring): + if isinstance(self.dialect, str): if self.dialect != bind.engine.name: return False elif isinstance(self.dialect, (tuple, list, set)): @@ -3090,7 +3093,7 @@ class DDLElement(expression.Executable, _DDLCompiles): def _should_execute_deprecated(self, event, target, bind, **kw): if self.on is None: return True - elif isinstance(self.on, basestring): + elif isinstance(self.on, str): return self.on == bind.engine.name elif isinstance(self.on, (tuple, list, set)): return bind.engine.name in self.on @@ -3105,7 +3108,7 @@ class DDLElement(expression.Executable, _DDLCompiles): def _check_ddl_on(self, on): if (on is not None and - (not isinstance(on, (basestring, tuple, list, set)) and + (not isinstance(on, (str, tuple, list, set)) and not util.callable(on))): raise exc.ArgumentError( "Expected the name of a database dialect, a tuple " @@ -3230,7 +3233,7 @@ class DDL(DDLElement): """ - if not isinstance(statement, basestring): + if not isinstance(statement, str): raise exc.ArgumentError( "Expected a string or unicode SQL statement, got '%r'" % statement) @@ -3262,7 +3265,7 @@ def _to_schema_column(element): def _to_schema_column_or_string(element): if hasattr(element, '__clause_element__'): element = element.__clause_element__() - if not isinstance(element, (basestring, expression.ColumnElement)): + if not isinstance(element, (str, expression.ColumnElement)): msg = "Element %r is not a string name or column element" raise exc.ArgumentError(msg % element) return element diff --git a/lib/sqlalchemy/sql/__init__.py b/lib/sqlalchemy/sql/__init__.py index 1b81a18c5..9700f26a0 100644 --- a/lib/sqlalchemy/sql/__init__.py +++ b/lib/sqlalchemy/sql/__init__.py @@ -64,5 +64,5 @@ from .expression import ( from .visitors import ClauseVisitor -__tmp = locals().keys() +__tmp = list(locals().keys()) __all__ = sorted([i for i in __tmp if not i.startswith('__')]) diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index b902f9ffc..e5a2da366 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -51,7 +51,7 @@ RESERVED_WORDS = set([ 'using', 'verbose', 'when', 'where']) LEGAL_CHARACTERS = re.compile(r'^[A-Z0-9_$]+$', re.I) -ILLEGAL_INITIAL_CHARACTERS = set([str(x) for x in xrange(0, 10)]).union(['$']) +ILLEGAL_INITIAL_CHARACTERS = set([str(x) for x in range(0, 10)]).union(['$']) BIND_PARAMS = re.compile(r'(?> sys.stderr, "Error emptying table %s: %r" % ( - table, ex) + except sa.exc.DBAPIError as ex: + print("Error emptying table %s: %r" % ( + table, ex), file=sys.stderr) def setup(self): self._setup_each_tables() @@ -187,10 +187,10 @@ class TablesTest(TestBase): def _load_fixtures(cls): """Insert rows as represented by the fixtures() method.""" headers, rows = {}, {} - for table, data in cls.fixtures().iteritems(): + for table, data in cls.fixtures().items(): if len(data) < 2: continue - if isinstance(table, basestring): + if isinstance(table, str): table = cls.tables[table] headers[table] = data[0] rows[table] = data[1:] @@ -199,7 +199,7 @@ class TablesTest(TestBase): continue cls.bind.execute( table.insert(), - [dict(zip(headers[table], column_values)) + [dict(list(zip(headers[table], column_values))) for column_values in rows[table]]) @@ -284,8 +284,8 @@ class MappedTest(_ORMTest, TablesTest, assertions.AssertsExecutionResults): cls_registry[classname] = cls return type.__init__(cls, classname, bases, dict_) - class _Base(object): - __metaclass__ = FindFixture + class _Base(object, metaclass=FindFixture): + pass class Basic(BasicEntity, _Base): pass diff --git a/lib/sqlalchemy/testing/plugin/noseplugin.py b/lib/sqlalchemy/testing/plugin/noseplugin.py index 5bd7ff3cd..7ad61c7b9 100644 --- a/lib/sqlalchemy/testing/plugin/noseplugin.py +++ b/lib/sqlalchemy/testing/plugin/noseplugin.py @@ -9,10 +9,10 @@ When third party libraries use this plugin, it can be imported normally as "from sqlalchemy.testing.plugin import noseplugin". """ -from __future__ import absolute_import + import os -import ConfigParser +import configparser from nose.plugins import Plugin from nose import SkipTest @@ -55,9 +55,9 @@ def _log(option, opt_str, value, parser): def _list_dbs(*args): - print "Available --db options (use --dburi to override)" + print("Available --db options (use --dburi to override)") for macro in sorted(file_config.options('db')): - print "%20s\t%s" % (macro, file_config.get('db', macro)) + print("%20s\t%s" % (macro, file_config.get('db', macro))) sys.exit(0) @@ -318,7 +318,7 @@ class NoseSQLAlchemy(Plugin): opt("--write-profiles", action="store_true", dest="write_profiles", default=False, help="Write/update profiling data.") global file_config - file_config = ConfigParser.ConfigParser() + file_config = configparser.ConfigParser() file_config.read(['setup.cfg', 'test.cfg']) def configure(self, options, conf): diff --git a/lib/sqlalchemy/testing/profiling.py b/lib/sqlalchemy/testing/profiling.py index 19a9731be..bda44d80c 100644 --- a/lib/sqlalchemy/testing/profiling.py +++ b/lib/sqlalchemy/testing/profiling.py @@ -60,9 +60,9 @@ def profiled(target=None, **target_opts): if report: sort_ = target_opts.get('sort', profile_config['sort']) limit = target_opts.get('limit', profile_config['limit']) - print ("Profile report for target '%s' (%s)" % ( + print(("Profile report for target '%s' (%s)" % ( target, filename) - ) + )) stats = load_stats() stats.sort_stats(*sort_) @@ -198,7 +198,7 @@ class ProfileStatsFile(object): profile_f.close() def _write(self): - print("Writing profile file %s" % self.fname) + print(("Writing profile file %s" % self.fname)) profile_f = open(self.fname, "w") profile_f.write(self._header()) for test_key in sorted(self.data): @@ -253,11 +253,11 @@ def function_call_count(variance=0.05): else: line_no, expected_count = expected - print("Pstats calls: %d Expected %s" % ( + print(("Pstats calls: %d Expected %s" % ( callcount, expected_count ) - ) + )) stats.print_stats() #stats.print_callers() diff --git a/lib/sqlalchemy/testing/schema.py b/lib/sqlalchemy/testing/schema.py index 325d74f1e..6f3e87cc9 100644 --- a/lib/sqlalchemy/testing/schema.py +++ b/lib/sqlalchemy/testing/schema.py @@ -11,7 +11,7 @@ table_options = {} def Table(*args, **kw): """A schema.Table wrapper/hook for dialect-specific tweaks.""" - test_opts = dict([(k, kw.pop(k)) for k in kw.keys() + test_opts = dict([(k, kw.pop(k)) for k in list(kw.keys()) if k.startswith('test_')]) kw.update(table_options) @@ -58,7 +58,7 @@ def Table(*args, **kw): def Column(*args, **kw): """A schema.Column wrapper/hook for dialect-specific tweaks.""" - test_opts = dict([(k, kw.pop(k)) for k in kw.keys() + test_opts = dict([(k, kw.pop(k)) for k in list(kw.keys()) if k.startswith('test_')]) if not config.requirements.foreign_key_ddl.enabled: diff --git a/lib/sqlalchemy/testing/suite/test_ddl.py b/lib/sqlalchemy/testing/suite/test_ddl.py index fc1c19362..28251b807 100644 --- a/lib/sqlalchemy/testing/suite/test_ddl.py +++ b/lib/sqlalchemy/testing/suite/test_ddl.py @@ -1,4 +1,4 @@ -from __future__ import with_statement + from .. import fixtures, config, util from ..config import requirements diff --git a/lib/sqlalchemy/testing/suite/test_reflection.py b/lib/sqlalchemy/testing/suite/test_reflection.py index 7cae48572..ff76bd2cd 100644 --- a/lib/sqlalchemy/testing/suite/test_reflection.py +++ b/lib/sqlalchemy/testing/suite/test_reflection.py @@ -1,4 +1,4 @@ -from __future__ import with_statement + import sqlalchemy as sa from sqlalchemy import exc as sa_exc @@ -386,7 +386,7 @@ class ComponentReflectionTest(fixtures.TablesTest): self.tables.email_addresses, self.tables.dingalings insp = inspect(meta.bind) oid = insp.get_table_oid(table_name, schema) - self.assert_(isinstance(oid, (int, long))) + self.assert_(isinstance(oid, int)) def test_get_table_oid(self): self._test_get_table_oid('users') diff --git a/lib/sqlalchemy/testing/suite/test_types.py b/lib/sqlalchemy/testing/suite/test_types.py index 0716b1b91..4dd3884ed 100644 --- a/lib/sqlalchemy/testing/suite/test_types.py +++ b/lib/sqlalchemy/testing/suite/test_types.py @@ -15,9 +15,9 @@ import datetime class _UnicodeFixture(object): __requires__ = 'unicode_data', - data = u"Alors vous imaginez ma surprise, au lever du jour, "\ - u"quand une drôle de petite voix m’a réveillé. Elle "\ - u"disait: « S’il vous plaît… dessine-moi un mouton! »" + data = "Alors vous imaginez ma surprise, au lever du jour, "\ + "quand une drôle de petite voix m’a réveillé. Elle "\ + "disait: « S’il vous plaît… dessine-moi un mouton! »" @classmethod def define_tables(cls, metadata): @@ -47,7 +47,7 @@ class _UnicodeFixture(object): row, (self.data, ) ) - assert isinstance(row[0], unicode) + assert isinstance(row[0], str) def test_round_trip_executemany(self): unicode_table = self.tables.unicode_table @@ -58,7 +58,7 @@ class _UnicodeFixture(object): { 'unicode_data': self.data, } - for i in xrange(3) + for i in range(3) ] ) @@ -69,22 +69,22 @@ class _UnicodeFixture(object): ).fetchall() eq_( rows, - [(self.data, ) for i in xrange(3)] + [(self.data, ) for i in range(3)] ) for row in rows: - assert isinstance(row[0], unicode) + assert isinstance(row[0], str) def _test_empty_strings(self): unicode_table = self.tables.unicode_table config.db.execute( unicode_table.insert(), - {"unicode_data": u''} + {"unicode_data": ''} ) row = config.db.execute( select([unicode_table.c.unicode_data]) ).first() - eq_(row, (u'',)) + eq_(row, ('',)) class UnicodeVarcharTest(_UnicodeFixture, fixtures.TablesTest): diff --git a/lib/sqlalchemy/testing/util.py b/lib/sqlalchemy/testing/util.py index d9ff14eaf..5facd2f06 100644 --- a/lib/sqlalchemy/testing/util.py +++ b/lib/sqlalchemy/testing/util.py @@ -32,13 +32,13 @@ else: def picklers(): picklers = set() - # Py2K - try: - import cPickle - picklers.add(cPickle) - except ImportError: - pass - # end Py2K +# start Py2K +# try: +# import cPickle +# picklers.add(cPickle) +# except ImportError: +# pass +# end Py2K import pickle picklers.add(pickle) @@ -130,8 +130,8 @@ def function_named(fn, name): try: fn.__name__ = name except TypeError: - fn = types.FunctionType(fn.func_code, fn.func_globals, name, - fn.func_defaults, fn.func_closure) + fn = types.FunctionType(fn.__code__, fn.__globals__, name, + fn.__defaults__, fn.__closure__) return fn diff --git a/lib/sqlalchemy/testing/warnings.py b/lib/sqlalchemy/testing/warnings.py index 41f3dbfed..9546945eb 100644 --- a/lib/sqlalchemy/testing/warnings.py +++ b/lib/sqlalchemy/testing/warnings.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import + import warnings from .. import exc as sa_exc @@ -10,7 +10,7 @@ def testing_warn(msg, stacklevel=3): filename = "sqlalchemy.testing.warnings" lineno = 1 - if isinstance(msg, basestring): + if isinstance(msg, str): warnings.warn_explicit(msg, sa_exc.SAWarning, filename, lineno) else: warnings.warn_explicit(msg, filename, lineno) diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index 46cf9e2a1..4fbadcb0c 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -156,8 +156,8 @@ class TypeEngine(AbstractType): """ - return self.__class__.column_expression.func_code \ - is not TypeEngine.column_expression.func_code + return self.__class__.column_expression.__code__ \ + is not TypeEngine.column_expression.__code__ def bind_expression(self, bindvalue): """"Given a bind value (i.e. a :class:`.BindParameter` instance), @@ -194,8 +194,8 @@ class TypeEngine(AbstractType): """ - return self.__class__.bind_expression.func_code \ - is not TypeEngine.bind_expression.func_code + return self.__class__.bind_expression.__code__ \ + is not TypeEngine.bind_expression.__code__ def compare_values(self, x, y): """Compare two values for equality.""" @@ -392,12 +392,13 @@ class TypeEngine(AbstractType): return default.DefaultDialect() def __str__(self): - # Py3K - #return unicode(self.compile()) - # Py2K - return unicode(self.compile()).\ - encode('ascii', 'backslashreplace') - # end Py2K +# start Py3K + return str(self.compile()) +# end Py3K +# start Py2K +# return unicode(self.compile()).\ +# encode('ascii', 'backslashreplace') +# end Py2K def __init__(self, *args, **kwargs): """Support implementations that were passing arguments""" @@ -723,8 +724,8 @@ class TypeDecorator(TypeEngine): """ - return self.__class__.process_bind_param.func_code \ - is not TypeDecorator.process_bind_param.func_code + return self.__class__.process_bind_param.__code__ \ + is not TypeDecorator.process_bind_param.__code__ def bind_processor(self, dialect): """Provide a bound value processing function for the @@ -769,8 +770,8 @@ class TypeDecorator(TypeEngine): exception throw. """ - return self.__class__.process_result_value.func_code \ - is not TypeDecorator.process_result_value.func_code + return self.__class__.process_result_value.__code__ \ + is not TypeDecorator.process_result_value.__code__ def result_processor(self, dialect, coltype): """Provide a result value processing function for the given @@ -1114,11 +1115,12 @@ class String(Concatenable, TypeEngine): self.convert_unicode != 'force': if self._warn_on_bytestring: def process(value): - # Py3K - #if isinstance(value, bytes): - # Py2K - if isinstance(value, str): - # end Py2K +# start Py3K + if isinstance(value, bytes): +# end Py3K +# start Py2K +# if isinstance(value, str): +# end Py2K util.warn("Unicode type received non-unicode bind " "param value.") return value @@ -1130,7 +1132,7 @@ class String(Concatenable, TypeEngine): warn_on_bytestring = self._warn_on_bytestring def process(value): - if isinstance(value, unicode): + if isinstance(value, str): return encoder(value, self.unicode_error)[0] elif warn_on_bytestring and value is not None: util.warn("Unicode type received non-unicode bind " @@ -1156,7 +1158,7 @@ class String(Concatenable, TypeEngine): # habits. since we will be getting back unicode # in most cases, we check for it (decode will fail). def process(value): - if isinstance(value, unicode): + if isinstance(value, str): return value else: return to_unicode(value) @@ -1171,7 +1173,7 @@ class String(Concatenable, TypeEngine): @property def python_type(self): if self.convert_unicode: - return unicode + return str else: return str @@ -1318,12 +1320,12 @@ class Integer(_DateAffinity, TypeEngine): Integer: self.__class__, Numeric: Numeric, }, - # Py2K - operators.div: { - Integer: self.__class__, - Numeric: Numeric, - }, - # end Py2K +# start Py2K +# operators.div: { +# Integer: self.__class__, +# Numeric: Numeric, +# }, +# end Py2K operators.truediv: { Integer: self.__class__, Numeric: Numeric, @@ -1488,12 +1490,12 @@ class Numeric(_DateAffinity, TypeEngine): Numeric: self.__class__, Integer: self.__class__, }, - # Py2K - operators.div: { - Numeric: self.__class__, - Integer: self.__class__, - }, - # end Py2K +# start Py2K +# operators.div: { +# Numeric: self.__class__, +# Integer: self.__class__, +# }, +# end Py2K operators.truediv: { Numeric: self.__class__, Integer: self.__class__, @@ -1558,11 +1560,11 @@ class Float(Numeric): Interval: Interval, Numeric: self.__class__, }, - # Py2K - operators.div: { - Numeric: self.__class__, - }, - # end Py2K +# start Py2K +# operators.div: { +# Numeric: self.__class__, +# }, +# end Py2K operators.truediv: { Numeric: self.__class__, }, @@ -1693,11 +1695,12 @@ class _Binary(TypeEngine): @property def python_type(self): - # Py3K - #return bytes - # Py2K - return str - # end Py2K +# start Py3K + return bytes +# end Py3K +# start Py2K +# return str +# end Py2K # Python 3 - sqlite3 doesn't need the `Binary` conversion # here, though pg8000 does to indicate "bytea" @@ -1715,32 +1718,33 @@ class _Binary(TypeEngine): # Python 3 has native bytes() type # both sqlite3 and pg8000 seem to return it, # psycopg2 as of 2.5 returns 'memoryview' - # Py3K - #def result_processor(self, dialect, coltype): - # def process(value): - # if value is not None: - # value = bytes(value) - # return value - # return process - # Py2K +# start Py3K def result_processor(self, dialect, coltype): - if util.jython: - def process(value): - if value is not None: - if isinstance(value, array.array): - return value.tostring() - return str(value) - else: - return None - else: - process = processors.to_str + def process(value): + if value is not None: + value = bytes(value) + return value return process - # end Py2K +# end Py3K +# start Py2K +# def result_processor(self, dialect, coltype): +# if util.jython: +# def process(value): +# if value is not None: +# if isinstance(value, array.array): +# return value.tostring() +# return str(value) +# else: +# return None +# else: +# process = processors.to_str +# return process +# end Py2K def coerce_compared_value(self, op, value): """See :meth:`.TypeEngine.coerce_compared_value` for a description.""" - if isinstance(value, basestring): + if isinstance(value, str): return self else: return super(_Binary, self).coerce_compared_value(op, value) @@ -1997,7 +2001,7 @@ class Enum(String, SchemaType): convert_unicode = kw.pop('convert_unicode', None) if convert_unicode is None: for e in enums: - if isinstance(e, unicode): + if isinstance(e, str): convert_unicode = True break else: @@ -2296,11 +2300,11 @@ class Interval(_DateAffinity, TypeDecorator): operators.truediv: { Numeric: self.__class__ }, - # Py2K - operators.div: { - Numeric: self.__class__ - } - # end Py2K +# start Py2K +# operators.div: { +# Numeric: self.__class__ +# } +# end Py2K } @property @@ -2451,11 +2455,12 @@ STRINGTYPE = String() _type_map = { str: String(), - # Py3K - #bytes: LargeBinary(), - # Py2K - unicode: Unicode(), - # end Py2K +# start Py3K + bytes: LargeBinary(), +# end Py3K +# start Py2K +# unicode: Unicode(), +# end Py2K int: Integer(), float: Numeric(), bool: BOOLEANTYPE, diff --git a/lib/sqlalchemy/util/_collections.py b/lib/sqlalchemy/util/_collections.py index 8e61275e7..e505bdd5f 100644 --- a/lib/sqlalchemy/util/_collections.py +++ b/lib/sqlalchemy/util/_collections.py @@ -55,7 +55,7 @@ class KeyedTuple(tuple): t = tuple.__new__(cls, vals) t._labels = [] if labels: - t.__dict__.update(zip(labels, vals)) + t.__dict__.update(list(zip(labels, vals))) t._labels = labels return t @@ -94,7 +94,7 @@ class KeyedTuple(tuple): .. versionadded:: 0.8 """ - return dict((key, self.__dict__[key]) for key in self.keys()) + return dict((key, self.__dict__[key]) for key in list(self.keys())) class ImmutableContainer(object): @@ -142,7 +142,7 @@ class Properties(object): return len(self._data) def __iter__(self): - return self._data.itervalues() + return iter(self._data.values()) def __add__(self, other): return list(self) + list(other) @@ -189,13 +189,13 @@ class Properties(object): return default def keys(self): - return self._data.keys() + return list(self._data.keys()) def values(self): - return self._data.values() + return list(self._data.values()) def items(self): - return self._data.items() + return list(self._data.items()) def has_key(self, key): return key in self._data @@ -242,7 +242,7 @@ class OrderedDict(dict): def update(self, ____sequence=None, **kwargs): if ____sequence is not None: if hasattr(____sequence, 'keys'): - for key in ____sequence.keys(): + for key in list(____sequence.keys()): self.__setitem__(key, ____sequence[key]) else: for key, value in ____sequence: @@ -270,13 +270,13 @@ class OrderedDict(dict): return list(self._list) def iterkeys(self): - return iter(self.keys()) + return iter(list(self.keys())) def items(self): - return [(key, self[key]) for key in self.keys()] + return [(key, self[key]) for key in list(self.keys())] def iteritems(self): - return iter(self.items()) + return iter(list(self.items())) def __setitem__(self, key, object): if key not in self: @@ -470,8 +470,8 @@ class IdentitySet(object): if len(self) > len(other): return False - for m in itertools.ifilterfalse(other._members.__contains__, - self._members.iterkeys()): + for m in itertools.filterfalse(other._members.__contains__, + iter(self._members.keys())): return False return True @@ -491,8 +491,8 @@ class IdentitySet(object): if len(self) < len(other): return False - for m in itertools.ifilterfalse(self._members.__contains__, - other._members.iterkeys()): + for m in itertools.filterfalse(self._members.__contains__, + iter(other._members.keys())): return False return True @@ -582,7 +582,7 @@ class IdentitySet(object): return result def _member_id_tuples(self): - return ((id(v), v) for v in self._members.itervalues()) + return ((id(v), v) for v in self._members.values()) def __xor__(self, other): if not isinstance(other, IdentitySet): @@ -599,7 +599,7 @@ class IdentitySet(object): return self def copy(self): - return type(self)(self._members.itervalues()) + return type(self)(iter(self._members.values())) __copy__ = copy @@ -607,13 +607,13 @@ class IdentitySet(object): return len(self._members) def __iter__(self): - return self._members.itervalues() + return iter(self._members.values()) def __hash__(self): raise TypeError('set objects are unhashable') def __repr__(self): - return '%s(%r)' % (type(self).__name__, self._members.values()) + return '%s(%r)' % (type(self).__name__, list(self._members.values())) class WeakSequence(object): @@ -623,7 +623,7 @@ class WeakSequence(object): ) def __iter__(self): - return self._storage.itervalues() + return iter(self._storage.values()) def __getitem__(self, index): try: @@ -754,7 +754,7 @@ def flatten_iterator(x): """ for elem in x: - if not isinstance(elem, basestring) and hasattr(elem, '__iter__'): + if not isinstance(elem, str) and hasattr(elem, '__iter__'): for y in flatten_iterator(elem): yield y else: diff --git a/lib/sqlalchemy/util/compat.py b/lib/sqlalchemy/util/compat.py index 033a87cc7..4eb915469 100644 --- a/lib/sqlalchemy/util/compat.py +++ b/lib/sqlalchemy/util/compat.py @@ -43,14 +43,14 @@ else: if sys.version_info < (2, 6): def next(iter): - return iter.next() + return iter.__next__() else: next = next if py3k_warning: import pickle else: try: - import cPickle as pickle + import pickle as pickle except ImportError: import pickle @@ -59,12 +59,13 @@ if sys.version_info < (2, 6): # in newer pythons from cgi import parse_qsl else: - from urlparse import parse_qsl + from urllib.parse import parse_qsl -# Py3K -#from inspect import getfullargspec as inspect_getfullargspec -# Py2K -from inspect import getargspec as inspect_getfullargspec +# start Py3K +from inspect import getfullargspec as inspect_getfullargspec +# end Py3K +# start Py2K +#from inspect import getargspec as inspect_getfullargspec # end Py2K if py3k_warning: diff --git a/lib/sqlalchemy/util/deprecations.py b/lib/sqlalchemy/util/deprecations.py index 34be4fbf8..e0dc168db 100644 --- a/lib/sqlalchemy/util/deprecations.py +++ b/lib/sqlalchemy/util/deprecations.py @@ -10,7 +10,7 @@ functionality.""" from .. import exc import warnings import re -from langhelpers import decorator +from .langhelpers import decorator def warn_deprecated(msg, stacklevel=3): diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py index f6d9164e6..26dd97549 100644 --- a/lib/sqlalchemy/util/langhelpers.py +++ b/lib/sqlalchemy/util/langhelpers.py @@ -21,10 +21,12 @@ from functools import update_wrapper from .. import exc import hashlib from . import compat +import collections def md5_hex(x): - # Py3K - #x = x.encode('utf-8') +# start Py3K + x = x.encode('utf-8') +# end Py3K m = hashlib.md5() m.update(x) return m.hexdigest() @@ -77,8 +79,8 @@ def _unique_symbols(used, *bases): used = set(used) for base in bases: pool = itertools.chain((base,), - itertools.imap(lambda i: base + str(i), - xrange(1000))) + map(lambda i: base + str(i), + range(1000))) for sym in pool: if sym not in used: used.add(sym) @@ -95,7 +97,7 @@ def decorator(target): if not inspect.isfunction(fn): raise Exception("not a decoratable function") spec = inspect_getfullargspec(fn) - names = tuple(spec[0]) + spec[1:3] + (fn.func_name,) + names = tuple(spec[0]) + spec[1:3] + (fn.__name__,) targ_name, fn_name = _unique_symbols(names, 'target', 'fn') metadata = dict(target=targ_name, fn=fn_name) @@ -104,7 +106,7 @@ def decorator(target): code = 'lambda %(args)s: %(target)s(%(fn)s, %(apply_kw)s)' % ( metadata) decorated = eval(code, {targ_name: target, fn_name: fn}) - decorated.func_defaults = getattr(fn, 'im_func', fn).func_defaults + decorated.__defaults__ = getattr(fn, 'im_func', fn).__defaults__ return update_wrapper(decorated, fn) return update_wrapper(decorate, target) @@ -176,7 +178,7 @@ def get_cls_kwargs(cls): ctr = class_.__dict__.get('__init__', False) if (not ctr or not isinstance(ctr, types.FunctionType) or - not isinstance(ctr.func_code, types.CodeType)): + not isinstance(ctr.__code__, types.CodeType)): stack.update(class_.__bases__) continue @@ -194,7 +196,7 @@ try: from inspect import CO_VARKEYWORDS def inspect_func_args(fn): - co = fn.func_code + co = fn.__code__ nargs = co.co_argcount names = co.co_varnames args = list(names[:nargs]) @@ -250,7 +252,7 @@ def format_argspec_plus(fn, grouped=True): 'apply_pos': '(self, a, b, c, **d)'} """ - if callable(fn): + if isinstance(fn, collections.Callable): spec = inspect_getfullargspec(fn) else: # we accept an existing argspec... @@ -263,22 +265,23 @@ def format_argspec_plus(fn, grouped=True): else: self_arg = None - # Py3K - #apply_pos = inspect.formatargspec(spec[0], spec[1], - # spec[2], None, spec[4]) - #num_defaults = 0 - #if spec[3]: - # num_defaults += len(spec[3]) - #if spec[4]: - # num_defaults += len(spec[4]) - #name_args = spec[0] + spec[4] - # Py2K - apply_pos = inspect.formatargspec(spec[0], spec[1], spec[2]) +# start Py3K + apply_pos = inspect.formatargspec(spec[0], spec[1], + spec[2], None, spec[4]) num_defaults = 0 if spec[3]: num_defaults += len(spec[3]) - name_args = spec[0] - # end Py2K + if spec[4]: + num_defaults += len(spec[4]) + name_args = spec[0] + spec[4] +# end Py3K +# start Py2K +# apply_pos = inspect.formatargspec(spec[0], spec[1], spec[2]) +# num_defaults = 0 +# if spec[3]: +# num_defaults += len(spec[3]) +# name_args = spec[0] +# end Py2K if num_defaults: defaulted_vals = name_args[0 - num_defaults:] @@ -341,8 +344,8 @@ def unbound_method_to_callable(func_or_cls): """ - if isinstance(func_or_cls, types.MethodType) and not func_or_cls.im_self: - return func_or_cls.im_func + if isinstance(func_or_cls, types.MethodType) and not func_or_cls.__self__: + return func_or_cls.__func__ else: return func_or_cls @@ -399,7 +402,7 @@ class portable_instancemethod(object): """ def __init__(self, meth): - self.target = meth.im_self + self.target = meth.__self__ self.name = meth.__name__ def __call__(self, *arg, **kw): @@ -419,32 +422,34 @@ def class_hierarchy(cls): will not be descended. """ - # Py2K - if isinstance(cls, types.ClassType): - return list() - # end Py2K +# start Py2K +# if isinstance(cls, types.ClassType): +# return list() +# end Py2K hier = set([cls]) process = list(cls.__mro__) while process: c = process.pop() - # Py2K - if isinstance(c, types.ClassType): - continue +# start Py2K +# if isinstance(c, types.ClassType): +# continue +# for b in (_ for _ in c.__bases__ +# if _ not in hier and not isinstance(_, types.ClassType)): +# end Py2K +# start Py3K for b in (_ for _ in c.__bases__ - if _ not in hier and not isinstance(_, types.ClassType)): - # end Py2K - # Py3K - #for b in (_ for _ in c.__bases__ - # if _ not in hier): + if _ not in hier): +# end Py3K process.append(b) hier.add(b) - # Py3K - #if c.__module__ == 'builtins' or not hasattr(c, '__subclasses__'): - # continue - # Py2K - if c.__module__ == '__builtin__' or not hasattr(c, '__subclasses__'): +# start Py3K + if c.__module__ == 'builtins' or not hasattr(c, '__subclasses__'): continue - # end Py2K +# end Py3K +# start Py2K +# if c.__module__ == '__builtin__' or not hasattr(c, '__subclasses__'): +# continue +# end Py2K for s in [_ for _ in c.__subclasses__() if _ not in hier]: process.append(s) hier.add(s) @@ -501,9 +506,9 @@ def monkeypatch_proxied_specials(into_cls, from_cls, skip=None, only=None, "return %(name)s.%(method)s%(d_args)s" % locals()) env = from_instance is not None and {name: from_instance} or {} - exec py in env + exec(py, env) try: - env[method].func_defaults = fn.func_defaults + env[method].__defaults__ = fn.__defaults__ except AttributeError: pass setattr(into_cls, method, env[method]) @@ -512,11 +517,12 @@ def monkeypatch_proxied_specials(into_cls, from_cls, skip=None, only=None, def methods_equivalent(meth1, meth2): """Return True if the two methods are the same implementation.""" - # Py3K - #return getattr(meth1, '__func__', meth1) is getattr(meth2, '__func__', meth2) - # Py2K - return getattr(meth1, 'im_func', meth1) is getattr(meth2, 'im_func', meth2) - # end Py2K +# start Py3K + return getattr(meth1, '__func__', meth1) is getattr(meth2, '__func__', meth2) +# end Py3K +# start Py2K +# return getattr(meth1, 'im_func', meth1) is getattr(meth2, 'im_func', meth2) +# end Py2K def as_interface(obj, cls=None, methods=None, required=None): @@ -589,7 +595,7 @@ def as_interface(obj, cls=None, methods=None, required=None): for method, impl in dictlike_iteritems(obj): if method not in interface: raise TypeError("%r: unknown in this interface" % method) - if not callable(impl): + if not isinstance(impl, collections.Callable): raise TypeError("%r=%r is not callable" % (method, impl)) setattr(AnonymousInterface, method, staticmethod(impl)) found.add(method) @@ -753,7 +759,7 @@ class importlater(object): # from paste.deploy.converters def asbool(obj): - if isinstance(obj, (str, unicode)): + if isinstance(obj, str): obj = obj.strip().lower() if obj in ['true', 'yes', 'on', 'y', 't', '1']: return True @@ -814,13 +820,13 @@ def counter(): """Return a threadsafe counter function.""" lock = threading.Lock() - counter = itertools.count(1L) + counter = itertools.count(1) # avoid the 2to3 "next" transformation... def _next(): lock.acquire() try: - return counter.next() + return next(counter) finally: lock.release() @@ -876,15 +882,16 @@ def assert_arg_type(arg, argtype, name): def dictlike_iteritems(dictlike): """Return a (key, value) iterator for almost any dict-like object.""" - # Py3K - #if hasattr(dictlike, 'items'): - # return dictlike.items() - # Py2K - if hasattr(dictlike, 'iteritems'): - return dictlike.iteritems() - elif hasattr(dictlike, 'items'): - return iter(dictlike.items()) - # end Py2K +# start Py3K + if hasattr(dictlike, 'items'): + return list(dictlike.items()) +# end Py3K +# start Py2K +# if hasattr(dictlike, 'iteritems'): +# return dictlike.iteritems() +# elif hasattr(dictlike, 'items'): +# return iter(dictlike.items()) +# end Py2K getter = getattr(dictlike, '__getitem__', getattr(dictlike, 'get', None)) if getter is None: @@ -893,11 +900,11 @@ def dictlike_iteritems(dictlike): if hasattr(dictlike, 'iterkeys'): def iterator(): - for key in dictlike.iterkeys(): + for key in dictlike.keys(): yield key, getter(key) return iterator() elif hasattr(dictlike, 'keys'): - return iter((key, getter(key)) for key in dictlike.keys()) + return iter((key, getter(key)) for key in list(dictlike.keys())) else: raise TypeError( "Object '%r' is not dict-like" % dictlike) @@ -1034,7 +1041,7 @@ def warn(msg, stacklevel=3): be controlled. """ - if isinstance(msg, basestring): + if isinstance(msg, str): warnings.warn(msg, exc.SAWarning, stacklevel=stacklevel) else: warnings.warn(msg, stacklevel=stacklevel) diff --git a/test/aaa_profiling/test_compiler.py b/test/aaa_profiling/test_compiler.py index 1b7798d06..8304296da 100644 --- a/test/aaa_profiling/test_compiler.py +++ b/test/aaa_profiling/test_compiler.py @@ -29,7 +29,7 @@ class CompileTest(fixtures.TestBase, AssertsExecutionResults): for c in t.c: c.type._type_affinity from sqlalchemy import types - for t in types._type_map.values(): + for t in list(types._type_map.values()): t._type_affinity cls.dialect = default.DefaultDialect() diff --git a/test/aaa_profiling/test_memusage.py b/test/aaa_profiling/test_memusage.py index 57bddc859..20c6f0a65 100644 --- a/test/aaa_profiling/test_memusage.py +++ b/test/aaa_profiling/test_memusage.py @@ -47,7 +47,7 @@ def profile_memory(times=50): gc_collect() samples[x] = len(get_objects_skipping_sqlite_issue()) - print "sample gc sizes:", samples + print("sample gc sizes:", samples) assert len(_sessions) == 0 diff --git a/test/aaa_profiling/test_orm.py b/test/aaa_profiling/test_orm.py index b9eeb8361..199b96e5f 100644 --- a/test/aaa_profiling/test_orm.py +++ b/test/aaa_profiling/test_orm.py @@ -144,7 +144,7 @@ class LoadManyToOneFromIdentityTest(fixtures.MappedTest): child.insert().execute([ {'id':i, 'data':'c%d' % i} - for i in xrange(1, 251) + for i in range(1, 251) ]) parent.insert().execute([ { @@ -152,7 +152,7 @@ class LoadManyToOneFromIdentityTest(fixtures.MappedTest): 'data':'p%dc%d' % (i, (i % 250) + 1), 'child_id':(i % 250) + 1 } - for i in xrange(1, 1000) + for i in range(1, 1000) ]) def test_many_to_one_load_no_identity(self): @@ -234,11 +234,11 @@ class MergeBackrefsTest(fixtures.MappedTest): s = Session() s.add_all([ A(id=i, - bs=[B(id=(i * 5) + j) for j in xrange(1, 5)], + bs=[B(id=(i * 5) + j) for j in range(1, 5)], c=C(id=i), - ds=[D(id=(i * 5) + j) for j in xrange(1, 5)] + ds=[D(id=(i * 5) + j) for j in range(1, 5)] ) - for i in xrange(1, 5) + for i in range(1, 5) ]) s.commit() @@ -249,11 +249,11 @@ class MergeBackrefsTest(fixtures.MappedTest): s = Session() for a in [ A(id=i, - bs=[B(id=(i * 5) + j) for j in xrange(1, 5)], + bs=[B(id=(i * 5) + j) for j in range(1, 5)], c=C(id=i), - ds=[D(id=(i * 5) + j) for j in xrange(1, 5)] + ds=[D(id=(i * 5) + j) for j in range(1, 5)] ) - for i in xrange(1, 5) + for i in range(1, 5) ]: s.merge(a) diff --git a/test/aaa_profiling/test_resultset.py b/test/aaa_profiling/test_resultset.py index 0146d1b08..95a1fa3ae 100644 --- a/test/aaa_profiling/test_resultset.py +++ b/test/aaa_profiling/test_resultset.py @@ -19,10 +19,10 @@ class ResultSetTest(fixtures.TestBase, AssertsExecutionResults): def setup(self): metadata.create_all() - t.insert().execute([dict(('field%d' % fnum, u'value%d' % fnum) + t.insert().execute([dict(('field%d' % fnum, 'value%d' % fnum) for fnum in range(NUM_FIELDS)) for r_num in range(NUM_RECORDS)]) - t2.insert().execute([dict(('field%d' % fnum, u'value%d' % fnum) + t2.insert().execute([dict(('field%d' % fnum, 'value%d' % fnum) for fnum in range(NUM_FIELDS)) for r_num in range(NUM_RECORDS)]) @@ -88,7 +88,7 @@ class RowProxyTest(fixtures.TestBase): keymap = {} for index, (keyobjs, processor, values) in \ - enumerate(zip(keys, processors, row)): + enumerate(list(zip(keys, processors, row))): for key in keyobjs: keymap[key] = (processor, key, index) keymap[index] = (processor, key, index) diff --git a/test/aaa_profiling/test_zoomark.py b/test/aaa_profiling/test_zoomark.py index 5fc9ffc2a..79417e2dc 100644 --- a/test/aaa_profiling/test_zoomark.py +++ b/test/aaa_profiling/test_zoomark.py @@ -72,68 +72,68 @@ class ZooMarkTest(fixtures.TestBase): Zoo = metadata.tables['Zoo'] Animal = metadata.tables['Animal'] engine = metadata.bind - wap = engine.execute(Zoo.insert(), Name=u'Wild Animal Park', + wap = engine.execute(Zoo.insert(), Name='Wild Animal Park', Founded=datetime.date(2000, 1, 1), Opens=datetime.time(8, 15, 59), LastEscape= datetime.datetime(2004, 7, 29, 5, 6, 7), Admission=4.95).inserted_primary_key[0] - sdz = engine.execute(Zoo.insert(), Name=u'San Diego Zoo', + sdz = engine.execute(Zoo.insert(), Name='San Diego Zoo', Founded=datetime.date(1935, 9, 13), Opens=datetime.time(9, 0, 0), Admission=0).inserted_primary_key[0] - engine.execute(Zoo.insert(inline=True), Name=u'Montr\xe9al Biod\xf4me', + engine.execute(Zoo.insert(inline=True), Name='Montr\xe9al Biod\xf4me', Founded=datetime.date(1992, 6, 19), Opens=datetime.time(9, 0, 0), Admission=11.75) - seaworld = engine.execute(Zoo.insert(), Name=u'Sea_World', + seaworld = engine.execute(Zoo.insert(), Name='Sea_World', Admission=60).inserted_primary_key[0] # Let's add a crazy futuristic Zoo to test large date values. - lp = engine.execute(Zoo.insert(), Name=u'Luna Park', + lp = engine.execute(Zoo.insert(), Name='Luna Park', Founded=datetime.date(2072, 7, 17), Opens=datetime.time(0, 0, 0), Admission=134.95).inserted_primary_key[0] # Animals - leopardid = engine.execute(Animal.insert(), Species=u'Leopard', + leopardid = engine.execute(Animal.insert(), Species='Leopard', Lifespan=73.5).inserted_primary_key[0] engine.execute(Animal.update(Animal.c.ID == leopardid), ZooID=wap, LastEscape=datetime.datetime( 2004, 12, 21, 8, 15, 0, 999907,) ) - lion = engine.execute(Animal.insert(), Species=u'Lion', + lion = engine.execute(Animal.insert(), Species='Lion', ZooID=wap).inserted_primary_key[0] - engine.execute(Animal.insert(), Species=u'Slug', Legs=1, Lifespan=.75) - tiger = engine.execute(Animal.insert(), Species=u'Tiger', + engine.execute(Animal.insert(), Species='Slug', Legs=1, Lifespan=.75) + tiger = engine.execute(Animal.insert(), Species='Tiger', ZooID=sdz).inserted_primary_key[0] # Override Legs.default with itself just to make sure it works. - engine.execute(Animal.insert(inline=True), Species=u'Bear', Legs=4) - engine.execute(Animal.insert(inline=True), Species=u'Ostrich', Legs=2, + engine.execute(Animal.insert(inline=True), Species='Bear', Legs=4) + engine.execute(Animal.insert(inline=True), Species='Ostrich', Legs=2, Lifespan=103.2) - engine.execute(Animal.insert(inline=True), Species=u'Centipede', + engine.execute(Animal.insert(inline=True), Species='Centipede', Legs=100) - emp = engine.execute(Animal.insert(), Species=u'Emperor Penguin', + emp = engine.execute(Animal.insert(), Species='Emperor Penguin', Legs=2, ZooID=seaworld).inserted_primary_key[0] - adelie = engine.execute(Animal.insert(), Species=u'Adelie Penguin', + adelie = engine.execute(Animal.insert(), Species='Adelie Penguin', Legs=2, ZooID=seaworld).inserted_primary_key[0] - engine.execute(Animal.insert(inline=True), Species=u'Millipede', + engine.execute(Animal.insert(inline=True), Species='Millipede', Legs=1000000, ZooID=sdz) # Add a mother and child to test relationships - bai_yun = engine.execute(Animal.insert(), Species=u'Ape', - Name=u'Bai Yun', Legs=2).inserted_primary_key[0] - engine.execute(Animal.insert(inline=True), Species=u'Ape', - Name=u'Hua Mei', Legs=2, MotherID=bai_yun) + bai_yun = engine.execute(Animal.insert(), Species='Ape', + Name='Bai Yun', Legs=2).inserted_primary_key[0] + engine.execute(Animal.insert(inline=True), Species='Ape', + Name='Hua Mei', Legs=2, MotherID=bai_yun) def test_baseline_2_insert(self): Animal = metadata.tables['Animal'] i = Animal.insert(inline=True) - for x in xrange(ITERATIONS): - tick = i.execute(Species=u'Tick', Name=u'Tick %d' % x, + for x in range(ITERATIONS): + tick = i.execute(Species='Tick', Name='Tick %d' % x, Legs=8) def test_baseline_3_properties(self): @@ -146,28 +146,28 @@ class ZooMarkTest(fixtures.TestBase): return list(engine.execute(select).first()) - for x in xrange(ITERATIONS): + for x in range(ITERATIONS): # Zoos WAP = fullobject(Zoo.select(Zoo.c.Name - == u'Wild Animal Park')) + == 'Wild Animal Park')) SDZ = fullobject(Zoo.select(Zoo.c.Founded == datetime.date(1935, 9, 13))) Biodome = fullobject(Zoo.select(Zoo.c.Name - == u'Montr\xe9al Biod\xf4me')) + == 'Montr\xe9al Biod\xf4me')) seaworld = fullobject(Zoo.select(Zoo.c.Admission == float(60))) # Animals leopard = fullobject(Animal.select(Animal.c.Species - == u'Leopard')) + == 'Leopard')) ostrich = fullobject(Animal.select(Animal.c.Species - == u'Ostrich')) + == 'Ostrich')) millipede = fullobject(Animal.select(Animal.c.Legs == 1000000)) - ticks = fullobject(Animal.select(Animal.c.Species == u'Tick' + ticks = fullobject(Animal.select(Animal.c.Species == 'Tick' )) def test_baseline_4_expressions(self): @@ -180,7 +180,7 @@ class ZooMarkTest(fixtures.TestBase): return [list(row) for row in engine.execute(select).fetchall()] - for x in xrange(ITERATIONS): + for x in range(ITERATIONS): assert len(fulltable(Zoo.select())) == 5 assert len(fulltable(Animal.select())) == ITERATIONS + 12 assert len(fulltable(Animal.select(Animal.c.Legs == 4))) \ @@ -194,9 +194,9 @@ class ZooMarkTest(fixtures.TestBase): assert len(fulltable(Animal.select(Animal.c.Lifespan > 70))) == 2 assert len(fulltable(Animal.select(Animal.c.Species. - startswith(u'L')))) == 2 + startswith('L')))) == 2 assert len(fulltable(Animal.select(Animal.c.Species. - endswith(u'pede')))) == 2 + endswith('pede')))) == 2 assert len(fulltable(Animal.select(Animal.c.LastEscape != None))) == 1 assert len(fulltable(Animal.select(None @@ -204,10 +204,10 @@ class ZooMarkTest(fixtures.TestBase): # In operator (containedby) - assert len(fulltable(Animal.select(Animal.c.Species.like(u'%pede%' + assert len(fulltable(Animal.select(Animal.c.Species.like('%pede%' )))) == 2 - assert len(fulltable(Animal.select(Animal.c.Species.in_([u'Lion' - , u'Tiger', u'Bear'])))) == 3 + assert len(fulltable(Animal.select(Animal.c.Species.in_(['Lion' + , 'Tiger', 'Bear'])))) == 3 # Try In with cell references class thing(object): @@ -215,20 +215,20 @@ class ZooMarkTest(fixtures.TestBase): pet, pet2 = thing(), thing() - pet.Name, pet2.Name = u'Slug', u'Ostrich' + pet.Name, pet2.Name = 'Slug', 'Ostrich' assert len(fulltable(Animal.select(Animal.c.Species.in_([pet.Name, pet2.Name])))) == 2 # logic and other functions - assert len(fulltable(Animal.select(Animal.c.Species.like(u'Slug' + assert len(fulltable(Animal.select(Animal.c.Species.like('Slug' )))) == 1 - assert len(fulltable(Animal.select(Animal.c.Species.like(u'%pede%' + assert len(fulltable(Animal.select(Animal.c.Species.like('%pede%' )))) == 2 - name = u'Lion' + name = 'Lion' assert len(fulltable(Animal.select(func.length(Animal.c.Species) == len(name)))) == ITERATIONS + 3 - assert len(fulltable(Animal.select(Animal.c.Species.like(u'%i%' + assert len(fulltable(Animal.select(Animal.c.Species.like('%i%' )))) == ITERATIONS + 7 # Test now(), today(), year(), month(), day() @@ -250,7 +250,7 @@ class ZooMarkTest(fixtures.TestBase): Zoo = metadata.tables['Zoo'] engine = metadata.bind - for x in xrange(ITERATIONS): + for x in range(ITERATIONS): # views @@ -274,7 +274,7 @@ class ZooMarkTest(fixtures.TestBase): for species, lifespan in engine.execute(select([Animal.c.Species, Animal.c.Lifespan])).fetchall(): assert lifespan == expected[species] - expected = [u'Montr\xe9al Biod\xf4me', 'Wild Animal Park'] + expected = ['Montr\xe9al Biod\xf4me', 'Wild Animal Park'] e = select([Zoo.c.Name], and_(Zoo.c.Founded != None, Zoo.c.Founded <= func.current_timestamp(), Zoo.c.Founded >= datetime.date(1990, 1, 1))) @@ -290,21 +290,21 @@ class ZooMarkTest(fixtures.TestBase): def test_baseline_6_editing(self): Zoo = metadata.tables['Zoo'] engine = metadata.bind - for x in xrange(ITERATIONS): + for x in range(ITERATIONS): # Edit - SDZ = engine.execute(Zoo.select(Zoo.c.Name == u'San Diego Zoo' + SDZ = engine.execute(Zoo.select(Zoo.c.Name == 'San Diego Zoo' )).first() engine.execute(Zoo.update(Zoo.c.ID == SDZ['ID' - ]), Name=u'The San Diego Zoo', + ]), Name='The San Diego Zoo', Founded=datetime.date(1900, 1, 1), Opens=datetime.time(7, 30, 0), Admission='35.00') # Test edits - SDZ = engine.execute(Zoo.select(Zoo.c.Name == u'The San Diego Zoo' + SDZ = engine.execute(Zoo.select(Zoo.c.Name == 'The San Diego Zoo' )).first() assert SDZ['Founded'] == datetime.date(1900, 1, 1), \ SDZ['Founded'] @@ -312,14 +312,14 @@ class ZooMarkTest(fixtures.TestBase): # Change it back engine.execute(Zoo.update(Zoo.c.ID == SDZ['ID' - ]), Name=u'San Diego Zoo', + ]), Name='San Diego Zoo', Founded=datetime.date(1935, 9, 13), Opens=datetime.time(9, 0, 0), Admission='0') # Test re-edits - SDZ = engine.execute(Zoo.select(Zoo.c.Name == u'San Diego Zoo' + SDZ = engine.execute(Zoo.select(Zoo.c.Name == 'San Diego Zoo' )).first() assert SDZ['Founded'] == datetime.date(1935, 9, 13) @@ -333,14 +333,14 @@ class ZooMarkTest(fixtures.TestBase): return [list(row) for row in engine.execute(select).fetchall()] - for x in xrange(ITERATIONS): + for x in range(ITERATIONS): za = fulltable(select([Zoo.c.ID] + list(Animal.c), - Zoo.c.Name == u'San Diego Zoo', + Zoo.c.Name == 'San Diego Zoo', from_obj=[join(Zoo, Animal)])) - SDZ = Zoo.select(Zoo.c.Name == u'San Diego Zoo') + SDZ = Zoo.select(Zoo.c.Name == 'San Diego Zoo') e = fulltable(select([Zoo.c.ID, Animal.c.ID], - and_(Zoo.c.Name == u'San Diego Zoo', - Animal.c.Species == u'Leopard'), + and_(Zoo.c.Name == 'San Diego Zoo', + Animal.c.Species == 'Leopard'), from_obj=[join(Zoo, Animal)])) # Now try the same query with INNER, LEFT, and RIGHT JOINs. diff --git a/test/aaa_profiling/test_zoomark_orm.py b/test/aaa_profiling/test_zoomark_orm.py index f8c5477f7..40fb8b03b 100644 --- a/test/aaa_profiling/test_zoomark_orm.py +++ b/test/aaa_profiling/test_zoomark_orm.py @@ -75,14 +75,14 @@ class ZooMarkTest(fixtures.TestBase): class Zoo(object): def __init__(self, **kwargs): - for k, v in kwargs.iteritems(): + for k, v in kwargs.items(): setattr(self, k, v) class Animal(object): def __init__(self, **kwargs): - for k, v in kwargs.iteritems(): + for k, v in kwargs.items(): setattr(self, k, v) @@ -90,93 +90,93 @@ class ZooMarkTest(fixtures.TestBase): mapper(Animal, animal) def test_baseline_1a_populate(self): - wap = Zoo(Name=u'Wild Animal Park', Founded=datetime.date(2000, + wap = Zoo(Name='Wild Animal Park', Founded=datetime.date(2000, 1, 1), Opens=datetime.time(8, 15, 59), LastEscape=datetime.datetime( 2004, 7, 29, 5, 6, 7, ), Admission=4.95) session.add(wap) - sdz = Zoo(Name=u'San Diego Zoo', Founded=datetime.date(1835, 9, + sdz = Zoo(Name='San Diego Zoo', Founded=datetime.date(1835, 9, 13), Opens=datetime.time(9, 0, 0), Admission=0) session.add(sdz) - bio = Zoo(Name=u'Montr\xe9al Biod\xf4me', + bio = Zoo(Name='Montr\xe9al Biod\xf4me', Founded=datetime.date(1992, 6, 19), Opens=datetime.time(9, 0, 0), Admission=11.75) session.add(bio) - seaworld = Zoo(Name=u'Sea_World', Admission=60) + seaworld = Zoo(Name='Sea_World', Admission=60) session.add(seaworld) # Let's add a crazy futuristic Zoo to test large date values. - lp = Zoo(Name=u'Luna Park', Founded=datetime.date(2072, 7, 17), + lp = Zoo(Name='Luna Park', Founded=datetime.date(2072, 7, 17), Opens=datetime.time(0, 0, 0), Admission=134.95) session.add(lp) session.flush() # Animals - leopard = Animal(Species=u'Leopard', Lifespan=73.5) + leopard = Animal(Species='Leopard', Lifespan=73.5) session.add(leopard) leopard.ZooID = wap.ID leopard.LastEscape = \ datetime.datetime(2004, 12, 21, 8, 15, 0, 999907, ) - session.add(Animal(Species=u'Lion', ZooID=wap.ID)) - session.add(Animal(Species=u'Slug', Legs=1, Lifespan=.75)) - session.add(Animal(Species=u'Tiger', ZooID=sdz.ID)) + session.add(Animal(Species='Lion', ZooID=wap.ID)) + session.add(Animal(Species='Slug', Legs=1, Lifespan=.75)) + session.add(Animal(Species='Tiger', ZooID=sdz.ID)) # Override Legs.default with itself just to make sure it works. - session.add(Animal(Species=u'Bear', Legs=4)) - session.add(Animal(Species=u'Ostrich', Legs=2, Lifespan=103.2)) - session.add(Animal(Species=u'Centipede', Legs=100)) - session.add(Animal(Species=u'Emperor Penguin', Legs=2, + session.add(Animal(Species='Bear', Legs=4)) + session.add(Animal(Species='Ostrich', Legs=2, Lifespan=103.2)) + session.add(Animal(Species='Centipede', Legs=100)) + session.add(Animal(Species='Emperor Penguin', Legs=2, ZooID=seaworld.ID)) - session.add(Animal(Species=u'Adelie Penguin', Legs=2, + session.add(Animal(Species='Adelie Penguin', Legs=2, ZooID=seaworld.ID)) - session.add(Animal(Species=u'Millipede', Legs=1000000, + session.add(Animal(Species='Millipede', Legs=1000000, ZooID=sdz.ID)) # Add a mother and child to test relationships - bai_yun = Animal(Species=u'Ape', Nameu=u'Bai Yun', Legs=2) + bai_yun = Animal(Species='Ape', Nameu='Bai Yun', Legs=2) session.add(bai_yun) - session.add(Animal(Species=u'Ape', Name=u'Hua Mei', Legs=2, + session.add(Animal(Species='Ape', Name='Hua Mei', Legs=2, MotherID=bai_yun.ID)) session.flush() session.commit() def test_baseline_2_insert(self): - for x in xrange(ITERATIONS): - session.add(Animal(Species=u'Tick', Name=u'Tick %d' % x, + for x in range(ITERATIONS): + session.add(Animal(Species='Tick', Name='Tick %d' % x, Legs=8)) session.flush() def test_baseline_3_properties(self): - for x in xrange(ITERATIONS): + for x in range(ITERATIONS): # Zoos WAP = list(session.query(Zoo).filter(Zoo.Name - == u'Wild Animal Park')) + == 'Wild Animal Park')) SDZ = list(session.query(Zoo).filter(Zoo.Founded == datetime.date(1835, 9, 13))) Biodome = list(session.query(Zoo).filter(Zoo.Name - == u'Montr\xe9al Biod\xf4me')) + == 'Montr\xe9al Biod\xf4me')) seaworld = list(session.query(Zoo).filter(Zoo.Admission == float(60))) # Animals leopard = list(session.query(Animal).filter(Animal.Species - == u'Leopard')) + == 'Leopard')) ostrich = list(session.query(Animal).filter(Animal.Species - == u'Ostrich')) + == 'Ostrich')) millipede = list(session.query(Animal).filter(Animal.Legs == 1000000)) ticks = list(session.query(Animal).filter(Animal.Species - == u'Tick')) + == 'Tick')) def test_baseline_4_expressions(self): - for x in xrange(ITERATIONS): + for x in range(ITERATIONS): assert len(list(session.query(Zoo))) == 5 assert len(list(session.query(Animal))) == ITERATIONS + 12 assert len(list(session.query(Animal).filter(Animal.Legs @@ -190,9 +190,9 @@ class ZooMarkTest(fixtures.TestBase): assert len(list(session.query(Animal).filter(Animal.Lifespan > 70))) == 2 assert len(list(session.query(Animal). - filter(Animal.Species.like(u'L%')))) == 2 + filter(Animal.Species.like('L%')))) == 2 assert len(list(session.query(Animal). - filter(Animal.Species.like(u'%pede')))) == 2 + filter(Animal.Species.like('%pede')))) == 2 assert len(list(session.query(Animal).filter(Animal.LastEscape != None))) == 1 assert len(list(session.query(Animal).filter(Animal.LastEscape @@ -201,29 +201,29 @@ class ZooMarkTest(fixtures.TestBase): # In operator (containedby) assert len(list(session.query(Animal).filter( - Animal.Species.like(u'%pede%')))) == 2 + Animal.Species.like('%pede%')))) == 2 assert len(list(session.query(Animal). - filter(Animal.Species.in_((u'Lion' - , u'Tiger', u'Bear'))))) == 3 + filter(Animal.Species.in_(('Lion' + , 'Tiger', 'Bear'))))) == 3 # Try In with cell references class thing(object): pass pet, pet2 = thing(), thing() - pet.Name, pet2.Name = u'Slug', u'Ostrich' + pet.Name, pet2.Name = 'Slug', 'Ostrich' assert len(list(session.query(Animal). filter(Animal.Species.in_((pet.Name, pet2.Name))))) == 2 # logic and other functions - name = u'Lion' + name = 'Lion' assert len(list(session.query(Animal). filter(func.length(Animal.Species) == len(name)))) == ITERATIONS + 3 assert len(list(session.query(Animal). - filter(Animal.Species.like(u'%i%' + filter(Animal.Species.like('%i%' )))) == ITERATIONS + 7 # Test now(), today(), year(), month(), day() @@ -246,7 +246,7 @@ class ZooMarkTest(fixtures.TestBase): # TODO: convert to ORM engine = metadata.bind - for x in xrange(ITERATIONS): + for x in range(ITERATIONS): # views @@ -270,7 +270,7 @@ class ZooMarkTest(fixtures.TestBase): for species, lifespan in engine.execute(select([Animal.c.Species, Animal.c.Lifespan])).fetchall(): assert lifespan == expected[species] - expected = [u'Montr\xe9al Biod\xf4me', 'Wild Animal Park'] + expected = ['Montr\xe9al Biod\xf4me', 'Wild Animal Park'] e = select([Zoo.c.Name], and_(Zoo.c.Founded != None, Zoo.c.Founded <= func.current_timestamp(), Zoo.c.Founded >= datetime.date(1990, 1, 1))) @@ -284,13 +284,13 @@ class ZooMarkTest(fixtures.TestBase): legs.sort() def test_baseline_6_editing(self): - for x in xrange(ITERATIONS): + for x in range(ITERATIONS): # Edit - SDZ = session.query(Zoo).filter(Zoo.Name == u'San Diego Zoo' + SDZ = session.query(Zoo).filter(Zoo.Name == 'San Diego Zoo' ).one() - SDZ.Name = u'The San Diego Zoo' + SDZ.Name = 'The San Diego Zoo' SDZ.Founded = datetime.date(1900, 1, 1) SDZ.Opens = datetime.time(7, 30, 0) SDZ.Admission = 35.00 @@ -298,19 +298,19 @@ class ZooMarkTest(fixtures.TestBase): # Test edits SDZ = session.query(Zoo).filter(Zoo.Name - == u'The San Diego Zoo').one() + == 'The San Diego Zoo').one() assert SDZ.Founded == datetime.date(1900, 1, 1), SDZ.Founded # Change it back - SDZ.Name = u'San Diego Zoo' + SDZ.Name = 'San Diego Zoo' SDZ.Founded = datetime.date(1835, 9, 13) SDZ.Opens = datetime.time(9, 0, 0) SDZ.Admission = 0 # Test re-edits - SDZ = session.query(Zoo).filter(Zoo.Name == u'San Diego Zoo' + SDZ = session.query(Zoo).filter(Zoo.Name == 'San Diego Zoo' ).one() assert SDZ.Founded == datetime.date(1835, 9, 13), \ SDZ.Founded diff --git a/test/base/test_dependency.py b/test/base/test_dependency.py index f4a0a4c8b..b16516f15 100644 --- a/test/base/test_dependency.py +++ b/test/base/test_dependency.py @@ -82,7 +82,7 @@ class DependencySortTest(fixtures.TestBase): try: list(topological.sort(tuples, allitems)) assert False - except exc.CircularDependencyError, err: + except exc.CircularDependencyError as err: eq_(err.cycles, set(['node1', 'node3', 'node2', 'node5', 'node4'])) eq_(err.edges, set([('node3', 'node1'), ('node4', 'node1'), @@ -105,7 +105,7 @@ class DependencySortTest(fixtures.TestBase): try: list(topological.sort(tuples, allitems)) assert False - except exc.CircularDependencyError, err: + except exc.CircularDependencyError as err: eq_(err.cycles, set(['node1', 'node3', 'node2'])) eq_(err.edges, set([('node3', 'node1'), ('node2', 'node3'), ('node3', 'node2'), ('node1', 'node2'), @@ -271,7 +271,7 @@ class DependencySortTest(fixtures.TestBase): ('node4', 'node17'), ('node2', 'node20'), ('node19', 'node10'), ('node8', 'node4'), ('node11', 'node3'), ('node6', 'node1') ] - allnodes = ['node%d' % i for i in xrange(1, 21)] + allnodes = ['node%d' % i for i in range(1, 21)] eq_( topological.find_cycles(tuples, allnodes), set(['node11', 'node10', 'node13', 'node15', 'node14', 'node17', diff --git a/test/base/test_events.py b/test/base/test_events.py index 4efb30aba..7cfb5fa7d 100644 --- a/test/base/test_events.py +++ b/test/base/test_events.py @@ -190,7 +190,7 @@ class ClsLevelListenTest(fixtures.TestBase): def test_lis_subcalss_lis(self): @event.listens_for(self.TargetOne, "event_one") def handler1(x, y): - print 'handler1' + print('handler1') class SubTarget(self.TargetOne): pass @@ -207,7 +207,7 @@ class ClsLevelListenTest(fixtures.TestBase): def test_lis_multisub_lis(self): @event.listens_for(self.TargetOne, "event_one") def handler1(x, y): - print 'handler1' + print('handler1') class SubTarget(self.TargetOne): pass diff --git a/test/base/test_except.py b/test/base/test_except.py index a8c7de201..f2428c22d 100644 --- a/test/base/test_except.py +++ b/test/base/test_except.py @@ -5,14 +5,15 @@ from sqlalchemy import exc as sa_exceptions from sqlalchemy.testing import fixtures from sqlalchemy.testing import eq_ -# Py3K -#StandardError = BaseException -# Py2K -from exceptions import StandardError, KeyboardInterrupt, SystemExit +# start Py3K +Exception = BaseException +# end Py3K +# start Py2K +#from exceptions import StandardError, KeyboardInterrupt, SystemExit # end Py2K -class Error(StandardError): +class Error(Exception): """This class will be old-style on <= 2.4 and new-style on >= 2.5.""" @@ -47,7 +48,7 @@ class WrapTest(fixtures.TestBase): try: raise sa_exceptions.DBAPIError.instance('this is a message' , None, OperationalError(), DatabaseError) - except sa_exceptions.DBAPIError, exc: + except sa_exceptions.DBAPIError as exc: assert str(exc) \ == "(OperationalError) 'this is a message' None" @@ -58,7 +59,7 @@ class WrapTest(fixtures.TestBase): {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, }, OperationalError(), DatabaseError) - except sa_exceptions.DBAPIError, exc: + except sa_exceptions.DBAPIError as exc: assert str(exc).startswith("(OperationalError) 'this is a " "message' {") @@ -67,7 +68,7 @@ class WrapTest(fixtures.TestBase): raise sa_exceptions.DBAPIError.instance('this is a message', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,], OperationalError(), DatabaseError) - except sa_exceptions.DBAPIError, exc: + except sa_exceptions.DBAPIError as exc: assert str(exc).startswith("(OperationalError) 'this is a " "message' [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]") @@ -77,7 +78,7 @@ class WrapTest(fixtures.TestBase): [{1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1:1}, {1: 1}, {1: 1},], OperationalError(), DatabaseError) - except sa_exceptions.DBAPIError, exc: + except sa_exceptions.DBAPIError as exc: eq_(str(exc) , "(OperationalError) 'this is a message' [{1: 1}, "\ "{1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: "\ @@ -87,7 +88,7 @@ class WrapTest(fixtures.TestBase): {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1:1}, {1: 1}, {1: 1}, {1: 1}, ], OperationalError(), DatabaseError) - except sa_exceptions.DBAPIError, exc: + except sa_exceptions.DBAPIError as exc: eq_(str(exc) , "(OperationalError) 'this is a message' [{1: 1}, " "{1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, " @@ -100,7 +101,7 @@ class WrapTest(fixtures.TestBase): (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), ], OperationalError(), DatabaseError) - except sa_exceptions.DBAPIError, exc: + except sa_exceptions.DBAPIError as exc: eq_(str(exc), "(OperationalError) 'this is a message' [(1,), "\ "(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,)]") @@ -109,7 +110,7 @@ class WrapTest(fixtures.TestBase): (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), ], OperationalError(), DatabaseError) - except sa_exceptions.DBAPIError, exc: + except sa_exceptions.DBAPIError as exc: eq_(str(exc), "(OperationalError) 'this is a message' [(1,), " "(1,), (1,), (1,), (1,), (1,), (1,), (1,) " @@ -121,7 +122,7 @@ class WrapTest(fixtures.TestBase): try: raise sa_exceptions.DBAPIError.instance('', [], ProgrammingError(), DatabaseError) - except sa_exceptions.DBAPIError, e: + except sa_exceptions.DBAPIError as e: self.assert_(True) self.assert_('Error in str() of DB-API' in e.args[0]) @@ -129,7 +130,7 @@ class WrapTest(fixtures.TestBase): try: raise sa_exceptions.DBAPIError.instance('', [], OutOfSpec(), DatabaseError) - except sa_exceptions.DBAPIError, e: + except sa_exceptions.DBAPIError as e: self.assert_(e.__class__ is sa_exceptions.DBAPIError) except OutOfSpec: self.assert_(False) @@ -137,7 +138,7 @@ class WrapTest(fixtures.TestBase): try: raise sa_exceptions.DBAPIError.instance('', [], sa_exceptions.ArgumentError(), DatabaseError) - except sa_exceptions.DBAPIError, e: + except sa_exceptions.DBAPIError as e: self.assert_(e.__class__ is sa_exceptions.DBAPIError) except sa_exceptions.ArgumentError: self.assert_(False) diff --git a/test/base/test_utils.py b/test/base/test_utils.py index af881af17..6dcfaf9d1 100644 --- a/test/base/test_utils.py +++ b/test/base/test_utils.py @@ -16,7 +16,7 @@ class KeyedTupleTest(): eq_(len(keyed_tuple), 0) eq_(keyed_tuple.__dict__, {'_labels': []}) - eq_(keyed_tuple.keys(), []) + eq_(list(keyed_tuple.keys()), []) eq_(keyed_tuple._fields, ()) eq_(keyed_tuple._asdict(), {}) @@ -27,7 +27,7 @@ class KeyedTupleTest(): eq_(len(keyed_tuple), 2) eq_(keyed_tuple.__dict__, {'_labels': []}) - eq_(keyed_tuple.keys(), []) + eq_(list(keyed_tuple.keys()), []) eq_(keyed_tuple._fields, ()) eq_(keyed_tuple._asdict(), {}) @@ -37,7 +37,7 @@ class KeyedTupleTest(): def test_basic_creation(self): keyed_tuple = util.KeyedTuple([1, 2], ['a', 'b']) eq_(str(keyed_tuple), '(1, 2)') - eq_(keyed_tuple.keys(), ['a', 'b']) + eq_(list(keyed_tuple.keys()), ['a', 'b']) eq_(keyed_tuple._fields, ('a', 'b')) eq_(keyed_tuple._asdict(), {'a': 1, 'b': 2}) @@ -66,7 +66,7 @@ class KeyedTupleTest(): # TODO: consider not allowing None labels expected = {'a': 1, None: 2, 'b': 3, '_labels': ['a', None, 'b']} eq_(keyed_tuple.__dict__, expected) - eq_(keyed_tuple.keys(), ['a', 'b']) + eq_(list(keyed_tuple.keys()), ['a', 'b']) eq_(keyed_tuple._fields, ('a', 'b')) eq_(keyed_tuple._asdict(), {'a': 1, 'b': 3}) @@ -86,7 +86,7 @@ class KeyedTupleTest(): # TODO: consider not allowing duplicate labels expected = {'a': 1, 'b': 3, '_labels': ['a', 'b', 'b']} eq_(keyed_tuple.__dict__, expected) - eq_(keyed_tuple.keys(), ['a', 'b', 'b']) + eq_(list(keyed_tuple.keys()), ['a', 'b', 'b']) eq_(keyed_tuple._fields, ('a', 'b', 'b')) eq_(keyed_tuple._asdict(), {'a': 1, 'b': 3}) @@ -125,12 +125,12 @@ class OrderedDictTest(fixtures.TestBase): o['snack'] = 'attack' o['c'] = 3 - eq_(o.keys(), ['a', 'b', 'snack', 'c']) - eq_(o.values(), [1, 2, 'attack', 3]) + eq_(list(o.keys()), ['a', 'b', 'snack', 'c']) + eq_(list(o.values()), [1, 2, 'attack', 3]) o.pop('snack') - eq_(o.keys(), ['a', 'b', 'c']) - eq_(o.values(), [1, 2, 3]) + eq_(list(o.keys()), ['a', 'b', 'c']) + eq_(list(o.values()), [1, 2, 3]) try: o.pop('eep') @@ -146,40 +146,40 @@ class OrderedDictTest(fixtures.TestBase): except TypeError: pass - eq_(o.keys(), ['a', 'b', 'c']) - eq_(o.values(), [1, 2, 3]) + eq_(list(o.keys()), ['a', 'b', 'c']) + eq_(list(o.values()), [1, 2, 3]) o2 = util.OrderedDict(d=4) o2['e'] = 5 - eq_(o2.keys(), ['d', 'e']) - eq_(o2.values(), [4, 5]) + eq_(list(o2.keys()), ['d', 'e']) + eq_(list(o2.values()), [4, 5]) o.update(o2) - eq_(o.keys(), ['a', 'b', 'c', 'd', 'e']) - eq_(o.values(), [1, 2, 3, 4, 5]) + eq_(list(o.keys()), ['a', 'b', 'c', 'd', 'e']) + eq_(list(o.values()), [1, 2, 3, 4, 5]) o.setdefault('c', 'zzz') o.setdefault('f', 6) - eq_(o.keys(), ['a', 'b', 'c', 'd', 'e', 'f']) - eq_(o.values(), [1, 2, 3, 4, 5, 6]) + eq_(list(o.keys()), ['a', 'b', 'c', 'd', 'e', 'f']) + eq_(list(o.values()), [1, 2, 3, 4, 5, 6]) def test_odict_constructor(self): o = util.OrderedDict([('name', 'jbe'), ('fullname', 'jonathan' ), ('password', '')]) - eq_(o.keys(), ['name', 'fullname', 'password']) + eq_(list(o.keys()), ['name', 'fullname', 'password']) def test_odict_copy(self): o = util.OrderedDict() o["zzz"] = 1 o["aaa"] = 2 - eq_(o.keys(), ['zzz', 'aaa']) + eq_(list(o.keys()), ['zzz', 'aaa']) o2 = o.copy() - eq_(o2.keys(), o.keys()) + eq_(list(o2.keys()), list(o.keys())) o3 = copy.copy(o) - eq_(o3.keys(), o.keys()) + eq_(list(o3.keys()), list(o.keys())) class OrderedSetTest(fixtures.TestBase): @@ -198,7 +198,7 @@ class FrozenDictTest(fixtures.TestBase): def test_serialize(self): d = util.immutabledict({1: 2, 3: 4}) for loads, dumps in picklers(): - print loads(dumps(d)) + print(loads(dumps(d))) class MemoizedAttrTest(fixtures.TestBase): @@ -252,7 +252,7 @@ class ColumnCollectionTest(fixtures.TestBase): try: cc['col1'] in cc assert False - except exc.ArgumentError, e: + except exc.ArgumentError as e: eq_(str(e), "__contains__ requires a string argument") def test_compare(self): @@ -414,14 +414,14 @@ class IdentitySetTest(fixtures.TestBase): for type_ in (object, ImmutableSubclass): data = [type_(), type_()] ids = util.IdentitySet() - for i in range(2) + range(2): + for i in list(range(2)) + list(range(2)): ids.add(data[i]) self.assert_eq(ids, data) for type_ in (EqOverride, HashOverride, HashEqOverride): data = [type_(1), type_(1), type_(2)] ids = util.IdentitySet() - for i in range(3) + range(3): + for i in list(range(3)) + list(range(3)): ids.add(data[i]) self.assert_eq(ids, data) @@ -843,13 +843,14 @@ class IdentitySetTest(fixtures.TestBase): return super_, sub_, twin1, twin2, unique1, unique2 def _assert_unorderable_types(self, callable_): - # Py3K - #assert_raises_message( - # TypeError, 'unorderable types', callable_) - # Py2K +# start Py3K assert_raises_message( - TypeError, 'cannot compare sets using cmp()', callable_) - # end Py2K + TypeError, 'unorderable types', callable_) +# end Py3K +# start Py2K +# assert_raises_message( +# TypeError, 'cannot compare sets using cmp()', callable_) +# end Py2K def test_basic_sanity(self): IdentitySet = util.IdentitySet @@ -969,23 +970,23 @@ class DictlikeIteritemsTest(fixtures.TestBase): d = subdict(a=1, b=2, c=3) self._ok(d) - # Py2K - def test_UserDict(self): - import UserDict - d = UserDict.UserDict(a=1, b=2, c=3) - self._ok(d) - # end Py2K +# start Py2K +# def test_UserDict(self): +# import UserDict +# d = UserDict.UserDict(a=1, b=2, c=3) +# self._ok(d) +# end Py2K def test_object(self): self._notok(object()) - # Py2K - def test_duck_1(self): - class duck1(object): - def iteritems(duck): - return iter(self.baseline) - self._ok(duck1()) - # end Py2K +# start Py2K +# def test_duck_1(self): +# class duck1(object): +# def iteritems(duck): +# return iter(self.baseline) +# self._ok(duck1()) +# end Py2K def test_duck_2(self): class duck2(object): @@ -993,16 +994,16 @@ class DictlikeIteritemsTest(fixtures.TestBase): return list(self.baseline) self._ok(duck2()) - # Py2K - def test_duck_3(self): - class duck3(object): - def iterkeys(duck): - return iter(['a', 'b', 'c']) - - def __getitem__(duck, key): - return dict(a=1, b=2, c=3).get(key) - self._ok(duck3()) - # end Py2K +# start Py2K +# def test_duck_3(self): +# class duck3(object): +# def iterkeys(duck): +# return iter(['a', 'b', 'c']) +# +# def __getitem__(duck, key): +# return dict(a=1, b=2, c=3).get(key) +# self._ok(duck3()) +# end Py2K def test_duck_4(self): class duck4(object): @@ -1029,9 +1030,9 @@ class DictlikeIteritemsTest(fixtures.TestBase): class DuckTypeCollectionTest(fixtures.TestBase): def test_sets(self): - # Py2K - import sets - # end Py2K +# start Py2K +# import sets +# end Py2K class SetLike(object): def add(self): @@ -1041,9 +1042,9 @@ class DuckTypeCollectionTest(fixtures.TestBase): __emulates__ = set for type_ in (set, - # Py2K - sets.Set, - # end Py2K +# start Py2K +# sets.Set, +# end Py2K SetLike, ForcedSet): eq_(util.duck_type_collection(type_), set) @@ -1051,9 +1052,9 @@ class DuckTypeCollectionTest(fixtures.TestBase): eq_(util.duck_type_collection(instance), set) for type_ in (frozenset, - # Py2K - sets.ImmutableSet - # end Py2K +# start Py2K +# sets.ImmutableSet +# end Py2K ): is_(util.duck_type_collection(type_), None) instance = type_() @@ -1175,7 +1176,7 @@ class SymbolTest(fixtures.TestBase): sym3 = util.pickle.loads(s) for protocol in 0, 1, 2: - print protocol + print(protocol) serial = util.pickle.dumps(sym1) rt = util.pickle.loads(serial) assert rt is sym1 @@ -1550,21 +1551,21 @@ class TestClassHierarchy(fixtures.TestBase): eq_(set(util.class_hierarchy(A)), set((A, B, C, object))) eq_(set(util.class_hierarchy(B)), set((A, B, C, object))) - # Py2K - def test_oldstyle_mixin(self): - class A(object): - pass - - class Mixin: - pass - - class B(A, Mixin): - pass - - eq_(set(util.class_hierarchy(B)), set((A, B, object))) - eq_(set(util.class_hierarchy(Mixin)), set()) - eq_(set(util.class_hierarchy(A)), set((A, B, object))) - # end Py2K +# start Py2K +# def test_oldstyle_mixin(self): +# class A(object): +# pass +# +# class Mixin: +# pass +# +# class B(A, Mixin): +# pass +# +# eq_(set(util.class_hierarchy(B)), set((A, B, object))) +# eq_(set(util.class_hierarchy(Mixin)), set()) +# eq_(set(util.class_hierarchy(A)), set((A, B, object))) +# end Py2K class TestClassProperty(fixtures.TestBase): diff --git a/test/dialect/test_firebird.py b/test/dialect/test_firebird.py index 5a80a3776..6019dc8f9 100644 --- a/test/dialect/test_firebird.py +++ b/test/dialect/test_firebird.py @@ -28,7 +28,7 @@ class DomainReflectionTest(fixtures.TestBase, AssertsExecutionResults): ) con.execute('CREATE DOMAIN img_domain AS BLOB SUB_TYPE ' 'BINARY') - except ProgrammingError, e: + except ProgrammingError as e: if not 'attempt to store duplicate value' in str(e): raise e con.execute('''CREATE GENERATOR gen_testtable_id''') diff --git a/test/dialect/test_mssql.py b/test/dialect/test_mssql.py index f1cd3fe85..cca06f1cc 100644 --- a/test/dialect/test_mssql.py +++ b/test/dialect/test_mssql.py @@ -403,7 +403,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile( s, "SELECT TOP 10 t.x, t.y FROM t WHERE t.x = :x_1 ORDER BY t.y", - checkparams={u'x_1': 5} + checkparams={'x_1': 5} ) def test_limit_zero_using_top(self): @@ -414,7 +414,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile( s, "SELECT TOP 0 t.x, t.y FROM t WHERE t.x = :x_1 ORDER BY t.y", - checkparams={u'x_1': 5} + checkparams={'x_1': 5} ) def test_offset_using_window(self): @@ -424,14 +424,14 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): # test that the select is not altered with subsequent compile # calls - for i in xrange(2): + for i in range(2): self.assert_compile( s, "SELECT anon_1.x, anon_1.y FROM (SELECT t.x AS x, t.y " "AS y, ROW_NUMBER() OVER (ORDER BY t.y) AS " "mssql_rn FROM t WHERE t.x = :x_1) AS " "anon_1 WHERE mssql_rn > :mssql_rn_1", - checkparams={u'mssql_rn_1': 20, u'x_1': 5} + checkparams={'mssql_rn_1': 20, 'x_1': 5} ) def test_limit_offset_using_window(self): @@ -447,7 +447,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): "FROM t " "WHERE t.x = :x_1) AS anon_1 " "WHERE mssql_rn > :mssql_rn_1 AND mssql_rn <= :mssql_rn_2", - checkparams={u'mssql_rn_1': 20, u'mssql_rn_2': 30, u'x_1': 5} + checkparams={'mssql_rn_1': 20, 'mssql_rn_2': 30, 'x_1': 5} ) def test_limit_offset_with_correlated_order_by(self): @@ -468,7 +468,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): "FROM t1 " "WHERE t1.x = :x_1) AS anon_1 " "WHERE mssql_rn > :mssql_rn_1 AND mssql_rn <= :mssql_rn_2", - checkparams={u'mssql_rn_1': 20, u'mssql_rn_2': 30, u'x_1': 5} + checkparams={'mssql_rn_1': 20, 'mssql_rn_2': 30, 'x_1': 5} ) def test_limit_zero_offset_using_window(self): @@ -482,7 +482,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): s, "SELECT TOP 0 t.x, t.y FROM t " "WHERE t.x = :x_1 ORDER BY t.y", - checkparams={u'x_1': 5} + checkparams={'x_1': 5} ) def test_sequence_start_0(self): @@ -851,11 +851,11 @@ class QueryUnicodeTest(fixtures.TestBase): # encode in UTF-8 (sting object) because this is the default # dialect encoding - con.execute(u"insert into unitest_table values ('bien u\ + con.execute("insert into unitest_table values ('bien u\ umang\xc3\xa9')".encode('UTF-8')) try: r = t1.select().execute().first() - assert isinstance(r[1], unicode), \ + assert isinstance(r[1], str), \ '%s is %s instead of unicode, working on %s' % (r[1], type(r[1]), meta.bind) finally: @@ -1707,7 +1707,7 @@ class TypeRoundTripTest(fixtures.TestBase, AssertsExecutionResults, ComparesTabl )] for value in test_items: float_table.insert().execute(floatcol=value) - except Exception, e: + except Exception as e: raise e @@ -1953,8 +1953,8 @@ class MonkeyPatchedBinaryTest(fixtures.TestBase): def test_unicode(self): module = __import__('pymssql') - result = module.Binary(u'foo') - eq_(result, u'foo') + result = module.Binary('foo') + eq_(result, 'foo') def test_bytes(self): module = __import__('pymssql') @@ -2073,7 +2073,7 @@ class InfoCoerceUnicodeTest(fixtures.TestBase): dialect = mssql.dialect() value = CoerceUnicode().bind_processor(dialect)('a string') - assert isinstance(value, unicode) + assert isinstance(value, str) class ReflectHugeViewTest(fixtures.TestBase): __only_on__ = 'mssql' @@ -2085,13 +2085,13 @@ class ReflectHugeViewTest(fixtures.TestBase): t = Table('base_table', self.metadata, *[ Column("long_named_column_number_%d" % i, Integer) - for i in xrange(self.col_num) + for i in range(self.col_num) ] ) self.view_str = view_str = \ "CREATE VIEW huge_named_view AS SELECT %s FROM base_table" % ( ",".join("long_named_column_number_%d" % i - for i in xrange(self.col_num)) + for i in range(self.col_num)) ) assert len(view_str) > 4000 diff --git a/test/dialect/test_mysql.py b/test/dialect/test_mysql.py index f89b0b229..df4eab86a 100644 --- a/test/dialect/test_mysql.py +++ b/test/dialect/test_mysql.py @@ -372,9 +372,9 @@ class TypesTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL): try: self.assert_(list(row) == expected) except: - print "Storing %s" % store - print "Expected %s" % expected - print "Found %s" % list(row) + print("Storing %s" % store) + print("Expected %s" % expected) + print("Found %s" % list(row)) raise table.delete().execute().close() @@ -684,17 +684,17 @@ class EnumTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL): metadata = MetaData(unicode_engine) t1 = Table('table', metadata, Column('id', Integer, primary_key=True), - Column('value', Enum(u'réveillé', u'drôle', u'S’il')), - Column('value2', mysql.ENUM(u'réveillé', u'drôle', u'S’il')) + Column('value', Enum('réveillé', 'drôle', 'S’il')), + Column('value2', mysql.ENUM('réveillé', 'drôle', 'S’il')) ) metadata.create_all() try: - t1.insert().execute(value=u'drôle', value2=u'drôle') - t1.insert().execute(value=u'réveillé', value2=u'réveillé') - t1.insert().execute(value=u'S’il', value2=u'S’il') + t1.insert().execute(value='drôle', value2='drôle') + t1.insert().execute(value='réveillé', value2='réveillé') + t1.insert().execute(value='S’il', value2='S’il') eq_(t1.select().order_by(t1.c.id).execute().fetchall(), - [(1, u'drôle', u'drôle'), (2, u'réveillé', u'réveillé'), - (3, u'S’il', u'S’il')] + [(1, 'drôle', 'drôle'), (2, 'réveillé', 'réveillé'), + (3, 'S’il', 'S’il')] ) # test reflection of the enum labels @@ -706,10 +706,10 @@ class EnumTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL): # latin-1 stuff forcing its way in ? assert t2.c.value.type.enums[0:2] == \ - (u'réveillé', u'drôle') # u'S’il') # eh ? + ('réveillé', 'drôle') # u'S’il') # eh ? assert t2.c.value2.type.enums[0:2] == \ - (u'réveillé', u'drôle') # u'S’il') # eh ? + ('réveillé', 'drôle') # u'S’il') # eh ? finally: metadata.drop_all() @@ -877,13 +877,13 @@ class ReflectionTest(fixtures.TestBase, AssertsExecutionResults): reflected = Table('mysql_case', MetaData(testing.db), autoload=True, include_columns=['c1', 'C2']) for t in case_table, reflected: - assert 'c1' in t.c.keys() - assert 'C2' in t.c.keys() + assert 'c1' in list(t.c.keys()) + assert 'C2' in list(t.c.keys()) reflected2 = Table('mysql_case', MetaData(testing.db), autoload=True, include_columns=['c1', 'c2']) - assert 'c1' in reflected2.c.keys() + assert 'c1' in list(reflected2.c.keys()) for c in ['c2', 'C2', 'C3']: - assert c not in reflected2.c.keys() + assert c not in list(reflected2.c.keys()) finally: case_table.drop() @@ -1370,7 +1370,7 @@ class SQLModeDetectionTest(fixtures.TestBase): def _options(self, modes): def connect(con, record): cursor = con.cursor() - print "DOING THiS:", "set sql_mode='%s'" % (",".join(modes)) + print("DOING THiS:", "set sql_mode='%s'" % (",".join(modes))) cursor.execute("set sql_mode='%s'" % (",".join(modes))) e = engines.testing_engine(options={ 'pool_events':[ diff --git a/test/dialect/test_oracle.py b/test/dialect/test_oracle.py index 861b28c5f..fd86d4ff9 100644 --- a/test/dialect/test_oracle.py +++ b/test/dialect/test_oracle.py @@ -1,5 +1,5 @@ # coding: utf-8 -from __future__ import with_statement + from sqlalchemy.testing import eq_ from sqlalchemy import * @@ -807,7 +807,7 @@ class TwoPhaseTest(fixtures.TablesTest): ) def test_twophase_prepare_false(self): conn = self._connection() - for i in xrange(2): + for i in range(2): trans = conn.begin_twophase() conn.execute("select 1 from dual") trans.prepare() @@ -817,7 +817,7 @@ class TwoPhaseTest(fixtures.TablesTest): def test_twophase_prepare_true(self): conn = self._connection() - for i in xrange(2): + for i in range(2): trans = conn.begin_twophase() conn.execute("insert into datatable (id, data) " "values (%s, 'somedata')" % i) @@ -870,7 +870,7 @@ class DialectTypesTest(fixtures.TestBase, AssertsCompiledSQL): b = bindparam("foo", "hello world!") assert b.type.dialect_impl(dialect).get_dbapi_type(dbapi) == 'STRING' - b = bindparam("foo", u"hello world!") + b = bindparam("foo", "hello world!") assert b.type.dialect_impl(dialect).get_dbapi_type(dbapi) == 'STRING' def test_long(self): @@ -1257,7 +1257,7 @@ class TypesTest(fixtures.TestBase): autoload=True, oracle_resolve_synonyms=True ) for row in types_table.select().execute().fetchall(): - [row[k] for k in row.keys()] + [row[k] for k in list(row.keys())] @testing.provide_metadata def test_raw_roundtrip(self): @@ -1291,11 +1291,11 @@ class TypesTest(fixtures.TestBase): t2.c.data.type.dialect_impl(testing.db.dialect), cx_oracle._OracleNVarChar) - data = u'm’a réveillé.' + data = 'm’a réveillé.' t2.insert().execute(data=data) res = t2.select().execute().first()['data'] eq_(res, data) - assert isinstance(res, unicode) + assert isinstance(res, str) def test_char_length(self): @@ -1426,7 +1426,7 @@ class DontReflectIOTTest(fixtures.TestBase): m = MetaData(testing.db) m.reflect() eq_( - set(t.name for t in m.tables.values()), + set(t.name for t in list(m.tables.values())), set(['admin_docindex']) ) @@ -1641,28 +1641,28 @@ class UnicodeSchemaTest(fixtures.TestBase): metadata.create_all() table.insert().execute( - {'_underscorecolumn': u'’é'}, + {'_underscorecolumn': '’é'}, ) result = testing.db.execute( - table.select().where(table.c._underscorecolumn==u'’é') + table.select().where(table.c._underscorecolumn=='’é') ).scalar() - eq_(result, u'’é') + eq_(result, '’é') @testing.provide_metadata def test_quoted_column_unicode(self): metadata = self.metadata table=Table("atable", metadata, - Column(u"méil", Unicode(255), primary_key=True), + Column("méil", Unicode(255), primary_key=True), ) metadata.create_all() table.insert().execute( - {u'méil': u'’é'}, + {'méil': '’é'}, ) result = testing.db.execute( - table.select().where(table.c[u'méil']==u'’é') + table.select().where(table.c['méil']=='’é') ).scalar() - eq_(result, u'’é') + eq_(result, '’é') class DBLinkReflectionTest(fixtures.TestBase): @@ -1702,5 +1702,5 @@ class DBLinkReflectionTest(fixtures.TestBase): t = Table('test_table_syn', m, autoload=True, autoload_with=testing.db, oracle_resolve_synonyms=True) - eq_(t.c.keys(), ['id', 'data']) + eq_(list(t.c.keys()), ['id', 'data']) eq_(list(t.primary_key), [t.c.id]) diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py index e217eb0b8..43ac7d7ae 100644 --- a/test/dialect/test_postgresql.py +++ b/test/dialect/test_postgresql.py @@ -1,6 +1,6 @@ # coding: utf-8 -from __future__ import with_statement + from sqlalchemy.testing.assertions import eq_, assert_raises, \ assert_raises_message, is_, AssertsExecutionResults, \ @@ -559,21 +559,21 @@ class EnumTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL): t1 = Table('table', metadata, Column('id', Integer, primary_key=True), Column('value', - Enum(u'réveillé', u'drôle', u'S’il', + Enum('réveillé', 'drôle', 'S’il', name='onetwothreetype')) ) metadata.create_all() try: - t1.insert().execute(value=u'drôle') - t1.insert().execute(value=u'réveillé') - t1.insert().execute(value=u'S’il') + t1.insert().execute(value='drôle') + t1.insert().execute(value='réveillé') + t1.insert().execute(value='S’il') eq_(t1.select().order_by(t1.c.id).execute().fetchall(), - [(1, u'drôle'), (2, u'réveillé'), (3, u'S’il')] + [(1, 'drôle'), (2, 'réveillé'), (3, 'S’il')] ) m2 = MetaData(testing.db) t2 = Table('table', m2, autoload=True) - assert t2.c.value.type.enums == (u'réveillé', u'drôle', u'S’il') + assert t2.c.value.type.enums == ('réveillé', 'drôle', 'S’il') finally: metadata.drop_all() @@ -1238,7 +1238,7 @@ class DomainReflectionTest(fixtures.TestBase, AssertsExecutionResults): : try: con.execute(ddl) - except exc.DBAPIError, e: + except exc.DBAPIError as e: if not 'already exists' in str(e): raise e con.execute('CREATE TABLE testtable (question integer, answer ' @@ -1476,7 +1476,7 @@ class ReflectionTest(fixtures.TestBase): meta1.create_all() meta2 = MetaData(testing.db) subject = Table('subject', meta2, autoload=True) - eq_(subject.primary_key.columns.keys(), [u'p2', u'p1']) + eq_(list(subject.primary_key.columns.keys()), ['p2', 'p1']) @testing.provide_metadata def test_pg_weirdchar_reflection(self): @@ -1749,7 +1749,7 @@ class ReflectionTest(fixtures.TestBase): conn.execute("ALTER TABLE t RENAME COLUMN x to y") ind = testing.db.dialect.get_indexes(conn, "t", None) - eq_(ind, [{'unique': False, 'column_names': [u'y'], 'name': u'idx1'}]) + eq_(ind, [{'unique': False, 'column_names': ['y'], 'name': 'idx1'}]) conn.close() class CustomTypeReflectionTest(fixtures.TestBase): @@ -2174,8 +2174,8 @@ class ArrayTest(fixtures.TablesTest, AssertsExecutionResults): def test_insert_array(self): arrtable = self.tables.arrtable - arrtable.insert().execute(intarr=[1, 2, 3], strarr=[u'abc', - u'def']) + arrtable.insert().execute(intarr=[1, 2, 3], strarr=['abc', + 'def']) results = arrtable.select().execute().fetchall() eq_(len(results), 1) eq_(results[0]['intarr'], [1, 2, 3]) @@ -2183,9 +2183,9 @@ class ArrayTest(fixtures.TablesTest, AssertsExecutionResults): def test_array_where(self): arrtable = self.tables.arrtable - arrtable.insert().execute(intarr=[1, 2, 3], strarr=[u'abc', - u'def']) - arrtable.insert().execute(intarr=[4, 5, 6], strarr=u'ABC') + arrtable.insert().execute(intarr=[1, 2, 3], strarr=['abc', + 'def']) + arrtable.insert().execute(intarr=[4, 5, 6], strarr='ABC') results = arrtable.select().where(arrtable.c.intarr == [1, 2, 3]).execute().fetchall() eq_(len(results), 1) @@ -2194,7 +2194,7 @@ class ArrayTest(fixtures.TablesTest, AssertsExecutionResults): def test_array_concat(self): arrtable = self.tables.arrtable arrtable.insert().execute(intarr=[1, 2, 3], - strarr=[u'abc', u'def']) + strarr=['abc', 'def']) results = select([arrtable.c.intarr + [4, 5, 6]]).execute().fetchall() eq_(len(results), 1) @@ -2203,15 +2203,15 @@ class ArrayTest(fixtures.TablesTest, AssertsExecutionResults): def test_array_subtype_resultprocessor(self): arrtable = self.tables.arrtable arrtable.insert().execute(intarr=[4, 5, 6], - strarr=[[u'm\xe4\xe4'], [u'm\xf6\xf6' + strarr=[['m\xe4\xe4'], ['m\xf6\xf6' ]]) - arrtable.insert().execute(intarr=[1, 2, 3], strarr=[u'm\xe4\xe4' - , u'm\xf6\xf6']) + arrtable.insert().execute(intarr=[1, 2, 3], strarr=['m\xe4\xe4' + , 'm\xf6\xf6']) results = \ arrtable.select(order_by=[arrtable.c.intarr]).execute().fetchall() eq_(len(results), 2) - eq_(results[0]['strarr'], [u'm\xe4\xe4', u'm\xf6\xf6']) - eq_(results[1]['strarr'], [[u'm\xe4\xe4'], [u'm\xf6\xf6']]) + eq_(results[0]['strarr'], ['m\xe4\xe4', 'm\xf6\xf6']) + eq_(results[1]['strarr'], [['m\xe4\xe4'], ['m\xf6\xf6']]) def test_array_literal(self): eq_( @@ -2263,7 +2263,7 @@ class ArrayTest(fixtures.TablesTest, AssertsExecutionResults): testing.db.execute( arrtable.insert(), intarr=[4, 5, 6], - strarr=[u'abc', u'def'] + strarr=['abc', 'def'] ) eq_( testing.db.scalar(select([arrtable.c.intarr[2:3]])), diff --git a/test/dialect/test_sqlite.py b/test/dialect/test_sqlite.py index 97962a54a..440fe1f43 100644 --- a/test/dialect/test_sqlite.py +++ b/test/dialect/test_sqlite.py @@ -84,7 +84,7 @@ class TestTypes(fixtures.TestBase, AssertsExecutionResults): eq_(row, (1, datetime.date(2010, 5, 10), datetime.datetime( 2010, 5, 10, 12, 15, 25, ))) r = engine.execute(func.current_date()).scalar() - assert isinstance(r, basestring) + assert isinstance(r, str) finally: t.drop(engine) engine.dispose() @@ -104,8 +104,8 @@ class TestTypes(fixtures.TestBase, AssertsExecutionResults): UnicodeText(), ): bindproc = t.dialect_impl(dialect).bind_processor(dialect) - assert not bindproc or isinstance(bindproc(u'some string'), - unicode) + assert not bindproc or isinstance(bindproc('some string'), + str) @testing.provide_metadata def test_type_reflection(self): @@ -566,7 +566,7 @@ class DialectTest(fixtures.TestBase, AssertsExecutionResults): eq_(inspector.get_indexes('foo'), []) eq_(inspector.get_indexes('foo', include_auto_indexes=True), [{'unique': 1, 'name' - : u'sqlite_autoindex_foo_1', 'column_names': [u'bar']}]) + : 'sqlite_autoindex_foo_1', 'column_names': ['bar']}]) finally: meta.drop_all() @@ -602,7 +602,7 @@ class SQLTest(fixtures.TestBase, AssertsCompiledSQL): 'dow': '%w', 'week': '%W', } - for field, subst in mapping.items(): + for field, subst in list(mapping.items()): self.assert_compile(select([extract(field, t.c.col1)]), "SELECT CAST(STRFTIME('%s', t.col1) AS " "INTEGER) AS anon_1 FROM t" % subst) diff --git a/test/dialect/test_sybase.py b/test/dialect/test_sybase.py index 025d49aae..1318a282b 100644 --- a/test/dialect/test_sybase.py +++ b/test/dialect/test_sybase.py @@ -19,7 +19,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): 'year': 'year', } - for field, subst in mapping.items(): + for field, subst in list(mapping.items()): self.assert_compile( select([extract(field, t.c.col1)]), 'SELECT DATEPART("%s", t.col1) AS anon_1 FROM t' % subst) diff --git a/test/engine/test_bind.py b/test/engine/test_bind.py index f76350fcc..973cf4d84 100644 --- a/test/engine/test_bind.py +++ b/test/engine/test_bind.py @@ -1,6 +1,6 @@ """tests the "bind" attribute/argument across schema and SQL, including the deprecated versions of these arguments""" -from __future__ import with_statement + from sqlalchemy.testing import eq_, assert_raises from sqlalchemy import engine, exc from sqlalchemy import MetaData, ThreadLocalMetaData @@ -61,7 +61,7 @@ class BindTest(fixtures.TestBase): try: meth() assert False - except exc.UnboundExecutionError, e: + except exc.UnboundExecutionError as e: eq_(str(e), "The MetaData is not bound to an Engine or " "Connection. Execution can not proceed without a " @@ -82,7 +82,7 @@ class BindTest(fixtures.TestBase): try: meth() assert False - except exc.UnboundExecutionError, e: + except exc.UnboundExecutionError as e: eq_( str(e), "The Table 'test_table' " diff --git a/test/engine/test_ddlemit.py b/test/engine/test_ddlemit.py index 3dbd5756a..deaf09cf7 100644 --- a/test/engine/test_ddlemit.py +++ b/test/engine/test_ddlemit.py @@ -47,7 +47,7 @@ class EmitDDLTest(fixtures.TestBase): return (m, ) + tuple( Table('t%d' % i, m, Column('x', Integer)) - for i in xrange(1, 6) + for i in range(1, 6) ) def _table_seq_fixture(self): diff --git a/test/engine/test_ddlevents.py b/test/engine/test_ddlevents.py index 71379ec7e..6cc652baf 100644 --- a/test/engine/test_ddlevents.py +++ b/test/engine/test_ddlevents.py @@ -1,4 +1,4 @@ -from __future__ import with_statement + from sqlalchemy.testing import assert_raises, assert_raises_message from sqlalchemy.schema import DDL, CheckConstraint, AddConstraint, \ DropConstraint diff --git a/test/engine/test_execute.py b/test/engine/test_execute.py index 203d7bd71..e737accdb 100644 --- a/test/engine/test_execute.py +++ b/test/engine/test_execute.py @@ -1,4 +1,4 @@ -from __future__ import with_statement + from sqlalchemy.testing import eq_, assert_raises, assert_raises_message, \ config, is_ @@ -18,7 +18,7 @@ from sqlalchemy.dialects.oracle.zxjdbc import ReturningParam from sqlalchemy.engine import result as _result, default from sqlalchemy.engine.base import Connection, Engine from sqlalchemy.testing import fixtures -import StringIO +import io users, metadata, users_autoinc = None, None, None class ExecuteTest(fixtures.TestBase): @@ -256,7 +256,7 @@ class ExecuteTest(fixtures.TestBase): try: cursor = raw.cursor() cursor.execute("SELECTINCORRECT") - except testing.db.dialect.dbapi.DatabaseError, orig: + except testing.db.dialect.dbapi.DatabaseError as orig: # py3k has "orig" in local scope... the_orig = orig finally: @@ -622,7 +622,7 @@ class LogParamsTest(fixtures.TestBase): def test_log_large_dict(self): self.eng.execute( "INSERT INTO foo (data) values (:data)", - [{"data":str(i)} for i in xrange(100)] + [{"data":str(i)} for i in range(100)] ) eq_( self.buf.buffer[1].message, @@ -635,7 +635,7 @@ class LogParamsTest(fixtures.TestBase): def test_log_large_list(self): self.eng.execute( "INSERT INTO foo (data) values (?)", - [(str(i), ) for i in xrange(100)] + [(str(i), ) for i in range(100)] ) eq_( self.buf.buffer[1].message, @@ -654,7 +654,7 @@ class LogParamsTest(fixtures.TestBase): "100 total bound parameter sets ... {'data': '98'}, {'data': '99'}\]", lambda: self.eng.execute( "INSERT INTO nonexistent (data) values (:data)", - [{"data":str(i)} for i in xrange(100)] + [{"data":str(i)} for i in range(100)] ) ) @@ -668,7 +668,7 @@ class LogParamsTest(fixtures.TestBase): "\('98',\), \('99',\)\]", lambda: self.eng.execute( "INSERT INTO nonexistent (data) values (?)", - [(str(i), ) for i in xrange(100)] + [(str(i), ) for i in range(100)] ) ) @@ -834,9 +834,9 @@ class EchoTest(fixtures.TestBase): class MockStrategyTest(fixtures.TestBase): def _engine_fixture(self): - buf = StringIO.StringIO() + buf = io.StringIO() def dump(sql, *multiparams, **params): - buf.write(unicode(sql.compile(dialect=engine.dialect))) + buf.write(str(sql.compile(dialect=engine.dialect))) engine = create_engine('postgresql://', strategy='mock', executor=dump) return engine, buf @@ -939,7 +939,7 @@ class ResultProxyTest(fixtures.TestBase): def test_row_c_sequence_check(self): import csv import collections - from StringIO import StringIO + from io import StringIO metadata = MetaData() metadata.bind = 'sqlite://' @@ -1026,7 +1026,7 @@ class AlternateResultProxyTest(fixtures.TestBase): ) m.create_all(engine) engine.execute(t.insert(), [ - {'x':i, 'y':"t_%d" % i} for i in xrange(1, 12) + {'x':i, 'y':"t_%d" % i} for i in range(1, 12) ]) def _test_proxy(self, cls): @@ -1039,13 +1039,13 @@ class AlternateResultProxyTest(fixtures.TestBase): assert isinstance(r, cls) for i in range(5): rows.append(r.fetchone()) - eq_(rows, [(i, "t_%d" % i) for i in xrange(1, 6)]) + eq_(rows, [(i, "t_%d" % i) for i in range(1, 6)]) rows = r.fetchmany(3) - eq_(rows, [(i, "t_%d" % i) for i in xrange(6, 9)]) + eq_(rows, [(i, "t_%d" % i) for i in range(6, 9)]) rows = r.fetchall() - eq_(rows, [(i, "t_%d" % i) for i in xrange(9, 12)]) + eq_(rows, [(i, "t_%d" % i) for i in range(9, 12)]) r = self.engine.execute(select([self.table])) rows = r.fetchmany(None) @@ -1059,7 +1059,7 @@ class AlternateResultProxyTest(fixtures.TestBase): r = self.engine.execute(select([self.table]).limit(5)) rows = r.fetchmany(6) - eq_(rows, [(i, "t_%d" % i) for i in xrange(1, 6)]) + eq_(rows, [(i, "t_%d" % i) for i in range(1, 6)]) def test_plain(self): self._test_proxy(_result.ResultProxy) @@ -1184,7 +1184,7 @@ class EngineEventsTest(fixtures.TestBase): try: conn.execute("SELECT FOO FROM I_DONT_EXIST") assert False - except tsa.exc.DBAPIError, e: + except tsa.exc.DBAPIError as e: assert canary[0][2] is e.orig assert canary[0][0] == "SELECT FOO FROM I_DONT_EXIST" diff --git a/test/engine/test_parseconnect.py b/test/engine/test_parseconnect.py index a00a942cb..3d99fd509 100644 --- a/test/engine/test_parseconnect.py +++ b/test/engine/test_parseconnect.py @@ -1,6 +1,6 @@ from sqlalchemy.testing import assert_raises, assert_raises_message, eq_ -import ConfigParser -import StringIO +import configparser +import io import sqlalchemy.engine.url as url from sqlalchemy import create_engine, engine_from_config, exc, pool from sqlalchemy.engine.util import _coerce_config @@ -103,8 +103,8 @@ pool_size=2 pool_threadlocal=1 pool_timeout=10 """ - ini = ConfigParser.ConfigParser() - ini.readfp(StringIO.StringIO(raw)) + ini = configparser.ConfigParser() + ini.readfp(io.StringIO(raw)) expected = { 'url': 'postgresql://scott:tiger@somehost/test?fooz=somevalue', @@ -234,7 +234,7 @@ pool_timeout=10 : True}, convert_unicode=True) try: e.connect() - except tsa.exc.DBAPIError, de: + except tsa.exc.DBAPIError as de: assert not de.connection_invalidated def test_ensure_dialect_does_is_disconnect_no_conn(self): @@ -266,7 +266,7 @@ pool_timeout=10 try: create_engine('sqlite://', module=ThrowOnConnect()).connect() assert False - except tsa.exc.DBAPIError, de: + except tsa.exc.DBAPIError as de: assert de.connection_invalidated def test_urlattr(self): diff --git a/test/engine/test_pool.py b/test/engine/test_pool.py index c01d14c4f..1d31c16b5 100644 --- a/test/engine/test_pool.py +++ b/test/engine/test_pool.py @@ -525,23 +525,23 @@ class DeprecatedPoolListenerTest(PoolTestBase): self.assert_((item in innerself.checked_out) == in_cout) self.assert_((item in innerself.checked_in) == in_cin) def inst_connect(self, con, record): - print "connect(%s, %s)" % (con, record) + print("connect(%s, %s)" % (con, record)) assert con is not None assert record is not None self.connected.append(con) def inst_first_connect(self, con, record): - print "first_connect(%s, %s)" % (con, record) + print("first_connect(%s, %s)" % (con, record)) assert con is not None assert record is not None self.first_connected.append(con) def inst_checkout(self, con, record, proxy): - print "checkout(%s, %s, %s)" % (con, record, proxy) + print("checkout(%s, %s, %s)" % (con, record, proxy)) assert con is not None assert record is not None assert proxy is not None self.checked_out.append(con) def inst_checkin(self, con, record): - print "checkin(%s, %s)" % (con, record) + print("checkin(%s, %s)" % (con, record)) # con can be None if invalidated assert record is not None self.checked_in.append(con) @@ -738,8 +738,8 @@ class QueuePoolTest(PoolTestBase): def status(pool): tup = pool.size(), pool.checkedin(), pool.overflow(), \ pool.checkedout() - print 'Pool size: %d Connections in pool: %d Current '\ - 'Overflow: %d Current Checked out connections: %d' % tup + print('Pool size: %d Connections in pool: %d Current '\ + 'Overflow: %d Current Checked out connections: %d' % tup) return tup c1 = p.connect() @@ -794,7 +794,7 @@ class QueuePoolTest(PoolTestBase): try: c4 = p.connect() assert False - except tsa.exc.TimeoutError, e: + except tsa.exc.TimeoutError as e: assert int(time.time() - now) == 2 def test_timeout_race(self): @@ -812,18 +812,18 @@ class QueuePoolTest(PoolTestBase): max_overflow = 1, use_threadlocal = False, timeout=3) timeouts = [] def checkout(): - for x in xrange(1): + for x in range(1): now = time.time() try: c1 = p.connect() - except tsa.exc.TimeoutError, e: + except tsa.exc.TimeoutError as e: timeouts.append(time.time() - now) continue time.sleep(4) c1.close() threads = [] - for i in xrange(10): + for i in range(10): th = threading.Thread(target=checkout) th.start() threads.append(th) @@ -860,7 +860,7 @@ class QueuePoolTest(PoolTestBase): except tsa.exc.TimeoutError: pass threads = [] - for i in xrange(thread_count): + for i in range(thread_count): th = threading.Thread(target=whammy) th.start() threads.append(th) @@ -1007,8 +1007,8 @@ class QueuePoolTest(PoolTestBase): strong_refs.add(c.connection) return c - for j in xrange(5): - conns = [_conn() for i in xrange(4)] + for j in range(5): + conns = [_conn() for i in range(4)] for c in conns: c.close() @@ -1152,7 +1152,7 @@ class SingletonThreadPoolTest(PoolTestBase): return p.connect() def checkout(): - for x in xrange(10): + for x in range(10): c = _conn() assert c c.cursor() @@ -1160,7 +1160,7 @@ class SingletonThreadPoolTest(PoolTestBase): time.sleep(.1) threads = [] - for i in xrange(10): + for i in range(10): th = threading.Thread(target=checkout) th.start() threads.append(th) diff --git a/test/engine/test_processors.py b/test/engine/test_processors.py index bc9af7305..b1c482f09 100644 --- a/test/engine/test_processors.py +++ b/test/engine/test_processors.py @@ -53,7 +53,7 @@ class PyDateProcessorTest(_DateProcessorTest): cls.module = type("util", (object,), dict( (k, staticmethod(v)) - for k, v in processors.py_fallback().items() + for k, v in list(processors.py_fallback().items()) ) ) @@ -156,7 +156,7 @@ class PyDistillArgsTest(_DistillArgsTest): cls.module = type("util", (object,), dict( (k, staticmethod(v)) - for k, v in util.py_fallback().items() + for k, v in list(util.py_fallback().items()) ) ) diff --git a/test/engine/test_reconnect.py b/test/engine/test_reconnect.py index 9aecb81a9..d75ef3b75 100644 --- a/test/engine/test_reconnect.py +++ b/test/engine/test_reconnect.py @@ -173,7 +173,7 @@ class MockReconnectTest(fixtures.TestBase): try: trans.commit() assert False - except tsa.exc.InvalidRequestError, e: + except tsa.exc.InvalidRequestError as e: assert str(e) \ == "Can't reconnect until invalid transaction is "\ "rolled back" @@ -370,7 +370,7 @@ class RealReconnectTest(fixtures.TestBase): try: conn.execute(select([1])) assert False - except tsa.exc.DBAPIError, e: + except tsa.exc.DBAPIError as e: if not e.connection_invalidated: raise @@ -386,7 +386,7 @@ class RealReconnectTest(fixtures.TestBase): try: conn.execute(select([1])) assert False - except tsa.exc.DBAPIError, e: + except tsa.exc.DBAPIError as e: if not e.connection_invalidated: raise assert conn.invalidated @@ -407,7 +407,7 @@ class RealReconnectTest(fixtures.TestBase): try: c1.execute(select([1])) assert False - except tsa.exc.DBAPIError, e: + except tsa.exc.DBAPIError as e: assert e.connection_invalidated p2 = engine.pool @@ -415,7 +415,7 @@ class RealReconnectTest(fixtures.TestBase): try: c2.execute(select([1])) assert False - except tsa.exc.DBAPIError, e: + except tsa.exc.DBAPIError as e: assert e.connection_invalidated # pool isn't replaced @@ -503,7 +503,7 @@ class RealReconnectTest(fixtures.TestBase): try: conn.execute(select([1])) assert False - except tsa.exc.DBAPIError, e: + except tsa.exc.DBAPIError as e: if not e.connection_invalidated: raise assert not conn.closed @@ -523,7 +523,7 @@ class RealReconnectTest(fixtures.TestBase): try: conn.execute(select([1])) assert False - except tsa.exc.DBAPIError, e: + except tsa.exc.DBAPIError as e: if not e.connection_invalidated: raise @@ -542,7 +542,7 @@ class RealReconnectTest(fixtures.TestBase): try: conn.execute(select([1])) assert False - except tsa.exc.DBAPIError, e: + except tsa.exc.DBAPIError as e: if not e.connection_invalidated: raise assert not conn.closed @@ -558,7 +558,7 @@ class RealReconnectTest(fixtures.TestBase): try: trans.commit() assert False - except tsa.exc.InvalidRequestError, e: + except tsa.exc.InvalidRequestError as e: assert str(e) \ == "Can't reconnect until invalid transaction is "\ "rolled back" @@ -634,13 +634,13 @@ class InvalidateDuringResultTest(fixtures.TestBase): def test_invalidate_on_results(self): conn = engine.connect() result = conn.execute('select * from sometable') - for x in xrange(20): + for x in range(20): result.fetchone() engine.test_shutdown() try: - print 'ghost result: %r' % result.fetchone() + print('ghost result: %r' % result.fetchone()) assert False - except tsa.exc.DBAPIError, e: + except tsa.exc.DBAPIError as e: if not e.connection_invalidated: raise assert conn.invalidated diff --git a/test/engine/test_reflection.py b/test/engine/test_reflection.py index 86df92987..c2e3493f3 100644 --- a/test/engine/test_reflection.py +++ b/test/engine/test_reflection.py @@ -811,7 +811,7 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): try: m4.reflect(only=['rt_a', 'rt_f']) self.assert_(False) - except sa.exc.InvalidRequestError, e: + except sa.exc.InvalidRequestError as e: self.assert_(e.args[0].endswith('(rt_f)')) m5 = MetaData(testing.db) @@ -833,7 +833,7 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): ) if existing: - print "Other tables present in database, skipping some checks." + print("Other tables present in database, skipping some checks.") else: baseline.drop_all() m9 = MetaData(testing.db) @@ -1041,19 +1041,19 @@ class UnicodeReflectionTest(fixtures.TestBase): cls.metadata = metadata = MetaData() no_multibyte_period = set([ - (u'plain', u'col_plain', u'ix_plain') + ('plain', 'col_plain', 'ix_plain') ]) no_has_table = [ - (u'no_has_table_1', u'col_Unit\u00e9ble', u'ix_Unit\u00e9ble'), - (u'no_has_table_2', u'col_\u6e2c\u8a66', u'ix_\u6e2c\u8a66'), + ('no_has_table_1', 'col_Unit\u00e9ble', 'ix_Unit\u00e9ble'), + ('no_has_table_2', 'col_\u6e2c\u8a66', 'ix_\u6e2c\u8a66'), ] no_case_sensitivity = [ - (u'\u6e2c\u8a66', u'col_\u6e2c\u8a66', u'ix_\u6e2c\u8a66'), - (u'unit\u00e9ble', u'col_unit\u00e9ble', u'ix_unit\u00e9ble'), + ('\u6e2c\u8a66', 'col_\u6e2c\u8a66', 'ix_\u6e2c\u8a66'), + ('unit\u00e9ble', 'col_unit\u00e9ble', 'ix_unit\u00e9ble'), ] full = [ - (u'Unit\u00e9ble', u'col_Unit\u00e9ble', u'ix_Unit\u00e9ble'), - (u'\u6e2c\u8a66', u'col_\u6e2c\u8a66', u'ix_\u6e2c\u8a66'), + ('Unit\u00e9ble', 'col_Unit\u00e9ble', 'ix_Unit\u00e9ble'), + ('\u6e2c\u8a66', 'col_\u6e2c\u8a66', 'ix_\u6e2c\u8a66'), ] # as you can see, our options for this kind of thing diff --git a/test/engine/test_transaction.py b/test/engine/test_transaction.py index 5558ff778..2d7f39253 100644 --- a/test/engine/test_transaction.py +++ b/test/engine/test_transaction.py @@ -74,8 +74,8 @@ class TransactionTest(fixtures.TestBase): connection.execute(users.insert(), user_id=1, user_name='user3') transaction.commit() assert False - except Exception , e: - print "Exception: ", e + except Exception as e: + print("Exception: ", e) transaction.rollback() result = connection.execute("select * from query_users") @@ -121,10 +121,10 @@ class TransactionTest(fixtures.TestBase): trans2.rollback() raise transaction.rollback() - except Exception, e: + except Exception as e: transaction.rollback() raise - except Exception, e: + except Exception as e: try: assert str(e) == 'uh oh' # and not "This transaction is # inactive" @@ -167,7 +167,7 @@ class TransactionTest(fixtures.TestBase): connection.execute(users.insert(), user_id=2, user_name='user2') try: connection.execute(users.insert(), user_id=2, user_name='user2.5') - except Exception, e: + except Exception as e: trans.__exit__(*sys.exc_info()) assert not trans.is_active @@ -1019,7 +1019,7 @@ class ForUpdateTest(fixtures.TestBase): con = testing.db.connect() sel = counters.select(for_update=update_style, whereclause=counters.c.counter_id == 1) - for i in xrange(count): + for i in range(count): trans = con.begin() try: existing = con.execute(sel).first() @@ -1033,7 +1033,7 @@ class ForUpdateTest(fixtures.TestBase): raise AssertionError('Got %s post-update, expected ' '%s' % (readback['counter_value'], incr)) trans.commit() - except Exception, e: + except Exception as e: trans.rollback() errors.append(e) break @@ -1057,7 +1057,7 @@ class ForUpdateTest(fixtures.TestBase): db.execute(counters.insert(), counter_id=1, counter_value=0) iterations, thread_count = 10, 5 threads, errors = [], [] - for i in xrange(thread_count): + for i in range(thread_count): thrd = threading.Thread(target=self.increment, args=(iterations, ), kwargs={'errors': errors, @@ -1088,7 +1088,7 @@ class ForUpdateTest(fixtures.TestBase): rows = con.execute(sel).fetchall() time.sleep(0.25) trans.commit() - except Exception, e: + except Exception as e: trans.rollback() errors.append(e) con.close() @@ -1105,7 +1105,7 @@ class ForUpdateTest(fixtures.TestBase): db.execute(counters.insert(), counter_id=cid + 1, counter_value=0) errors, threads = [], [] - for i in xrange(thread_count): + for i in range(thread_count): thrd = threading.Thread(target=self.overlap, args=(groups.pop(0), errors, update_style)) diff --git a/test/ext/declarative/test_basic.py b/test/ext/declarative/test_basic.py index 0fe54a154..50d40e8fc 100644 --- a/test/ext/declarative/test_basic.py +++ b/test/ext/declarative/test_basic.py @@ -127,14 +127,13 @@ class DeclarativeTest(DeclarativeTestBase): class BrokenMeta(type): def __getattribute__(self, attr): if attr == 'xyzzy': - raise AttributeError, 'xyzzy' + raise AttributeError('xyzzy') else: return object.__getattribute__(self,attr) # even though this class has an xyzzy attribute, getattr(cls,"xyzzy") # fails - class BrokenParent(object): - __metaclass__ = BrokenMeta + class BrokenParent(object, metaclass=BrokenMeta): xyzzy = "magic" # _as_declarative() inspects obj.__class__.__bases__ @@ -1458,12 +1457,12 @@ def _produce_test(inline, stringbased): @classmethod def insert_data(cls): - params = [dict(zip(('id', 'name'), column_values)) + params = [dict(list(zip(('id', 'name'), column_values))) for column_values in [(7, 'jack'), (8, 'ed'), (9, 'fred'), (10, 'chuck')]] User.__table__.insert().execute(params) - Address.__table__.insert().execute([dict(zip(('id', - 'user_id', 'email'), column_values)) + Address.__table__.insert().execute([dict(list(zip(('id', + 'user_id', 'email'), column_values))) for column_values in [(1, 7, 'jack@bean.com'), (2, 8, 'ed@wood.com'), (3, 8, 'ed@bettyboop.com'), (4, 8, 'ed@lala.com'), (5, 9, 'fred@fred.com')]]) @@ -1492,6 +1491,6 @@ def _produce_test(inline, stringbased): for inline in True, False: for stringbased in True, False: testclass = _produce_test(inline, stringbased) - exec '%s = testclass' % testclass.__name__ + exec('%s = testclass' % testclass.__name__) del testclass diff --git a/test/ext/declarative/test_clsregistry.py b/test/ext/declarative/test_clsregistry.py index 1d09f158e..e78a1abbe 100644 --- a/test/ext/declarative/test_clsregistry.py +++ b/test/ext/declarative/test_clsregistry.py @@ -124,7 +124,7 @@ class ClsRegistryTest(fixtures.TestBase): base = weakref.WeakValueDictionary() - for i in xrange(3): + for i in range(3): f1 = MockClass(base, "foo.bar.Foo") f2 = MockClass(base, "foo.alt.Foo") clsregistry.add_class("Foo", f1) diff --git a/test/ext/declarative/test_inheritance.py b/test/ext/declarative/test_inheritance.py index 1a3a4aba5..01bf3f3f6 100644 --- a/test/ext/declarative/test_inheritance.py +++ b/test/ext/declarative/test_inheritance.py @@ -573,7 +573,7 @@ class DeclarativeInheritanceTest(DeclarativeTestBase): primary_language = Column(String(50)) assert Person.__table__.c.golf_swing is not None - assert not Person.__table__.c.has_key('primary_language') + assert 'primary_language' not in Person.__table__.c assert Engineer.__table__.c.primary_language is not None assert Engineer.primary_language is not None assert Manager.golf_swing is not None diff --git a/test/ext/declarative/test_mixin.py b/test/ext/declarative/test_mixin.py index fb674f27a..d8ec484e1 100644 --- a/test/ext/declarative/test_mixin.py +++ b/test/ext/declarative/test_mixin.py @@ -685,7 +685,7 @@ class DeclarativeMixinTest(DeclarativeTestBase): __mapper_args__ = dict(polymorphic_identity='specific') assert Specific.__table__ is Generic.__table__ - eq_(Generic.__table__.c.keys(), ['id', 'type', 'value']) + eq_(list(Generic.__table__.c.keys()), ['id', 'type', 'value']) assert class_mapper(Specific).polymorphic_on \ is Generic.__table__.c.type eq_(class_mapper(Specific).polymorphic_identity, 'specific') @@ -714,9 +714,9 @@ class DeclarativeMixinTest(DeclarativeTestBase): eq_(Generic.__table__.name, 'generic') eq_(Specific.__table__.name, 'specific') - eq_(Generic.__table__.c.keys(), ['timestamp', 'id', + eq_(list(Generic.__table__.c.keys()), ['timestamp', 'id', 'python_type']) - eq_(Specific.__table__.c.keys(), ['id']) + eq_(list(Specific.__table__.c.keys()), ['id']) eq_(Generic.__table__.kwargs, {'mysql_engine': 'InnoDB'}) eq_(Specific.__table__.kwargs, {'mysql_engine': 'InnoDB'}) @@ -749,12 +749,12 @@ class DeclarativeMixinTest(DeclarativeTestBase): primary_key=True) eq_(BaseType.__table__.name, 'basetype') - eq_(BaseType.__table__.c.keys(), ['timestamp', 'type', 'id', + eq_(list(BaseType.__table__.c.keys()), ['timestamp', 'type', 'id', 'value']) eq_(BaseType.__table__.kwargs, {'mysql_engine': 'InnoDB'}) assert Single.__table__ is BaseType.__table__ eq_(Joined.__table__.name, 'joined') - eq_(Joined.__table__.c.keys(), ['id']) + eq_(list(Joined.__table__.c.keys()), ['id']) eq_(Joined.__table__.kwargs, {'mysql_engine': 'InnoDB'}) def test_col_copy_vs_declared_attr_joined_propagation(self): @@ -839,7 +839,7 @@ class DeclarativeMixinTest(DeclarativeTestBase): __mapper_args__ = dict(polymorphic_identity='specific') eq_(BaseType.__table__.name, 'basetype') - eq_(BaseType.__table__.c.keys(), ['type', 'id', 'value']) + eq_(list(BaseType.__table__.c.keys()), ['type', 'id', 'value']) assert Specific.__table__ is BaseType.__table__ assert class_mapper(Specific).polymorphic_on \ is BaseType.__table__.c.type @@ -870,9 +870,9 @@ class DeclarativeMixinTest(DeclarativeTestBase): primary_key=True) eq_(BaseType.__table__.name, 'basetype') - eq_(BaseType.__table__.c.keys(), ['type', 'id', 'value']) + eq_(list(BaseType.__table__.c.keys()), ['type', 'id', 'value']) eq_(Specific.__table__.name, 'specific') - eq_(Specific.__table__.c.keys(), ['id']) + eq_(list(Specific.__table__.c.keys()), ['id']) def test_single_back_propagate(self): @@ -891,7 +891,7 @@ class DeclarativeMixinTest(DeclarativeTestBase): __mapper_args__ = dict(polymorphic_identity='specific') - eq_(BaseType.__table__.c.keys(), ['type', 'id', 'timestamp']) + eq_(list(BaseType.__table__.c.keys()), ['type', 'id', 'timestamp']) def test_table_in_model_and_same_column_in_mixin(self): @@ -987,7 +987,7 @@ class DeclarativeMixinTest(DeclarativeTestBase): id = Column(Integer, primary_key=True) __tablename__ = 'model' - eq_(Model.__table__.c.keys(), ['col1', 'col3', 'col2', 'col4', + eq_(list(Model.__table__.c.keys()), ['col1', 'col3', 'col2', 'col4', 'id']) def test_honor_class_mro_one(self): @@ -1078,8 +1078,8 @@ class DeclarativeMixinTest(DeclarativeTestBase): filter_class = FilterB id = Column(Integer(), primary_key=True) - TypeA(filters=[u'foo']) - TypeB(filters=[u'foo']) + TypeA(filters=['foo']) + TypeB(filters=['foo']) class DeclarativeMixinPropertyTest(DeclarativeTestBase): diff --git a/test/ext/test_associationproxy.py b/test/ext/test_associationproxy.py index c15b98bf2..a5fcc45cc 100644 --- a/test/ext/test_associationproxy.py +++ b/test/ext/test_associationproxy.py @@ -288,7 +288,7 @@ class CustomDictTest(DictTest): ch = Child('a', 'regular') p1._children.append(ch) - self.assert_(ch in p1._children.values()) + self.assert_(ch in list(p1._children.values())) self.assert_(len(p1._children) == 1) self.assert_(p1.children) @@ -300,7 +300,7 @@ class CustomDictTest(DictTest): p1.children['b'] = 'proxied' - self.assert_('proxied' in p1.children.values()) + self.assert_('proxied' in list(p1.children.values())) self.assert_('b' in p1.children) self.assert_('proxied' not in p1._children) self.assert_(len(p1.children) == 2) @@ -526,9 +526,9 @@ class SetTest(_CollectionOperations): try: self.assert_(p.children == control) except: - print 'Test %s.%s(%s):' % (set(base), op, other) - print 'want', repr(control) - print 'got', repr(p.children) + print('Test %s.%s(%s):' % (set(base), op, other)) + print('want', repr(control)) + print('got', repr(p.children)) raise p = self.roundtrip(p) @@ -536,9 +536,9 @@ class SetTest(_CollectionOperations): try: self.assert_(p.children == control) except: - print 'Test %s.%s(%s):' % (base, op, other) - print 'want', repr(control) - print 'got', repr(p.children) + print('Test %s.%s(%s):' % (base, op, other)) + print('want', repr(control)) + print('got', repr(p.children)) raise # in-place mutations @@ -553,15 +553,15 @@ class SetTest(_CollectionOperations): p.children = base[:] control = set(base[:]) - exec "p.children %s other" % op - exec "control %s other" % op + exec("p.children %s other" % op) + exec("control %s other" % op) try: self.assert_(p.children == control) except: - print 'Test %s %s %s:' % (set(base), op, other) - print 'want', repr(control) - print 'got', repr(p.children) + print('Test %s %s %s:' % (set(base), op, other)) + print('want', repr(control)) + print('got', repr(p.children)) raise p = self.roundtrip(p) @@ -569,9 +569,9 @@ class SetTest(_CollectionOperations): try: self.assert_(p.children == control) except: - print 'Test %s %s %s:' % (base, op, other) - print 'want', repr(control) - print 'got', repr(p.children) + print('Test %s %s %s:' % (base, op, other)) + print('want', repr(control)) + print('got', repr(p.children)) raise diff --git a/test/ext/test_serializer.py b/test/ext/test_serializer.py index 8d4394e2d..47edbdaaa 100644 --- a/test/ext/test_serializer.py +++ b/test/ext/test_serializer.py @@ -47,12 +47,12 @@ class SerializeTest(fixtures.MappedTest): @classmethod def insert_data(cls): - params = [dict(zip(('id', 'name'), column_values)) + params = [dict(list(zip(('id', 'name'), column_values))) for column_values in [(7, 'jack'), (8, 'ed'), (9, 'fred'), (10, 'chuck')]] users.insert().execute(params) - addresses.insert().execute([dict(zip(('id', 'user_id', 'email' - ), column_values)) + addresses.insert().execute([dict(list(zip(('id', 'user_id', 'email' + ), column_values))) for column_values in [(1, 7, 'jack@bean.com'), (2, 8, 'ed@wood.com'), (3, 8, @@ -85,8 +85,8 @@ class SerializeTest(fixtures.MappedTest): users.metadata, None) eq_(str(expr), str(re_expr)) assert re_expr.bind is testing.db - eq_(re_expr.execute().fetchall(), [(7, u'jack'), (8, u'ed'), - (8, u'ed'), (8, u'ed'), (9, u'fred')]) + eq_(re_expr.execute().fetchall(), [(7, 'jack'), (8, 'ed'), + (8, 'ed'), (8, 'ed'), (9, 'fred')]) def test_query_one(self): q = Session.query(User).\ @@ -121,7 +121,7 @@ class SerializeTest(fixtures.MappedTest): q2 = serializer.loads(serializer.dumps(q, -1), users.metadata, Session) eq_(q2.all(), [User(name='fred')]) - eq_(list(q2.values(User.id, User.name)), [(9, u'fred')]) + eq_(list(q2.values(User.id, User.name)), [(9, 'fred')]) def test_query_three(self): ua = aliased(User) @@ -134,7 +134,7 @@ class SerializeTest(fixtures.MappedTest): # try to pull out the aliased entity here... ua_2 = q2._entities[0].entity_zero.entity - eq_(list(q2.values(ua_2.id, ua_2.name)), [(9, u'fred')]) + eq_(list(q2.values(ua_2.id, ua_2.name)), [(9, 'fred')]) def test_orm_join(self): from sqlalchemy.orm.util import join diff --git a/test/orm/inheritance/test_assorted_poly.py b/test/orm/inheritance/test_assorted_poly.py index e8e6ba82a..d05a22f39 100644 --- a/test/orm/inheritance/test_assorted_poly.py +++ b/test/orm/inheritance/test_assorted_poly.py @@ -18,7 +18,7 @@ from sqlalchemy.testing.schema import Table, Column class AttrSettable(object): def __init__(self, **kwargs): - [setattr(self, k, v) for k, v in kwargs.iteritems()] + [setattr(self, k, v) for k, v in kwargs.items()] def __repr__(self): return self.__class__.__name__ + "(%s)" % (hex(id(self))) @@ -386,7 +386,7 @@ class RelationshipTest4(fixtures.MappedTest): # class definitions class Person(object): def __init__(self, **kwargs): - for key, value in kwargs.iteritems(): + for key, value in kwargs.items(): setattr(self, key, value) def __repr__(self): return "Ordinary person %s" % self.name @@ -400,7 +400,7 @@ class RelationshipTest4(fixtures.MappedTest): (self.name, self.longer_status) class Car(object): def __init__(self, **kwargs): - for key, value in kwargs.iteritems(): + for key, value in kwargs.items(): setattr(self, key, value) def __repr__(self): return "Car number %d" % self.car_id @@ -512,7 +512,7 @@ class RelationshipTest5(fixtures.MappedTest): class Person(object): def __init__(self, **kwargs): - for key, value in kwargs.iteritems(): + for key, value in kwargs.items(): setattr(self, key, value) def __repr__(self): return "Ordinary person %s" % self.name @@ -526,7 +526,7 @@ class RelationshipTest5(fixtures.MappedTest): (self.name, self.longer_status) class Car(object): def __init__(self, **kwargs): - for key, value in kwargs.iteritems(): + for key, value in kwargs.items(): setattr(self, key, value) def __repr__(self): return "Car number %d" % self.car_id @@ -646,7 +646,7 @@ class RelationshipTest7(fixtures.MappedTest): class PersistentObject(object): def __init__(self, **kwargs): - for key, value in kwargs.iteritems(): + for key, value in kwargs.items(): setattr(self, key, value) class Status(PersistentObject): @@ -838,7 +838,7 @@ class GenerativeTest(fixtures.TestBase, AssertsExecutionResults): # class definitions class PersistentObject(object): def __init__(self, **kwargs): - for key, value in kwargs.iteritems(): + for key, value in kwargs.items(): setattr(self, key, value) class Status(PersistentObject): def __repr__(self): @@ -968,7 +968,7 @@ class MultiLevelTest(fixtures.MappedTest): def test_threelevels(self): class Employee( object): def set( me, **kargs): - for k,v in kargs.iteritems(): setattr( me, k, v) + for k,v in kargs.items(): setattr( me, k, v) return me def __str__(me): return str(me.__class__.__name__)+':'+str(me.name) diff --git a/test/orm/inheritance/test_basic.py b/test/orm/inheritance/test_basic.py index bbfa54383..afd63f2b4 100644 --- a/test/orm/inheritance/test_basic.py +++ b/test/orm/inheritance/test_basic.py @@ -1355,7 +1355,7 @@ class SyncCompileTest(fixtures.MappedTest): def _do_test(self, j1, j2): class A(object): def __init__(self, **kwargs): - for key, value in kwargs.items(): + for key, value in list(kwargs.items()): setattr(self, key, value) class B(A): @@ -1830,7 +1830,7 @@ class OptimizedLoadTest(fixtures.MappedTest): "SELECT sub.counter AS sub_counter, base.counter AS base_counter, " "sub.counter2 AS sub_counter2 FROM base JOIN sub ON " "base.id = sub.id WHERE base.id = :param_1", - lambda ctx:{u'param_1': s1.id} + lambda ctx:{'param_1': s1.id} ), ) @@ -1910,7 +1910,7 @@ class OptimizedLoadTest(fixtures.MappedTest): "SELECT subsub.counter2 AS subsub_counter2, " "sub.counter2 AS sub_counter2 FROM subsub, sub " "WHERE :param_1 = sub.id AND sub.id = subsub.id", - lambda ctx:{u'param_1': s1.id} + lambda ctx:{'param_1': s1.id} ), ) @@ -2409,9 +2409,9 @@ class NameConflictTest(fixtures.MappedTest): polymorphic_identity='foo') sess = create_session() f = Foo() - f.content_type = u'bar' + f.content_type = 'bar' sess.add(f) sess.flush() f_id = f.id sess.expunge_all() - assert sess.query(Content).get(f_id).content_type == u'bar' + assert sess.query(Content).get(f_id).content_type == 'bar' diff --git a/test/orm/inheritance/test_concrete.py b/test/orm/inheritance/test_concrete.py index 40c3ab31b..5d6b82a15 100644 --- a/test/orm/inheritance/test_concrete.py +++ b/test/orm/inheritance/test_concrete.py @@ -722,10 +722,10 @@ class ColKeysTest(fixtures.MappedTest): @classmethod def insert_data(cls): refugees_table.insert().execute(dict(refugee_fid=1, - name=u'refugee1'), dict(refugee_fid=2, name=u'refugee2' + name='refugee1'), dict(refugee_fid=2, name='refugee2' )) offices_table.insert().execute(dict(office_fid=1, - name=u'office1'), dict(office_fid=2, name=u'office2')) + name='office1'), dict(office_fid=2, name='office2')) def test_keys(self): pjoin = polymorphic_union({'refugee': refugees_table, 'office' diff --git a/test/orm/inheritance/test_magazine.py b/test/orm/inheritance/test_magazine.py index ae5aa8c8d..b459a01ae 100644 --- a/test/orm/inheritance/test_magazine.py +++ b/test/orm/inheritance/test_magazine.py @@ -8,7 +8,7 @@ from sqlalchemy.testing.schema import Table, Column class BaseObject(object): def __init__(self, *args, **kwargs): - for key, value in kwargs.iteritems(): + for key, value in kwargs.items(): setattr(self, key, value) class Publication(BaseObject): pass @@ -200,15 +200,15 @@ def _generate_round_trip_test(use_unions=False, use_joins=False): session.flush() - print [x for x in session] + print([x for x in session]) session.expunge_all() session.flush() session.expunge_all() p = session.query(Publication).filter(Publication.name=="Test").one() - print p.issues[0].locations[0].magazine.pages - print [page, page2, page3] + print(p.issues[0].locations[0].magazine.pages) + print([page, page2, page3]) assert repr(p.issues[0].locations[0].magazine.pages) == repr([page, page2, page3]), repr(p.issues[0].locations[0].magazine.pages) test_roundtrip = function_named( diff --git a/test/orm/inheritance/test_manytomany.py b/test/orm/inheritance/test_manytomany.py index e4df5d133..31c4ba40a 100644 --- a/test/orm/inheritance/test_manytomany.py +++ b/test/orm/inheritance/test_manytomany.py @@ -42,7 +42,7 @@ class InheritTest(fixtures.MappedTest): def testbasic(self): class Principal(object): def __init__(self, **kwargs): - for key, value in kwargs.iteritems(): + for key, value in kwargs.items(): setattr(self, key, value) class User(Principal): @@ -94,8 +94,8 @@ class InheritTest2(fixtures.MappedTest): mapper(Foo, foo) mapper(Bar, bar, inherits=Foo) - print foo.join(bar).primary_key - print class_mapper(Bar).primary_key + print(foo.join(bar).primary_key) + print(class_mapper(Bar).primary_key) b = Bar('somedata') sess = create_session() sess.add(b) @@ -133,8 +133,8 @@ class InheritTest2(fixtures.MappedTest): sess.expunge_all() l = sess.query(Bar).all() - print l[0] - print l[0].foos + print(l[0]) + print(l[0].foos) self.assert_unordered_result(l, Bar, # {'id':1, 'data':'barfoo', 'bid':1, 'foos':(Foo, [{'id':2,'data':'subfoo1'}, {'id':3,'data':'subfoo2'}])}, {'id':b.id, 'data':'barfoo', 'foos':(Foo, [{'id':f1.id,'data':'subfoo1'}, {'id':f2.id,'data':'subfoo2'}])}, @@ -197,7 +197,7 @@ class InheritTest3(fixtures.MappedTest): compare = [repr(b)] + sorted([repr(o) for o in b.foos]) sess.expunge_all() l = sess.query(Bar).all() - print repr(l[0]) + repr(l[0].foos) + print(repr(l[0]) + repr(l[0].foos)) found = [repr(l[0])] + sorted([repr(o) for o in l[0].foos]) eq_(found, compare) @@ -239,11 +239,11 @@ class InheritTest3(fixtures.MappedTest): sess.expunge_all() l = sess.query(Blub).all() - print l + print(l) self.assert_(repr(l[0]) == compare) sess.expunge_all() x = sess.query(Blub).filter_by(id=blubid).one() - print x + print(x) self.assert_(repr(x) == compare) diff --git a/test/orm/inheritance/test_polymorphic_rel.py b/test/orm/inheritance/test_polymorphic_rel.py index 1b9acb787..8c1f22114 100644 --- a/test/orm/inheritance/test_polymorphic_rel.py +++ b/test/orm/inheritance/test_polymorphic_rel.py @@ -7,7 +7,7 @@ from sqlalchemy import exc as sa_exc from sqlalchemy import testing from sqlalchemy.testing import assert_raises, eq_ -from _poly_fixtures import Company, Person, Engineer, Manager, Boss, \ +from ._poly_fixtures import Company, Person, Engineer, Manager, Boss, \ Machine, Paperwork, _Polymorphic,\ _PolymorphicPolymorphic, _PolymorphicUnions, _PolymorphicJoins,\ _PolymorphicAliasedJoins @@ -118,24 +118,24 @@ class _PolymorphicTestBase(object): eq_(q.count(), 1) eq_(q.all(), [ ( - Company(company_id=1, name=u'MegaCorp, Inc.'), + Company(company_id=1, name='MegaCorp, Inc.'), Engineer( - status=u'regular engineer', - engineer_name=u'dilbert', - name=u'dilbert', + status='regular engineer', + engineer_name='dilbert', + name='dilbert', company_id=1, - primary_language=u'java', + primary_language='java', person_id=1, - type=u'engineer'), - Company(company_id=1, name=u'MegaCorp, Inc.'), + type='engineer'), + Company(company_id=1, name='MegaCorp, Inc.'), Engineer( - status=u'regular engineer', - engineer_name=u'wally', - name=u'wally', + status='regular engineer', + engineer_name='wally', + name='wally', company_id=1, - primary_language=u'c++', + primary_language='c++', person_id=2, - type=u'engineer') + type='engineer') ) ]) @@ -337,8 +337,8 @@ class _PolymorphicTestBase(object): sess = create_session() expected = [ - (u'dogbert',), - (u'pointy haired boss',)] + ('dogbert',), + ('pointy haired boss',)] eq_(sess.query(Manager.name) .order_by(Manager.name).all(), expected) @@ -346,9 +346,9 @@ class _PolymorphicTestBase(object): def test_join_from_columns_or_subclass_two(self): sess = create_session() expected = [ - (u'dogbert',), - (u'dogbert',), - (u'pointy haired boss',)] + ('dogbert',), + ('dogbert',), + ('pointy haired boss',)] eq_(sess.query(Manager.name) .join(Paperwork, Manager.paperwork) .order_by(Manager.name).all(), @@ -357,14 +357,14 @@ class _PolymorphicTestBase(object): def test_join_from_columns_or_subclass_three(self): sess = create_session() expected = [ - (u'dilbert',), - (u'dilbert',), - (u'dogbert',), - (u'dogbert',), - (u'pointy haired boss',), - (u'vlad',), - (u'wally',), - (u'wally',)] + ('dilbert',), + ('dilbert',), + ('dogbert',), + ('dogbert',), + ('pointy haired boss',), + ('vlad',), + ('wally',), + ('wally',)] eq_(sess.query(Person.name) .join(Paperwork, Person.paperwork) .order_by(Person.name).all(), @@ -375,14 +375,14 @@ class _PolymorphicTestBase(object): # Load Person.name, joining from Person -> paperwork, get all # the people. expected = [ - (u'dilbert',), - (u'dilbert',), - (u'dogbert',), - (u'dogbert',), - (u'pointy haired boss',), - (u'vlad',), - (u'wally',), - (u'wally',)] + ('dilbert',), + ('dilbert',), + ('dogbert',), + ('dogbert',), + ('pointy haired boss',), + ('vlad',), + ('wally',), + ('wally',)] eq_(sess.query(Person.name) .join(paperwork, Person.person_id == paperwork.c.person_id) @@ -393,9 +393,9 @@ class _PolymorphicTestBase(object): sess = create_session() # same, on manager. get only managers. expected = [ - (u'dogbert',), - (u'dogbert',), - (u'pointy haired boss',)] + ('dogbert',), + ('dogbert',), + ('pointy haired boss',)] eq_(sess.query(Manager.name) .join(paperwork, Manager.person_id == paperwork.c.person_id) @@ -418,14 +418,14 @@ class _PolymorphicTestBase(object): # here, it joins to the full result set. This is 0.6's # behavior and is more or less wrong. expected = [ - (u'dilbert',), - (u'dilbert',), - (u'dogbert',), - (u'dogbert',), - (u'pointy haired boss',), - (u'vlad',), - (u'wally',), - (u'wally',)] + ('dilbert',), + ('dilbert',), + ('dogbert',), + ('dogbert',), + ('pointy haired boss',), + ('vlad',), + ('wally',), + ('wally',)] eq_(sess.query(Person.name) .join(paperwork, Manager.person_id == paperwork.c.person_id) @@ -435,9 +435,9 @@ class _PolymorphicTestBase(object): # when a join is present and managers.person_id is available, # you get the managers. expected = [ - (u'dogbert',), - (u'dogbert',), - (u'pointy haired boss',)] + ('dogbert',), + ('dogbert',), + ('pointy haired boss',)] eq_(sess.query(Person.name) .join(paperwork, Manager.person_id == paperwork.c.person_id) @@ -454,9 +454,9 @@ class _PolymorphicTestBase(object): def test_join_from_columns_or_subclass_eight(self): sess = create_session() expected = [ - (u'dogbert',), - (u'dogbert',), - (u'pointy haired boss',)] + ('dogbert',), + ('dogbert',), + ('pointy haired boss',)] eq_(sess.query(Manager.name) .join(paperwork, Manager.person_id == paperwork.c.person_id) @@ -474,9 +474,9 @@ class _PolymorphicTestBase(object): def test_join_from_columns_or_subclass_ten(self): sess = create_session() expected = [ - (u'pointy haired boss', u'review #1'), - (u'dogbert', u'review #2'), - (u'dogbert', u'review #3')] + ('pointy haired boss', 'review #1'), + ('dogbert', 'review #2'), + ('dogbert', 'review #3')] eq_(sess.query(Manager.name, Paperwork.description) .join(Paperwork, Manager.person_id == Paperwork.person_id) @@ -486,9 +486,9 @@ class _PolymorphicTestBase(object): def test_join_from_columns_or_subclass_eleven(self): sess = create_session() expected = [ - (u'pointy haired boss',), - (u'dogbert',), - (u'dogbert',)] + ('pointy haired boss',), + ('dogbert',), + ('dogbert',)] malias = aliased(Manager) eq_(sess.query(malias.name) .join(paperwork, @@ -977,32 +977,32 @@ class _PolymorphicTestBase(object): expected = [ (Engineer( - status=u'regular engineer', - engineer_name=u'dilbert', - name=u'dilbert', + status='regular engineer', + engineer_name='dilbert', + name='dilbert', company_id=1, - primary_language=u'java', + primary_language='java', person_id=1, - type=u'engineer'), - u'MegaCorp, Inc.'), + type='engineer'), + 'MegaCorp, Inc.'), (Engineer( - status=u'regular engineer', - engineer_name=u'wally', - name=u'wally', + status='regular engineer', + engineer_name='wally', + name='wally', company_id=1, - primary_language=u'c++', + primary_language='c++', person_id=2, - type=u'engineer'), - u'MegaCorp, Inc.'), + type='engineer'), + 'MegaCorp, Inc.'), (Engineer( - status=u'elbonian engineer', - engineer_name=u'vlad', - name=u'vlad', + status='elbonian engineer', + engineer_name='vlad', + name='vlad', company_id=2, - primary_language=u'cobol', + primary_language='cobol', person_id=5, - type=u'engineer'), - u'Elbonia, Inc.')] + type='engineer'), + 'Elbonia, Inc.')] eq_(sess.query(Engineer, Company.name) .join(Company.employees) .filter(Person.type == 'engineer').all(), @@ -1011,9 +1011,9 @@ class _PolymorphicTestBase(object): def test_mixed_entities_two(self): sess = create_session() expected = [ - (u'java', u'MegaCorp, Inc.'), - (u'cobol', u'Elbonia, Inc.'), - (u'c++', u'MegaCorp, Inc.')] + ('java', 'MegaCorp, Inc.'), + ('cobol', 'Elbonia, Inc.'), + ('c++', 'MegaCorp, Inc.')] eq_(sess.query(Engineer.primary_language, Company.name) .join(Company.employees) .filter(Person.type == 'engineer') @@ -1025,19 +1025,19 @@ class _PolymorphicTestBase(object): palias = aliased(Person) expected = [( Engineer( - status=u'elbonian engineer', - engineer_name=u'vlad', - name=u'vlad', - primary_language=u'cobol'), - u'Elbonia, Inc.', + status='elbonian engineer', + engineer_name='vlad', + name='vlad', + primary_language='cobol'), + 'Elbonia, Inc.', Engineer( - status=u'regular engineer', - engineer_name=u'dilbert', - name=u'dilbert', + status='regular engineer', + engineer_name='dilbert', + name='dilbert', company_id=1, - primary_language=u'java', + primary_language='java', person_id=1, - type=u'engineer'))] + type='engineer'))] eq_(sess.query(Person, Company.name, palias) .join(Company.employees) .filter(Company.name == 'Elbonia, Inc.') @@ -1049,19 +1049,19 @@ class _PolymorphicTestBase(object): palias = aliased(Person) expected = [( Engineer( - status=u'regular engineer', - engineer_name=u'dilbert', - name=u'dilbert', + status='regular engineer', + engineer_name='dilbert', + name='dilbert', company_id=1, - primary_language=u'java', + primary_language='java', person_id=1, - type=u'engineer'), - u'Elbonia, Inc.', + type='engineer'), + 'Elbonia, Inc.', Engineer( - status=u'elbonian engineer', - engineer_name=u'vlad', - name=u'vlad', - primary_language=u'cobol'),)] + status='elbonian engineer', + engineer_name='vlad', + name='vlad', + primary_language='cobol'),)] eq_(sess.query(palias, Company.name, Person) .join(Company.employees) .filter(Company.name == 'Elbonia, Inc.') @@ -1071,7 +1071,7 @@ class _PolymorphicTestBase(object): def test_mixed_entities_five(self): sess = create_session() palias = aliased(Person) - expected = [(u'vlad', u'Elbonia, Inc.', u'dilbert')] + expected = [('vlad', 'Elbonia, Inc.', 'dilbert')] eq_(sess.query(Person.name, Company.name, palias.name) .join(Company.employees) .filter(Company.name == 'Elbonia, Inc.') @@ -1082,9 +1082,9 @@ class _PolymorphicTestBase(object): sess = create_session() palias = aliased(Person) expected = [ - (u'manager', u'dogbert', u'engineer', u'dilbert'), - (u'manager', u'dogbert', u'engineer', u'wally'), - (u'manager', u'dogbert', u'boss', u'pointy haired boss')] + ('manager', 'dogbert', 'engineer', 'dilbert'), + ('manager', 'dogbert', 'engineer', 'wally'), + ('manager', 'dogbert', 'boss', 'pointy haired boss')] eq_(sess.query(Person.type, Person.name, palias.type, palias.name) .filter(Person.company_id == palias.company_id) .filter(Person.name == 'dogbert') @@ -1095,14 +1095,14 @@ class _PolymorphicTestBase(object): def test_mixed_entities_seven(self): sess = create_session() expected = [ - (u'dilbert', u'tps report #1'), - (u'dilbert', u'tps report #2'), - (u'dogbert', u'review #2'), - (u'dogbert', u'review #3'), - (u'pointy haired boss', u'review #1'), - (u'vlad', u'elbonian missive #3'), - (u'wally', u'tps report #3'), - (u'wally', u'tps report #4')] + ('dilbert', 'tps report #1'), + ('dilbert', 'tps report #2'), + ('dogbert', 'review #2'), + ('dogbert', 'review #3'), + ('pointy haired boss', 'review #1'), + ('vlad', 'elbonian missive #3'), + ('wally', 'tps report #3'), + ('wally', 'tps report #4')] eq_(sess.query(Person.name, Paperwork.description) .filter(Person.person_id == Paperwork.person_id) .order_by(Person.name, Paperwork.description).all(), @@ -1116,7 +1116,7 @@ class _PolymorphicTestBase(object): def test_mixed_entities_nine(self): sess = create_session() - expected = [(u'Elbonia, Inc.', 1), (u'MegaCorp, Inc.', 4)] + expected = [('Elbonia, Inc.', 1), ('MegaCorp, Inc.', 4)] eq_(sess.query(Company.name, func.count(Person.person_id)) .filter(Company.company_id == Person.company_id) .group_by(Company.name) @@ -1125,7 +1125,7 @@ class _PolymorphicTestBase(object): def test_mixed_entities_ten(self): sess = create_session() - expected = [(u'Elbonia, Inc.', 1), (u'MegaCorp, Inc.', 4)] + expected = [('Elbonia, Inc.', 1), ('MegaCorp, Inc.', 4)] eq_(sess.query(Company.name, func.count(Person.person_id)) .join(Company.employees) .group_by(Company.name) @@ -1153,14 +1153,14 @@ class _PolymorphicTestBase(object): def test_mixed_entities_eleven(self): sess = create_session() - expected = [(u'java',), (u'c++',), (u'cobol',)] + expected = [('java',), ('c++',), ('cobol',)] eq_(sess.query(Engineer.primary_language) .filter(Person.type == 'engineer').all(), expected) def test_mixed_entities_twelve(self): sess = create_session() - expected = [(u'vlad', u'Elbonia, Inc.')] + expected = [('vlad', 'Elbonia, Inc.')] eq_(sess.query(Person.name, Company.name) .join(Company.employees) .filter(Company.name == 'Elbonia, Inc.').all(), @@ -1168,15 +1168,15 @@ class _PolymorphicTestBase(object): def test_mixed_entities_thirteen(self): sess = create_session() - expected = [(u'pointy haired boss', u'fore')] + expected = [('pointy haired boss', 'fore')] eq_(sess.query(Boss.name, Boss.golf_swing).all(), expected) def test_mixed_entities_fourteen(self): sess = create_session() expected = [ - (u'dilbert', u'java'), - (u'wally', u'c++'), - (u'vlad', u'cobol')] + ('dilbert', 'java'), + ('wally', 'c++'), + ('vlad', 'cobol')] eq_(sess.query(Engineer.name, Engineer.primary_language).all(), expected) @@ -1184,12 +1184,12 @@ class _PolymorphicTestBase(object): sess = create_session() expected = [( - u'Elbonia, Inc.', + 'Elbonia, Inc.', Engineer( - status=u'elbonian engineer', - engineer_name=u'vlad', - name=u'vlad', - primary_language=u'cobol'))] + status='elbonian engineer', + engineer_name='vlad', + name='vlad', + primary_language='cobol'))] eq_(sess.query(Company.name, Person) .join(Company.employees) .filter(Company.name == 'Elbonia, Inc.').all(), @@ -1199,11 +1199,11 @@ class _PolymorphicTestBase(object): sess = create_session() expected = [( Engineer( - status=u'elbonian engineer', - engineer_name=u'vlad', - name=u'vlad', - primary_language=u'cobol'), - u'Elbonia, Inc.')] + status='elbonian engineer', + engineer_name='vlad', + name='vlad', + primary_language='cobol'), + 'Elbonia, Inc.')] eq_(sess.query(Person, Company.name) .join(Company.employees) .filter(Company.name == 'Elbonia, Inc.').all(), diff --git a/test/orm/inheritance/test_productspec.py b/test/orm/inheritance/test_productspec.py index c1e99e338..3de5e3695 100644 --- a/test/orm/inheritance/test_productspec.py +++ b/test/orm/inheritance/test_productspec.py @@ -122,8 +122,8 @@ class InheritTest(fixtures.MappedTest): a1 = session.query(Product).filter_by(name='a1').one() new = repr(a1) - print orig - print new + print(orig) + print(new) assert orig == new == ' specification=[>, >] documents=None' def testtwo(self): @@ -153,8 +153,8 @@ class InheritTest(fixtures.MappedTest): session.flush() session.expunge_all() new = repr(session.query(SpecLine).all()) - print orig - print new + print(orig) + print(new) assert orig == new == '[>, >]' def testthree(self): @@ -206,8 +206,8 @@ class InheritTest(fixtures.MappedTest): a1 = session.query(Product).filter_by(name='a1').one() new = repr(a1) - print orig - print new + print(orig) + print(new) assert orig == new == ' specification=[>] documents=[, ]' def testfour(self): @@ -245,8 +245,8 @@ class InheritTest(fixtures.MappedTest): a1 = session.query(Product).filter_by(name='a1').one() new = repr(a1) - print orig - print new + print(orig) + print(new) assert orig == new == ' specification=None documents=[]' del a1.documents[0] @@ -312,7 +312,7 @@ class InheritTest(fixtures.MappedTest): a1 = session.query(Product).filter_by(name='a1').one() new = repr(a1) - print orig - print new + print(orig) + print(new) assert orig == new == ' specification=[>] documents=[, ]' diff --git a/test/orm/inheritance/test_relationship.py b/test/orm/inheritance/test_relationship.py index 36dbb7d27..809884f52 100644 --- a/test/orm/inheritance/test_relationship.py +++ b/test/orm/inheritance/test_relationship.py @@ -287,7 +287,7 @@ class SelfReferentialJ2JSelfTest(fixtures.MappedTest): def _five_obj_fixture(self): sess = Session() e1, e2, e3, e4, e5 = [ - Engineer(name='e%d' % (i + 1)) for i in xrange(5) + Engineer(name='e%d' % (i + 1)) for i in range(5) ] e3.reports_to = e1 e4.reports_to = e2 diff --git a/test/orm/inheritance/test_with_poly.py b/test/orm/inheritance/test_with_poly.py index 93cccee7a..87251a4c2 100644 --- a/test/orm/inheritance/test_with_poly.py +++ b/test/orm/inheritance/test_with_poly.py @@ -11,7 +11,7 @@ from sqlalchemy import testing from sqlalchemy.testing.schema import Table, Column from sqlalchemy.testing import assert_raises, eq_ -from _poly_fixtures import Company, Person, Engineer, Manager, Boss, \ +from ._poly_fixtures import Company, Person, Engineer, Manager, Boss, \ Machine, Paperwork, _PolymorphicFixtureBase, _Polymorphic,\ _PolymorphicPolymorphic, _PolymorphicUnions, _PolymorphicJoins,\ _PolymorphicAliasedJoins @@ -37,8 +37,8 @@ class _WithPolymorphicBase(_PolymorphicFixtureBase): pa.Manager.manager_name=='dogbert')).\ order_by(pa.Engineer.type).all(), [ - (u'dilbert', u'java', None), - (u'dogbert', None, u'dogbert'), + ('dilbert', 'java', None), + ('dogbert', None, 'dogbert'), ] ) @@ -63,10 +63,10 @@ class _WithPolymorphicBase(_PolymorphicFixtureBase): ) ).order_by(pa.name, pa_alias.name)], [ - (u'dilbert', Engineer, u'dilbert', Engineer), - (u'dogbert', Manager, u'pointy haired boss', Boss), - (u'vlad', Engineer, u'vlad', Engineer), - (u'wally', Engineer, u'wally', Engineer) + ('dilbert', Engineer, 'dilbert', Engineer), + ('dogbert', Manager, 'pointy haired boss', Boss), + ('vlad', Engineer, 'vlad', Engineer), + ('wally', Engineer, 'wally', Engineer) ] ) @@ -91,10 +91,10 @@ class _WithPolymorphicBase(_PolymorphicFixtureBase): ) ).order_by(pa.name, pa_alias.name)], [ - (u'dilbert', u'java', u'dilbert', u'java'), - (u'dogbert', None, u'pointy haired boss', None), - (u'vlad', u'cobol', u'vlad', u'cobol'), - (u'wally', u'c++', u'wally', u'c++') + ('dilbert', 'java', 'dilbert', 'java'), + ('dogbert', None, 'pointy haired boss', None), + ('vlad', 'cobol', 'vlad', 'cobol'), + ('wally', 'c++', 'wally', 'c++') ] ) diff --git a/test/orm/test_assorted_eager.py b/test/orm/test_assorted_eager.py index a1c96bdfa..e650a1bea 100644 --- a/test/orm/test_assorted_eager.py +++ b/test/orm/test_assorted_eager.py @@ -129,7 +129,7 @@ class EagerTest(fixtures.MappedTest): # 3 " # not orm style correct query - print "Obtaining correct results without orm" + print("Obtaining correct results without orm") result = sa.select( [tests.c.id,categories.c.name], sa.and_(tests.c.owner_id == 1, @@ -140,7 +140,7 @@ class EagerTest(fixtures.MappedTest): tests.c.id == options.c.test_id, tests.c.owner_id == options.c.owner_id))] ).execute().fetchall() - eq_(result, [(1, u'Some Category'), (3, u'Some Category')]) + eq_(result, [(1, 'Some Category'), (3, 'Some Category')]) def test_withoutjoinedload(self): Thing, tests, options = (self.classes.Thing, @@ -158,7 +158,7 @@ class EagerTest(fixtures.MappedTest): options.c.someoption==False)))) result = ["%d %s" % ( t.id,t.category.name ) for t in l] - eq_(result, [u'1 Some Category', u'3 Some Category']) + eq_(result, ['1 Some Category', '3 Some Category']) def test_withjoinedload(self): """ @@ -185,7 +185,7 @@ class EagerTest(fixtures.MappedTest): options.c.someoption==False)))) result = ["%d %s" % ( t.id,t.category.name ) for t in l] - eq_(result, [u'1 Some Category', u'3 Some Category']) + eq_(result, ['1 Some Category', '3 Some Category']) def test_dslish(self): """test the same as withjoinedload except using generative""" @@ -203,7 +203,7 @@ class EagerTest(fixtures.MappedTest): ).outerjoin('owner_option') result = ["%d %s" % ( t.id,t.category.name ) for t in l] - eq_(result, [u'1 Some Category', u'3 Some Category']) + eq_(result, ['1 Some Category', '3 Some Category']) @testing.crashes('sybase', 'FIXME: unknown, verify not fails_on') def test_without_outerjoin_literal(self): @@ -219,7 +219,7 @@ class EagerTest(fixtures.MappedTest): join('owner_option')) result = ["%d %s" % ( t.id,t.category.name ) for t in l] - eq_(result, [u'3 Some Category']) + eq_(result, ['3 Some Category']) def test_withoutouterjoin(self): Thing, tests, options = (self.classes.Thing, @@ -234,7 +234,7 @@ class EagerTest(fixtures.MappedTest): ).join('owner_option') result = ["%d %s" % ( t.id,t.category.name ) for t in l] - eq_(result, [u'3 Some Category']) + eq_(result, ['3 Some Category']) class EagerTest2(fixtures.MappedTest): @@ -764,7 +764,7 @@ class EagerTest8(fixtures.MappedTest): (1,),), task=(('title', 'task_type_id', 'status_id', 'prj_id'), - (u'task 1', 1, 1, 1))) + ('task 1', 1, 1, 1))) @classmethod def setup_classes(cls): @@ -804,7 +804,7 @@ class EagerTest8(fixtures.MappedTest): session = create_session() eq_(session.query(Joined).limit(10).offset(0).one(), - Joined(id=1, title=u'task 1', props_cnt=0)) + Joined(id=1, title='task 1', props_cnt=0)) class EagerTest9(fixtures.MappedTest): diff --git a/test/orm/test_attributes.py b/test/orm/test_attributes.py index d60c55edd..2b5d14695 100644 --- a/test/orm/test_attributes.py +++ b/test/orm/test_attributes.py @@ -838,7 +838,7 @@ class AttributesTest(fixtures.ORMTest): attributes.register_attribute(Foo, 'collection', uselist=True, typecallable=dict, useobject=True) assert False - except sa_exc.ArgumentError, e: + except sa_exc.ArgumentError as e: assert str(e) \ == 'Type InstrumentedDict must elect an appender '\ 'method to be a collection class' @@ -865,7 +865,7 @@ class AttributesTest(fixtures.ORMTest): attributes.register_attribute(Foo, 'collection', uselist=True, typecallable=MyColl, useobject=True) assert False - except sa_exc.ArgumentError, e: + except sa_exc.ArgumentError as e: assert str(e) \ == 'Type MyColl must elect an appender method to be a '\ 'collection class' @@ -889,7 +889,7 @@ class AttributesTest(fixtures.ORMTest): try: Foo().collection assert True - except sa_exc.ArgumentError, e: + except sa_exc.ArgumentError as e: assert False class GetNoValueTest(fixtures.ORMTest): @@ -1410,7 +1410,7 @@ class HistoryTest(fixtures.TestBase): class Foo(fixtures.BasicEntity): pass class Bar(fixtures.BasicEntity): - def __nonzero__(self): + def __bool__(self): assert False instrumentation.register_class(Foo) diff --git a/test/orm/test_collection.py b/test/orm/test_collection.py index f6cf51037..c9f9f6951 100644 --- a/test/orm/test_collection.py +++ b/test/orm/test_collection.py @@ -1106,7 +1106,7 @@ class CollectionsTest(fixtures.ORMTest): @collection.converter def _convert(self, dictlike): - for key, value in dictlike.iteritems(): + for key, value in dictlike.items(): yield value + 5 class Foo(object): @@ -1145,12 +1145,12 @@ class CollectionsTest(fixtures.ORMTest): def __delitem__(self, key): del self.data[key] def values(self): - return self.data.values() + return list(self.data.values()) def __contains__(self, key): return key in self.data @collection.iterator def itervalues(self): - return self.data.itervalues() + return iter(self.data.values()) __hash__ = object.__hash__ def __eq__(self, other): return self.data == other @@ -1158,7 +1158,7 @@ class CollectionsTest(fixtures.ORMTest): return 'DictLike(%s)' % repr(self.data) self._test_adapter(DictLike, self.dictable_entity, - to_set=lambda c: set(c.itervalues())) + to_set=lambda c: set(c.values())) self._test_dict(DictLike) self._test_dict_bulk(DictLike) self.assert_(getattr(DictLike, '_sa_instrumented') == id(DictLike)) @@ -1185,12 +1185,12 @@ class CollectionsTest(fixtures.ORMTest): def __delitem__(self, key): del self.data[key] def values(self): - return self.data.values() + return list(self.data.values()) def __contains__(self, key): return key in self.data @collection.iterator def itervalues(self): - return self.data.itervalues() + return iter(self.data.values()) __hash__ = object.__hash__ def __eq__(self, other): return self.data == other @@ -1198,7 +1198,7 @@ class CollectionsTest(fixtures.ORMTest): return 'DictIsh(%s)' % repr(self.data) self._test_adapter(DictIsh, self.dictable_entity, - to_set=lambda c: set(c.itervalues())) + to_set=lambda c: set(c.values())) self._test_dict(DictIsh) self._test_dict_bulk(DictIsh) self.assert_(getattr(DictIsh, '_sa_instrumented') == id(DictIsh)) @@ -1859,7 +1859,7 @@ class CustomCollectionsTest(fixtures.MappedTest): f = sess.query(Foo).get(f.col1) assert len(list(f.bars)) == 2 - existing = set([id(b) for b in f.bars.values()]) + existing = set([id(b) for b in list(f.bars.values())]) col = collections.collection_adapter(f.bars) col.append_with_event(Bar('b')) @@ -1869,7 +1869,7 @@ class CustomCollectionsTest(fixtures.MappedTest): f = sess.query(Foo).get(f.col1) assert len(list(f.bars)) == 2 - replaced = set([id(b) for b in f.bars.values()]) + replaced = set([id(b) for b in list(f.bars.values())]) self.assert_(existing != replaced) def test_list(self): diff --git a/test/orm/test_composites.py b/test/orm/test_composites.py index f9af0c702..b6e5d81a1 100644 --- a/test/orm/test_composites.py +++ b/test/orm/test_composites.py @@ -510,11 +510,11 @@ class MappedSelectTest(fixtures.MappedTest): session.commit() eq_( testing.db.execute(descriptions.select()).fetchall(), - [(1, u'Color', u'Number')] + [(1, 'Color', 'Number')] ) eq_( testing.db.execute(values.select()).fetchall(), - [(1, 1, u'Red', u'5'), (2, 1, u'Blue', u'1')] + [(1, 1, 'Red', '5'), (2, 1, 'Blue', '1')] ) class ManyToOneTest(fixtures.MappedTest): diff --git a/test/orm/test_deprecations.py b/test/orm/test_deprecations.py index 95fa9dd29..a8be34971 100644 --- a/test/orm/test_deprecations.py +++ b/test/orm/test_deprecations.py @@ -122,7 +122,7 @@ class QueryAlternativesTest(fixtures.MappedTest): session = sessionmaker(query_cls=MyQuery)() ad1 = session.query(Address).get(1) - assert ad1 in cache.values() + assert ad1 in list(cache.values()) def test_load(self): """x = session.query(Address).load(1) diff --git a/test/orm/test_dynamic.py b/test/orm/test_dynamic.py index c8a675e3b..21dcfd436 100644 --- a/test/orm/test_dynamic.py +++ b/test/orm/test_dynamic.py @@ -119,9 +119,9 @@ class DynamicTest(_DynamicFixture, _fixtures.FixtureTest, AssertsCompiledSQL): eq_( list(u.addresses.order_by(desc(Address.email_address))), [ - Address(email_address=u'ed@wood.com'), - Address(email_address=u'ed@lala.com'), - Address(email_address=u'ed@bettyboop.com') + Address(email_address='ed@wood.com'), + Address(email_address='ed@lala.com'), + Address(email_address='ed@bettyboop.com') ] ) @@ -137,9 +137,9 @@ class DynamicTest(_DynamicFixture, _fixtures.FixtureTest, AssertsCompiledSQL): eq_( list(u.addresses), [ - Address(email_address=u'ed@wood.com'), - Address(email_address=u'ed@lala.com'), - Address(email_address=u'ed@bettyboop.com') + Address(email_address='ed@wood.com'), + Address(email_address='ed@lala.com'), + Address(email_address='ed@bettyboop.com') ] ) @@ -147,9 +147,9 @@ class DynamicTest(_DynamicFixture, _fixtures.FixtureTest, AssertsCompiledSQL): eq_( list(u.addresses.order_by(None).order_by(Address.email_address)), [ - Address(email_address=u'ed@bettyboop.com'), - Address(email_address=u'ed@lala.com'), - Address(email_address=u'ed@wood.com') + Address(email_address='ed@bettyboop.com'), + Address(email_address='ed@lala.com'), + Address(email_address='ed@wood.com') ] ) @@ -157,9 +157,9 @@ class DynamicTest(_DynamicFixture, _fixtures.FixtureTest, AssertsCompiledSQL): eq_( set(u.addresses.order_by(None)), set([ - Address(email_address=u'ed@bettyboop.com'), - Address(email_address=u'ed@lala.com'), - Address(email_address=u'ed@wood.com') + Address(email_address='ed@bettyboop.com'), + Address(email_address='ed@lala.com'), + Address(email_address='ed@wood.com') ]) ) @@ -529,12 +529,12 @@ class UOWTest(_DynamicFixture, _fixtures.FixtureTest, "SELECT addresses.id AS addresses_id, addresses.email_address " "AS addresses_email_address FROM addresses " "WHERE addresses.id = :param_1", - lambda ctx: [{u'param_1': a2_id}] + lambda ctx: [{'param_1': a2_id}] ), CompiledSQL( "UPDATE addresses SET user_id=:user_id WHERE addresses.id = " ":addresses_id", - lambda ctx: [{u'addresses_id': a2_id, 'user_id': None}] + lambda ctx: [{'addresses_id': a2_id, 'user_id': None}] ) ) diff --git a/test/orm/test_eager_relations.py b/test/orm/test_eager_relations.py index 2c59491b1..20ee693f3 100644 --- a/test/orm/test_eager_relations.py +++ b/test/orm/test_eager_relations.py @@ -747,11 +747,11 @@ class EagerTest(_fixtures.FixtureTest, testing.AssertsCompiledSQL): sess = create_session() eq_(sess.query(User).first(), - User(name=u'jack',orders=[ - Order(address_id=1,description=u'order 1',isopen=0,user_id=7,id=1), - Order(address_id=1,description=u'order 3',isopen=1,user_id=7,id=3), - Order(address_id=None,description=u'order 5',isopen=0,user_id=7,id=5)], - email_address=u'jack@bean.com',id=7) + User(name='jack',orders=[ + Order(address_id=1,description='order 1',isopen=0,user_id=7,id=1), + Order(address_id=1,description='order 3',isopen=1,user_id=7,id=3), + Order(address_id=None,description='order 5',isopen=0,user_id=7,id=5)], + email_address='jack@bean.com',id=7) ) def test_useget_cancels_eager(self): @@ -2131,15 +2131,15 @@ class SelfReferentialM2MEagerTest(fixtures.MappedTest): }) sess = create_session() - w1 = Widget(name=u'w1') - w2 = Widget(name=u'w2') + w1 = Widget(name='w1') + w2 = Widget(name='w2') w1.children.append(w2) sess.add(w1) sess.flush() sess.expunge_all() eq_([Widget(name='w1', children=[Widget(name='w2')])], - sess.query(Widget).filter(Widget.name==u'w1').all()) + sess.query(Widget).filter(Widget.name=='w1').all()) class MixedEntitiesTest(_fixtures.FixtureTest, testing.AssertsCompiledSQL): run_setup_mappers = 'once' @@ -2223,24 +2223,24 @@ class MixedEntitiesTest(_fixtures.FixtureTest, testing.AssertsCompiledSQL): eq_( [ ( - User(addresses=[Address(email_address=u'fred@fred.com')], name=u'fred'), - Order(description=u'order 2', isopen=0, items=[Item(description=u'item 1'), Item(description=u'item 2'), Item(description=u'item 3')]), - User(addresses=[Address(email_address=u'jack@bean.com')], name=u'jack'), - Order(description=u'order 3', isopen=1, items=[Item(description=u'item 3'), Item(description=u'item 4'), Item(description=u'item 5')]) + User(addresses=[Address(email_address='fred@fred.com')], name='fred'), + Order(description='order 2', isopen=0, items=[Item(description='item 1'), Item(description='item 2'), Item(description='item 3')]), + User(addresses=[Address(email_address='jack@bean.com')], name='jack'), + Order(description='order 3', isopen=1, items=[Item(description='item 3'), Item(description='item 4'), Item(description='item 5')]) ), ( - User(addresses=[Address(email_address=u'fred@fred.com')], name=u'fred'), - Order(description=u'order 2', isopen=0, items=[Item(description=u'item 1'), Item(description=u'item 2'), Item(description=u'item 3')]), - User(addresses=[Address(email_address=u'jack@bean.com')], name=u'jack'), - Order(address_id=None, description=u'order 5', isopen=0, items=[Item(description=u'item 5')]) + User(addresses=[Address(email_address='fred@fred.com')], name='fred'), + Order(description='order 2', isopen=0, items=[Item(description='item 1'), Item(description='item 2'), Item(description='item 3')]), + User(addresses=[Address(email_address='jack@bean.com')], name='jack'), + Order(address_id=None, description='order 5', isopen=0, items=[Item(description='item 5')]) ), ( - User(addresses=[Address(email_address=u'fred@fred.com')], name=u'fred'), - Order(description=u'order 4', isopen=1, items=[Item(description=u'item 1'), Item(description=u'item 5')]), - User(addresses=[Address(email_address=u'jack@bean.com')], name=u'jack'), - Order(address_id=None, description=u'order 5', isopen=0, items=[Item(description=u'item 5')]) + User(addresses=[Address(email_address='fred@fred.com')], name='fred'), + Order(description='order 4', isopen=1, items=[Item(description='item 1'), Item(description='item 5')]), + User(addresses=[Address(email_address='jack@bean.com')], name='jack'), + Order(address_id=None, description='order 5', isopen=0, items=[Item(description='item 5')]) ), ], sess.query(User, Order, u1, o1).\ @@ -2651,9 +2651,9 @@ class CyclicalInheritingEagerTestTwo(fixtures.DeclarativeMappedTest, Movie = self.classes.Movie session = Session(testing.db) - rscott = Director(name=u"Ridley Scott") - alien = Movie(title=u"Alien") - brunner = Movie(title=u"Blade Runner") + rscott = Director(name="Ridley Scott") + alien = Movie(title="Alien") + brunner = Movie(title="Blade Runner") rscott.movies.append(brunner) rscott.movies.append(alien) session.add_all([rscott, alien, brunner]) diff --git a/test/orm/test_expire.py b/test/orm/test_expire.py index 0b1350e0a..6eb124cd2 100644 --- a/test/orm/test_expire.py +++ b/test/orm/test_expire.py @@ -850,7 +850,7 @@ class ExpireTest(_fixtures.FixtureTest): assert len(u.addresses) == 3 sess.expire(u) assert 'addresses' not in u.__dict__ - print "-------------------------------------------" + print("-------------------------------------------") sess.query(User).filter_by(id=8).all() assert 'addresses' in u.__dict__ assert len(u.addresses) == 3 diff --git a/test/orm/test_froms.py b/test/orm/test_froms.py index c701a7076..5040c4685 100644 --- a/test/orm/test_froms.py +++ b/test/orm/test_froms.py @@ -315,12 +315,12 @@ class FromSelfTest(QueryTest, AssertsCompiledSQL): from_self(User.name, ualias.name). order_by(User.name, ualias.name).all(), [ - (u'chuck', u'ed'), - (u'chuck', u'fred'), - (u'chuck', u'jack'), - (u'ed', u'jack'), - (u'fred', u'ed'), - (u'fred', u'jack') + ('chuck', 'ed'), + ('chuck', 'fred'), + ('chuck', 'jack'), + ('ed', 'jack'), + ('fred', 'ed'), + ('fred', 'jack') ] ) @@ -330,7 +330,7 @@ class FromSelfTest(QueryTest, AssertsCompiledSQL): from_self(User.name, ualias.name). filter(ualias.name=='ed')\ .order_by(User.name, ualias.name).all(), - [(u'chuck', u'ed'), (u'fred', u'ed')] + [('chuck', 'ed'), ('fred', 'ed')] ) eq_( @@ -340,11 +340,11 @@ class FromSelfTest(QueryTest, AssertsCompiledSQL): join(ualias.addresses). order_by(ualias.name, Address.email_address).all(), [ - (u'ed', u'fred@fred.com'), - (u'jack', u'ed@bettyboop.com'), - (u'jack', u'ed@lala.com'), - (u'jack', u'ed@wood.com'), - (u'jack', u'fred@fred.com')] + ('ed', 'fred@fred.com'), + ('jack', 'ed@bettyboop.com'), + ('jack', 'ed@lala.com'), + ('jack', 'ed@wood.com'), + ('jack', 'fred@fred.com')] ) @@ -629,8 +629,8 @@ class AddEntityEquivalenceTest(fixtures.MappedTest, AssertsCompiledSQL): eq_( q.all(), [( - A(bid=2, id=1, name=u'a1', type=u'a'), - C(age=3, id=2, name=u'c1', type=u'c') + A(bid=2, id=1, name='a1', type='a'), + C(age=3, id=2, name='c1', type='c') )] ) @@ -642,8 +642,8 @@ class AddEntityEquivalenceTest(fixtures.MappedTest, AssertsCompiledSQL): eq_( q.all(), [( - C(age=3, id=2, name=u'c1', type=u'c'), - A(bid=2, id=1, name=u'a1', type=u'a') + C(age=3, id=2, name='c1', type='c'), + A(bid=2, id=1, name='a1', type='a') )] ) @@ -929,12 +929,12 @@ class InstancesTest(QueryTest, AssertsCompiledSQL): # have a Dingaling here due to using the inner # join for the eager load [ - User(name=u'ed', addresses=[ - Address(email_address=u'ed@wood.com', + User(name='ed', addresses=[ + Address(email_address='ed@wood.com', dingaling=Dingaling(data='ding 1/2')), ]), - User(name=u'fred', addresses=[ - Address(email_address=u'fred@fred.com', + User(name='fred', addresses=[ + Address(email_address='fred@fred.com', dingaling=Dingaling(data='ding 2/5')) ]) ] @@ -965,12 +965,12 @@ class InstancesTest(QueryTest, AssertsCompiledSQL): # have a Dingaling here due to using the inner # join for the eager load [ - User(name=u'ed', addresses=[ - Address(email_address=u'ed@wood.com', + User(name='ed', addresses=[ + Address(email_address='ed@wood.com', dingaling=Dingaling(data='ding 1/2')), ]), - User(name=u'fred', addresses=[ - Address(email_address=u'fred@fred.com', + User(name='fred', addresses=[ + Address(email_address='fred@fred.com', dingaling=Dingaling(data='ding 2/5')) ]) ] @@ -998,11 +998,11 @@ class InstancesTest(QueryTest, AssertsCompiledSQL): contains_eager(User.orders)).order_by(User.id, Order.id).offset(1).limit(2).all() eq_(l, [User(id=7, - addresses=[Address(email_address=u'jack@bean.com', - user_id=7, id=1)], name=u'jack', + addresses=[Address(email_address='jack@bean.com', + user_id=7, id=1)], name='jack', orders=[Order(address_id=1, user_id=7, - description=u'order 3', isopen=1, id=3), - Order(address_id=None, user_id=7, description=u'order 5' + description='order 3', isopen=1, id=3), + Order(address_id=None, user_id=7, description='order 5' , isopen=0, id=5)])]) self.assert_sql_count(testing.db, go, 1) @@ -1020,11 +1020,11 @@ class InstancesTest(QueryTest, AssertsCompiledSQL): order_by(User.id, oalias.id).\ offset(1).limit(2).all() eq_(l, [User(id=7, - addresses=[Address(email_address=u'jack@bean.com', - user_id=7, id=1)], name=u'jack', + addresses=[Address(email_address='jack@bean.com', + user_id=7, id=1)], name='jack', orders=[Order(address_id=1, user_id=7, - description=u'order 3', isopen=1, id=3), - Order(address_id=None, user_id=7, description=u'order 5' + description='order 3', isopen=1, id=3), + Order(address_id=None, user_id=7, description='order 5' , isopen=0, id=5)])]) self.assert_sql_count(testing.db, go, 1) @@ -1045,15 +1045,15 @@ class MixedEntitiesTest(QueryTest, AssertsCompiledSQL): sel = users.select(User.id.in_([7, 8])).alias() q = sess.query(User) q2 = q.select_from(sel).values(User.name) - eq_(list(q2), [(u'jack',), (u'ed',)]) + eq_(list(q2), [('jack',), ('ed',)]) q = sess.query(User) q2 = q.order_by(User.id).\ values(User.name, User.name + " " + cast(User.id, String(50))) eq_( list(q2), - [(u'jack', u'jack 7'), (u'ed', u'ed 8'), - (u'fred', u'fred 9'), (u'chuck', u'chuck 10')] + [('jack', 'jack 7'), ('ed', 'ed 8'), + ('fred', 'fred 9'), ('chuck', 'chuck 10')] ) q2 = q.join('addresses').\ @@ -1061,27 +1061,27 @@ class MixedEntitiesTest(QueryTest, AssertsCompiledSQL): order_by(User.id, Address.id).\ values(User.name, Address.email_address) eq_(list(q2), - [(u'ed', u'ed@wood.com'), (u'ed', u'ed@bettyboop.com'), - (u'ed', u'ed@lala.com'), (u'fred', u'fred@fred.com')]) + [('ed', 'ed@wood.com'), ('ed', 'ed@bettyboop.com'), + ('ed', 'ed@lala.com'), ('fred', 'fred@fred.com')]) q2 = q.join('addresses').\ filter(User.name.like('%e%')).\ order_by(desc(Address.email_address)).\ slice(1, 3).values(User.name, Address.email_address) - eq_(list(q2), [(u'ed', u'ed@wood.com'), (u'ed', u'ed@lala.com')]) + eq_(list(q2), [('ed', 'ed@wood.com'), ('ed', 'ed@lala.com')]) adalias = aliased(Address) q2 = q.join(adalias, 'addresses').\ filter(User.name.like('%e%')).order_by(adalias.email_address).\ values(User.name, adalias.email_address) - eq_(list(q2), [(u'ed', u'ed@bettyboop.com'), (u'ed', u'ed@lala.com'), - (u'ed', u'ed@wood.com'), (u'fred', u'fred@fred.com')]) + eq_(list(q2), [('ed', 'ed@bettyboop.com'), ('ed', 'ed@lala.com'), + ('ed', 'ed@wood.com'), ('fred', 'fred@fred.com')]) q2 = q.values(func.count(User.name)) - assert q2.next() == (4,) + assert next(q2) == (4,) q2 = q.select_from(sel).filter(User.id==8).values(User.name, sel.c.name, User.name) - eq_(list(q2), [(u'ed', u'ed', u'ed')]) + eq_(list(q2), [('ed', 'ed', 'ed')]) # using User.xxx is alised against "sel", so this query returns nothing q2 = q.select_from(sel).\ @@ -1093,7 +1093,7 @@ class MixedEntitiesTest(QueryTest, AssertsCompiledSQL): q2 = q.select_from(sel).\ filter(users.c.id==8).\ filter(users.c.id>sel.c.id).values(users.c.name, sel.c.name, User.name) - eq_(list(q2), [(u'ed', u'jack', u'jack')]) + eq_(list(q2), [('ed', 'jack', 'jack')]) def test_alias_naming(self): User = self.classes.User @@ -1123,10 +1123,10 @@ class MixedEntitiesTest(QueryTest, AssertsCompiledSQL): filter(u2.id>1).\ order_by(User.id, sel.c.id, u2.id).\ values(User.name, sel.c.name, u2.name) - eq_(list(q2), [(u'jack', u'jack', u'jack'), (u'jack', u'jack', u'ed'), - (u'jack', u'jack', u'fred'), (u'jack', u'jack', u'chuck'), - (u'ed', u'ed', u'jack'), (u'ed', u'ed', u'ed'), - (u'ed', u'ed', u'fred'), (u'ed', u'ed', u'chuck')]) + eq_(list(q2), [('jack', 'jack', 'jack'), ('jack', 'jack', 'ed'), + ('jack', 'jack', 'fred'), ('jack', 'jack', 'chuck'), + ('ed', 'ed', 'jack'), ('ed', 'ed', 'ed'), + ('ed', 'ed', 'fred'), ('ed', 'ed', 'chuck')]) @testing.fails_on('mssql', 'FIXME: unknown') @testing.fails_on('oracle', @@ -1177,8 +1177,8 @@ class MixedEntitiesTest(QueryTest, AssertsCompiledSQL): # we don't want Address to be outside of the subquery here eq_( list(sess.query(User, subq)[0:3]), - [(User(id=7,name=u'jack'), 1), (User(id=8,name=u'ed'), 3), - (User(id=9,name=u'fred'), 1)] + [(User(id=7,name='jack'), 1), (User(id=8,name='ed'), 3), + (User(id=9,name='fred'), 1)] ) # same thing without the correlate, as it should @@ -1190,8 +1190,8 @@ class MixedEntitiesTest(QueryTest, AssertsCompiledSQL): # we don't want Address to be outside of the subquery here eq_( list(sess.query(User, subq)[0:3]), - [(User(id=7,name=u'jack'), 1), (User(id=8,name=u'ed'), 3), - (User(id=9,name=u'fred'), 1)] + [(User(id=7,name='jack'), 1), (User(id=8,name='ed'), 3), + (User(id=9,name='fred'), 1)] ) @@ -1202,23 +1202,23 @@ class MixedEntitiesTest(QueryTest, AssertsCompiledSQL): sess = create_session() - eq_(sess.query(User.name).all(), [(u'jack',), (u'ed',), (u'fred',), (u'chuck',)]) + eq_(sess.query(User.name).all(), [('jack',), ('ed',), ('fred',), ('chuck',)]) sel = users.select(User.id.in_([7, 8])).alias() q = sess.query(User.name) q2 = q.select_from(sel).all() - eq_(list(q2), [(u'jack',), (u'ed',)]) + eq_(list(q2), [('jack',), ('ed',)]) eq_(sess.query(User.name, Address.email_address).filter(User.id==Address.user_id).all(), [ - (u'jack', u'jack@bean.com'), (u'ed', u'ed@wood.com'), - (u'ed', u'ed@bettyboop.com'), (u'ed', u'ed@lala.com'), - (u'fred', u'fred@fred.com') + ('jack', 'jack@bean.com'), ('ed', 'ed@wood.com'), + ('ed', 'ed@bettyboop.com'), ('ed', 'ed@lala.com'), + ('fred', 'fred@fred.com') ]) eq_(sess.query(User.name, func.count(Address.email_address)).\ outerjoin(User.addresses).group_by(User.id, User.name).\ order_by(User.id).all(), - [(u'jack', 1), (u'ed', 3), (u'fred', 1), (u'chuck', 0)] + [('jack', 1), ('ed', 3), ('fred', 1), ('chuck', 0)] ) eq_(sess.query(User, func.count(Address.email_address)).\ @@ -1246,8 +1246,8 @@ class MixedEntitiesTest(QueryTest, AssertsCompiledSQL): eq_(sess.query(func.count(adalias.email_address), User).\ outerjoin(adalias, User.addresses).group_by(User).\ order_by(User.id).all(), - [(1, User(name=u'jack',id=7)), (3, User(name=u'ed',id=8)), - (1, User(name=u'fred',id=9)), (0, User(name=u'chuck',id=10))] + [(1, User(name='jack',id=7)), (3, User(name='ed',id=8)), + (1, User(name='fred',id=9)), (0, User(name='chuck',id=10))] ) # select from aliasing + explicit aliasing @@ -1257,12 +1257,12 @@ class MixedEntitiesTest(QueryTest, AssertsCompiledSQL): from_self(User, adalias.email_address).\ order_by(User.id, adalias.id).all(), [ - (User(name=u'jack',id=7), u'jack@bean.com'), - (User(name=u'ed',id=8), u'ed@wood.com'), - (User(name=u'ed',id=8), u'ed@bettyboop.com'), - (User(name=u'ed',id=8), u'ed@lala.com'), - (User(name=u'fred',id=9), u'fred@fred.com'), - (User(name=u'chuck',id=10), None) + (User(name='jack',id=7), 'jack@bean.com'), + (User(name='ed',id=8), 'ed@wood.com'), + (User(name='ed',id=8), 'ed@bettyboop.com'), + (User(name='ed',id=8), 'ed@lala.com'), + (User(name='fred',id=9), 'fred@fred.com'), + (User(name='chuck',id=10), None) ] ) @@ -1272,8 +1272,8 @@ class MixedEntitiesTest(QueryTest, AssertsCompiledSQL): filter(Address.email_address.like('%ed%')).\ from_self().all(), [ - User(name=u'ed',id=8), - User(name=u'fred',id=9), + User(name='ed',id=8), + User(name='fred',id=9), ] ) @@ -1293,27 +1293,27 @@ class MixedEntitiesTest(QueryTest, AssertsCompiledSQL): q.all(), [(User(addresses=[ - Address(user_id=7,email_address=u'jack@bean.com',id=1)], - name=u'jack',id=7), u'jack@bean.com'), + Address(user_id=7,email_address='jack@bean.com',id=1)], + name='jack',id=7), 'jack@bean.com'), (User(addresses=[ - Address(user_id=8,email_address=u'ed@wood.com',id=2), - Address(user_id=8,email_address=u'ed@bettyboop.com',id=3), - Address(user_id=8,email_address=u'ed@lala.com',id=4)], - name=u'ed',id=8), u'ed@wood.com'), + Address(user_id=8,email_address='ed@wood.com',id=2), + Address(user_id=8,email_address='ed@bettyboop.com',id=3), + Address(user_id=8,email_address='ed@lala.com',id=4)], + name='ed',id=8), 'ed@wood.com'), (User(addresses=[ - Address(user_id=8,email_address=u'ed@wood.com',id=2), - Address(user_id=8,email_address=u'ed@bettyboop.com',id=3), - Address(user_id=8,email_address=u'ed@lala.com',id=4)],name=u'ed',id=8), - u'ed@bettyboop.com'), + Address(user_id=8,email_address='ed@wood.com',id=2), + Address(user_id=8,email_address='ed@bettyboop.com',id=3), + Address(user_id=8,email_address='ed@lala.com',id=4)],name='ed',id=8), + 'ed@bettyboop.com'), (User(addresses=[ - Address(user_id=8,email_address=u'ed@wood.com',id=2), - Address(user_id=8,email_address=u'ed@bettyboop.com',id=3), - Address(user_id=8,email_address=u'ed@lala.com',id=4)],name=u'ed',id=8), - u'ed@lala.com'), - (User(addresses=[Address(user_id=9,email_address=u'fred@fred.com',id=5)],name=u'fred',id=9), - u'fred@fred.com'), + Address(user_id=8,email_address='ed@wood.com',id=2), + Address(user_id=8,email_address='ed@bettyboop.com',id=3), + Address(user_id=8,email_address='ed@lala.com',id=4)],name='ed',id=8), + 'ed@lala.com'), + (User(addresses=[Address(user_id=9,email_address='fred@fred.com',id=5)],name='fred',id=9), + 'fred@fred.com'), - (User(addresses=[],name=u'chuck',id=10), None)] + (User(addresses=[],name='chuck',id=10), None)] ) def test_column_from_limited_joinedload(self): @@ -1367,19 +1367,19 @@ class MixedEntitiesTest(QueryTest, AssertsCompiledSQL): eq_( q.all(), [ - (Order(address_id=1,description=u'order 3',isopen=1,user_id=7,id=3), - Order(address_id=1,description=u'order 1',isopen=0,user_id=7,id=1)), - (Order(address_id=None,description=u'order 5',isopen=0,user_id=7,id=5), - Order(address_id=1,description=u'order 1',isopen=0,user_id=7,id=1)), - (Order(address_id=None,description=u'order 5',isopen=0,user_id=7,id=5), - Order(address_id=1,description=u'order 3',isopen=1,user_id=7,id=3)) + (Order(address_id=1,description='order 3',isopen=1,user_id=7,id=3), + Order(address_id=1,description='order 1',isopen=0,user_id=7,id=1)), + (Order(address_id=None,description='order 5',isopen=0,user_id=7,id=5), + Order(address_id=1,description='order 1',isopen=0,user_id=7,id=1)), + (Order(address_id=None,description='order 5',isopen=0,user_id=7,id=5), + Order(address_id=1,description='order 3',isopen=1,user_id=7,id=3)) ] ) # ensure column expressions are taken from inside the subquery, not restated at the top q = sess.query(Order.id, Order.description, literal_column("'q'").label('foo')).\ - filter(Order.description == u'order 3').from_self() + filter(Order.description == 'order 3').from_self() self.assert_compile(q, "SELECT anon_1.orders_id AS " "anon_1_orders_id, anon_1.orders_descriptio" @@ -1392,7 +1392,7 @@ class MixedEntitiesTest(QueryTest, AssertsCompiledSQL): "anon_1") eq_( q.all(), - [(3, u'order 3', 'q')] + [(3, 'order 3', 'q')] ) @@ -1518,7 +1518,7 @@ class MixedEntitiesTest(QueryTest, AssertsCompiledSQL): eq_( sess.query(User.id).add_column(users).all(), - [(7, 7, u'jack'), (8, 8, u'ed'), (9, 9, u'fred'), (10, 10, u'chuck')] + [(7, 7, 'jack'), (8, 8, 'ed'), (9, 9, 'fred'), (10, 10, 'chuck')] ) def test_multi_columns_2(self): @@ -1936,7 +1936,7 @@ class SelectFromTest(QueryTest, AssertsCompiledSQL): filter(Keyword.name.in_(['red', 'big', 'round'])).\ all(), [ - User(name=u'jack',id=7) + User(name='jack',id=7) ]) eq_(sess.query(User).select_from(sel).\ @@ -1944,7 +1944,7 @@ class SelectFromTest(QueryTest, AssertsCompiledSQL): filter(Keyword.name.in_(['red', 'big', 'round'])).\ all(), [ - User(name=u'jack',id=7) + User(name='jack',id=7) ]) def go(): @@ -1955,39 +1955,39 @@ class SelectFromTest(QueryTest, AssertsCompiledSQL): filter(Keyword.name.in_(['red', 'big', 'round'])).\ all(), [ - User(name=u'jack',orders=[ - Order(description=u'order 1',items=[ - Item(description=u'item 1', + User(name='jack',orders=[ + Order(description='order 1',items=[ + Item(description='item 1', keywords=[ - Keyword(name=u'red'), - Keyword(name=u'big'), - Keyword(name=u'round') + Keyword(name='red'), + Keyword(name='big'), + Keyword(name='round') ]), - Item(description=u'item 2', + Item(description='item 2', keywords=[ - Keyword(name=u'red',id=2), - Keyword(name=u'small',id=5), - Keyword(name=u'square') + Keyword(name='red',id=2), + Keyword(name='small',id=5), + Keyword(name='square') ]), - Item(description=u'item 3', + Item(description='item 3', keywords=[ - Keyword(name=u'green',id=3), - Keyword(name=u'big',id=4), - Keyword(name=u'round',id=6)]) + Keyword(name='green',id=3), + Keyword(name='big',id=4), + Keyword(name='round',id=6)]) ]), - Order(description=u'order 3',items=[ - Item(description=u'item 3', + Order(description='order 3',items=[ + Item(description='item 3', keywords=[ - Keyword(name=u'green',id=3), - Keyword(name=u'big',id=4), - Keyword(name=u'round',id=6) + Keyword(name='green',id=3), + Keyword(name='big',id=4), + Keyword(name='round',id=6) ]), - Item(description=u'item 4',keywords=[],id=4), - Item(description=u'item 5',keywords=[],id=5) + Item(description='item 4',keywords=[],id=4), + Item(description='item 5',keywords=[],id=5) ]), - Order(description=u'order 5', + Order(description='order 5', items=[ - Item(description=u'item 5',keywords=[])]) + Item(description='item 5',keywords=[])]) ]) ]) self.assert_sql_count(testing.db, go, 1) @@ -1998,15 +1998,15 @@ class SelectFromTest(QueryTest, AssertsCompiledSQL): join('items', 'keywords').\ filter(Keyword.name == 'red').\ order_by(Order.id).all(), [ - Order(description=u'order 1',id=1), - Order(description=u'order 2',id=2), + Order(description='order 1',id=1), + Order(description='order 2',id=2), ]) eq_(sess.query(Order).select_from(sel2).\ join('items', 'keywords', aliased=True).\ filter(Keyword.name == 'red').\ order_by(Order.id).all(), [ - Order(description=u'order 1',id=1), - Order(description=u'order 2',id=2), + Order(description='order 1',id=1), + Order(description='order 2',id=2), ]) diff --git a/test/orm/test_generative.py b/test/orm/test_generative.py index 3f5da69c3..84e60d8ea 100644 --- a/test/orm/test_generative.py +++ b/test/orm/test_generative.py @@ -78,13 +78,14 @@ class GenerativeQueryTest(fixtures.MappedTest): assert sess.query(func.min(foo.c.bar)).filter(foo.c.bar<30).one() == (0,) assert sess.query(func.max(foo.c.bar)).filter(foo.c.bar<30).one() == (29,) - # Py3K - #assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).__next__()[0] == 29 - #assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).__next__()[0] == 29 - # Py2K - assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).next()[0] == 29 - assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).next()[0] == 29 - # end Py2K +# start Py3K + assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).__next__()[0] == 29 + assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).__next__()[0] == 29 +# end Py3K +# start Py2K +# assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).next()[0] == 29 +# assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).next()[0] == 29 +# end Py2K @testing.fails_if(lambda:testing.against('mysql+mysqldb') and testing.db.dialect.dbapi.version_info[:4] == (1, 2, 1, 'gamma'), @@ -111,18 +112,20 @@ class GenerativeQueryTest(fixtures.MappedTest): query = create_session().query(Foo) - # Py3K - #avg_f = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).__next__()[0] - # Py2K - avg_f = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).next()[0] - # end Py2K +# start Py3K + avg_f = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).__next__()[0] +# end Py3K +# start Py2K +# avg_f = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).next()[0] +# end Py2K assert float(round(avg_f, 1)) == 14.5 - # Py3K - #avg_o = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).__next__()[0] - # Py2K - avg_o = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).next()[0] - # end Py2K +# start Py3K + avg_o = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).__next__()[0] +# end Py3K +# start Py2K +# avg_o = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).next()[0] +# end Py2K assert float(round(avg_o, 1)) == 14.5 def test_filter(self): diff --git a/test/orm/test_inspect.py b/test/orm/test_inspect.py index 2a401f91d..78d84f505 100644 --- a/test/orm/test_inspect.py +++ b/test/orm/test_inspect.py @@ -142,7 +142,7 @@ class TestORMInspection(_fixtures.FixtureTest): [insp.get_property('id'), insp.get_property('name')] ) eq_( - insp.column_attrs.keys(), + list(insp.column_attrs.keys()), ['id', 'name'] ) is_( @@ -274,7 +274,7 @@ class TestORMInspection(_fixtures.FixtureTest): insp = inspect(SomeSubClass) eq_( dict((k, v.extension_type) - for k, v in insp.all_orm_descriptors.items() + for k, v in list(insp.all_orm_descriptors.items()) ), { 'id': NOT_EXTENSION, diff --git a/test/orm/test_instrumentation.py b/test/orm/test_instrumentation.py index 3c564d910..a18f53737 100644 --- a/test/orm/test_instrumentation.py +++ b/test/orm/test_instrumentation.py @@ -522,30 +522,31 @@ class NativeInstrumentationTest(fixtures.ORMTest): class Py3KFunctionInstTest(fixtures.ORMTest): __requires__ = ("python3", ) - # Py3K - #def _kw_only_fixture(self): - # class A(object): - # def __init__(self, a, *, b, c): - # self.a = a - # self.b = b - # self.c = c - # return self._instrument(A) - # - #def _kw_plus_posn_fixture(self): - # class A(object): - # def __init__(self, a, *args, b, c): - # self.a = a - # self.b = b - # self.c = c - # return self._instrument(A) - # - #def _kw_opt_fixture(self): - # class A(object): - # def __init__(self, a, *, b, c="c"): - # self.a = a - # self.b = b - # self.c = c - # return self._instrument(A) +# start Py3K + def _kw_only_fixture(self): + class A(object): + def __init__(self, a, *, b, c): + self.a = a + self.b = b + self.c = c + return self._instrument(A) + + def _kw_plus_posn_fixture(self): + class A(object): + def __init__(self, a, *args, b, c): + self.a = a + self.b = b + self.c = c + return self._instrument(A) + + def _kw_opt_fixture(self): + class A(object): + def __init__(self, a, *, b, c="c"): + self.a = a + self.b = b + self.c = c + return self._instrument(A) +# end Py3K def _instrument(self, cls): manager = instrumentation.register_class(cls) diff --git a/test/orm/test_joins.py b/test/orm/test_joins.py index 2bf0d8d92..320104acb 100644 --- a/test/orm/test_joins.py +++ b/test/orm/test_joins.py @@ -774,14 +774,14 @@ class JoinTest(QueryTest, AssertsCompiledSQL): eq_( sess.query(User).join(Address.user).\ filter(Address.email_address=='ed@wood.com').all(), - [User(id=8,name=u'ed')] + [User(id=8,name='ed')] ) # its actually not so controversial if you view it in terms # of multiple entities. eq_( sess.query(User, Address).join(Address.user).filter(Address.email_address=='ed@wood.com').all(), - [(User(id=8,name=u'ed'), Address(email_address='ed@wood.com'))] + [(User(id=8,name='ed'), Address(email_address='ed@wood.com'))] ) # this was the controversial part. now, raise an error if the feature is abused. @@ -1162,9 +1162,9 @@ class JoinTest(QueryTest, AssertsCompiledSQL): sess.query(OrderAlias).join('items').filter_by(description='item 3').\ order_by(OrderAlias.id).all(), [ - Order(address_id=1,description=u'order 1',isopen=0,user_id=7,id=1), - Order(address_id=4,description=u'order 2',isopen=0,user_id=9,id=2), - Order(address_id=1,description=u'order 3',isopen=1,user_id=7,id=3) + Order(address_id=1,description='order 1',isopen=0,user_id=7,id=1), + Order(address_id=4,description='order 2',isopen=0,user_id=9,id=2), + Order(address_id=1,description='order 3',isopen=1,user_id=7,id=3) ] ) @@ -1175,9 +1175,9 @@ class JoinTest(QueryTest, AssertsCompiledSQL): filter_by(description='item 3').\ order_by(User.id, OrderAlias.id).all(), [ - (User(name=u'jack',id=7), Order(address_id=1,description=u'order 1',isopen=0,user_id=7,id=1), u'item 3'), - (User(name=u'jack',id=7), Order(address_id=1,description=u'order 3',isopen=1,user_id=7,id=3), u'item 3'), - (User(name=u'fred',id=9), Order(address_id=4,description=u'order 2',isopen=0,user_id=9,id=2), u'item 3') + (User(name='jack',id=7), Order(address_id=1,description='order 1',isopen=0,user_id=7,id=1), 'item 3'), + (User(name='jack',id=7), Order(address_id=1,description='order 3',isopen=1,user_id=7,id=3), 'item 3'), + (User(name='fred',id=9), Order(address_id=4,description='order 2',isopen=0,user_id=9,id=2), 'item 3') ] ) @@ -1334,12 +1334,12 @@ class JoinTest(QueryTest, AssertsCompiledSQL): eq_( sess.query(User, ualias).filter(User.id > ualias.id).order_by(desc(ualias.id), User.name).all(), [ - (User(id=10,name=u'chuck'), User(id=9,name=u'fred')), - (User(id=10,name=u'chuck'), User(id=8,name=u'ed')), - (User(id=9,name=u'fred'), User(id=8,name=u'ed')), - (User(id=10,name=u'chuck'), User(id=7,name=u'jack')), - (User(id=8,name=u'ed'), User(id=7,name=u'jack')), - (User(id=9,name=u'fred'), User(id=7,name=u'jack')) + (User(id=10,name='chuck'), User(id=9,name='fred')), + (User(id=10,name='chuck'), User(id=8,name='ed')), + (User(id=9,name='fred'), User(id=8,name='ed')), + (User(id=10,name='chuck'), User(id=7,name='jack')), + (User(id=8,name='ed'), User(id=7,name='jack')), + (User(id=9,name='fred'), User(id=7,name='jack')) ] ) @@ -1351,7 +1351,7 @@ class JoinTest(QueryTest, AssertsCompiledSQL): eq_( sess.query(User.name).join(addresses, User.id==addresses.c.user_id).order_by(User.id).all(), - [(u'jack',), (u'ed',), (u'ed',), (u'ed',), (u'fred',)] + [('jack',), ('ed',), ('ed',), ('ed',), ('fred',)] ) def test_no_joinpoint_expr(self): @@ -2066,13 +2066,13 @@ class SelfReferentialTest(fixtures.MappedTest, AssertsCompiledSQL): # using 'n1.parent' implicitly joins to unaliased Node eq_( sess.query(n1).join(n1.parent).filter(Node.data=='n1').all(), - [Node(parent_id=1,data=u'n11',id=2), Node(parent_id=1,data=u'n12',id=3), Node(parent_id=1,data=u'n13',id=4)] + [Node(parent_id=1,data='n11',id=2), Node(parent_id=1,data='n12',id=3), Node(parent_id=1,data='n13',id=4)] ) # explicit (new syntax) eq_( sess.query(n1).join(Node, n1.parent).filter(Node.data=='n1').all(), - [Node(parent_id=1,data=u'n11',id=2), Node(parent_id=1,data=u'n12',id=3), Node(parent_id=1,data=u'n13',id=4)] + [Node(parent_id=1,data='n11',id=2), Node(parent_id=1,data='n12',id=3), Node(parent_id=1,data='n13',id=4)] ) diff --git a/test/orm/test_loading.py b/test/orm/test_loading.py index 20dc082c5..97c08ea29 100644 --- a/test/orm/test_loading.py +++ b/test/orm/test_loading.py @@ -73,7 +73,7 @@ class MergeResultTest(_fixtures.FixtureTest): [(x.id, y) for x, y in it], [(1, 1), (2, 2), (7, 7), (8, 8)] ) - eq_(it[0].keys(), ['User', 'id']) + eq_(list(it[0].keys()), ['User', 'id']) def test_entity_col_mix_keyed_tuple(self): s, (u1, u2, u3, u4) = self._fixture() @@ -91,7 +91,7 @@ class MergeResultTest(_fixtures.FixtureTest): [(x.id, y) for x, y in it], [(1, 1), (2, 2), (7, 7), (8, 8)] ) - eq_(it[0].keys(), ['User', 'id']) + eq_(list(it[0].keys()), ['User', 'id']) def test_none_entity(self): s, (u1, u2, u3, u4) = self._fixture() diff --git a/test/orm/test_mapper.py b/test/orm/test_mapper.py index 6b97fb135..19ff78004 100644 --- a/test/orm/test_mapper.py +++ b/test/orm/test_mapper.py @@ -272,13 +272,14 @@ class MapperTest(_fixtures.FixtureTest, AssertsCompiledSQL): ) m = mapper(Foo, foo_t) class DontCompareMeToString(int): - # Py3K - # pass - # Py2K - def __lt__(self, other): - assert not isinstance(other, basestring) - return int(self) < other - # end Py2K +# start Py3K + pass +# end Py3K +# start Py2K +# def __lt__(self, other): +# assert not isinstance(other, basestring) +# return int(self) < other +# end Py2K foos = [Foo(id='f%d' % i) for i in range(5)] states = [attributes.instance_state(f) for f in foos] @@ -847,7 +848,7 @@ class MapperTest(_fixtures.FixtureTest, AssertsCompiledSQL): def test_we_dont_call_bool(self): class NoBoolAllowed(object): - def __nonzero__(self): + def __bool__(self): raise Exception("nope") mapper(NoBoolAllowed, self.tables.users) u1 = NoBoolAllowed() @@ -1057,12 +1058,12 @@ class MapperTest(_fixtures.FixtureTest, AssertsCompiledSQL): eq_( create_session().query(User).all(), - [User(id=7, name=u'jack'), User(id=9, name=u'fred'), User(id=8, name=u'ed'), User(id=10, name=u'chuck')] + [User(id=7, name='jack'), User(id=9, name='fred'), User(id=8, name='ed'), User(id=10, name='chuck')] ) eq_( create_session().query(User).order_by(User.name).all(), - [User(id=10, name=u'chuck'), User(id=8, name=u'ed'), User(id=9, name=u'fred'), User(id=7, name=u'jack')] + [User(id=10, name='chuck'), User(id=8, name='ed'), User(id=9, name='fred'), User(id=7, name='jack')] ) # 'Raises a "expression evaluation not supported" error at prepare time @@ -2123,7 +2124,7 @@ class ValidatorTest(_fixtures.FixtureTest): mapper(Address, addresses) eq_( - dict((k, v[0].__name__) for k, v in u_m.validators.items()), + dict((k, v[0].__name__) for k, v in list(u_m.validators.items())), {'name':'validate_name', 'addresses':'validate_address'} ) @@ -2992,29 +2993,29 @@ class RequirementsTest(fixtures.MappedTest): Column('ht1b_id', Integer, ForeignKey('ht1.id'), primary_key=True), Column('value', String(10))) - # Py2K - def test_baseclass(self): - ht1 = self.tables.ht1 - - class OldStyle: - pass - - assert_raises(sa.exc.ArgumentError, mapper, OldStyle, ht1) - - assert_raises(sa.exc.ArgumentError, mapper, 123) - - class NoWeakrefSupport(str): - pass - - # TODO: is weakref support detectable without an instance? - #self.assertRaises(sa.exc.ArgumentError, mapper, NoWeakrefSupport, t2) - # end Py2K +# start Py2K +# def test_baseclass(self): +# ht1 = self.tables.ht1 +# +# class OldStyle: +# pass +# +# assert_raises(sa.exc.ArgumentError, mapper, OldStyle, ht1) +# +# assert_raises(sa.exc.ArgumentError, mapper, 123) +# +# class NoWeakrefSupport(str): +# pass +# +# # TODO: is weakref support detectable without an instance? +# #self.assertRaises(sa.exc.ArgumentError, mapper, NoWeakrefSupport, t2) +# end Py2K class _ValueBase(object): def __init__(self, value='abc', id=None): self.id = id self.value = value - def __nonzero__(self): + def __bool__(self): return False def __hash__(self): return hash(self.value) @@ -3173,7 +3174,7 @@ class RequirementsTest(fixtures.MappedTest): return self.value class H2(object): - def __nonzero__(self): + def __bool__(self): return bool(self.get_value()) def get_value(self): @@ -3224,7 +3225,7 @@ class IsUserlandTest(fixtures.MappedTest): self._test("someprop") def test_unicode(self): - self._test(u"someprop") + self._test("someprop") def test_int(self): self._test(5) diff --git a/test/orm/test_merge.py b/test/orm/test_merge.py index e1474f39b..494f5e349 100644 --- a/test/orm/test_merge.py +++ b/test/orm/test_merge.py @@ -346,7 +346,7 @@ class MergeTest(_fixtures.FixtureTest): sess = create_session() sess.merge(u1) sess.flush() - assert u1.addresses.keys() == ['foo@bar.com'] + assert list(u1.addresses.keys()) == ['foo@bar.com'] def test_attribute_cascade(self): """Merge of a persistent entity with two child @@ -803,7 +803,7 @@ class MergeTest(_fixtures.FixtureTest): try: sess2.merge(u, load=False) assert False - except sa.exc.InvalidRequestError, e: + except sa.exc.InvalidRequestError as e: assert "merge() with load=False option does not support "\ "objects marked as 'dirty'. flush() all changes on "\ "mapped instances before merging with load=False." \ @@ -924,7 +924,7 @@ class MergeTest(_fixtures.FixtureTest): sess2.expunge_all() eq_(sess2.query(User).get(u2.id).addresses[0].email_address, 'somenewaddress') - except sa.exc.InvalidRequestError, e: + except sa.exc.InvalidRequestError as e: assert "load=False option does not support" in str(e) def test_synonym_comparable(self): diff --git a/test/orm/test_naturalpks.py b/test/orm/test_naturalpks.py index d30cdc598..7a636a5a9 100644 --- a/test/orm/test_naturalpks.py +++ b/test/orm/test_naturalpks.py @@ -2,7 +2,7 @@ Primary key changing capabilities and passive/non-passive cascading updates. """ -from __future__ import with_statement + from sqlalchemy.testing import eq_, ne_, \ assert_raises, assert_raises_message import sqlalchemy as sa @@ -519,11 +519,11 @@ class ReversePKsTest(fixtures.MappedTest): session = sa.orm.sessionmaker()() - a_published = User(1, PUBLISHED, u'a') + a_published = User(1, PUBLISHED, 'a') session.add(a_published) session.commit() - a_editable = User(1, EDITABLE, u'a') + a_editable = User(1, EDITABLE, 'a') session.add(a_editable) session.commit() diff --git a/test/orm/test_pickled.py b/test/orm/test_pickled.py index 5ac34f914..b54af93f2 100644 --- a/test/orm/test_pickled.py +++ b/test/orm/test_pickled.py @@ -443,21 +443,21 @@ class TupleLabelTest(_fixtures.FixtureTest): if pickled is not False: row = pickle.loads(pickle.dumps(row, pickled)) - eq_(row.keys(), ['User', 'Address']) + eq_(list(row.keys()), ['User', 'Address']) eq_(row.User, row[0]) eq_(row.Address, row[1]) for row in sess.query(User.name, User.id.label('foobar')): if pickled is not False: row = pickle.loads(pickle.dumps(row, pickled)) - eq_(row.keys(), ['name', 'foobar']) + eq_(list(row.keys()), ['name', 'foobar']) eq_(row.name, row[0]) eq_(row.foobar, row[1]) for row in sess.query(User).values(User.name, User.id.label('foobar')): if pickled is not False: row = pickle.loads(pickle.dumps(row, pickled)) - eq_(row.keys(), ['name', 'foobar']) + eq_(list(row.keys()), ['name', 'foobar']) eq_(row.name, row[0]) eq_(row.foobar, row[1]) @@ -465,21 +465,21 @@ class TupleLabelTest(_fixtures.FixtureTest): for row in sess.query(User, oalias).join(User.orders).all(): if pickled is not False: row = pickle.loads(pickle.dumps(row, pickled)) - eq_(row.keys(), ['User']) + eq_(list(row.keys()), ['User']) eq_(row.User, row[0]) oalias = aliased(Order, name='orders') for row in sess.query(User, oalias).join(oalias, User.orders).all(): if pickled is not False: row = pickle.loads(pickle.dumps(row, pickled)) - eq_(row.keys(), ['User', 'orders']) + eq_(list(row.keys()), ['User', 'orders']) eq_(row.User, row[0]) eq_(row.orders, row[1]) # test here that first col is not labeled, only # one name in keys, matches correctly for row in sess.query(User.name + 'hoho', User.name): - eq_(row.keys(), ['name']) + eq_(list(row.keys()), ['name']) eq_(row[0], row.name + 'hoho') if pickled is not False: diff --git a/test/orm/test_query.py b/test/orm/test_query.py index 3882ec4b5..2e0355e63 100644 --- a/test/orm/test_query.py +++ b/test/orm/test_query.py @@ -407,11 +407,12 @@ class GetTest(QueryTest): Column('data', Unicode(40))) try: metadata.create_all() - # Py3K - #ustring = b'petit voix m\xe2\x80\x99a'.decode('utf-8') - # Py2K - ustring = 'petit voix m\xe2\x80\x99a'.decode('utf-8') - # end Py2K +# start Py3K + ustring = b'petit voix m\xe2\x80\x99a'.decode('utf-8') +# end Py3K +# start Py2K +# ustring = 'petit voix m\xe2\x80\x99a'.decode('utf-8') +# end Py2K table.insert().execute(id=ustring, data=ustring) class LocalFoo(self.classes.Base): @@ -637,9 +638,9 @@ class OperatorTest(QueryTest, AssertsCompiledSQL): (operator.sub, '-'), # Py3k #(operator.truediv, '/'), - # Py2K - (operator.div, '/'), - # end Py2K +# start Py2K +# (operator.div, '/'), +# end Py2K ): for (lhs, rhs, res) in ( (5, User.id, ':id_1 %s users.id'), @@ -1047,7 +1048,7 @@ class ExpressionTest(QueryTest, AssertsCompiledSQL): adalias = aliased(Address, q1.subquery()) eq_( s.query(User, adalias).join(adalias, User.id==adalias.user_id).all(), - [(User(id=7,name=u'jack'), Address(email_address=u'jack@bean.com',user_id=7,id=1))] + [(User(id=7,name='jack'), Address(email_address='jack@bean.com',user_id=7,id=1))] ) # more slice tests are available in test/orm/generative.py @@ -1196,7 +1197,7 @@ class FilterTest(QueryTest, AssertsCompiledSQL): "users.name AS users_name FROM users WHERE users.id = :param_1 " "UNION SELECT users.id AS users_id, users.name AS users_name " "FROM users WHERE users.id = :param_2) AS anon_1", - checkparams = {u'param_1': 7, u'param_2': 8} + checkparams = {'param_1': 7, 'param_2': 8} ) def test_any(self): @@ -1319,7 +1320,7 @@ class FilterTest(QueryTest, AssertsCompiledSQL): "FROM users JOIN addresses ON users.id = addresses.user_id " "WHERE users.name = :name_1 AND " "addresses.email_address = :email_address_1", - checkparams={u'email_address_1': 'ed@ed.com', u'name_1': 'ed'} + checkparams={'email_address_1': 'ed@ed.com', 'name_1': 'ed'} ) def test_filter_by_no_property(self): @@ -1468,14 +1469,14 @@ class SetOpsTest(QueryTest, AssertsCompiledSQL): for q in (q3.order_by(User.id, "anon_1_param_1"), q6.order_by(User.id, "foo")): eq_(q.all(), [ - (User(id=7, name=u'jack'), u'x'), - (User(id=7, name=u'jack'), u'y'), - (User(id=8, name=u'ed'), u'x'), - (User(id=8, name=u'ed'), u'y'), - (User(id=9, name=u'fred'), u'x'), - (User(id=9, name=u'fred'), u'y'), - (User(id=10, name=u'chuck'), u'x'), - (User(id=10, name=u'chuck'), u'y') + (User(id=7, name='jack'), 'x'), + (User(id=7, name='jack'), 'y'), + (User(id=8, name='ed'), 'x'), + (User(id=8, name='ed'), 'y'), + (User(id=9, name='fred'), 'x'), + (User(id=9, name='fred'), 'y'), + (User(id=10, name='chuck'), 'x'), + (User(id=10, name='chuck'), 'y') ] ) @@ -1603,7 +1604,7 @@ class AggregateTest(QueryTest): sess = create_session() orders = sess.query(Order).filter(Order.id.in_([2, 3, 4])) - eq_(orders.values(func.sum(Order.user_id * Order.address_id)).next(), (79,)) + eq_(next(orders.values(func.sum(Order.user_id * Order.address_id))), (79,)) eq_(orders.value(func.sum(Order.user_id * Order.address_id)), 79) def test_apply(self): @@ -1616,9 +1617,9 @@ class AggregateTest(QueryTest): User, Address = self.classes.User, self.classes.Address sess = create_session() - assert [User(name=u'ed',id=8)] == sess.query(User).order_by(User.id).group_by(User).join('addresses').having(func.count(Address.id)> 2).all() + assert [User(name='ed',id=8)] == sess.query(User).order_by(User.id).group_by(User).join('addresses').having(func.count(Address.id)> 2).all() - assert [User(name=u'jack',id=7), User(name=u'fred',id=9)] == sess.query(User).order_by(User.id).group_by(User).join('addresses').having(func.count(Address.id)< 2).all() + assert [User(name='jack',id=7), User(name='fred',id=9)] == sess.query(User).order_by(User.id).group_by(User).join('addresses').having(func.count(Address.id)< 2).all() class ExistsTest(QueryTest, AssertsCompiledSQL): @@ -1798,14 +1799,14 @@ class YieldTest(QueryTest): ret = [] eq_(len(sess.identity_map), 0) - ret.append(q.next()) - ret.append(q.next()) + ret.append(next(q)) + ret.append(next(q)) eq_(len(sess.identity_map), 2) - ret.append(q.next()) - ret.append(q.next()) + ret.append(next(q)) + ret.append(next(q)) eq_(len(sess.identity_map), 4) try: - q.next() + next(q) assert False except StopIteration: pass @@ -1915,7 +1916,7 @@ class TextTest(QueryTest): User.id, text("users.name")) eq_(s.query(User.id, "name").order_by(User.id).all(), - [(7, u'jack'), (8, u'ed'), (9, u'fred'), (10, u'chuck')]) + [(7, 'jack'), (8, 'ed'), (9, 'fred'), (10, 'chuck')]) def test_via_select(self): User = self.classes.User @@ -1973,7 +1974,7 @@ class ParentTest(QueryTest, AssertsCompiledSQL): try: q = sess.query(Item).with_parent(u1) assert False - except sa_exc.InvalidRequestError, e: + except sa_exc.InvalidRequestError as e: assert str(e) \ == "Could not locate a property which relates "\ "instances of class 'Item' to instances of class 'User'" @@ -2058,7 +2059,7 @@ class ParentTest(QueryTest, AssertsCompiledSQL): "addresses.id AS addresses_id, addresses.user_id AS " "addresses_user_id, addresses.email_address AS addresses_email_address " "FROM addresses WHERE :param_2 = addresses.user_id) AS anon_1", - checkparams={u'param_1': 7, u'param_2': 8}, + checkparams={'param_1': 7, 'param_2': 8}, ) def test_unique_binds_or(self): @@ -2075,7 +2076,7 @@ class ParentTest(QueryTest, AssertsCompiledSQL): "addresses_user_id, addresses.email_address AS " "addresses_email_address FROM addresses WHERE " ":param_1 = addresses.user_id OR :param_2 = addresses.user_id", - checkparams={u'param_1': 7, u'param_2': 8}, + checkparams={'param_1': 7, 'param_2': 8}, ) class SynonymTest(QueryTest): @@ -2117,9 +2118,9 @@ class SynonymTest(QueryTest): options(joinedload(User.orders_syn)).all() eq_(result, [ User(id=7, name='jack', orders=[ - Order(description=u'order 1'), - Order(description=u'order 3'), - Order(description=u'order 5') + Order(description='order 1'), + Order(description='order 3'), + Order(description='order 5') ]) ]) self.assert_sql_count(testing.db, go, 1) @@ -2133,9 +2134,9 @@ class SynonymTest(QueryTest): options(joinedload(User.orders_syn_2)).all() eq_(result, [ User(id=7, name='jack', orders=[ - Order(description=u'order 1'), - Order(description=u'order 3'), - Order(description=u'order 5') + Order(description='order 1'), + Order(description='order 3'), + Order(description='order 5') ]) ]) self.assert_sql_count(testing.db, go, 1) @@ -2149,9 +2150,9 @@ class SynonymTest(QueryTest): options(joinedload('orders_syn_2')).all() eq_(result, [ User(id=7, name='jack', orders=[ - Order(description=u'order 1'), - Order(description=u'order 3'), - Order(description=u'order 5') + Order(description='order 1'), + Order(description='order 3'), + Order(description='order 5') ]) ]) self.assert_sql_count(testing.db, go, 1) @@ -2355,7 +2356,7 @@ class OptionsTest(QueryTest): if isinstance(item, type): item = class_mapper(item) else: - if isinstance(item, basestring): + if isinstance(item, str): item = inspect(r[-1]).mapper.attrs[item] r.append(item) return tuple(r) diff --git a/test/orm/test_relationships.py b/test/orm/test_relationships.py index e5789eb7c..124202dcc 100644 --- a/test/orm/test_relationships.py +++ b/test/orm/test_relationships.py @@ -426,13 +426,13 @@ class CompositeSelfRefFKTest(fixtures.MappedTest): c1 = Company('c1') c2 = Company('c2') - e1 = Employee(u'emp1', c1, 1) - e2 = Employee(u'emp2', c1, 2, e1) - e3 = Employee(u'emp3', c1, 3, e1) - e4 = Employee(u'emp4', c1, 4, e3) - e5 = Employee(u'emp5', c2, 1) - e6 = Employee(u'emp6', c2, 2, e5) - e7 = Employee(u'emp7', c2, 3, e5) + e1 = Employee('emp1', c1, 1) + e2 = Employee('emp2', c1, 2, e1) + e3 = Employee('emp3', c1, 3, e1) + e4 = Employee('emp4', c1, 4, e3) + e5 = Employee('emp5', c2, 1) + e6 = Employee('emp6', c2, 2, e5) + e7 = Employee('emp7', c2, 3, e5) sess.add_all((c1, c2)) sess.commit() @@ -642,7 +642,7 @@ class FKsAsPksTest(fixtures.MappedTest): try: sess.flush() assert False - except AssertionError, e: + except AssertionError as e: startswith_(str(e), "Dependency rule tried to blank-out " "primary key column 'tableB.id' on instance ") @@ -667,7 +667,7 @@ class FKsAsPksTest(fixtures.MappedTest): try: sess.flush() assert False - except AssertionError, e: + except AssertionError as e: startswith_(str(e), "Dependency rule tried to blank-out " "primary key column 'tableB.id' on instance ") @@ -1106,9 +1106,9 @@ class AmbiguousJoinInterpretedAsSelfRef(fixtures.MappedTest): eq_( sess.query(Subscriber).order_by(Subscriber.type).all(), [ - Subscriber(id=1, type=u'A'), - Subscriber(id=2, type=u'B'), - Subscriber(id=2, type=u'C') + Subscriber(id=1, type='A'), + Subscriber(id=2, type='B'), + Subscriber(id=2, type='C') ] ) @@ -1365,7 +1365,7 @@ class TypeMatchTest(fixtures.MappedTest): try: sess.add(a1) assert False - except AssertionError, err: + except AssertionError as err: eq_(str(err), "Attribute 'bs' on class '%s' doesn't handle " "objects of type '%s'" % (A, C)) diff --git a/test/orm/test_session.py b/test/orm/test_session.py index 7c2e8a3b8..45164483b 100644 --- a/test/orm/test_session.py +++ b/test/orm/test_session.py @@ -232,7 +232,7 @@ class ExecutionTest(_fixtures.FixtureTest): # use :bindparam style eq_(sess.execute("select * from users where id=:id", {'id': 7}).fetchall(), - [(7, u'jack')]) + [(7, 'jack')]) # use :bindparam style @@ -733,7 +733,7 @@ class SessionStateTest(_fixtures.FixtureTest): # withstand a change? should this be # more directly attempting to manipulate the identity_map ? u1, u2, u3 = sess.query(User).all() - for i, (key, value) in enumerate(sess.identity_map.iteritems()): + for i, (key, value) in enumerate(iter(sess.identity_map.items())): if i == 2: del u3 gc_collect() @@ -747,7 +747,7 @@ class SessionStateTest(_fixtures.FixtureTest): @event.listens_for(m, "after_update") def e(mapper, conn, target): sess = object_session(target) - for entry in sess.identity_map.values(): + for entry in list(sess.identity_map.values()): entry.name = "5" a1, a2 = User(name="1"), User(name="2") @@ -845,7 +845,7 @@ class SessionStateWFixtureTest(_fixtures.FixtureTest): u = session.query(User).filter_by(id=7).one() # get everything to load in both directions - print [a.user for a in u.addresses] + print([a.user for a in u.addresses]) # then see if expunge fails session.expunge(u) @@ -1187,7 +1187,7 @@ class StrongIdentityMapTest(_fixtures.FixtureTest): s.flush() user = s.query(User).one() user = None - print s.identity_map + print(s.identity_map) gc_collect() assert len(s.identity_map) == 1 @@ -1207,7 +1207,7 @@ class StrongIdentityMapTest(_fixtures.FixtureTest): s = create_session(weak_identity_map=False) mapper(User, users) - for o in [User(name='u%s' % x) for x in xrange(10)]: + for o in [User(name='u%s' % x) for x in range(10)]: s.add(o) # o is still live after this loop... diff --git a/test/orm/test_subquery_relations.py b/test/orm/test_subquery_relations.py index 3ee94cae9..d493e0b7e 100644 --- a/test/orm/test_subquery_relations.py +++ b/test/orm/test_subquery_relations.py @@ -1552,9 +1552,9 @@ class CyclicalInheritingEagerTestTwo(fixtures.DeclarativeMappedTest, Movie = self.classes.Movie session = Session(testing.db) - rscott = Director(name=u"Ridley Scott") - alien = Movie(title=u"Alien") - brunner = Movie(title=u"Blade Runner") + rscott = Director(name="Ridley Scott") + alien = Movie(title="Alien") + brunner = Movie(title="Blade Runner") rscott.movies.append(brunner) rscott.movies.append(alien) session.add_all([rscott, alien, brunner]) diff --git a/test/orm/test_unitofwork.py b/test/orm/test_unitofwork.py index 6be1672e1..1675ed60f 100644 --- a/test/orm/test_unitofwork.py +++ b/test/orm/test_unitofwork.py @@ -87,7 +87,7 @@ class UnicodeTest(fixtures.MappedTest): mapper(Test, uni_t1) - txt = u"\u0160\u0110\u0106\u010c\u017d" + txt = "\u0160\u0110\u0106\u010c\u017d" t1 = Test(id=1, txt=txt) self.assert_(t1.txt == txt) @@ -107,7 +107,7 @@ class UnicodeTest(fixtures.MappedTest): 't2s': relationship(Test2)}) mapper(Test2, uni_t2) - txt = u"\u0160\u0110\u0106\u010c\u017d" + txt = "\u0160\u0110\u0106\u010c\u017d" t1 = Test(txt=txt) t1.t2s.append(Test2()) t1.t2s.append(Test2()) @@ -132,16 +132,16 @@ class UnicodeSchemaTest(fixtures.MappedTest): @classmethod def define_tables(cls, metadata): t1 = Table('unitable1', metadata, - Column(u'méil', Integer, primary_key=True, key='a', test_needs_autoincrement=True), - Column(u'\u6e2c\u8a66', Integer, key='b'), + Column('méil', Integer, primary_key=True, key='a', test_needs_autoincrement=True), + Column('\u6e2c\u8a66', Integer, key='b'), Column('type', String(20)), test_needs_fk=True, test_needs_autoincrement=True) - t2 = Table(u'Unitéble2', metadata, - Column(u'méil', Integer, primary_key=True, key="cc", test_needs_autoincrement=True), - Column(u'\u6e2c\u8a66', Integer, - ForeignKey(u'unitable1.a'), key="d"), - Column(u'\u6e2c\u8a66_2', Integer, key="e"), + t2 = Table('Unitéble2', metadata, + Column('méil', Integer, primary_key=True, key="cc", test_needs_autoincrement=True), + Column('\u6e2c\u8a66', Integer, + ForeignKey('unitable1.a'), key="d"), + Column('\u6e2c\u8a66_2', Integer, key="e"), test_needs_fk=True, test_needs_autoincrement=True) @@ -238,11 +238,12 @@ class BinaryHistTest(fixtures.MappedTest, testing.AssertsExecutionResults): Foo, t1 = self.classes.Foo, self.tables.t1 - # Py3K - #data = b"this is some data" - # Py2K - data = "this is some data" - # end Py2K +# start Py3K + data = b"this is some data" +# end Py3K +# start Py2K +# data = "this is some data" +# end Py2K mapper(Foo, t1) @@ -1054,13 +1055,13 @@ class OneToManyTest(_fixtures.FixtureTest): session.flush() user_rows = users.select(users.c.id.in_([u.id])).execute().fetchall() - eq_(user_rows[0].values(), [u.id, 'one2manytester']) + eq_(list(user_rows[0].values()), [u.id, 'one2manytester']) address_rows = addresses.select( addresses.c.id.in_([a.id, a2.id]), order_by=[addresses.c.email_address]).execute().fetchall() - eq_(address_rows[0].values(), [a2.id, u.id, 'lala@test.org']) - eq_(address_rows[1].values(), [a.id, u.id, 'one2many@test.org']) + eq_(list(address_rows[0].values()), [a2.id, u.id, 'lala@test.org']) + eq_(list(address_rows[1].values()), [a.id, u.id, 'one2many@test.org']) userid = u.id addressid = a2.id @@ -1071,7 +1072,7 @@ class OneToManyTest(_fixtures.FixtureTest): address_rows = addresses.select( addresses.c.id == addressid).execute().fetchall() - eq_(address_rows[0].values(), + eq_(list(address_rows[0].values()), [addressid, userid, 'somethingnew@foo.com']) self.assert_(u.id == userid and a2.id == addressid) @@ -1501,18 +1502,18 @@ class SaveTest(_fixtures.FixtureTest): assert u.name == 'multitester' user_rows = users.select(users.c.id.in_([u.foo_id])).execute().fetchall() - eq_(user_rows[0].values(), [u.foo_id, 'multitester']) + eq_(list(user_rows[0].values()), [u.foo_id, 'multitester']) address_rows = addresses.select(addresses.c.id.in_([u.id])).execute().fetchall() - eq_(address_rows[0].values(), [u.id, u.foo_id, 'multi@test.org']) + eq_(list(address_rows[0].values()), [u.id, u.foo_id, 'multi@test.org']) u.email = 'lala@hey.com' u.name = 'imnew' session.flush() user_rows = users.select(users.c.id.in_([u.foo_id])).execute().fetchall() - eq_(user_rows[0].values(), [u.foo_id, 'imnew']) + eq_(list(user_rows[0].values()), [u.foo_id, 'imnew']) address_rows = addresses.select(addresses.c.id.in_([u.id])).execute().fetchall() - eq_(address_rows[0].values(), [u.id, u.foo_id, 'lala@hey.com']) + eq_(list(address_rows[0].values()), [u.id, u.foo_id, 'lala@hey.com']) session.expunge_all() u = session.query(User).get(id) @@ -1650,7 +1651,7 @@ class ManyToOneTest(_fixtures.FixtureTest): l = sa.select([users, addresses], sa.and_(users.c.id==addresses.c.user_id, addresses.c.id==a.id)).execute() - eq_(l.first().values(), + eq_(list(l.first().values()), [a.user.id, 'asdf8d', a.id, a.user_id, 'theater@foo.com']) def test_many_to_one_1(self): @@ -2127,7 +2128,7 @@ class SaveTest3(fixtures.MappedTest): assert assoc.count().scalar() == 2 i.keywords = [] - print i.keywords + print(i.keywords) session.flush() assert assoc.count().scalar() == 0 diff --git a/test/orm/test_unitofworkv2.py b/test/orm/test_unitofworkv2.py index 7c7337c62..34648c256 100644 --- a/test/orm/test_unitofworkv2.py +++ b/test/orm/test_unitofworkv2.py @@ -26,7 +26,7 @@ class AssertsUOW(object): def _assert_uow_size(self, session, expected ): uow = self._get_test_uow(session) postsort_actions = uow._generate_actions() - print postsort_actions + print(postsort_actions) eq_(len(postsort_actions), expected, postsort_actions) class UOWTest(_fixtures.FixtureTest, @@ -125,12 +125,12 @@ class RudimentaryFlushTest(UOWTest): CompiledSQL( "UPDATE addresses SET user_id=:user_id WHERE " "addresses.id = :addresses_id", - lambda ctx: [{u'addresses_id': a1.id, 'user_id': None}] + lambda ctx: [{'addresses_id': a1.id, 'user_id': None}] ), CompiledSQL( "UPDATE addresses SET user_id=:user_id WHERE " "addresses.id = :addresses_id", - lambda ctx: [{u'addresses_id': a2.id, 'user_id': None}] + lambda ctx: [{'addresses_id': a2.id, 'user_id': None}] ), CompiledSQL( "DELETE FROM users WHERE users.id = :id", @@ -235,12 +235,12 @@ class RudimentaryFlushTest(UOWTest): CompiledSQL( "UPDATE addresses SET user_id=:user_id WHERE " "addresses.id = :addresses_id", - lambda ctx: [{u'addresses_id': a1.id, 'user_id': None}] + lambda ctx: [{'addresses_id': a1.id, 'user_id': None}] ), CompiledSQL( "UPDATE addresses SET user_id=:user_id WHERE " "addresses.id = :addresses_id", - lambda ctx: [{u'addresses_id': a2.id, 'user_id': None}] + lambda ctx: [{'addresses_id': a2.id, 'user_id': None}] ), CompiledSQL( "DELETE FROM users WHERE users.id = :id", @@ -1149,7 +1149,7 @@ class SingleCycleM2MTest(fixtures.MappedTest, "nodes, node_to_nodes WHERE :param_1 = " "node_to_nodes.right_node_id AND nodes.id = " "node_to_nodes.left_node_id" , - lambda ctx:{u'param_1': n1.id}, + lambda ctx:{'param_1': n1.id}, ), CompiledSQL( "DELETE FROM node_to_nodes WHERE " diff --git a/test/orm/test_update_delete.py b/test/orm/test_update_delete.py index 65d69538e..6915ac8a2 100644 --- a/test/orm/test_update_delete.py +++ b/test/orm/test_update_delete.py @@ -188,22 +188,22 @@ class UpdateDeleteTest(fixtures.MappedTest): update({'age': User.age - 10}, synchronize_session='evaluate') eq_([john.age, jack.age, jill.age, jane.age], [25,37,29,27]) - eq_(sess.query(User.age).order_by(User.id).all(), zip([25,37,29,27])) + eq_(sess.query(User.age).order_by(User.id).all(), list(zip([25,37,29,27]))) sess.query(User).filter(User.age > 29).\ update({User.age: User.age - 10}, synchronize_session='evaluate') eq_([john.age, jack.age, jill.age, jane.age], [25,27,29,27]) - eq_(sess.query(User.age).order_by(User.id).all(), zip([25,27,29,27])) + eq_(sess.query(User.age).order_by(User.id).all(), list(zip([25,27,29,27]))) sess.query(User).filter(User.age > 27).\ update({users.c.age: User.age - 10}, synchronize_session='evaluate') eq_([john.age, jack.age, jill.age, jane.age], [25,27,19,27]) - eq_(sess.query(User.age).order_by(User.id).all(), zip([25,27,19,27])) + eq_(sess.query(User.age).order_by(User.id).all(), list(zip([25,27,19,27]))) sess.query(User).filter(User.age == 25).\ update({User.age: User.age - 10}, synchronize_session='fetch') eq_([john.age, jack.age, jill.age, jane.age], [15,27,19,27]) - eq_(sess.query(User.age).order_by(User.id).all(), zip([15,27,19,27])) + eq_(sess.query(User.age).order_by(User.id).all(), list(zip([15,27,19,27]))) def test_update_against_metadata(self): User, users = self.classes.User, self.tables.users @@ -211,7 +211,7 @@ class UpdateDeleteTest(fixtures.MappedTest): sess = Session() sess.query(users).update({users.c.age: 29}, synchronize_session=False) - eq_(sess.query(User.age).order_by(User.id).all(), zip([29,29,29,29])) + eq_(sess.query(User.age).order_by(User.id).all(), list(zip([29,29,29,29]))) def test_update_with_bindparams(self): User = self.classes.User @@ -224,7 +224,7 @@ class UpdateDeleteTest(fixtures.MappedTest): update({'age': User.age - 10}, synchronize_session='fetch') eq_([john.age, jack.age, jill.age, jane.age], [25,37,29,27]) - eq_(sess.query(User.age).order_by(User.id).all(), zip([25,37,29,27])) + eq_(sess.query(User.age).order_by(User.id).all(), list(zip([25,37,29,27]))) def test_update_without_load(self): User = self.classes.User @@ -233,7 +233,7 @@ class UpdateDeleteTest(fixtures.MappedTest): sess.query(User).filter(User.id == 3).\ update({'age': 44}, synchronize_session='fetch') - eq_(sess.query(User.age).order_by(User.id).all(), zip([25,47,44,37])) + eq_(sess.query(User.age).order_by(User.id).all(), list(zip([25,47,44,37]))) def test_update_changes_resets_dirty(self): User = self.classes.User @@ -300,7 +300,7 @@ class UpdateDeleteTest(fixtures.MappedTest): update({'age': User.age - 10}, synchronize_session='fetch') eq_([john.age, jack.age, jill.age, jane.age], [25,37,29,27]) - eq_(sess.query(User.age).order_by(User.id).all(), zip([25,37,29,27])) + eq_(sess.query(User.age).order_by(User.id).all(), list(zip([25,37,29,27]))) @testing.fails_if(lambda: not testing.db.dialect.supports_sane_rowcount) def test_update_returns_rowcount(self): @@ -334,7 +334,7 @@ class UpdateDeleteTest(fixtures.MappedTest): sess.query(User).update({'age': 42}, synchronize_session='evaluate') eq_([john.age, jack.age, jill.age, jane.age], [42,42,42,42]) - eq_(sess.query(User.age).order_by(User.id).all(), zip([42,42,42,42])) + eq_(sess.query(User.age).order_by(User.id).all(), list(zip([42,42,42,42]))) def test_delete_all(self): User = self.classes.User @@ -516,7 +516,7 @@ class UpdateDeleteIgnoresLoadersTest(fixtures.MappedTest): eq_([foo.title, bar.title, baz.title], ['foofoo','barbar', 'baz']) eq_(sess.query(Document.title).order_by(Document.id).all(), - zip(['foofoo','barbar', 'baz'])) + list(zip(['foofoo','barbar', 'baz']))) def test_update_with_explicit_joinedload(self): User = self.classes.User @@ -528,7 +528,7 @@ class UpdateDeleteIgnoresLoadersTest(fixtures.MappedTest): update({'age': User.age - 10}, synchronize_session='fetch') eq_([john.age, jack.age, jill.age, jane.age], [25,37,29,27]) - eq_(sess.query(User.age).order_by(User.id).all(), zip([25,37,29,27])) + eq_(sess.query(User.age).order_by(User.id).all(), list(zip([25,37,29,27]))) def test_delete_with_eager_relationships(self): Document = self.classes.Document @@ -538,7 +538,7 @@ class UpdateDeleteIgnoresLoadersTest(fixtures.MappedTest): sess.query(Document).filter(Document.user_id == 1).\ delete(synchronize_session=False) - eq_(sess.query(Document.title).all(), zip(['baz'])) + eq_(sess.query(Document.title).all(), list(zip(['baz']))) class UpdateDeleteFromTest(fixtures.MappedTest): @classmethod diff --git a/test/orm/test_utils.py b/test/orm/test_utils.py index b2853a8b8..e0059eef9 100644 --- a/test/orm/test_utils.py +++ b/test/orm/test_utils.py @@ -52,10 +52,10 @@ class AliasedClassTest(fixtures.TestBase): alias = aliased(Point) assert Point.zero - # Py2K - # TODO: what is this testing ?? - assert not getattr(alias, 'zero') - # end Py2K +# start Py2K +# # TODO: what is this testing ?? +# assert not getattr(alias, 'zero') +# end Py2K def test_classmethods(self): class Point(object): @@ -123,17 +123,19 @@ class AliasedClassTest(fixtures.TestBase): self.func = func def __get__(self, instance, owner): if instance is None: - # Py3K - #args = (self.func, owner) - # Py2K - args = (self.func, owner, owner.__class__) - # end Py2K +# start Py3K + args = (self.func, owner) +# end Py3K +# start Py2K +# args = (self.func, owner, owner.__class__) +# end Py2K else: - # Py3K - #args = (self.func, instance) - # Py2K - args = (self.func, instance, owner) - # end Py2K +# start Py3K + args = (self.func, instance) +# end Py3K +# start Py2K +# args = (self.func, instance, owner) +# end Py2K return types.MethodType(*args) class PropertyDescriptor(object): diff --git a/test/perf/insertspeed.py b/test/perf/insertspeed.py index 03d2c4144..88e73fef9 100644 --- a/test/perf/insertspeed.py +++ b/test/perf/insertspeed.py @@ -13,18 +13,18 @@ Person_table = Table('Person', metadata, def sa_unprofiled_insertmany(n): i = Person_table.insert() - i.execute([{'name':'John Doe','sex':1,'age':35} for j in xrange(n)]) + i.execute([{'name':'John Doe','sex':1,'age':35} for j in range(n)]) def sqlite_unprofiled_insertmany(n): conn = db.connect().connection c = conn.cursor() - persons = [('john doe', 1, 35) for i in xrange(n)] + persons = [('john doe', 1, 35) for i in range(n)] c.executemany("insert into Person(name, sex, age) values (?,?,?)", persons) @profiling.profiled('sa_profiled_insert_many', always=True) def sa_profiled_insert_many(n): i = Person_table.insert() - i.execute([{'name':'John Doe','sex':1,'age':35} for j in xrange(n)]) + i.execute([{'name':'John Doe','sex':1,'age':35} for j in range(n)]) s = Person_table.select() r = s.execute() res = [[value for value in row] for row in r.fetchall()] @@ -32,7 +32,7 @@ def sa_profiled_insert_many(n): def sqlite_unprofiled_insert(n): conn = db.connect().connection c = conn.cursor() - for j in xrange(n): + for j in range(n): c.execute("insert into Person(name, sex, age) values (?,?,?)", ('john doe', 1, 35)) @@ -40,13 +40,13 @@ def sa_unprofiled_insert(n): # Another option is to build Person_table.insert() outside of the # loop. But it doesn't make much of a difference, so might as well # use the worst-case/naive version here. - for j in xrange(n): + for j in range(n): Person_table.insert().execute({'name':'John Doe','sex':1,'age':35}) @profiling.profiled('sa_profiled_insert', always=True) def sa_profiled_insert(n): i = Person_table.insert() - for j in xrange(n): + for j in range(n): i.execute({'name':'John Doe','sex':1,'age':35}) s = Person_table.select() r = s.execute() @@ -69,12 +69,12 @@ def run_profiled(fn, label, *args, **kw): metadata.drop_all() metadata.create_all() - print "%s (%s)" % (label, ', '.join([str(a) for a in args])) + print("%s (%s)" % (label, ', '.join([str(a) for a in args]))) fn(*args, **kw) def all(): try: - print "Bulk INSERTS via executemany():\n" + print("Bulk INSERTS via executemany():\n") run_timed(sqlite_unprofiled_insertmany, 'pysqlite bulk insert', @@ -88,7 +88,7 @@ def all(): 'SQLAlchemy bulk insert/select, profiled', 50000) - print "\nIndividual INSERTS via execute():\n" + print("\nIndividual INSERTS via execute():\n") run_timed(sqlite_unprofiled_insert, "pysqlite individual insert", diff --git a/test/perf/objselectspeed.py b/test/perf/objselectspeed.py index c0ed88444..dc790ab17 100644 --- a/test/perf/objselectspeed.py +++ b/test/perf/objselectspeed.py @@ -36,7 +36,7 @@ def setup(): metadata.create_all() i = Person_table.insert() data = [{'name':'John Doe','sex':1,'age':35, 'type':'employee'}] * 100 - for j in xrange(500): + for j in range(500): i.execute(data) # note we arent fetching from employee_table, @@ -46,7 +46,7 @@ def setup(): #for j in xrange(500): # i.execute(data) - print "Inserted 50,000 rows" + print("Inserted 50,000 rows") def sqlite_select(entity_cls): conn = db.connect().connection @@ -89,10 +89,10 @@ def all(): t, t2 = 0, 0 def usage(label): now = resource.getrusage(resource.RUSAGE_SELF) - print "%s: %0.3fs real, %0.3fs user, %0.3fs sys" % ( + print("%s: %0.3fs real, %0.3fs user, %0.3fs sys" % ( label, t2 - t, now.ru_utime - usage.last.ru_utime, - now.ru_stime - usage.last.ru_stime) + now.ru_stime - usage.last.ru_stime)) usage.snap(now) usage.snap = lambda stats=None: setattr( usage, 'last', stats or resource.getrusage(resource.RUSAGE_SELF)) diff --git a/test/perf/objupdatespeed.py b/test/perf/objupdatespeed.py index 98d10180e..95a5fbc9b 100644 --- a/test/perf/objupdatespeed.py +++ b/test/perf/objupdatespeed.py @@ -39,12 +39,12 @@ def setup(): i.execute(data) i = Email_table.insert() - for j in xrange(1, NUM + 1): + for j in range(1, NUM + 1): i.execute(address='foo@bar', person_id=j) if j % 2: i.execute(address='baz@quux', person_id=j) - print "Inserted %d rows." % (NUM + NUM + (NUM // 2)) + print("Inserted %d rows." % (NUM + NUM + (NUM // 2))) def orm_select(session): return session.query(Person).all() @@ -63,10 +63,10 @@ def all(): t, t2 = 0, 0 def usage(label): now = resource.getrusage(resource.RUSAGE_SELF) - print "%s: %0.3fs real, %0.3fs user, %0.3fs sys" % ( + print("%s: %0.3fs real, %0.3fs user, %0.3fs sys" % ( label, t2 - t, now.ru_utime - usage.last.ru_utime, - now.ru_stime - usage.last.ru_stime) + now.ru_stime - usage.last.ru_stime)) usage.snap(now) usage.snap = lambda stats=None: setattr( usage, 'last', stats or resource.getrusage(resource.RUSAGE_SELF)) diff --git a/test/perf/orm2010.py b/test/perf/orm2010.py index 47257ba87..937e6ddff 100644 --- a/test/perf/orm2010.py +++ b/test/perf/orm2010.py @@ -95,7 +95,7 @@ def runit(): name="Boss %d" % i, golf_average=Decimal(random.randint(40, 150)) ) - for i in xrange(1000) + for i in range(1000) ] sess.add_all(bosses) @@ -107,7 +107,7 @@ def runit(): name="Grunt %d" % i, savings=Decimal(random.randint(5000000, 15000000) / 100) ) - for i in xrange(10000) + for i in range(10000) ] # Assign each Grunt a Boss. Look them up in the DB @@ -149,15 +149,15 @@ stats = pstats.Stats(filename) counts_by_methname = dict((key[2], stats.stats[key][0]) for key in stats.stats) -print "SQLA Version: %s" % __version__ -print "Total calls %d" % stats.total_calls -print "Total cpu seconds: %.2f" % stats.total_tt -print 'Total execute calls: %d' \ +print("SQLA Version: %s" % __version__) +print("Total calls %d" % stats.total_calls) +print("Total cpu seconds: %.2f" % stats.total_tt) +print('Total execute calls: %d' \ % counts_by_methname[""] -print 'Total executemany calls: %d' \ + "objects>"]) +print('Total executemany calls: %d' \ % counts_by_methname.get("", 0) + "objects>", 0)) #stats.sort_stats('time', 'calls') #stats.print_stats() diff --git a/test/perf/ormsession.py b/test/perf/ormsession.py index 5e38d6e80..2fc656117 100644 --- a/test/perf/ormsession.py +++ b/test/perf/ormsession.py @@ -81,9 +81,9 @@ def insert_data(): transaction = con.begin() data, subdata = [], [] - for item_id in xrange(1, q_items + 1): + for item_id in range(1, q_items + 1): data.append({'name': "item number %s" % item_id}) - for subitem_id in xrange(1, (item_id % q_sub_per_item) + 1): + for subitem_id in range(1, (item_id % q_sub_per_item) + 1): subdata.append({'item_id': item_id, 'name': "subitem number %s" % subitem_id}) if item_id % 100 == 0: @@ -99,7 +99,7 @@ def insert_data(): transaction = con.begin() data = [] - for customer_id in xrange(1, q_customers): + for customer_id in range(1, q_customers): data.append({'name': "customer number %s" % customer_id}) if customer_id % 100 == 0: customers.insert().execute(*data) @@ -111,7 +111,7 @@ def insert_data(): transaction = con.begin() data, subdata = [], [] order_t = int(time.time()) - (5000 * 5 * 60) - current = xrange(1, q_customers) + current = range(1, q_customers) step, purchase_id = 1, 0 while current: next = [] diff --git a/test/perf/stress_all.py b/test/perf/stress_all.py index 890ef24a3..b2e034e7d 100644 --- a/test/perf/stress_all.py +++ b/test/perf/stress_all.py @@ -2,7 +2,7 @@ from datetime import * import decimal #from fastdec import mpd as Decimal -from cPickle import dumps, loads +from pickle import dumps, loads #from sqlalchemy.dialects.postgresql.base import ARRAY @@ -42,9 +42,9 @@ def getitem_int_results(raw_results): def getitem_long_results(raw_results): return [ - (r[0L], - r[1L], r[2L], r[3L], r[4L], r[5L], - r[6L], r[7L], r[8L], r[9L], r[10L]) + (r[0], + r[1], r[2], r[3], r[4], r[5], + r[6], r[7], r[8], r[9], r[10]) for r in raw_results] def getitem_obj_results(raw_results): @@ -128,7 +128,7 @@ typedecoratortest = (MyIntType, genmyintvalue, # Unicode def genunicodevalue(rnum, fnum): - return (rnum % 4) and (u"value%d" % fnum) or None + return (rnum % 4) and ("value%d" % fnum) or None unicodetest = (Unicode(20, ), genunicodevalue, dict(num_records=100000)) # dict(engineurl='mysql:///test', freshdata=False)) @@ -139,10 +139,10 @@ if test_types: pickletypetest, typedecoratortest, unicodetest] for engineurl in ('postgresql://scott:tiger@localhost/test', 'sqlite://', 'mysql://scott:tiger@localhost/test'): - print "\n%s\n" % engineurl + print("\n%s\n" % engineurl) for datatype, genvalue, kwargs in tests: - print "%s:" % getattr(datatype, '__name__', - datatype.__class__.__name__), + print("%s:" % getattr(datatype, '__name__', + datatype.__class__.__name__), end=' ') profile_and_time_dbfunc(iter_results, datatype, genvalue, profile=False, engineurl=engineurl, verbose=verbose, **kwargs) @@ -158,13 +158,13 @@ if test_methods: slice_results] for engineurl in ('postgresql://scott:tiger@localhost/test', 'sqlite://', 'mysql://scott:tiger@localhost/test'): - print "\n%s\n" % engineurl + print("\n%s\n" % engineurl) test_table = prepare(Unicode(20,), genunicodevalue, num_fields=10, num_records=100000, verbose=verbose, engineurl=engineurl) for method in methods: - print "%s:" % method.__name__, + print("%s:" % method.__name__, end=' ') time_dbfunc(test_table, method, genunicodevalue, num_fields=10, num_records=100000, profile=False, verbose=verbose) @@ -174,9 +174,9 @@ if test_methods: # -------------------------------- def pickletofile_results(raw_results): - from cPickle import dump, load + from pickle import dump, load for protocol in (0, 1, 2): - print "dumping protocol %d..." % protocol + print("dumping protocol %d..." % protocol) f = file('noext.pickle%d' % protocol, 'wb') dump(raw_results, f, protocol) f.close() @@ -198,7 +198,7 @@ if test_pickle: num_fields=10, num_records=10000) funcs = [pickle_rows, pickle_results] for func in funcs: - print "%s:" % func.__name__, + print("%s:" % func.__name__, end=' ') time_dbfunc(test_table, func, genunicodevalue, num_records=10000, profile=False, verbose=verbose) @@ -217,9 +217,9 @@ if test_orm: def get_results(): return session.query(Test).all() - print "ORM:", + print("ORM:", end=' ') for engineurl in ('postgresql:///test', 'sqlite://', 'mysql:///test'): - print "\n%s\n" % engineurl + print("\n%s\n" % engineurl) profile_and_time_dbfunc(getattr_results, Unicode(20), genunicodevalue, class_=Test, getresults_func=get_results, engineurl=engineurl, #freshdata=False, diff --git a/test/perf/stresstest.py b/test/perf/stresstest.py index cf9404f53..ca7c1da4f 100644 --- a/test/perf/stresstest.py +++ b/test/perf/stresstest.py @@ -17,13 +17,13 @@ def gen_table(num_fields, field_type, metadata): def insert(test_table, num_fields, num_records, genvalue, verbose=True): if verbose: - print "building insert values...", + print("building insert values...", end=' ') sys.stdout.flush() values = [dict(("field%d" % fnum, genvalue(rnum, fnum)) for fnum in range(num_fields)) for rnum in range(num_records)] if verbose: - print "inserting...", + print("inserting...", end=' ') sys.stdout.flush() def db_insert(): test_table.insert().execute(values) @@ -32,11 +32,11 @@ def insert(test_table, num_fields, num_records, genvalue, verbose=True): "from __main__ import db_insert", number=1) if verbose: - print "%s" % round(timing, 3) + print("%s" % round(timing, 3)) def check_result(results, num_fields, genvalue, verbose=True): if verbose: - print "checking...", + print("checking...", end=' ') sys.stdout.flush() for rnum, row in enumerate(results): expected = tuple([rnum + 1] + @@ -49,28 +49,28 @@ def avgdev(values, comparison): def nicer_res(values, printvalues=False): if printvalues: - print values + print(values) min_time = min(values) return round(min_time, 3), round(avgdev(values, min_time), 2) def profile_func(func_name, verbose=True): if verbose: - print "profiling...", + print("profiling...", end=' ') sys.stdout.flush() cProfile.run('%s()' % func_name, 'prof') def time_func(func_name, num_tests=1, verbose=True): if verbose: - print "timing...", + print("timing...", end=' ') sys.stdout.flush() timings = timeit.repeat('%s()' % func_name, "from __main__ import %s" % func_name, number=num_tests, repeat=5) avg, dev = nicer_res(timings) if verbose: - print "%s (%s)" % (avg, dev) + print("%s (%s)" % (avg, dev)) else: - print avg + print(avg) def profile_and_time(func_name, num_tests=1): profile_func(func_name) @@ -121,7 +121,7 @@ def time_dbfunc(test_table, test_func, genvalue, check_results=check_result, profile=True, check_leaks=True, print_leaks=False, verbose=True): if verbose: - print "testing '%s'..." % test_func.__name__, + print("testing '%s'..." % test_func.__name__, end=' ') sys.stdout.flush() if class_ is not None: clear_mappers() @@ -148,12 +148,12 @@ def time_dbfunc(test_table, test_func, genvalue, diff = hashable_objects_after - hashable_objects_before ldiff = len(diff) if print_leaks and ldiff < num_records: - print "\n*** hashable objects leaked (%d) ***" % ldiff - print '\n'.join(map(str, diff)) - print "***\n" + print("\n*** hashable objects leaked (%d) ***" % ldiff) + print('\n'.join(map(str, diff))) + print("***\n") if num_leaks > num_records: - print "(leaked: %d !)" % num_leaks, + print("(leaked: %d !)" % num_leaks, end=' ') if profile: profile_func('test', verbose) time_func('test', num_tests, verbose) diff --git a/test/perf/threaded_compile.py b/test/perf/threaded_compile.py index 0facf0ec2..23474a1c6 100644 --- a/test/perf/threaded_compile.py +++ b/test/perf/threaded_compile.py @@ -4,7 +4,7 @@ collection is being compiled.""" from sqlalchemy import * from sqlalchemy.orm import * -import thread, time +import _thread, time from sqlalchemy.orm import mapperlib @@ -42,20 +42,20 @@ class FakeLock(object): def run1(): for i in range(50): - print "T1", thread.get_ident() + print("T1", _thread.get_ident()) class_mapper(T1) time.sleep(.05) def run2(): for i in range(50): - print "T2", thread.get_ident() + print("T2", _thread.get_ident()) class_mapper(T2) time.sleep(.057) def run3(): for i in range(50): def foo(): - print "FOO", thread.get_ident() + print("FOO", _thread.get_ident()) class Foo(object):pass mapper(Foo, t3) class_mapper(Foo).compile() @@ -64,12 +64,12 @@ def run3(): mapper(T1, t1, properties={'t2':relationship(T2, backref="t1")}) mapper(T2, t2) -print "START" +print("START") for j in range(0, 5): - thread.start_new_thread(run1, ()) - thread.start_new_thread(run2, ()) - thread.start_new_thread(run3, ()) - thread.start_new_thread(run3, ()) - thread.start_new_thread(run3, ()) -print "WAIT" + _thread.start_new_thread(run1, ()) + _thread.start_new_thread(run2, ()) + _thread.start_new_thread(run3, ()) + _thread.start_new_thread(run3, ()) + _thread.start_new_thread(run3, ()) +print("WAIT") time.sleep(5) diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index 9cd893c1a..329d7543e 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -661,13 +661,13 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): s = select([table1.c.myid]).as_scalar() try: s.c.foo - except exc.InvalidRequestError, err: + except exc.InvalidRequestError as err: assert str(err) \ == 'Scalar Select expression has no columns; use this '\ 'object directly within a column-level expression.' try: s.columns.foo - except exc.InvalidRequestError, err: + except exc.InvalidRequestError as err: assert str(err) \ == 'Scalar Select expression has no columns; use this '\ 'object directly within a column-level expression.' @@ -1116,9 +1116,9 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): # test unicode self.assert_compile(select( - [u"foobar(a)", u"pk_foo_bar(syslaal)"], - u"a = 12", - from_obj=[u"foobar left outer join lala on foobar.foo = lala.foo"] + ["foobar(a)", "pk_foo_bar(syslaal)"], + "a = 12", + from_obj=["foobar left outer join lala on foobar.foo = lala.foo"] ), "SELECT foobar(a), pk_foo_bar(syslaal) FROM foobar " "left outer join lala on foobar.foo = lala.foo WHERE a = 12" @@ -2245,7 +2245,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): func.lala(table1.c.name).label('gg')]) eq_( - s1.c.keys(), + list(s1.c.keys()), ['myid', 'foobar', str(f1), 'gg'] ) @@ -2273,7 +2273,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): t = table1 s1 = select([col], from_obj=t) - assert s1.c.keys() == [key], s1.c.keys() + assert list(s1.c.keys()) == [key], list(s1.c.keys()) if label: self.assert_compile(s1, @@ -2679,11 +2679,11 @@ class DDLTest(fixtures.TestBase, AssertsCompiledSQL): def test_reraise_of_column_spec_issue_unicode(self): MyType = self._illegal_type_fixture() t1 = Table('t', MetaData(), - Column(u'méil', MyType()) + Column('méil', MyType()) ) assert_raises_message( exc.CompileError, - ur"\(in table 't', column 'méil'\): Couldn't compile type", + r"\(in table 't', column 'méil'\): Couldn't compile type", schema.CreateTable(t1).compile ) diff --git a/test/sql/test_defaults.py b/test/sql/test_defaults.py index 1c31314d8..38c56f8be 100644 --- a/test/sql/test_defaults.py +++ b/test/sql/test_defaults.py @@ -600,7 +600,7 @@ class AutoIncrementTest(fixtures.TablesTest): nonai.insert().execute(data='row 1') nonai.insert().execute(data='row 2') assert False - except sa.exc.DBAPIError, e: + except sa.exc.DBAPIError as e: assert True nonai.insert().execute(id=1, data='row 1') @@ -649,7 +649,7 @@ class SequenceExecTest(fixtures.TestBase): def _assert_seq_result(self, ret): """asserts return of next_value is an int""" - assert isinstance(ret, (int, long)) + assert isinstance(ret, int) assert ret > 0 def test_implicit_connectionless(self): @@ -781,7 +781,7 @@ class SequenceTest(fixtures.TestBase, testing.AssertsCompiledSQL): ] start = seq.start or 1 inc = seq.increment or 1 - assert values == list(xrange(start, start + inc * 3, inc)) + assert values == list(range(start, start + inc * 3, inc)) finally: seq.drop(testing.db) @@ -1156,20 +1156,22 @@ class UnicodeDefaultsTest(fixtures.TestBase): c = Column(Unicode(32)) def test_unicode_default(self): - # Py3K - #default = 'foo' - # Py2K - default = u'foo' - # end Py2K +# start Py3K + default = 'foo' +# end Py3K +# start Py2K +# default = u'foo' +# end Py2K c = Column(Unicode(32), default=default) def test_nonunicode_default(self): - # Py3K - #default = b'foo' - # Py2K - default = 'foo' - # end Py2K +# start Py3K + default = b'foo' +# end Py3K +# start Py2K +# default = 'foo' +# end Py2K assert_raises_message( sa.exc.SAWarning, "Unicode column received non-unicode default value.", diff --git a/test/sql/test_functions.py b/test/sql/test_functions.py index b325b7763..ee503dbb7 100644 --- a/test/sql/test_functions.py +++ b/test/sql/test_functions.py @@ -381,7 +381,7 @@ class ExecuteTest(fixtures.TestBase): assert t.select(t.c.id == id).execute().first()['value'] == 9 t.update(values={t.c.value: func.length("asdf")}).execute() assert t.select().execute().first()['value'] == 4 - print "--------------------------" + print("--------------------------") t2.insert().execute() t2.insert(values=dict(value=func.length("one"))).execute() t2.insert(values=dict(value=func.length("asfda") + -19)).\ @@ -409,7 +409,7 @@ class ExecuteTest(fixtures.TestBase): t2.update(values={t2.c.value: func.length("asfdaasdf"), t2.c.stuff: "foo"}).execute() - print "HI", select([t2.c.value, t2.c.stuff]).execute().first() + print("HI", select([t2.c.value, t2.c.stuff]).execute().first()) eq_(select([t2.c.value, t2.c.stuff]).execute().first(), (9, "foo") ) diff --git a/test/sql/test_generative.py b/test/sql/test_generative.py index 8b2abef0e..09b20d8ea 100644 --- a/test/sql/test_generative.py +++ b/test/sql/test_generative.py @@ -176,7 +176,7 @@ class BinaryEndpointTraversalTest(fixtures.TestBase): canary = [] def visit(binary, l, r): canary.append((binary.operator, l, r)) - print binary.operator, l, r + print(binary.operator, l, r) sql_util.visit_binary_product(visit, expr) eq_( canary, expected @@ -433,7 +433,7 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): clause2 = Vis().traverse(clause) assert c1 == str(clause) assert str(clause2) == c1 + " SOME MODIFIER=:lala" - assert clause.bindparams.keys() == ['bar'] + assert list(clause.bindparams.keys()) == ['bar'] assert set(clause2.bindparams.keys()) == set(['bar', 'lala']) def test_select(self): @@ -446,8 +446,8 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): s3 = Vis().traverse(s2) assert str(s3) == s3_assert assert str(s2) == s2_assert - print str(s2) - print str(s3) + print(str(s2)) + print(str(s3)) class Vis(ClauseVisitor): def visit_select(self, select): select.append_whereclause(t1.c.col2 == 7) @@ -459,8 +459,8 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): def visit_select(self, select): select.append_whereclause(t1.c.col3 == 9) s4 = Vis().traverse(s3) - print str(s3) - print str(s4) + print(str(s3)) + print(str(s4)) assert str(s4) == s4_assert assert str(s3) == s3_assert @@ -471,8 +471,8 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): binary.left = t1.c.col1 binary.right = bindparam("col1", unique=True) s5 = Vis().traverse(s4) - print str(s4) - print str(s5) + print(str(s4)) + print(str(s5)) assert str(s5) == s5_assert assert str(s4) == s4_assert diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py index db2eaa4fa..c0873862d 100644 --- a/test/sql/test_metadata.py +++ b/test/sql/test_metadata.py @@ -89,7 +89,7 @@ class MetaDataTest(fixtures.TestBase, ComparesTables): msgs.append("attach %s.%s" % (t.name, c.name)) c1 = Column('foo', String()) m = MetaData() - for i in xrange(3): + for i in range(3): cx = c1.copy() # as of 0.7, these events no longer copy. its expected # that listeners will be re-established from the @@ -511,7 +511,7 @@ class MetaDataTest(fixtures.TestBase, ComparesTables): def _get_key(i): return [i.name, i.unique] + \ sorted(i.kwargs.items()) + \ - i.columns.keys() + list(i.columns.keys()) eq_( sorted([_get_key(i) for i in table.indexes]), diff --git a/test/sql/test_query.py b/test/sql/test_query.py index 293e629c8..3e9045fa5 100644 --- a/test/sql/test_query.py +++ b/test/sql/test_query.py @@ -367,10 +367,10 @@ class QueryTest(fixtures.TestBase): ) if use_labels: eq_(result[0]['query_users_user_id'], 7) - eq_(result[0].keys(), ["query_users_user_id", "query_users_user_name"]) + eq_(list(result[0].keys()), ["query_users_user_id", "query_users_user_name"]) else: eq_(result[0]['user_id'], 7) - eq_(result[0].keys(), ["user_id", "user_name"]) + eq_(list(result[0].keys()), ["user_id", "user_name"]) eq_(result[0][0], 7) eq_(result[0][users.c.user_id], 7) @@ -523,13 +523,13 @@ class QueryTest(fixtures.TestBase): def a_eq(got, wanted): if got != wanted: - print "Wanted %s" % wanted - print "Received %s" % got + print("Wanted %s" % wanted) + print("Received %s" % got) self.assert_(got == wanted, got) a_eq(prep('select foo'), 'select foo') a_eq(prep("time='12:30:00'"), "time='12:30:00'") - a_eq(prep(u"time='12:30:00'"), u"time='12:30:00'") + a_eq(prep("time='12:30:00'"), "time='12:30:00'") a_eq(prep(":this:that"), ":this:that") a_eq(prep(":this :that"), "? ?") a_eq(prep("(:this),(:that :other)"), "(?),(? ?)") @@ -769,7 +769,7 @@ class QueryTest(fixtures.TestBase): ).first() eq_(r['user_id'], 1) eq_(r['user_name'], "john") - eq_(r.keys(), ["user_id", "user_name"]) + eq_(list(r.keys()), ["user_id", "user_name"]) @testing.only_on("sqlite", "sqlite specific feature") def test_column_accessor_sqlite_raw(self): @@ -784,7 +784,7 @@ class QueryTest(fixtures.TestBase): assert 'user_name' not in r eq_(r['query_users.user_id'], 1) eq_(r['query_users.user_name'], "john") - eq_(r.keys(), ["query_users.user_id", "query_users.user_name"]) + eq_(list(r.keys()), ["query_users.user_id", "query_users.user_name"]) @testing.only_on("sqlite", "sqlite specific feature") def test_column_accessor_sqlite_translated(self): @@ -799,7 +799,7 @@ class QueryTest(fixtures.TestBase): eq_(r['user_name'], "john") eq_(r['query_users.user_id'], 1) eq_(r['query_users.user_name'], "john") - eq_(r.keys(), ["user_id", "user_name"]) + eq_(list(r.keys()), ["user_id", "user_name"]) def test_column_accessor_labels_w_dots(self): users.insert().execute( @@ -812,7 +812,7 @@ class QueryTest(fixtures.TestBase): eq_(r['query_users.user_id'], 1) eq_(r['query_users.user_name'], "john") assert "user_name" not in r - eq_(r.keys(), ["query_users.user_id", "query_users.user_name"]) + eq_(list(r.keys()), ["query_users.user_id", "query_users.user_name"]) def test_column_accessor_unary(self): users.insert().execute( @@ -889,7 +889,7 @@ class QueryTest(fixtures.TestBase): ]) ).first() - eq_(row.keys(), ["case_insensitive", "CaseSensitive"]) + eq_(list(row.keys()), ["case_insensitive", "CaseSensitive"]) eq_(row["case_insensitive"], 1) eq_(row["CaseSensitive"], 2) @@ -911,7 +911,7 @@ class QueryTest(fixtures.TestBase): ]) ).first() - eq_(row.keys(), ["case_insensitive", "CaseSensitive"]) + eq_(list(row.keys()), ["case_insensitive", "CaseSensitive"]) eq_(row["case_insensitive"], 1) eq_(row["CaseSensitive"], 2) eq_(row["Case_insensitive"],1) @@ -1072,14 +1072,14 @@ class QueryTest(fixtures.TestBase): def test_keys(self): users.insert().execute(user_id=1, user_name='foo') r = users.select().execute() - eq_([x.lower() for x in r.keys()], ['user_id', 'user_name']) + eq_([x.lower() for x in list(r.keys())], ['user_id', 'user_name']) r = r.first() - eq_([x.lower() for x in r.keys()], ['user_id', 'user_name']) + eq_([x.lower() for x in list(r.keys())], ['user_id', 'user_name']) def test_items(self): users.insert().execute(user_id=1, user_name='foo') r = users.select().execute().first() - eq_([(x[0].lower(), x[1]) for x in r.items()], [('user_id', 1), ('user_name', 'foo')]) + eq_([(x[0].lower(), x[1]) for x in list(r.items())], [('user_id', 1), ('user_name', 'foo')]) def test_len(self): users.insert().execute(user_id=1, user_name='foo') @@ -1098,8 +1098,8 @@ class QueryTest(fixtures.TestBase): r = users.select(users.c.user_id==1).execute().first() eq_(r[0], 1) eq_(r[1], 'foo') - eq_([x.lower() for x in r.keys()], ['user_id', 'user_name']) - eq_(r.values(), [1, 'foo']) + eq_([x.lower() for x in list(r.keys())], ['user_id', 'user_name']) + eq_(list(r.values()), [1, 'foo']) def test_column_order_with_text_query(self): # should return values in query order @@ -1107,8 +1107,8 @@ class QueryTest(fixtures.TestBase): r = testing.db.execute('select user_name, user_id from query_users').first() eq_(r[0], 'foo') eq_(r[1], 1) - eq_([x.lower() for x in r.keys()], ['user_name', 'user_id']) - eq_(r.values(), ['foo', 1]) + eq_([x.lower() for x in list(r.keys())], ['user_name', 'user_id']) + eq_(list(r.values()), ['foo', 1]) @testing.crashes('oracle', 'FIXME: unknown, varify not fails_on()') @testing.crashes('firebird', 'An identifier must begin with a letter') @@ -1137,7 +1137,7 @@ class QueryTest(fixtures.TestBase): self.assert_(r['_parent'] == 'Hidden parent') self.assert_(r['_row'] == 'Hidden row') try: - print r._parent, r._row + print(r._parent, r._row) self.fail('Should not allow access to private attributes') except AttributeError: pass # expected @@ -2334,7 +2334,7 @@ class JoinTest(fixtures.TestBase): expr = select( [t1.c.t1_id, t2.c.t2_id, t3.c.t3_id], from_obj=[(t1.join(t2).outerjoin(t3, criteria))]) - print expr + print(expr) self.assertRows(expr, [(10, 20, 30), (11, 21, None)]) def test_mixed_where(self): @@ -2416,7 +2416,7 @@ class OperatorTest(fixtures.TestBase): select([ flds.c.intcol, func.row_number().over(order_by=flds.c.strcol) ]).execute().fetchall(), - [(13, 1L), (5, 2L)] + [(13, 1), (5, 2)] ) diff --git a/test/sql/test_quote.py b/test/sql/test_quote.py index 8b14d23a9..717f0f797 100644 --- a/test/sql/test_quote.py +++ b/test/sql/test_quote.py @@ -552,8 +552,8 @@ class PreparerTest(fixtures.TestBase): def a_eq(have, want): if have != want: - print "Wanted %s" % want - print "Received %s" % have + print("Wanted %s" % want) + print("Received %s" % have) self.assert_(have == want) a_eq(unformat('foo'), ['foo']) @@ -584,13 +584,13 @@ class PreparerTest(fixtures.TestBase): def a_eq(have, want): if have != want: - print "Wanted %s" % want - print "Received %s" % have + print("Wanted %s" % want) + print("Received %s" % have) self.assert_(have == want) a_eq(unformat('foo'), ['foo']) a_eq(unformat('`foo`'), ['foo']) - a_eq(unformat(`'foo'`), ["'foo'"]) + a_eq(unformat(repr('foo')), ["'foo'"]) a_eq(unformat('foo.bar'), ['foo', 'bar']) a_eq(unformat('`foo`.`bar`'), ['foo', 'bar']) a_eq(unformat('foo.`bar`'), ['foo', 'bar']) diff --git a/test/sql/test_rowcount.py b/test/sql/test_rowcount.py index f14f78989..2dbf4f3ea 100644 --- a/test/sql/test_rowcount.py +++ b/test/sql/test_rowcount.py @@ -53,20 +53,20 @@ class FoundRowsTest(fixtures.TestBase, AssertsExecutionResults): # WHERE matches 3, 3 rows changed department = employees_table.c.department r = employees_table.update(department=='C').execute(department='Z') - print "expecting 3, dialect reports %s" % r.rowcount + print("expecting 3, dialect reports %s" % r.rowcount) assert r.rowcount == 3 def test_update_rowcount2(self): # WHERE matches 3, 0 rows changed department = employees_table.c.department r = employees_table.update(department=='C').execute(department='C') - print "expecting 3, dialect reports %s" % r.rowcount + print("expecting 3, dialect reports %s" % r.rowcount) assert r.rowcount == 3 def test_delete_rowcount(self): # WHERE matches 3, 3 rows deleted department = employees_table.c.department r = employees_table.delete(department=='C').execute() - print "expecting 3, dialect reports %s" % r.rowcount + print("expecting 3, dialect reports %s" % r.rowcount) assert r.rowcount == 3 diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index e881298a7..e697a7e08 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -174,11 +174,11 @@ class SelectableTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiled def test_clone_append_column(self): sel = select([literal_column('1').label('a')]) - eq_(sel.c.keys(), ['a']) + eq_(list(sel.c.keys()), ['a']) cloned = visitors.ReplacingCloningVisitor().traverse(sel) cloned.append_column(literal_column('2').label('b')) cloned.append_column(func.foo()) - eq_(cloned.c.keys(), ['a', 'b', 'foo()']) + eq_(list(cloned.c.keys()), ['a', 'b', 'foo()']) def test_append_column_after_replace_selectable(self): basesel = select([literal_column('1').label('a')]) @@ -362,10 +362,10 @@ class SelectableTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiled def test_join(self): a = join(table1, table2) - print str(a.select(use_labels=True)) + print(str(a.select(use_labels=True))) b = table2.alias('b') j = join(a, b) - print str(j) + print(str(j)) criterion = a.c.table1_col1 == b.c.col2 self.assert_(criterion.compare(j.onclause)) @@ -949,7 +949,7 @@ class PrimaryKeyTest(fixtures.TestBase, AssertsExecutionResults): primary_key=True), Column('x', Integer)) d = Table('d', meta, Column('id', Integer, ForeignKey('c.id'), primary_key=True), Column('x', Integer)) - print list(a.join(b, a.c.x == b.c.id).primary_key) + print(list(a.join(b, a.c.x == b.c.id).primary_key)) assert list(a.join(b, a.c.x == b.c.id).primary_key) == [a.c.id] assert list(b.join(c, b.c.x == c.c.id).primary_key) == [b.c.id] assert list(a.join(b).join(c, c.c.id == b.c.x).primary_key) \ @@ -1618,7 +1618,7 @@ class WithLabelsTest(fixtures.TestBase): def test_names_overlap_label(self): sel = self._names_overlap().apply_labels() eq_( - sel.c.keys(), + list(sel.c.keys()), ['t1_x', 't2_x'] ) self._assert_result_keys(sel, ['t1_x', 't2_x']) @@ -1632,7 +1632,7 @@ class WithLabelsTest(fixtures.TestBase): def test_names_overlap_keys_dont_nolabel(self): sel = self._names_overlap_keys_dont() eq_( - sel.c.keys(), + list(sel.c.keys()), ['a', 'b'] ) self._assert_result_keys(sel, ['x']) @@ -1640,7 +1640,7 @@ class WithLabelsTest(fixtures.TestBase): def test_names_overlap_keys_dont_label(self): sel = self._names_overlap_keys_dont().apply_labels() eq_( - sel.c.keys(), + list(sel.c.keys()), ['t1_a', 't2_b'] ) self._assert_result_keys(sel, ['t1_x', 't2_x']) @@ -1654,7 +1654,7 @@ class WithLabelsTest(fixtures.TestBase): def test_labels_overlap_nolabel(self): sel = self._labels_overlap() eq_( - sel.c.keys(), + list(sel.c.keys()), ['x_id', 'id'] ) self._assert_result_keys(sel, ['x_id', 'id']) @@ -1663,7 +1663,7 @@ class WithLabelsTest(fixtures.TestBase): sel = self._labels_overlap().apply_labels() t2 = sel.froms[1] eq_( - sel.c.keys(), + list(sel.c.keys()), ['t_x_id', t2.c.id.anon_label] ) self._assert_result_keys(sel, ['t_x_id', 'id_1']) @@ -1677,12 +1677,12 @@ class WithLabelsTest(fixtures.TestBase): def test_labels_overlap_keylabels_dont_nolabel(self): sel = self._labels_overlap_keylabels_dont() - eq_(sel.c.keys(), ['a', 'b']) + eq_(list(sel.c.keys()), ['a', 'b']) self._assert_result_keys(sel, ['x_id', 'id']) def test_labels_overlap_keylabels_dont_label(self): sel = self._labels_overlap_keylabels_dont().apply_labels() - eq_(sel.c.keys(), ['t_a', 't_x_b']) + eq_(list(sel.c.keys()), ['t_a', 't_x_b']) self._assert_result_keys(sel, ['t_x_id', 'id_1']) def _keylabels_overlap_labels_dont(self): @@ -1693,13 +1693,13 @@ class WithLabelsTest(fixtures.TestBase): def test_keylabels_overlap_labels_dont_nolabel(self): sel = self._keylabels_overlap_labels_dont() - eq_(sel.c.keys(), ['x_id', 'id']) + eq_(list(sel.c.keys()), ['x_id', 'id']) self._assert_result_keys(sel, ['a', 'b']) def test_keylabels_overlap_labels_dont_label(self): sel = self._keylabels_overlap_labels_dont().apply_labels() t2 = sel.froms[1] - eq_(sel.c.keys(), ['t_x_id', t2.c.id.anon_label]) + eq_(list(sel.c.keys()), ['t_x_id', t2.c.id.anon_label]) self._assert_result_keys(sel, ['t_a', 't_x_b']) self._assert_subq_result_keys(sel, ['t_a', 't_x_b']) @@ -1711,14 +1711,14 @@ class WithLabelsTest(fixtures.TestBase): def test_keylabels_overlap_labels_overlap_nolabel(self): sel = self._keylabels_overlap_labels_overlap() - eq_(sel.c.keys(), ['x_a', 'a']) + eq_(list(sel.c.keys()), ['x_a', 'a']) self._assert_result_keys(sel, ['x_id', 'id']) self._assert_subq_result_keys(sel, ['x_id', 'id']) def test_keylabels_overlap_labels_overlap_label(self): sel = self._keylabels_overlap_labels_overlap().apply_labels() t2 = sel.froms[1] - eq_(sel.c.keys(), ['t_x_a', t2.c.a.anon_label]) + eq_(list(sel.c.keys()), ['t_x_a', t2.c.a.anon_label]) self._assert_result_keys(sel, ['t_x_id', 'id_1']) self._assert_subq_result_keys(sel, ['t_x_id', 'id_1']) @@ -1736,7 +1736,7 @@ class WithLabelsTest(fixtures.TestBase): def test_keys_overlap_names_dont_label(self): sel = self._keys_overlap_names_dont().apply_labels() eq_( - sel.c.keys(), + list(sel.c.keys()), ['t1_x', 't2_x'] ) self._assert_result_keys(sel, ['t1_a', 't2_b']) diff --git a/test/sql/test_types.py b/test/sql/test_types.py index 407869f15..f44ee9286 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -141,22 +141,24 @@ class AdaptTest(fixtures.TestBase): eq_(types.Integer().python_type, int) eq_(types.Numeric().python_type, decimal.Decimal) eq_(types.Numeric(asdecimal=False).python_type, float) - # Py3K - #eq_(types.LargeBinary().python_type, bytes) - # Py2K - eq_(types.LargeBinary().python_type, str) - # end Py2K +# start Py3K + eq_(types.LargeBinary().python_type, bytes) +# end Py3K +# start Py2K +# eq_(types.LargeBinary().python_type, str) +# end Py2K eq_(types.Float().python_type, float) eq_(types.Interval().python_type, datetime.timedelta) eq_(types.Date().python_type, datetime.date) eq_(types.DateTime().python_type, datetime.datetime) - # Py3K - #eq_(types.String().python_type, unicode) - # Py2K +# start Py3K eq_(types.String().python_type, str) - # end Py2K - eq_(types.Unicode().python_type, unicode) - eq_(types.String(convert_unicode=True).python_type, unicode) +# end Py3K +# start Py2K +# eq_(types.String().python_type, str) +# end Py2K + eq_(types.Unicode().python_type, str) + eq_(types.String(convert_unicode=True).python_type, str) assert_raises( NotImplementedError, @@ -257,14 +259,14 @@ class UserDefinedTest(fixtures.TablesTest, AssertsCompiledSQL): def test_processing(self): users = self.tables.users users.insert().execute( - user_id=2, goofy='jack', goofy2='jack', goofy4=u'jack', - goofy7=u'jack', goofy8=12, goofy9=12) + user_id=2, goofy='jack', goofy2='jack', goofy4='jack', + goofy7='jack', goofy8=12, goofy9=12) users.insert().execute( - user_id=3, goofy='lala', goofy2='lala', goofy4=u'lala', - goofy7=u'lala', goofy8=15, goofy9=15) + user_id=3, goofy='lala', goofy2='lala', goofy4='lala', + goofy7='lala', goofy8=15, goofy9=15) users.insert().execute( - user_id=4, goofy='fred', goofy2='fred', goofy4=u'fred', - goofy7=u'fred', goofy8=9, goofy9=9) + user_id=4, goofy='fred', goofy2='fred', goofy4='fred', + goofy7='fred', goofy8=9, goofy9=9) l = users.select().order_by(users.c.user_id).execute().fetchall() for assertstr, assertint, assertint2, row in zip( @@ -278,7 +280,7 @@ class UserDefinedTest(fixtures.TablesTest, AssertsCompiledSQL): eq_(row[5], assertint) eq_(row[6], assertint2) for col in row[3], row[4]: - assert isinstance(col, unicode) + assert isinstance(col, str) def test_typedecorator_impl(self): for impl_, exp, kw in [ @@ -715,9 +717,9 @@ class UnicodeTest(fixtures.TestBase): expected ) - data = u"Alors vous imaginez ma surprise, au lever du jour, quand "\ - u"une drôle de petite voix m’a réveillé. "\ - u"Elle disait: « S’il vous plaît… dessine-moi un mouton! »" + data = "Alors vous imaginez ma surprise, au lever du jour, quand "\ + "une drôle de petite voix m’a réveillé. "\ + "Elle disait: « S’il vous plaît… dessine-moi un mouton! »" def test_unicode_warnings_typelevel_native_unicode(self): @@ -726,13 +728,14 @@ class UnicodeTest(fixtures.TestBase): dialect = default.DefaultDialect() dialect.supports_unicode_binds = True uni = u.dialect_impl(dialect).bind_processor(dialect) - # Py3K - #assert_raises(exc.SAWarning, uni, b'x') - #assert isinstance(uni(unicodedata), str) - # Py2K - assert_raises(exc.SAWarning, uni, 'x') - assert isinstance(uni(unicodedata), unicode) - # end Py2K +# start Py3K + assert_raises(exc.SAWarning, uni, b'x') + assert isinstance(uni(unicodedata), str) +# end Py3K +# start Py2K +# assert_raises(exc.SAWarning, uni, 'x') +# assert isinstance(uni(unicodedata), unicode) +# end Py2K def test_unicode_warnings_typelevel_sqla_unicode(self): unicodedata = self.data @@ -740,13 +743,14 @@ class UnicodeTest(fixtures.TestBase): dialect = default.DefaultDialect() dialect.supports_unicode_binds = False uni = u.dialect_impl(dialect).bind_processor(dialect) - # Py3K - #assert_raises(exc.SAWarning, uni, b'x') - #assert isinstance(uni(unicodedata), bytes) - # Py2K - assert_raises(exc.SAWarning, uni, 'x') - assert isinstance(uni(unicodedata), str) - # end Py2K +# start Py3K + assert_raises(exc.SAWarning, uni, b'x') + assert isinstance(uni(unicodedata), bytes) +# end Py3K +# start Py2K +# assert_raises(exc.SAWarning, uni, 'x') +# assert isinstance(uni(unicodedata), str) +# end Py2K eq_(uni(unicodedata), unicodedata.encode('utf-8')) @@ -760,13 +764,14 @@ class UnicodeTest(fixtures.TestBase): s = String() uni = s.dialect_impl(dialect).bind_processor(dialect) # this is not the unicode type - no warning - # Py3K - #uni(b'x') - #assert isinstance(uni(unicodedata), bytes) - # Py2K - uni('x') - assert isinstance(uni(unicodedata), str) - # end Py2K +# start Py3K + uni(b'x') + assert isinstance(uni(unicodedata), bytes) +# end Py3K +# start Py2K +# uni('x') +# assert isinstance(uni(unicodedata), str) +# end Py2K eq_(uni(unicodedata), unicodedata.encode('utf-8')) @@ -1366,7 +1371,7 @@ class NumericRawSQLTest(fixtures.TestBase): metadata = self.metadata t = self._fixture(metadata, Integer, 45) val = testing.db.execute("select val from t").scalar() - assert isinstance(val, (int, long)) + assert isinstance(val, int) eq_(val, 45) @testing.provide_metadata diff --git a/test/sql/test_unicode.py b/test/sql/test_unicode.py index 37e44522e..2ab081dad 100644 --- a/test/sql/test_unicode.py +++ b/test/sql/test_unicode.py @@ -19,13 +19,13 @@ class UnicodeSchemaTest(fixtures.TestBase): metadata = MetaData(unicode_bind) t1 = Table('unitable1', metadata, - Column(u'méil', Integer, primary_key=True), - Column(u'\u6e2c\u8a66', Integer), + Column('méil', Integer, primary_key=True), + Column('\u6e2c\u8a66', Integer), test_needs_fk=True, ) - t2 = Table(u'Unitéble2', metadata, - Column(u'méil', Integer, primary_key=True, key="a"), - Column(u'\u6e2c\u8a66', Integer, ForeignKey(u'unitable1.méil'), + t2 = Table('Unitéble2', metadata, + Column('méil', Integer, primary_key=True, key="a"), + Column('\u6e2c\u8a66', Integer, ForeignKey('unitable1.méil'), key="b" ), test_needs_fk=True, @@ -33,27 +33,27 @@ class UnicodeSchemaTest(fixtures.TestBase): # Few DBs support Unicode foreign keys if testing.against('sqlite'): - t3 = Table(u'\u6e2c\u8a66', metadata, - Column(u'\u6e2c\u8a66_id', Integer, primary_key=True, + t3 = Table('\u6e2c\u8a66', metadata, + Column('\u6e2c\u8a66_id', Integer, primary_key=True, autoincrement=False), - Column(u'unitable1_\u6e2c\u8a66', Integer, - ForeignKey(u'unitable1.\u6e2c\u8a66') + Column('unitable1_\u6e2c\u8a66', Integer, + ForeignKey('unitable1.\u6e2c\u8a66') ), - Column(u'Unitéble2_b', Integer, - ForeignKey(u'Unitéble2.b') + Column('Unitéble2_b', Integer, + ForeignKey('Unitéble2.b') ), - Column(u'\u6e2c\u8a66_self', Integer, - ForeignKey(u'\u6e2c\u8a66.\u6e2c\u8a66_id') + Column('\u6e2c\u8a66_self', Integer, + ForeignKey('\u6e2c\u8a66.\u6e2c\u8a66_id') ), test_needs_fk=True, ) else: - t3 = Table(u'\u6e2c\u8a66', metadata, - Column(u'\u6e2c\u8a66_id', Integer, primary_key=True, + t3 = Table('\u6e2c\u8a66', metadata, + Column('\u6e2c\u8a66_id', Integer, primary_key=True, autoincrement=False), - Column(u'unitable1_\u6e2c\u8a66', Integer), - Column(u'Unitéble2_b', Integer), - Column(u'\u6e2c\u8a66_self', Integer), + Column('unitable1_\u6e2c\u8a66', Integer), + Column('Unitéble2_b', Integer), + Column('\u6e2c\u8a66_self', Integer), test_needs_fk=True, ) metadata.create_all() @@ -72,42 +72,42 @@ class UnicodeSchemaTest(fixtures.TestBase): del unicode_bind def test_insert(self): - t1.insert().execute({u'méil':1, u'\u6e2c\u8a66':5}) + t1.insert().execute({'méil':1, '\u6e2c\u8a66':5}) t2.insert().execute({'a':1, 'b':1}) - t3.insert().execute({u'\u6e2c\u8a66_id': 1, - u'unitable1_\u6e2c\u8a66': 5, - u'Unitéble2_b': 1, - u'\u6e2c\u8a66_self': 1}) + t3.insert().execute({'\u6e2c\u8a66_id': 1, + 'unitable1_\u6e2c\u8a66': 5, + 'Unitéble2_b': 1, + '\u6e2c\u8a66_self': 1}) assert t1.select().execute().fetchall() == [(1, 5)] assert t2.select().execute().fetchall() == [(1, 1)] assert t3.select().execute().fetchall() == [(1, 5, 1, 1)] def test_reflect(self): - t1.insert().execute({u'méil':2, u'\u6e2c\u8a66':7}) + t1.insert().execute({'méil':2, '\u6e2c\u8a66':7}) t2.insert().execute({'a':2, 'b':2}) - t3.insert().execute({u'\u6e2c\u8a66_id': 2, - u'unitable1_\u6e2c\u8a66': 7, - u'Unitéble2_b': 2, - u'\u6e2c\u8a66_self': 2}) + t3.insert().execute({'\u6e2c\u8a66_id': 2, + 'unitable1_\u6e2c\u8a66': 7, + 'Unitéble2_b': 2, + '\u6e2c\u8a66_self': 2}) meta = MetaData(unicode_bind) tt1 = Table(t1.name, meta, autoload=True) tt2 = Table(t2.name, meta, autoload=True) tt3 = Table(t3.name, meta, autoload=True) - tt1.insert().execute({u'méil':1, u'\u6e2c\u8a66':5}) - tt2.insert().execute({u'méil':1, u'\u6e2c\u8a66':1}) - tt3.insert().execute({u'\u6e2c\u8a66_id': 1, - u'unitable1_\u6e2c\u8a66': 5, - u'Unitéble2_b': 1, - u'\u6e2c\u8a66_self': 1}) + tt1.insert().execute({'méil':1, '\u6e2c\u8a66':5}) + tt2.insert().execute({'méil':1, '\u6e2c\u8a66':1}) + tt3.insert().execute({'\u6e2c\u8a66_id': 1, + 'unitable1_\u6e2c\u8a66': 5, + 'Unitéble2_b': 1, + '\u6e2c\u8a66_self': 1}) - self.assert_(tt1.select(order_by=desc(u'méil')).execute().fetchall() == + self.assert_(tt1.select(order_by=desc('méil')).execute().fetchall() == [(2, 7), (1, 5)]) - self.assert_(tt2.select(order_by=desc(u'méil')).execute().fetchall() == + self.assert_(tt2.select(order_by=desc('méil')).execute().fetchall() == [(2, 2), (1, 1)]) - self.assert_(tt3.select(order_by=desc(u'\u6e2c\u8a66_id')). + self.assert_(tt3.select(order_by=desc('\u6e2c\u8a66_id')). execute().fetchall() == [(2, 7, 2, 2), (1, 5, 1, 1)]) meta.drop_all() @@ -117,7 +117,7 @@ class EscapesDefaultsTest(fixtures.TestBase): def test_default_exec(self): metadata = MetaData(testing.db) t1 = Table('t1', metadata, - Column(u'special_col', Integer, Sequence('special_col'), primary_key=True), + Column('special_col', Integer, Sequence('special_col'), primary_key=True), Column('data', String(50)) # to appease SQLite without DEFAULT VALUES ) metadata.create_all() @@ -128,8 +128,8 @@ class EscapesDefaultsTest(fixtures.TestBase): # reset the identifier preparer, so that we can force it to cache # a unicode identifier engine.dialect.identifier_preparer = engine.dialect.preparer(engine.dialect) - select([column(u'special_col')]).select_from(t1).execute().close() - assert isinstance(engine.dialect.identifier_preparer.format_sequence(Sequence('special_col')), unicode) + select([column('special_col')]).select_from(t1).execute().close() + assert isinstance(engine.dialect.identifier_preparer.format_sequence(Sequence('special_col')), str) # now execute, run the sequence. it should run in u"Special_col.nextid" or similar as # a unicode object; cx_oracle asserts that this is None or a String (postgresql lets it pass thru). diff --git a/test/sql/test_update.py b/test/sql/test_update.py index a8df86cd2..8695760fb 100644 --- a/test/sql/test_update.py +++ b/test/sql/test_update.py @@ -242,7 +242,7 @@ class UpdateFromCompileTest(_UpdateFromTestBase, fixtures.TablesTest, 'WHERE ' 'users.id = addresses.user_id AND ' 'addresses.email_address = :email_address_1', - checkparams={u'email_address_1': 'e1', 'name': 'newname'}) + checkparams={'email_address_1': 'e1', 'name': 'newname'}) def test_render_multi_table(self): users = self.tables.users @@ -250,8 +250,8 @@ class UpdateFromCompileTest(_UpdateFromTestBase, fixtures.TablesTest, dingalings = self.tables.dingalings checkparams = { - u'email_address_1': 'e1', - u'id_1': 2, + 'email_address_1': 'e1', + 'id_1': 2, 'name': 'newname' } @@ -285,15 +285,15 @@ class UpdateFromCompileTest(_UpdateFromTestBase, fixtures.TablesTest, 'WHERE ' 'users.id = addresses.user_id AND ' 'addresses.email_address = %s', - checkparams={u'email_address_1': 'e1', 'name': 'newname'}, + checkparams={'email_address_1': 'e1', 'name': 'newname'}, dialect=mysql.dialect()) def test_render_subquery(self): users, addresses = self.tables.users, self.tables.addresses checkparams = { - u'email_address_1': 'e1', - u'id_1': 7, + 'email_address_1': 'e1', + 'id_1': 7, 'name': 'newname' } -- cgit v1.2.1 From 2709ae46884f405d95dc16be0667a6cbbebcfb69 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 27 Apr 2013 20:02:24 -0400 Subject: work through dialects --- lib/sqlalchemy/connectors/pyodbc.py | 29 ++++++++++++--------------- lib/sqlalchemy/dialects/informix/base.py | 6 +++--- lib/sqlalchemy/dialects/mssql/adodbapi.py | 2 +- lib/sqlalchemy/dialects/mssql/base.py | 8 ++++---- lib/sqlalchemy/util/__init__.py | 2 +- lib/sqlalchemy/util/compat.py | 33 +++++++++++++++---------------- 6 files changed, 38 insertions(+), 42 deletions(-) diff --git a/lib/sqlalchemy/connectors/pyodbc.py b/lib/sqlalchemy/connectors/pyodbc.py index 504414b0f..784344b82 100644 --- a/lib/sqlalchemy/connectors/pyodbc.py +++ b/lib/sqlalchemy/connectors/pyodbc.py @@ -5,11 +5,11 @@ # the MIT License: http://www.opensource.org/licenses/mit-license.php from . import Connector -from ..util import asbool +from .. import util + import sys import re -import urllib.request, urllib.parse, urllib.error class PyODBCConnector(Connector): @@ -56,10 +56,10 @@ class PyODBCConnector(Connector): connect_args = {} for param in ('ansi', 'unicode_results', 'autocommit'): if param in keys: - connect_args[param] = asbool(keys.pop(param)) + connect_args[param] = util.asbool(keys.pop(param)) if 'odbc_connect' in keys: - connectors = [urllib.parse.unquote_plus(keys.pop('odbc_connect'))] + connectors = [util.unquote_plus(keys.pop('odbc_connect'))] else: dsn_connection = 'dsn' in keys or \ ('host' in keys and 'database' not in keys) @@ -121,18 +121,15 @@ class PyODBCConnector(Connector): self.freetds_driver_version = dbapi_con.getinfo( pyodbc.SQL_DRIVER_VER) - # the "Py2K only" part here is theoretical. - # have not tried pyodbc + python3.1 yet. -# start Py2K -# self.supports_unicode_statements = ( -# not self.freetds and not self.easysoft) -# if self._user_supports_unicode_binds is not None: -# self.supports_unicode_binds = self._user_supports_unicode_binds -# else: -# self.supports_unicode_binds = ( -# not self.freetds or self.freetds_driver_version >= '0.91' -# ) and not self.easysoft -# end Py2K + if not util.py3k: + self.supports_unicode_statements = ( + not self.freetds and not self.easysoft) + if self._user_supports_unicode_binds is not None: + self.supports_unicode_binds = self._user_supports_unicode_binds + else: + self.supports_unicode_binds = ( + not self.freetds or self.freetds_driver_version >= '0.91' + ) and not self.easysoft # run other initialization which asks for user name, etc. super(PyODBCConnector, self).initialize(connection) diff --git a/lib/sqlalchemy/dialects/informix/base.py b/lib/sqlalchemy/dialects/informix/base.py index 691400e05..a5a6917af 100644 --- a/lib/sqlalchemy/dialects/informix/base.py +++ b/lib/sqlalchemy/dialects/informix/base.py @@ -299,7 +299,7 @@ class InfoDDLCompiler(compiler.DDLCompiler): def get_column_default_string(self, column): if (isinstance(column.server_default, schema.DefaultClause) and - isinstance(column.server_default.arg, str)): + isinstance(column.server_default.arg, util.string_type)): if isinstance(column.type, (sqltypes.Integer, sqltypes.Numeric)): return self.sql_compiler.process(text(column.server_default.arg)) @@ -323,10 +323,10 @@ class InfoDDLCompiler(compiler.DDLCompiler): remote_table = list(constraint._elements.values())[0].column.table text = "FOREIGN KEY (%s) REFERENCES %s (%s)" % ( ', '.join(preparer.quote(f.parent.name, f.parent.quote) - for f in list(constraint._elements.values())), + for f in constraint._elements.values()), preparer.format_table(remote_table), ', '.join(preparer.quote(f.column.name, f.column.quote) - for f in list(constraint._elements.values())) + for f in constraint._elements.values()) ) text += self.define_constraint_cascades(constraint) text += self.define_constraint_deferrability(constraint) diff --git a/lib/sqlalchemy/dialects/mssql/adodbapi.py b/lib/sqlalchemy/dialects/mssql/adodbapi.py index 080382d55..167b4e807 100644 --- a/lib/sqlalchemy/dialects/mssql/adodbapi.py +++ b/lib/sqlalchemy/dialects/mssql/adodbapi.py @@ -44,7 +44,7 @@ class MSDialect_adodbapi(MSDialect): @classmethod def import_dbapi(cls): - from . import adodbapi as module + import adodbapi as module return module colspecs = util.update_copy( diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index 827cf0186..c5b86b887 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -295,7 +295,7 @@ class _MSDate(sqltypes.Date): def process(value): if isinstance(value, datetime.datetime): return value.date() - elif isinstance(value, str): + elif isinstance(value, util.string_type): return datetime.date(*[ int(x or 0) for x in self._reg.match(value).groups() @@ -328,7 +328,7 @@ class TIME(sqltypes.TIME): def process(value): if isinstance(value, datetime.datetime): return value.time() - elif isinstance(value, str): + elif isinstance(value, util.string_type): return datetime.time(*[ int(x or 0) for x in self._reg.match(value).groups()]) @@ -1002,7 +1002,7 @@ class MSDDLCompiler(compiler.DDLCompiler): # handle other included columns if index.kwargs.get("mssql_include"): inclusions = [index.table.c[col] - if isinstance(col, str) else col + if isinstance(col, util.string_type) else col for col in index.kwargs["mssql_include"]] text += " INCLUDE (%s)" \ @@ -1150,7 +1150,7 @@ class MSDialect(default.DefaultDialect): try: default_schema_name = connection.scalar(query, name=user_name) if default_schema_name is not None: - return str(default_schema_name) + return util.text_type(default_schema_name) except: pass return self.schema_name diff --git a/lib/sqlalchemy/util/__init__.py b/lib/sqlalchemy/util/__init__.py index 3fa06c793..2fcfabefd 100644 --- a/lib/sqlalchemy/util/__init__.py +++ b/lib/sqlalchemy/util/__init__.py @@ -7,7 +7,7 @@ from .compat import callable, cmp, reduce, \ threading, py3k, py3k_warning, jython, pypy, cpython, win32, set_types, \ pickle, dottedgetter, parse_qsl, namedtuple, next, WeakSet, reraise, \ - raise_from_cause + raise_from_cause, text_type, string_type, binary_type, quote_plus from ._collections import KeyedTuple, ImmutableContainer, immutabledict, \ Properties, OrderedProperties, ImmutableProperties, OrderedDict, \ diff --git a/lib/sqlalchemy/util/compat.py b/lib/sqlalchemy/util/compat.py index 4eb915469..d00e3ab23 100644 --- a/lib/sqlalchemy/util/compat.py +++ b/lib/sqlalchemy/util/compat.py @@ -21,11 +21,8 @@ pypy = hasattr(sys, 'pypy_version_info') win32 = sys.platform.startswith('win') cpython = not pypy and not jython # TODO: something better for this ? -if py3k_warning: +if py3k: set_types = set -elif sys.version_info < (2, 6): - import sets - set_types = set, sets.Set else: # 2.6 deprecates sets.Set, but we still need to be able to detect them # in user code and as return values from DB-APIs @@ -46,7 +43,7 @@ if sys.version_info < (2, 6): return iter.__next__() else: next = next -if py3k_warning: +if py3k: import pickle else: try: @@ -54,19 +51,21 @@ else: except ImportError: import pickle -if sys.version_info < (2, 6): - # emits a nasty deprecation warning - # in newer pythons - from cgi import parse_qsl +from urllib.parse import parse_qsl + + +if py3k: + from inspect import getfullargspec as inspect_getfullargspec + from urllib.parse import quote_plus, unquote_plus + string_types = str, + binary_type = bytes + text_type = str else: - from urllib.parse import parse_qsl - -# start Py3K -from inspect import getfullargspec as inspect_getfullargspec -# end Py3K -# start Py2K -#from inspect import getargspec as inspect_getfullargspec -# end Py2K + from inspect import getargspec as inspect_getfullargspec + from urllib import quote_plus, unquote_plus + string_types = basestring, + binary_type = str + text_type = unicode if py3k_warning: # they're bringing it back in 3.2. brilliant ! -- cgit v1.2.1 From c926f0a9d8910c67554f053ed0f7902542679f0d Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 27 Apr 2013 20:38:53 -0400 Subject: plugging away --- 09notes.txt | 6 +++ lib/sqlalchemy/dialects/informix/base.py | 2 +- lib/sqlalchemy/dialects/mssql/base.py | 6 +-- .../dialects/mssql/information_schema.py | 7 ++- lib/sqlalchemy/dialects/mysql/base.py | 27 ++++------- lib/sqlalchemy/dialects/mysql/cymysql.py | 9 +--- lib/sqlalchemy/dialects/mysql/oursql.py | 20 ++++---- lib/sqlalchemy/engine/base.py | 6 +-- lib/sqlalchemy/engine/ddl.py | 4 +- lib/sqlalchemy/engine/default.py | 53 ++++++++++------------ lib/sqlalchemy/event.py | 5 +- lib/sqlalchemy/schema.py | 27 ++++------- lib/sqlalchemy/sql/visitors.py | 2 +- lib/sqlalchemy/util/__init__.py | 5 +- lib/sqlalchemy/util/compat.py | 41 ++++++++--------- lib/sqlalchemy/util/langhelpers.py | 40 ++++++++-------- 16 files changed, 113 insertions(+), 147 deletions(-) create mode 100644 09notes.txt diff --git a/09notes.txt b/09notes.txt new file mode 100644 index 000000000..6b6295c4f --- /dev/null +++ b/09notes.txt @@ -0,0 +1,6 @@ +-- temporary notes -- + + +- make sure input() function in dogpile example works in py2 +- we want to get rid of any support for sets.Set entirely; check to see what +impact this has diff --git a/lib/sqlalchemy/dialects/informix/base.py b/lib/sqlalchemy/dialects/informix/base.py index a5a6917af..e13ea8819 100644 --- a/lib/sqlalchemy/dialects/informix/base.py +++ b/lib/sqlalchemy/dialects/informix/base.py @@ -299,7 +299,7 @@ class InfoDDLCompiler(compiler.DDLCompiler): def get_column_default_string(self, column): if (isinstance(column.server_default, schema.DefaultClause) and - isinstance(column.server_default.arg, util.string_type)): + isinstance(column.server_default.arg, util.string_types)): if isinstance(column.type, (sqltypes.Integer, sqltypes.Numeric)): return self.sql_compiler.process(text(column.server_default.arg)) diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index c5b86b887..d463b379d 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -295,7 +295,7 @@ class _MSDate(sqltypes.Date): def process(value): if isinstance(value, datetime.datetime): return value.date() - elif isinstance(value, util.string_type): + elif isinstance(value, util.string_types): return datetime.date(*[ int(x or 0) for x in self._reg.match(value).groups() @@ -328,7 +328,7 @@ class TIME(sqltypes.TIME): def process(value): if isinstance(value, datetime.datetime): return value.time() - elif isinstance(value, util.string_type): + elif isinstance(value, util.string_types): return datetime.time(*[ int(x or 0) for x in self._reg.match(value).groups()]) @@ -1002,7 +1002,7 @@ class MSDDLCompiler(compiler.DDLCompiler): # handle other included columns if index.kwargs.get("mssql_include"): inclusions = [index.table.c[col] - if isinstance(col, util.string_type) else col + if isinstance(col, util.string_types) else col for col in index.kwargs["mssql_include"]] text += " INCLUDE (%s)" \ diff --git a/lib/sqlalchemy/dialects/mssql/information_schema.py b/lib/sqlalchemy/dialects/mssql/information_schema.py index 61403271f..a7628f213 100644 --- a/lib/sqlalchemy/dialects/mssql/information_schema.py +++ b/lib/sqlalchemy/dialects/mssql/information_schema.py @@ -9,6 +9,7 @@ from ... import Table, MetaData, Column from ...types import String, Unicode, Integer, TypeDecorator from ... import cast +from ... import util ischema = MetaData() @@ -17,10 +18,8 @@ class CoerceUnicode(TypeDecorator): impl = Unicode def process_bind_param(self, value, dialect): -# start Py2K -# if isinstance(value, str): -# value = value.decode(dialect.encoding) -# end Py2K + if util.py2k and isinstance(value, util.binary_type): + value = value.decode(dialect.encoding) return value def bind_expression(self, bindvalue): diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index c0497b14f..1857c9a46 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -1171,7 +1171,7 @@ class SET(_StringType): super_convert = super(SET, self).bind_processor(dialect) def process(value): - if value is None or isinstance(value, (int, str)): + if value is None or isinstance(value, util.int_types + util.string_types): pass else: if None in value: @@ -1352,7 +1352,7 @@ class MySQLCompiler(compiler.SQLCompiler): of a SELECT. """ - if isinstance(select._distinct, str): + if isinstance(select._distinct, util.string_types): return select._distinct.upper() + " " elif select._distinct: return "DISTINCT " @@ -1494,7 +1494,7 @@ class MySQLDDLCompiler(compiler.DDLCompiler): k[len(self.dialect.name) + 1:].upper(), v ) - for k, v in list(table.kwargs.items()) + for k, v in table.kwargs.items() if k.startswith('%s_' % self.dialect.name) ) @@ -2485,7 +2485,7 @@ class MySQLTableDefinitionParser(object): for nope in ('auto_increment', 'data directory', 'index directory'): options.pop(nope, None) - for opt, val in list(options.items()): + for opt, val in options.items(): state.table_options['%s_%s' % (self.dialect.name, opt)] = val def _parse_column(self, line, state): @@ -2626,11 +2626,11 @@ class MySQLTableDefinitionParser(object): _final = self.preparer.final_quote - quotes = dict(list(zip(('iq', 'fq', 'esc_fq'), + quotes = dict(zip(('iq', 'fq', 'esc_fq'), [re.escape(s) for s in (self.preparer.initial_quote, _final, - self.preparer._escape_identifier(_final))]))) + self.preparer._escape_identifier(_final))])) self._pr_name = _pr_compile( r'^CREATE (?:\w+ +)?TABLE +' @@ -2802,12 +2802,8 @@ class _DecodingRowProxy(object): item = self.rowproxy[index] if isinstance(item, _array): item = item.tostring() -# start Py2K -# if self.charset and isinstance(item, str): -# end Py2K -# start Py3K - if self.charset and isinstance(item, bytes): -# end Py3K + + if self.charset and isinstance(item, util.binary_type): return item.decode(self.charset) else: return item @@ -2816,12 +2812,7 @@ class _DecodingRowProxy(object): item = getattr(self.rowproxy, attr) if isinstance(item, _array): item = item.tostring() -# start Py2K -# if self.charset and isinstance(item, str): -# end Py2K -# start Py3K - if self.charset and isinstance(item, bytes): -# end Py3K + if self.charset and isinstance(item, util.binary_type): return item.decode(self.charset) else: return item diff --git a/lib/sqlalchemy/dialects/mysql/cymysql.py b/lib/sqlalchemy/dialects/mysql/cymysql.py index 6fcbc2307..deb2de449 100644 --- a/lib/sqlalchemy/dialects/mysql/cymysql.py +++ b/lib/sqlalchemy/dialects/mysql/cymysql.py @@ -25,16 +25,9 @@ class _cymysqlBIT(BIT): def process(value): if value is not None: -# start Py2K -# v = 0L -# for i in map(ord, value): -# v = v << 8 | i -# end Py2K -# start Py3K v = 0 - for i in value: + for i in util.iterbytes(value): v = v << 8 | i -# end Py3K return v return value return process diff --git a/lib/sqlalchemy/dialects/mysql/oursql.py b/lib/sqlalchemy/dialects/mysql/oursql.py index b97afe933..77370f91d 100644 --- a/lib/sqlalchemy/dialects/mysql/oursql.py +++ b/lib/sqlalchemy/dialects/mysql/oursql.py @@ -55,10 +55,10 @@ class MySQLExecutionContext_oursql(MySQLExecutionContext): class MySQLDialect_oursql(MySQLDialect): driver = 'oursql' -# start Py2K -# supports_unicode_binds = True -# supports_unicode_statements = True -# end Py2K + + if util.py2k: + supports_unicode_binds = True + supports_unicode_statements = True supports_native_decimal = True @@ -90,13 +90,11 @@ class MySQLDialect_oursql(MySQLDialect): connection.cursor().execute('BEGIN', plain_query=True) def _xa_query(self, connection, query, xid): -# start Py2K -# arg = connection.connection._escape_string(xid) -# end Py2K -# start Py3K - charset = self._connection_charset - arg = connection.connection._escape_string(xid.encode(charset)).decode(charset) -# end Py3K + if util.py2k: + arg = connection.connection._escape_string(xid) + else: + charset = self._connection_charset + arg = connection.connection._escape_string(xid.encode(charset)).decode(charset) arg = "'%s'" % arg connection.execution_options(_oursql_plain_query=True).execute(query % arg) diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 9eb3d6128..dbc1ff820 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -3,7 +3,7 @@ # # This module is part of SQLAlchemy and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php - +from __future__ import with_statement """Defines :class:`.Connection` and :class:`.Engine`. @@ -734,7 +734,7 @@ class Connection(Connectable): distilled_params = _distill_params(multiparams, params) if distilled_params: - keys = list(distilled_params[0].keys()) + keys = list(distilled_params[0]) else: keys = [] @@ -1045,7 +1045,7 @@ class Connection(Connectable): Compiled: _execute_compiled, schema.SchemaItem: _execute_default, schema.DDLElement: _execute_ddl, - str: _execute_text + util.string_types[0]: _execute_text } def default_schema_name(self): diff --git a/lib/sqlalchemy/engine/ddl.py b/lib/sqlalchemy/engine/ddl.py index 56f475e30..6daa9be6b 100644 --- a/lib/sqlalchemy/engine/ddl.py +++ b/lib/sqlalchemy/engine/ddl.py @@ -55,7 +55,7 @@ class SchemaGenerator(DDLBase): tables = list(metadata.tables.values()) collection = [t for t in sql_util.sort_tables(tables) if self._can_create_table(t)] - seq_coll = [s for s in list(metadata._sequences.values()) + seq_coll = [s for s in metadata._sequences.values() if s.column is None and self._can_create_sequence(s)] metadata.dispatch.before_create(metadata, self.connection, @@ -130,7 +130,7 @@ class SchemaDropper(DDLBase): seq_coll = [ s - for s in list(metadata._sequences.values()) + for s in metadata._sequences.values() if s.column is None and self._can_drop_sequence(s) ] diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index 9dda6d81e..e52aac427 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -57,18 +57,16 @@ class DefaultDialect(interfaces.Dialect): # *not* the FLOAT type however. supports_native_decimal = False -# start Py3K - supports_unicode_statements = True - supports_unicode_binds = True - returns_unicode_strings = True - description_encoding = None -# end Py3K -# start Py2K -# supports_unicode_statements = False -# supports_unicode_binds = False -# returns_unicode_strings = False -# description_encoding = 'use_encoding' -# end Py2K + if util.py3k: + supports_unicode_statements = True + supports_unicode_binds = True + returns_unicode_strings = True + description_encoding = None + else: + supports_unicode_statements = False + supports_unicode_binds = False + returns_unicode_strings = False + description_encoding = 'use_encoding' name = 'default' @@ -202,15 +200,10 @@ class DefaultDialect(interfaces.Dialect): return None def _check_unicode_returns(self, connection): -# start Py2K -# if self.supports_unicode_statements: -# cast_to = unicode -# else: -# cast_to = str -# end Py2K -# start Py3K - cast_to = str -# end Py3K + if util.py2k and not self.supports_unicode_statements: + cast_to = util.binary_type + else: + cast_to = util.text_type def check_unicode(formatstr, type_): cursor = connection.connection.cursor() @@ -219,8 +212,8 @@ class DefaultDialect(interfaces.Dialect): cursor.execute( cast_to( expression.select( - [expression.cast( - expression.literal_column( + [expression.cast( + expression.literal_column( "'test %s returns'" % formatstr), type_) ]).compile(dialect=self) @@ -228,7 +221,7 @@ class DefaultDialect(interfaces.Dialect): ) row = cursor.fetchone() - return isinstance(row[0], str) + return isinstance(row[0], util.string_types) except self.dbapi.Error as de: util.warn("Exception attempting to " "detect unicode returns: %r" % de) @@ -375,10 +368,10 @@ class DefaultExecutionContext(interfaces.ExecutionContext): self.execution_options.update(connection._execution_options) if not dialect.supports_unicode_statements: - self.unicode_statement = str(compiled) + self.unicode_statement = util.text_type(compiled) self.statement = dialect._encoder(self.unicode_statement)[0] else: - self.statement = self.unicode_statement = str(compiled) + self.statement = self.unicode_statement = util.text_type(compiled) self.cursor = self.create_cursor() self.compiled_parameters = [] @@ -416,7 +409,7 @@ class DefaultExecutionContext(interfaces.ExecutionContext): self.result_map = compiled.result_map - self.unicode_statement = str(compiled) + self.unicode_statement = util.text_type(compiled) if not dialect.supports_unicode_statements: self.statement = self.unicode_statement.encode( self.dialect.encoding) @@ -521,7 +514,7 @@ class DefaultExecutionContext(interfaces.ExecutionContext): self.executemany = len(parameters) > 1 if not dialect.supports_unicode_statements and \ - isinstance(statement, str): + isinstance(statement, util.text_type): self.unicode_statement = statement self.statement = dialect._encoder(statement)[0] else: @@ -575,8 +568,8 @@ class DefaultExecutionContext(interfaces.ExecutionContext): """ conn = self.root_connection - if isinstance(stmt, str) and \ - not self.dialect.supports_unicode_statements: + if isinstance(stmt, util.text_type) and \ + not self.dialect.supports_unicode_statements: stmt = self.dialect._encoder(stmt)[0] if self.dialect.positional: diff --git a/lib/sqlalchemy/event.py b/lib/sqlalchemy/event.py index de054b0fd..316161fdf 100644 --- a/lib/sqlalchemy/event.py +++ b/lib/sqlalchemy/event.py @@ -200,10 +200,11 @@ def _remove_dispatcher(cls): if not _registrars[k]: del _registrars[k] - -class Events(object, metaclass=_EventMeta): +class Events(object): #util.with_metaclass(_EventMeta, object)): """Define event listening functions for a particular target type.""" + __metaclass__ = _EventMeta + @classmethod def _accept_with(cls, target): # Mapper, ClassManager, Session override this to diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index 030c400a7..b53eb8887 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -1154,24 +1154,15 @@ class Column(SchemaItem, expression.ColumnClause): nullable=self.nullable, quote=self.quote, _proxies=[self], *fk) - except TypeError as e: -# start Py3K - raise TypeError( - "Could not create a copy of this %r object. " - "Ensure the class includes a _constructor() " - "attribute or method which accepts the " - "standard Column constructor arguments, or " - "references the Column class itself." % self.__class__) from e -# end Py3K -# start Py2K -# raise TypeError( -# "Could not create a copy of this %r object. " -# "Ensure the class includes a _constructor() " -# "attribute or method which accepts the " -# "standard Column constructor arguments, or " -# "references the Column class itself. " -# "Original error: %s" % (self.__class__, e)) -# end Py2K + except TypeError: + util.raise_from_cause( + TypeError( + "Could not create a copy of this %r object. " + "Ensure the class includes a _constructor() " + "attribute or method which accepts the " + "standard Column constructor arguments, or " + "references the Column class itself." % self.__class__) + ) c.table = selectable selectable._columns.add(c) diff --git a/lib/sqlalchemy/sql/visitors.py b/lib/sqlalchemy/sql/visitors.py index 2ff7750ca..6efce504a 100644 --- a/lib/sqlalchemy/sql/visitors.py +++ b/lib/sqlalchemy/sql/visitors.py @@ -87,7 +87,7 @@ def _generate_dispatch(cls): cls._compiler_dispatch = _compiler_dispatch -class Visitable(object, metaclass=VisitableType): +class Visitable(util.with_metaclass(VisitableType, object)): """Base class for visitable objects, applies the ``VisitableType`` metaclass. diff --git a/lib/sqlalchemy/util/__init__.py b/lib/sqlalchemy/util/__init__.py index 2fcfabefd..9e562402d 100644 --- a/lib/sqlalchemy/util/__init__.py +++ b/lib/sqlalchemy/util/__init__.py @@ -5,9 +5,10 @@ # the MIT License: http://www.opensource.org/licenses/mit-license.php from .compat import callable, cmp, reduce, \ - threading, py3k, py3k_warning, jython, pypy, cpython, win32, set_types, \ + threading, py3k, py2k, jython, pypy, cpython, win32, \ pickle, dottedgetter, parse_qsl, namedtuple, next, WeakSet, reraise, \ - raise_from_cause, text_type, string_type, binary_type, quote_plus + raise_from_cause, text_type, string_types, int_types, binary_type, \ + quote_plus, with_metaclass from ._collections import KeyedTuple, ImmutableContainer, immutabledict, \ Properties, OrderedProperties, ImmutableProperties, OrderedDict, \ diff --git a/lib/sqlalchemy/util/compat.py b/lib/sqlalchemy/util/compat.py index d00e3ab23..5042d505b 100644 --- a/lib/sqlalchemy/util/compat.py +++ b/lib/sqlalchemy/util/compat.py @@ -14,29 +14,13 @@ except ImportError: import dummy_threading as threading py32 = sys.version_info >= (3, 2) -py3k_warning = getattr(sys, 'py3kwarning', False) or sys.version_info >= (3, 0) py3k = sys.version_info >= (3, 0) +py2k = not py3k jython = sys.platform.startswith('java') pypy = hasattr(sys, 'pypy_version_info') win32 = sys.platform.startswith('win') cpython = not pypy and not jython # TODO: something better for this ? -if py3k: - set_types = set -else: - # 2.6 deprecates sets.Set, but we still need to be able to detect them - # in user code and as return values from DB-APIs - ignore = ('ignore', None, DeprecationWarning, None, 0) - import warnings - try: - warnings.filters.insert(0, ignore) - except Exception: - import sets - else: - import sets - warnings.filters.remove(ignore) - - set_types = set, sets.Set if sys.version_info < (2, 6): def next(iter): @@ -51,23 +35,28 @@ else: except ImportError: import pickle -from urllib.parse import parse_qsl if py3k: from inspect import getfullargspec as inspect_getfullargspec - from urllib.parse import quote_plus, unquote_plus + from urllib.parse import quote_plus, unquote_plus, parse_qsl string_types = str, binary_type = bytes text_type = str + int_types = int, + iterbytes = iter else: from inspect import getargspec as inspect_getfullargspec from urllib import quote_plus, unquote_plus + from urlparse import parse_qsl string_types = basestring, binary_type = str text_type = unicode + int_types = int, long + def iterbytes(buf): + return (ord(byte) for byte in buf) -if py3k_warning: +if py3k: # they're bringing it back in 3.2. brilliant ! def callable(fn): return hasattr(fn, '__call__') @@ -149,19 +138,25 @@ if py3k: raise value.with_traceback(tb) raise value - def raise_from_cause(exception, exc_info): + def raise_from_cause(exception, exc_info=None): + if exc_info is None: + exc_info = sys.exc_info() exc_type, exc_value, exc_tb = exc_info reraise(type(exception), exception, tb=exc_tb, cause=exc_value) else: exec("def reraise(tp, value, tb=None, cause=None):\n" " raise tp, value, tb\n") - def raise_from_cause(exception, exc_info): + def raise_from_cause(exception, exc_info=None): # not as nice as that of Py3K, but at least preserves # the code line where the issue occurred + if exc_info is None: + exc_info = sys.exc_info() exc_type, exc_value, exc_tb = exc_info reraise(type(exception), exception, tb=exc_tb) +def with_metaclass(meta, *bases): + """Create a base class with a metaclass.""" - + return meta("MetaBase", bases, {}) diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py index 26dd97549..f65803dc6 100644 --- a/lib/sqlalchemy/util/langhelpers.py +++ b/lib/sqlalchemy/util/langhelpers.py @@ -15,8 +15,8 @@ import re import sys import types import warnings -from .compat import set_types, threading, \ - callable, inspect_getfullargspec +from .compat import threading, \ + callable, inspect_getfullargspec, py3k from functools import update_wrapper from .. import exc import hashlib @@ -265,23 +265,21 @@ def format_argspec_plus(fn, grouped=True): else: self_arg = None -# start Py3K - apply_pos = inspect.formatargspec(spec[0], spec[1], - spec[2], None, spec[4]) - num_defaults = 0 - if spec[3]: - num_defaults += len(spec[3]) - if spec[4]: - num_defaults += len(spec[4]) - name_args = spec[0] + spec[4] -# end Py3K -# start Py2K -# apply_pos = inspect.formatargspec(spec[0], spec[1], spec[2]) -# num_defaults = 0 -# if spec[3]: -# num_defaults += len(spec[3]) -# name_args = spec[0] -# end Py2K + if py3k: + apply_pos = inspect.formatargspec(spec[0], spec[1], + spec[2], None, spec[4]) + num_defaults = 0 + if spec[3]: + num_defaults += len(spec[3]) + if spec[4]: + num_defaults += len(spec[4]) + name_args = spec[0] + spec[4] + else: + apply_pos = inspect.formatargspec(spec[0], spec[1], spec[2]) + num_defaults = 0 + if spec[3]: + num_defaults += len(spec[3]) + name_args = spec[0] if num_defaults: defaulted_vals = name_args[0 - num_defaults:] @@ -842,7 +840,7 @@ def duck_type_collection(specimen, default=None): if hasattr(specimen, '__emulates__'): # canonicalize set vs sets.Set to a standard: the builtin set if (specimen.__emulates__ is not None and - issubclass(specimen.__emulates__, set_types)): + issubclass(specimen.__emulates__, set)): return set else: return specimen.__emulates__ @@ -850,7 +848,7 @@ def duck_type_collection(specimen, default=None): isa = isinstance(specimen, type) and issubclass or isinstance if isa(specimen, list): return list - elif isa(specimen, set_types): + elif isa(specimen, set): return set elif isa(specimen, dict): return dict -- cgit v1.2.1 From 32e0a1624bf1ae3cb6309062adefd2f5c89b541c Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 27 Apr 2013 20:58:13 -0400 Subject: import of "sqlalchemy" and "sqlalchemy.orm" works. --- 09notes.txt | 6 +++++- lib/sqlalchemy/engine/strategies.py | 19 ++++++------------- lib/sqlalchemy/engine/url.py | 13 +++++-------- lib/sqlalchemy/event.py | 7 +++---- lib/sqlalchemy/orm/collections.py | 6 +----- lib/sqlalchemy/orm/interfaces.py | 1 + lib/sqlalchemy/orm/mapper.py | 5 +++-- lib/sqlalchemy/sql/compiler.py | 16 +++------------- lib/sqlalchemy/sql/functions.py | 17 +++++++++-------- lib/sqlalchemy/sql/visitors.py | 8 +++----- 10 files changed, 39 insertions(+), 59 deletions(-) diff --git a/09notes.txt b/09notes.txt index 6b6295c4f..73652f96d 100644 --- a/09notes.txt +++ b/09notes.txt @@ -3,4 +3,8 @@ - make sure input() function in dogpile example works in py2 - we want to get rid of any support for sets.Set entirely; check to see what -impact this has +impact this has. in langhelpers as well as in collections.py +- give raise_from_cause some more manual tests: + - schema.py has one + - engine/strategies.py on connect + - sql/compiler.py for column errors in create table \ No newline at end of file diff --git a/lib/sqlalchemy/engine/strategies.py b/lib/sqlalchemy/engine/strategies.py index bed14c671..c65986ca2 100644 --- a/lib/sqlalchemy/engine/strategies.py +++ b/lib/sqlalchemy/engine/strategies.py @@ -80,19 +80,12 @@ class DefaultEngineStrategy(EngineStrategy): return dialect.connect(*cargs, **cparams) except Exception as e: invalidated = dialect.is_disconnect(e, None, None) -# start Py3K - raise exc.DBAPIError.instance(None, None, - e, dialect.dbapi.Error, - connection_invalidated=invalidated - ) from e -# end Py3K -# start Py2K -# import sys -# raise exc.DBAPIError.instance( -# None, None, e, dialect.dbapi.Error, -# connection_invalidated=invalidated -# ), None, sys.exc_info()[2] -# end Py2K + util.raise_from_cause( + exc.DBAPIError.instance(None, None, + e, dialect.dbapi.Error, + connection_invalidated=invalidated + ) + ) creator = kwargs.pop('creator', connect) diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py index 45768c5dc..b7d56374e 100644 --- a/lib/sqlalchemy/engine/url.py +++ b/lib/sqlalchemy/engine/url.py @@ -14,7 +14,6 @@ be used directly and is also accepted directly by ``create_engine()``. """ import re -import urllib.request, urllib.parse, urllib.error from .. import exc, util from . import Dialect @@ -67,7 +66,7 @@ class URL(object): if self.username is not None: s += self.username if self.password is not None: - s += ':' + urllib.parse.quote_plus(self.password) + s += ':' + util.quote_plus(self.password) s += "@" if self.host is not None: s += self.host @@ -76,7 +75,7 @@ class URL(object): if self.database is not None: s += '/' + self.database if self.query: - keys = list(self.query.keys()) + keys = list(self.query) keys.sort() s += '?' + "&".join("%s=%s" % (k, self.query[k]) for k in keys) return s @@ -177,17 +176,15 @@ def _parse_rfc1738_args(name): tokens = components['database'].split('?', 2) components['database'] = tokens[0] query = (len(tokens) > 1 and dict(util.parse_qsl(tokens[1]))) or None -# start Py2K -# if query is not None: -# query = dict((k.encode('ascii'), query[k]) for k in query) -# end Py2K + if util.py2k and query is not None: + query = dict((k.encode('ascii'), query[k]) for k in query) else: query = None components['query'] = query if components['password'] is not None: components['password'] = \ - urllib.parse.unquote_plus(components['password']) + util.unquote_plus(components['password']) name = components.pop('name') return URL(name, **components) diff --git a/lib/sqlalchemy/event.py b/lib/sqlalchemy/event.py index 316161fdf..79d024f9b 100644 --- a/lib/sqlalchemy/event.py +++ b/lib/sqlalchemy/event.py @@ -171,7 +171,8 @@ class _EventMeta(type): associated _Dispatch classes.""" def __init__(cls, classname, bases, dict_): - _create_dispatcher_class(cls, classname, bases, dict_) + if classname != 'MetaBase': + _create_dispatcher_class(cls, classname, bases, dict_) return type.__init__(cls, classname, bases, dict_) @@ -200,11 +201,9 @@ def _remove_dispatcher(cls): if not _registrars[k]: del _registrars[k] -class Events(object): #util.with_metaclass(_EventMeta, object)): +class Events(util.with_metaclass(_EventMeta, object)): """Define event listening functions for a particular target type.""" - __metaclass__ = _EventMeta - @classmethod def _accept_with(cls, target): # Mapper, ClassManager, Session override this to diff --git a/lib/sqlalchemy/orm/collections.py b/lib/sqlalchemy/orm/collections.py index 0a11b83c6..c2a2c23f0 100644 --- a/lib/sqlalchemy/orm/collections.py +++ b/lib/sqlalchemy/orm/collections.py @@ -1272,11 +1272,7 @@ def _dict_decorators(): l.pop('Unspecified') return l -if util.py3k_warning: - _set_binop_bases = (set, frozenset) -else: - import sets - _set_binop_bases = (set, frozenset, sets.BaseSet) +_set_binop_bases = (set, frozenset) def _set_binops_check_strict(self, obj): diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py index f14c8ca47..a81404401 100644 --- a/lib/sqlalchemy/orm/interfaces.py +++ b/lib/sqlalchemy/orm/interfaces.py @@ -16,6 +16,7 @@ classes within should be considered mostly private. """ +from __future__ import absolute_import from .. import exc as sa_exc, util, inspect from ..sql import operators diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 91c678547..645bf86e7 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -13,6 +13,7 @@ This is a semi-private module; the main configurational API of the ORM is available in :class:`~sqlalchemy.orm.`. """ +from __future__ import absolute_import import types import weakref @@ -26,8 +27,8 @@ from . import instrumentation, attributes, \ from .interfaces import MapperProperty, _InspectionAttr, _MappedAttribute from .util import _INSTRUMENTOR, _class_to_mapper, \ - _state_mapper, class_mapper, \ - PathRegistry + _state_mapper, class_mapper, \ + PathRegistry import sys properties = util.importlater("sqlalchemy.orm", "properties") descriptor_props = util.importlater("sqlalchemy.orm", "descriptor_props") diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index e5a2da366..b3f74ceef 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -1869,22 +1869,12 @@ class DDLCompiler(engine.Compiled): if column.primary_key: first_pk = True except exc.CompileError as ce: -# start Py3K - raise exc.CompileError("(in table '%s', column '%s'): %s" - % ( + util.raise_from_cause( + exc.CompileError("(in table '%s', column '%s'): %s" % ( table.description, column.name, ce.args[0] - )) from ce -# end Py3K -# start Py2K -# raise exc.CompileError("(in table '%s', column '%s'): %s" -# % ( -# table.description, -# column.name, -# ce.args[0] -# )), None, sys.exc_info()[2] -# end Py2K + ))) const = self.create_table_constraints(table) if const: diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py index a2b7ac628..244505bed 100644 --- a/lib/sqlalchemy/sql/functions.py +++ b/lib/sqlalchemy/sql/functions.py @@ -31,17 +31,18 @@ def register_function(identifier, fn, package="_default"): class _GenericMeta(VisitableType): def __init__(cls, clsname, bases, clsdict): - cls.name = name = clsdict.get('name', clsname) - cls.identifier = identifier = clsdict.get('identifier', name) - package = clsdict.pop('package', '_default') - # legacy - if '__return_type__' in clsdict: - cls.type = clsdict['__return_type__'] - register_function(identifier, cls, package) + if clsname != 'MetaBase': + cls.name = name = clsdict.get('name', clsname) + cls.identifier = identifier = clsdict.get('identifier', name) + package = clsdict.pop('package', '_default') + # legacy + if '__return_type__' in clsdict: + cls.type = clsdict['__return_type__'] + register_function(identifier, cls, package) super(_GenericMeta, cls).__init__(clsname, bases, clsdict) -class GenericFunction(Function, metaclass=_GenericMeta): +class GenericFunction(util.with_metaclass(_GenericMeta, Function)): """Define a 'generic' function. A generic function is a pre-established :class:`.Function` diff --git a/lib/sqlalchemy/sql/visitors.py b/lib/sqlalchemy/sql/visitors.py index 6efce504a..4d2948462 100644 --- a/lib/sqlalchemy/sql/visitors.py +++ b/lib/sqlalchemy/sql/visitors.py @@ -49,11 +49,9 @@ class VisitableType(type): Classes having no __visit_name__ attribute will remain unaffected. """ def __init__(cls, clsname, bases, clsdict): - if cls.__name__ == 'Visitable' or not hasattr(cls, '__visit_name__'): - super(VisitableType, cls).__init__(clsname, bases, clsdict) - return - - _generate_dispatch(cls) + if clsname not in ('MetaBase', 'Visitable') and \ + hasattr(cls, '__visit_name__'): + _generate_dispatch(cls) super(VisitableType, cls).__init__(clsname, bases, clsdict) -- cgit v1.2.1 From 1c647a879cbec0a301eb2cb021a30553abdced54 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 27 Apr 2013 21:01:54 -0400 Subject: cleanup --- lib/sqlalchemy/util/compat.py | 66 ++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 45 deletions(-) diff --git a/lib/sqlalchemy/util/compat.py b/lib/sqlalchemy/util/compat.py index 5042d505b..bdeb69d1e 100644 --- a/lib/sqlalchemy/util/compat.py +++ b/lib/sqlalchemy/util/compat.py @@ -22,11 +22,8 @@ win32 = sys.platform.startswith('win') cpython = not pypy and not jython # TODO: something better for this ? -if sys.version_info < (2, 6): - def next(iter): - return iter.__next__() -else: - next = next +next = next + if py3k: import pickle else: @@ -35,8 +32,6 @@ else: except ImportError: import pickle - - if py3k: from inspect import getfullargspec as inspect_getfullargspec from urllib.parse import quote_plus, unquote_plus, parse_qsl @@ -45,6 +40,21 @@ if py3k: text_type = str int_types = int, iterbytes = iter + + def b(s): + return s.encode("latin-1") + + if py32: + callable = callable + else: + def callable(fn): + return hasattr(fn, '__call__') + + def cmp(a, b): + return (a > b) - (a < b) + + from functools import reduce + else: from inspect import getargspec as inspect_getfullargspec from urllib import quote_plus, unquote_plus @@ -56,31 +66,13 @@ else: def iterbytes(buf): return (ord(byte) for byte in buf) -if py3k: - # they're bringing it back in 3.2. brilliant ! - def callable(fn): - return hasattr(fn, '__call__') - - def cmp(a, b): - return (a > b) - (a < b) + def b(s): + return s - from functools import reduce -else: callable = callable cmp = cmp reduce = reduce -try: - from collections import namedtuple -except ImportError: - def namedtuple(typename, fieldnames): - def __new__(cls, *values): - tup = tuple.__new__(cls, values) - for i, fname in enumerate(fieldnames): - setattr(tup, fname, tup[i]) - return tup - tuptype = type(typename, (tuple, ), {'__new__': __new__}) - return tuptype try: from weakref import WeakSet @@ -110,24 +102,8 @@ if win32 or jython: else: time_func = time.time - -if sys.version_info >= (2, 6): - from operator import attrgetter as dottedgetter -else: - def dottedgetter(attr): - def g(obj): - for name in attr.split("."): - obj = getattr(obj, name) - return obj - return g - -# Adapted from six.py -if py3k: - def b(s): - return s.encode("latin-1") -else: - def b(s): - return s +from collections import namedtuple +from operator import attrgetter as dottedgetter if py3k: -- cgit v1.2.1 From d37431d7a5f7c930527ad9418756d102adebffdb Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 28 Apr 2013 12:55:22 -0400 Subject: result --- lib/sqlalchemy/engine/result.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sqlalchemy/engine/result.py b/lib/sqlalchemy/engine/result.py index 0bd501423..65ce3b742 100644 --- a/lib/sqlalchemy/engine/result.py +++ b/lib/sqlalchemy/engine/result.py @@ -274,7 +274,7 @@ class ResultMetaData(object): def _key_fallback(self, key, raiseerr=True): map = self._keymap result = None - if isinstance(key, str): + if isinstance(key, util.string_types): result = map.get(key if self.case_sensitive else key.lower()) # fallback for targeting a ColumnElement to a textual expression # this is a rare use case which only occurs when matching text() @@ -329,7 +329,7 @@ class ResultMetaData(object): '_pickled_keymap': dict( (key, index) for key, (processor, obj, index) in self._keymap.items() - if isinstance(key, (str, int)) + if isinstance(key, util.string_types + util.int_types) ), 'keys': self.keys, "case_sensitive": self.case_sensitive, -- cgit v1.2.1 From 18370ac032a84da539c54640a425c0fca7613dc9 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 28 Apr 2013 14:08:28 -0400 Subject: - endless isinstance(x, str)s.... --- lib/sqlalchemy/schema.py | 66 +++++++++--------- lib/sqlalchemy/sql/compiler.py | 22 +++--- lib/sqlalchemy/sql/expression.py | 95 +++++++++++++------------- lib/sqlalchemy/sql/operators.py | 19 +++--- lib/sqlalchemy/testing/assertions.py | 24 +++---- lib/sqlalchemy/testing/fixtures.py | 12 ++-- lib/sqlalchemy/testing/plugin/noseplugin.py | 10 ++- lib/sqlalchemy/testing/warnings.py | 4 +- lib/sqlalchemy/util/__init__.py | 2 +- lib/sqlalchemy/util/compat.py | 40 +++++++++++ lib/sqlalchemy/util/langhelpers.py | 101 +++++++++++++--------------- 11 files changed, 212 insertions(+), 183 deletions(-) diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index b53eb8887..a8705beb4 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -679,11 +679,11 @@ class Table(SchemaItem, expression.TableClause): # skip indexes that would be generated # by the 'index' flag on Column if len(index.columns) == 1 and \ - list(index.columns)[0].index: + list(index.columns)[0].index: continue Index(index.name, unique=index.unique, - *[table.c[col] for col in list(index.columns.keys())], + *[table.c[col] for col in index.columns.keys()], **index.kwargs) table.dispatch._update(self.dispatch) return table @@ -898,7 +898,7 @@ class Column(SchemaItem, expression.ColumnClause): type_ = kwargs.pop('type_', None) args = list(args) if args: - if isinstance(args[0], str): + if isinstance(args[0], util.string_types): if name is not None: raise exc.ArgumentError( "May not pass name positionally and as a keyword.") @@ -944,12 +944,7 @@ class Column(SchemaItem, expression.ColumnClause): args.append(self.default) else: if getattr(self.type, '_warn_on_bytestring', False): -# start Py3K - if isinstance(self.default, bytes): -# end Py3K -# start Py2K -# if isinstance(self.default, str): -# end Py2K + if isinstance(self.default, util.binary_type): util.warn("Unicode column received non-unicode " "default value.") args.append(ColumnDefault(self.default)) @@ -984,7 +979,7 @@ class Column(SchemaItem, expression.ColumnClause): if kwargs: raise exc.ArgumentError( - "Unknown arguments passed to Column: " + repr(list(kwargs.keys()))) + "Unknown arguments passed to Column: " + repr(list(kwargs))) def __str__(self): if self.name is None: @@ -1070,7 +1065,7 @@ class Column(SchemaItem, expression.ColumnClause): self.table = table if self.index: - if isinstance(self.index, str): + if isinstance(self.index, util.string_types): raise exc.ArgumentError( "The 'index' keyword argument on Column is boolean only. " "To create indexes with a specific name, create an " @@ -1078,7 +1073,7 @@ class Column(SchemaItem, expression.ColumnClause): Index(expression._truncated_label('ix_%s' % self._label), self, unique=self.unique) elif self.unique: - if isinstance(self.unique, str): + if isinstance(self.unique, util.string_types): raise exc.ArgumentError( "The 'unique' keyword argument on Column is boolean " "only. To create unique constraints or indexes with a " @@ -1338,7 +1333,7 @@ class ForeignKey(SchemaItem): if schema: return schema + "." + self.column.table.name + \ "." + self.column.key - elif isinstance(self._colspec, str): + elif isinstance(self._colspec, util.string_types): return self._colspec elif hasattr(self._colspec, '__clause_element__'): _column = self._colspec.__clause_element__() @@ -1383,7 +1378,7 @@ class ForeignKey(SchemaItem): """ # ForeignKey inits its remote column as late as possible, so tables # can be defined without dependencies - if isinstance(self._colspec, str): + if isinstance(self._colspec, util.string_types): # locate the parent table this foreign key is attached to. we # use the "original" column which our parent column represents # (its a list of columns/other ColumnElements if the parent @@ -1650,8 +1645,7 @@ class ColumnDefault(DefaultGenerator): defaulted = argspec[3] is not None and len(argspec[3]) or 0 positionals = len(argspec[0]) - defaulted -# start Py3K -# end Py3K + # Py3K compat - no unbound methods if inspect.ismethod(inspectable) or inspect.isclass(fn): positionals -= 1 @@ -1913,7 +1907,7 @@ class DefaultClause(FetchedValue): has_argument = True def __init__(self, arg, for_update=False, _reflected=False): - util.assert_arg_type(arg, (str, + util.assert_arg_type(arg, (util.string_types[0], expression.ClauseElement, expression.TextClause), 'arg') super(DefaultClause, self).__init__(for_update) @@ -2023,7 +2017,7 @@ class ColumnCollectionMixin(object): def _set_parent(self, table): for col in self._pending_colargs: - if isinstance(col, str): + if isinstance(col, util.string_types): col = table.c[col] self.columns.add(col) @@ -2060,7 +2054,7 @@ class ColumnCollectionConstraint(ColumnCollectionMixin, Constraint): def copy(self, **kw): c = self.__class__(name=self.name, deferrable=self.deferrable, - initially=self.initially, *list(self.columns.keys())) + initially=self.initially, *self.columns.keys()) c.dispatch._update(self.dispatch) return c @@ -2241,7 +2235,7 @@ class ForeignKeyConstraint(Constraint): self._set_parent_with_dispatch(table) elif columns and \ isinstance(columns[0], Column) and \ - columns[0].table is not None: + columns[0].table is not None: self._set_parent_with_dispatch(columns[0].table) @property @@ -2250,7 +2244,7 @@ class ForeignKeyConstraint(Constraint): @property def columns(self): - return list(self._elements.keys()) + return list(self._elements) @property def elements(self): @@ -2262,7 +2256,7 @@ class ForeignKeyConstraint(Constraint): for col, fk in self._elements.items(): # string-specified column names now get # resolved to Column objects - if isinstance(col, str): + if isinstance(col, util.string_types): try: col = table.c[col] except KeyError: @@ -2272,7 +2266,7 @@ class ForeignKeyConstraint(Constraint): "named '%s' is present." % (table.description, col)) if not hasattr(fk, 'parent') or \ - fk.parent is not col: + fk.parent is not col: fk._set_parent_with_dispatch(col) if self.use_alter: @@ -2287,8 +2281,8 @@ class ForeignKeyConstraint(Constraint): def copy(self, schema=None, **kw): fkc = ForeignKeyConstraint( - [x.parent.key for x in list(self._elements.values())], - [x._get_colspec(schema=schema) for x in list(self._elements.values())], + [x.parent.key for x in self._elements.values()], + [x._get_colspec(schema=schema) for x in self._elements.values()], name=self.name, onupdate=self.onupdate, ondelete=self.ondelete, @@ -2563,7 +2557,7 @@ class MetaData(SchemaItem): return 'MetaData(bind=%r)' % self.bind def __contains__(self, table_or_key): - if not isinstance(table_or_key, str): + if not isinstance(table_or_key, util.string_types): table_or_key = table_or_key.key return table_or_key in self.tables @@ -2578,7 +2572,7 @@ class MetaData(SchemaItem): dict.pop(self.tables, key, None) if self._schemas: self._schemas = set([t.schema - for t in list(self.tables.values()) + for t in self.tables.values() if t.schema is not None]) def __getstate__(self): @@ -2623,7 +2617,7 @@ class MetaData(SchemaItem): def _bind_to(self, bind): """Bind this MetaData to an Engine, Connection, string or URL.""" - if isinstance(bind, (str, url.URL)): + if isinstance(bind, util.string_types + (url.URL, )): from sqlalchemy import create_engine self._bind = create_engine(bind) else: @@ -2656,7 +2650,7 @@ class MetaData(SchemaItem): :meth:`.Inspector.sorted_tables` """ - return sqlutil.sort_tables(iter(self.tables.values())) + return sqlutil.sort_tables(self.tables.values()) def reflect(self, bind=None, schema=None, views=False, only=None): """Load all available table definitions from the database. @@ -2717,7 +2711,7 @@ class MetaData(SchemaItem): bind.dialect.get_view_names(conn, schema) ) - current = set(self.tables.keys()) + current = set(self.tables) if only is None: load = [name for name in available if name not in current] @@ -2839,7 +2833,7 @@ class ThreadLocalMetaData(MetaData): def _bind_to(self, bind): """Bind to a Connectable in the caller's thread.""" - if isinstance(bind, (str, url.URL)): + if isinstance(bind, util.string_types + (url.URL, )): try: self.context._engine = self.__engines[bind] except KeyError: @@ -3069,7 +3063,7 @@ class DDLElement(expression.Executable, _DDLCompiles): not self._should_execute_deprecated(None, target, bind, **kw): return False - if isinstance(self.dialect, str): + if isinstance(self.dialect, util.string_types): if self.dialect != bind.engine.name: return False elif isinstance(self.dialect, (tuple, list, set)): @@ -3084,7 +3078,7 @@ class DDLElement(expression.Executable, _DDLCompiles): def _should_execute_deprecated(self, event, target, bind, **kw): if self.on is None: return True - elif isinstance(self.on, str): + elif isinstance(self.on, util.string_types): return self.on == bind.engine.name elif isinstance(self.on, (tuple, list, set)): return bind.engine.name in self.on @@ -3099,7 +3093,7 @@ class DDLElement(expression.Executable, _DDLCompiles): def _check_ddl_on(self, on): if (on is not None and - (not isinstance(on, (str, tuple, list, set)) and + (not isinstance(on, util.string_types + (tuple, list, set)) and not util.callable(on))): raise exc.ArgumentError( "Expected the name of a database dialect, a tuple " @@ -3224,7 +3218,7 @@ class DDL(DDLElement): """ - if not isinstance(statement, str): + if not isinstance(statement, util.string_types): raise exc.ArgumentError( "Expected a string or unicode SQL statement, got '%r'" % statement) @@ -3256,7 +3250,7 @@ def _to_schema_column(element): def _to_schema_column_or_string(element): if hasattr(element, '__clause_element__'): element = element.__clause_element__() - if not isinstance(element, (str, expression.ColumnElement)): + if not isinstance(element, util.string_types + (expression.ColumnElement, )): msg = "Element %r is not a string name or column element" raise exc.ArgumentError(msg % element) return element diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index b3f74ceef..d51dd625a 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -83,9 +83,7 @@ OPERATORS = { operators.add: ' + ', operators.mul: ' * ', operators.sub: ' - ', -# start Py2K -# operators.div: ' / ', -# end Py2K + operators.div: ' / ', operators.mod: ' % ', operators.truediv: ' / ', operators.neg: '-', @@ -826,12 +824,12 @@ class SQLCompiler(engine.Compiled): of the DBAPI. """ - if isinstance(value, str): + if isinstance(value, util.string_types): value = value.replace("'", "''") return "'%s'" % value elif value is None: return "NULL" - elif isinstance(value, (float, int)): + elif isinstance(value, (float, ) + util.int_types): return repr(value) elif isinstance(value, decimal.Decimal): return str(value) @@ -1214,7 +1212,7 @@ class SQLCompiler(engine.Compiled): self.positiontup = self.cte_positional + self.positiontup cte_text = self.get_cte_preamble(self.ctes_recursive) + " " cte_text += ", \n".join( - [txt for txt in list(self.ctes.values())] + [txt for txt in self.ctes.values()] ) cte_text += "\n " return cte_text @@ -1325,7 +1323,7 @@ class SQLCompiler(engine.Compiled): dialect_hints = dict([ (table, hint_text) for (table, dialect), hint_text in - list(insert_stmt._hints.items()) + insert_stmt._hints.items() if dialect in ('*', self.dialect.name) ]) if insert_stmt.table in dialect_hints: @@ -1422,7 +1420,7 @@ class SQLCompiler(engine.Compiled): dialect_hints = dict([ (table, hint_text) for (table, dialect), hint_text in - list(update_stmt._hints.items()) + update_stmt._hints.items() if dialect in ('*', self.dialect.name) ]) if update_stmt.table in dialect_hints: @@ -1559,7 +1557,7 @@ class SQLCompiler(engine.Compiled): if extra_tables and stmt_parameters: normalized_params = dict( (sql._clause_element_as_expr(c), param) - for c, param in list(stmt_parameters.items()) + for c, param in stmt_parameters.items() ) assert self.isupdate affected_tables = set() @@ -1752,7 +1750,7 @@ class SQLCompiler(engine.Compiled): dialect_hints = dict([ (table, hint_text) for (table, dialect), hint_text in - list(delete_stmt._hints.items()) + delete_stmt._hints.items() if dialect in ('*', self.dialect.name) ]) if delete_stmt.table in dialect_hints: @@ -1870,11 +1868,11 @@ class DDLCompiler(engine.Compiled): first_pk = True except exc.CompileError as ce: util.raise_from_cause( - exc.CompileError("(in table '%s', column '%s'): %s" % ( + exc.CompileError(util.u("(in table '%s', column '%s'): %s" % ( table.description, column.name, ce.args[0] - ))) + )))) const = self.create_table_constraints(table) if const: diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 1ad6364d2..aff5512d3 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -26,7 +26,7 @@ to stay the same in future releases. """ - +from __future__ import unicode_literals import itertools import re from operator import attrgetter @@ -1375,7 +1375,7 @@ func = _FunctionGenerator() modifier = _FunctionGenerator(group=False) -class _truncated_label(str): +class _truncated_label(util.text_type): """A unicode subclass used to identify symbolic " "names that may require truncation.""" @@ -1395,13 +1395,13 @@ class _anonymous_label(_truncated_label): def __add__(self, other): return _anonymous_label( - str(self) + - str(other)) + util.text_type(self) + + util.text_type(other)) def __radd__(self, other): return _anonymous_label( - str(other) + - str(self)) + util.text_type(other) + + util.text_type(self)) def apply_map(self, map_): return self % map_ @@ -1422,7 +1422,7 @@ def _as_truncated(value): def _string_or_unprintable(element): - if isinstance(element, str): + if isinstance(element, util.string_types): return element else: try: @@ -1486,7 +1486,7 @@ def _labeled(element): def _column_as_key(element): - if isinstance(element, str): + if isinstance(element, util.string_types): return element if hasattr(element, '__clause_element__'): element = element.__clause_element__() @@ -1508,8 +1508,8 @@ def _literal_as_text(element): return element elif hasattr(element, '__clause_element__'): return element.__clause_element__() - elif isinstance(element, str): - return TextClause(str(element)) + elif isinstance(element, util.string_types): + return TextClause(util.text_type(element)) elif isinstance(element, (util.NoneType, bool)): return _const_expr(element) else: @@ -1583,8 +1583,8 @@ def _interpret_as_column_or_from(element): def _interpret_as_from(element): insp = inspection.inspect(element, raiseerr=False) if insp is None: - if isinstance(element, str): - return TextClause(str(element)) + if isinstance(element, util.string_types): + return TextClause(util.text_type(element)) elif hasattr(insp, "selectable"): return insp.selectable raise exc.ArgumentError("FROM expression expected") @@ -1914,12 +1914,10 @@ class ClauseElement(Visitable): return dialect.statement_compiler(dialect, self, **kw) def __str__(self): -# start Py3K - return str(self.compile()) -# end Py3K -# start Py2K -# return unicode(self.compile()).encode('ascii', 'backslashreplace') -# end Py2K + if util.py3k: + return str(self.compile()) + else: + return unicode(self.compile()).encode('ascii', 'backslashreplace') def __and__(self, other): return and_(self, other) @@ -1933,6 +1931,8 @@ class ClauseElement(Visitable): def __bool__(self): raise TypeError("Boolean value of this clause is not defined") + __nonzero__ = __bool__ + def _negate(self): if hasattr(self, 'negation_clause'): return self.negation_clause @@ -2508,7 +2508,7 @@ class ColumnCollection(util.OrderedProperties): def update(self, value): self._data.update(value) self._all_cols.clear() - self._all_cols.update(list(self._data.values())) + self._all_cols.update(self._data.values()) def extend(self, iter): self.update((c.key, c) for c in iter) @@ -2524,13 +2524,13 @@ class ColumnCollection(util.OrderedProperties): return and_(*l) def __contains__(self, other): - if not isinstance(other, str): + if not isinstance(other, util.string_types): raise exc.ArgumentError("__contains__ requires a string argument") return util.OrderedProperties.__contains__(self, other) def __setstate__(self, state): self.__dict__['_data'] = state['_data'] - self.__dict__['_all_cols'] = util.column_set(list(self._data.values())) + self.__dict__['_all_cols'] = util.column_set(self._data.values()) def contains_column(self, col): # this has to be done via set() membership @@ -3185,13 +3185,13 @@ class TextClause(Executable, ClauseElement): _hide_froms = [] def __init__( - self, - text='', - bind=None, - bindparams=None, - typemap=None, - autocommit=None, - ): + self, + text='', + bind=None, + bindparams=None, + typemap=None, + autocommit=None): + self._bind = bind self.bindparams = {} self.typemap = typemap @@ -3201,9 +3201,9 @@ class TextClause(Executable, ClauseElement): 'e)') self._execution_options = \ self._execution_options.union( - {'autocommit': autocommit}) + {'autocommit': autocommit}) if typemap is not None: - for key in list(typemap.keys()): + for key in typemap: typemap[key] = sqltypes.to_instance(typemap[key]) def repl(m): @@ -3237,7 +3237,7 @@ class TextClause(Executable, ClauseElement): def _copy_internals(self, clone=_clone, **kw): self.bindparams = dict((b.key, clone(b, **kw)) - for b in list(self.bindparams.values())) + for b in self.bindparams.values()) def get_children(self, **kwargs): return list(self.bindparams.values()) @@ -3751,7 +3751,7 @@ class BinaryExpression(ColumnElement): negate=None, modifiers=None): # allow compatibility with libraries that # refer to BinaryExpression directly and pass strings - if isinstance(operator, str): + if isinstance(operator, util.string_types): operator = operators.custom_op(operator) self._orig = (left, right) self.left = _literal_as_text(left).self_group(against=operator) @@ -3770,6 +3770,7 @@ class BinaryExpression(ColumnElement): return self.operator(hash(self._orig[0]), hash(self._orig[1])) else: raise TypeError("Boolean value of this clause is not defined") + __nonzero__ = __bool__ @property def is_comparison(self): @@ -4058,12 +4059,10 @@ class Alias(FromClause): @property def description(self): -# start Py3K - return self.name -# end Py3K -# start Py2K -# return self.name.encode('ascii', 'backslashreplace') -# end Py2K + if util.py3k: + return self.name + else: + return self.name.encode('ascii', 'backslashreplace') def as_scalar(self): try: @@ -4473,12 +4472,10 @@ class ColumnClause(Immutable, ColumnElement): @util.memoized_property def description(self): -# start Py3K - return self.name -# end Py3K -# start Py2K -# return self.name.encode('ascii', 'backslashreplace') -# end Py2K + if util.py3k: + return self.name + else: + return self.name.encode('ascii', 'backslashreplace') @_memoized_property def _key_label(self): @@ -4605,12 +4602,10 @@ class TableClause(Immutable, FromClause): @util.memoized_property def description(self): -# start Py3K - return self.name -# end Py3K -# start Py2K -# return self.name.encode('ascii', 'backslashreplace') -# end Py2K + if util.py3k: + return self.name + else: + return self.name.encode('ascii', 'backslashreplace') def append_column(self, c): self._columns[c.key] = c diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py index cf1c484d0..4afb3db48 100644 --- a/lib/sqlalchemy/sql/operators.py +++ b/lib/sqlalchemy/sql/operators.py @@ -9,16 +9,19 @@ """Defines operators used in SQL expressions.""" +from .. import util + + from operator import ( and_, or_, inv, add, mul, sub, mod, truediv, lt, le, ne, gt, ge, eq, neg, getitem, lshift, rshift ) -# start Py2K -#from operator import (div,) -# end Py2K +if util.py2k: + from operator import div +else: + div = truediv -from ..util import symbol class Operators(object): @@ -781,17 +784,15 @@ parenthesize (a op b). """ -_smallest = symbol('_smallest', canonical=-100) -_largest = symbol('_largest', canonical=100) +_smallest = util.symbol('_smallest', canonical=-100) +_largest = util.symbol('_largest', canonical=100) _PRECEDENCE = { from_: 15, getitem: 15, mul: 8, truediv: 8, -# start Py2K -# div: 8, -# end Py2K + div: 8, mod: 8, neg: 8, add: 7, diff --git a/lib/sqlalchemy/testing/assertions.py b/lib/sqlalchemy/testing/assertions.py index e01948f9c..c04153961 100644 --- a/lib/sqlalchemy/testing/assertions.py +++ b/lib/sqlalchemy/testing/assertions.py @@ -1,4 +1,4 @@ - +from __future__ import absolute_import from . import util as testutil from sqlalchemy import pool, orm, util @@ -63,7 +63,7 @@ def emits_warning_on(db, *warnings): @decorator def decorate(fn, *args, **kw): - if isinstance(db, str): + if isinstance(db, util.string_types): if not spec(config.db): return fn(*args, **kw) else: @@ -172,8 +172,8 @@ def assert_raises_message(except_cls, msg, callable_, *args, **kwargs): callable_(*args, **kwargs) assert False, "Callable did not raise an exception" except except_cls as e: - assert re.search(msg, str(e), re.UNICODE), "%r !~ %s" % (msg, e) - print(str(e).encode('utf-8')) + assert re.search(msg, util.text_type(e), re.UNICODE), "%r !~ %s" % (msg, e) + print(util.text_type(e).encode('utf-8')) class AssertsCompiledSQL(object): @@ -190,12 +190,12 @@ class AssertsCompiledSQL(object): dialect = default.DefaultDialect() elif dialect is None: dialect = config.db.dialect - elif isinstance(dialect, str): + elif isinstance(dialect, util.string_types): dialect = create_engine("%s://" % dialect).dialect kw = {} if params is not None: - kw['column_keys'] = list(params.keys()) + kw['column_keys'] = list(params) if isinstance(clause, orm.Query): context = clause._compile_context() @@ -205,13 +205,13 @@ class AssertsCompiledSQL(object): c = clause.compile(dialect=dialect, **kw) param_str = repr(getattr(c, 'params', {})) -# start Py3K - param_str = param_str.encode('utf-8').decode('ascii', 'ignore') -# end Py3K - print("\nSQL String:\n" + str(c) + param_str) + if util.py3k: + param_str = param_str.encode('utf-8').decode('ascii', 'ignore') + + print("\nSQL String:\n" + util.text_type(c) + param_str) - cc = re.sub(r'[\n\t]', '', str(c)) + cc = re.sub(r'[\n\t]', '', util.text_type(c)) eq_(cc, result, "%r != %r on dialect %r" % (cc, result, dialect)) @@ -301,7 +301,7 @@ class AssertsExecutionResults(object): found = util.IdentitySet(result) expected = set([immutabledict(e) for e in expected]) - for wrong in itertools.filterfalse(lambda o: type(o) == cls, found): + for wrong in util.itertools_filterfalse(lambda o: type(o) == cls, found): fail('Unexpected type "%s", expected "%s"' % ( type(wrong).__name__, cls.__name__)) diff --git a/lib/sqlalchemy/testing/fixtures.py b/lib/sqlalchemy/testing/fixtures.py index 08b2361f2..daa779ae3 100644 --- a/lib/sqlalchemy/testing/fixtures.py +++ b/lib/sqlalchemy/testing/fixtures.py @@ -1,6 +1,7 @@ from . import config from . import assertions, schema from .util import adict +from .. import util from .engines import drop_all_tables from .entities import BasicEntity, ComparableEntity import sys @@ -126,8 +127,9 @@ class TablesTest(TestBase): try: table.delete().execute().close() except sa.exc.DBAPIError as ex: - print("Error emptying table %s: %r" % ( - table, ex), file=sys.stderr) + util.print_( + ("Error emptying table %s: %r" % (table, ex)), + file=sys.stderr) def setup(self): self._setup_each_tables() @@ -190,7 +192,7 @@ class TablesTest(TestBase): for table, data in cls.fixtures().items(): if len(data) < 2: continue - if isinstance(table, str): + if isinstance(table, util.string_types): table = cls.tables[table] headers[table] = data[0] rows[table] = data[1:] @@ -199,7 +201,7 @@ class TablesTest(TestBase): continue cls.bind.execute( table.insert(), - [dict(list(zip(headers[table], column_values))) + [dict(zip(headers[table], column_values)) for column_values in rows[table]]) @@ -284,7 +286,7 @@ class MappedTest(_ORMTest, TablesTest, assertions.AssertsExecutionResults): cls_registry[classname] = cls return type.__init__(cls, classname, bases, dict_) - class _Base(object, metaclass=FindFixture): + class _Base(util.with_metaclass(FindFixture, object)): pass class Basic(BasicEntity, _Base): diff --git a/lib/sqlalchemy/testing/plugin/noseplugin.py b/lib/sqlalchemy/testing/plugin/noseplugin.py index 7ad61c7b9..b3cd3a4e3 100644 --- a/lib/sqlalchemy/testing/plugin/noseplugin.py +++ b/lib/sqlalchemy/testing/plugin/noseplugin.py @@ -10,13 +10,19 @@ normally as "from sqlalchemy.testing.plugin import noseplugin". """ +from __future__ import absolute_import import os -import configparser +import sys +py3k = sys.version_info >= (3, 0) + +if py3k: + import configparser +else: + import ConfigParser as configparser from nose.plugins import Plugin from nose import SkipTest -import time import sys import re diff --git a/lib/sqlalchemy/testing/warnings.py b/lib/sqlalchemy/testing/warnings.py index 9546945eb..6193acd88 100644 --- a/lib/sqlalchemy/testing/warnings.py +++ b/lib/sqlalchemy/testing/warnings.py @@ -1,4 +1,4 @@ - +from __future__ import absolute_import import warnings from .. import exc as sa_exc @@ -10,7 +10,7 @@ def testing_warn(msg, stacklevel=3): filename = "sqlalchemy.testing.warnings" lineno = 1 - if isinstance(msg, str): + if isinstance(msg, util.string_types): warnings.warn_explicit(msg, sa_exc.SAWarning, filename, lineno) else: warnings.warn_explicit(msg, filename, lineno) diff --git a/lib/sqlalchemy/util/__init__.py b/lib/sqlalchemy/util/__init__.py index 9e562402d..25dcce335 100644 --- a/lib/sqlalchemy/util/__init__.py +++ b/lib/sqlalchemy/util/__init__.py @@ -8,7 +8,7 @@ from .compat import callable, cmp, reduce, \ threading, py3k, py2k, jython, pypy, cpython, win32, \ pickle, dottedgetter, parse_qsl, namedtuple, next, WeakSet, reraise, \ raise_from_cause, text_type, string_types, int_types, binary_type, \ - quote_plus, with_metaclass + quote_plus, with_metaclass, print_, itertools_filterfalse, u, b from ._collections import KeyedTuple, ImmutableContainer, immutabledict, \ Properties, OrderedProperties, ImmutableProperties, OrderedDict, \ diff --git a/lib/sqlalchemy/util/compat.py b/lib/sqlalchemy/util/compat.py index bdeb69d1e..bc7a0fe21 100644 --- a/lib/sqlalchemy/util/compat.py +++ b/lib/sqlalchemy/util/compat.py @@ -33,6 +33,8 @@ else: import pickle if py3k: + import builtins + from inspect import getfullargspec as inspect_getfullargspec from urllib.parse import quote_plus, unquote_plus, parse_qsl string_types = str, @@ -41,6 +43,9 @@ if py3k: int_types = int, iterbytes = iter + def u(s): + return s + def b(s): return s.encode("latin-1") @@ -55,6 +60,13 @@ if py3k: from functools import reduce + print_ = getattr(builtins, "print") + + import_ = getattr(builtins, '__import__') + + import itertools + itertools_filterfalse = itertools.filterfalse + itertools_imap = map else: from inspect import getargspec as inspect_getfullargspec from urllib import quote_plus, unquote_plus @@ -66,13 +78,35 @@ else: def iterbytes(buf): return (ord(byte) for byte in buf) + def u(s): + return unicode(s, "unicode_escape") + def b(s): return s + def import_(*args): + if len(args) == 4: + args = args[0:3] + ([str(arg) for arg in args[3]],) + return __import__(*args) + callable = callable cmp = cmp reduce = reduce + def print_(*args, **kwargs): + fp = kwargs.pop("file", sys.stdout) + if fp is None: + return + for arg in enumerate(args): + if not isinstance(arg, basestring): + arg = str(arg) + fp.write(arg) + + import itertools + itertools_filterfalse = itertools.ifilterfalse + itertools_imap = itertools.imap + + try: from weakref import WeakSet @@ -131,6 +165,12 @@ else: exc_type, exc_value, exc_tb = exc_info reraise(type(exception), exception, tb=exc_tb) +if py3k: + exec_ = getattr(builtins, 'exec') +else: + def exec_(func_text, globals_, lcl): + exec('exec func_text in globals_, lcl') + def with_metaclass(meta, *bases): """Create a base class with a metaclass.""" diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py index f65803dc6..8a6af3758 100644 --- a/lib/sqlalchemy/util/langhelpers.py +++ b/lib/sqlalchemy/util/langhelpers.py @@ -15,18 +15,14 @@ import re import sys import types import warnings -from .compat import threading, \ - callable, inspect_getfullargspec, py3k from functools import update_wrapper from .. import exc import hashlib from . import compat -import collections def md5_hex(x): -# start Py3K - x = x.encode('utf-8') -# end Py3K + if compat.py3k: + x = x.encode('utf-8') m = hashlib.md5() m.update(x) return m.hexdigest() @@ -79,7 +75,7 @@ def _unique_symbols(used, *bases): used = set(used) for base in bases: pool = itertools.chain((base,), - map(lambda i: base + str(i), + compat.itertools_imap(lambda i: base + str(i), range(1000))) for sym in pool: if sym not in used: @@ -96,7 +92,7 @@ def decorator(target): def decorate(fn): if not inspect.isfunction(fn): raise Exception("not a decoratable function") - spec = inspect_getfullargspec(fn) + spec = compat.inspect_getfullargspec(fn) names = tuple(spec[0]) + spec[1:3] + (fn.__name__,) targ_name, fn_name = _unique_symbols(names, 'target', 'fn') @@ -145,7 +141,7 @@ class PluginLoader(object): def register(self, name, modulepath, objname): def load(): - mod = __import__(modulepath) + mod = compat.import_(modulepath) for token in modulepath.split(".")[1:]: mod = getattr(mod, token) return getattr(mod, objname) @@ -252,8 +248,8 @@ def format_argspec_plus(fn, grouped=True): 'apply_pos': '(self, a, b, c, **d)'} """ - if isinstance(fn, collections.Callable): - spec = inspect_getfullargspec(fn) + if compat.callable(fn): + spec = compat.inspect_getfullargspec(fn) else: # we accept an existing argspec... spec = fn @@ -265,7 +261,7 @@ def format_argspec_plus(fn, grouped=True): else: self_arg = None - if py3k: + if compat.py3k: apply_pos = inspect.formatargspec(spec[0], spec[1], spec[2], None, spec[4]) num_defaults = 0 @@ -420,34 +416,33 @@ def class_hierarchy(cls): will not be descended. """ -# start Py2K -# if isinstance(cls, types.ClassType): -# return list() -# end Py2K + if compat.py2k: + if isinstance(cls, types.ClassType): + return list() + hier = set([cls]) process = list(cls.__mro__) while process: c = process.pop() -# start Py2K -# if isinstance(c, types.ClassType): -# continue -# for b in (_ for _ in c.__bases__ -# if _ not in hier and not isinstance(_, types.ClassType)): -# end Py2K -# start Py3K - for b in (_ for _ in c.__bases__ - if _ not in hier): -# end Py3K + if compat.py2k: + if isinstance(c, types.ClassType): + continue + bases = (_ for _ in c.__bases__ + if _ not in hier and not isinstance(_, types.ClassType)) + else: + bases = (_ for _ in c.__bases__ if _ not in hier) + + for b in bases: process.append(b) hier.add(b) -# start Py3K - if c.__module__ == 'builtins' or not hasattr(c, '__subclasses__'): - continue -# end Py3K -# start Py2K -# if c.__module__ == '__builtin__' or not hasattr(c, '__subclasses__'): -# continue -# end Py2K + + if compat.py3k: + if c.__module__ == 'builtins' or not hasattr(c, '__subclasses__'): + continue + else: + if c.__module__ == '__builtin__' or not hasattr(c, '__subclasses__'): + continue + for s in [_ for _ in c.__subclasses__() if _ not in hier]: process.append(s) hier.add(s) @@ -504,7 +499,7 @@ def monkeypatch_proxied_specials(into_cls, from_cls, skip=None, only=None, "return %(name)s.%(method)s%(d_args)s" % locals()) env = from_instance is not None and {name: from_instance} or {} - exec(py, env) + compat.exec_(py, env, {}) try: env[method].__defaults__ = fn.__defaults__ except AttributeError: @@ -593,7 +588,7 @@ def as_interface(obj, cls=None, methods=None, required=None): for method, impl in dictlike_iteritems(obj): if method not in interface: raise TypeError("%r: unknown in this interface" % method) - if not isinstance(impl, collections.Callable): + if not compat.callable(impl): raise TypeError("%r=%r is not callable" % (method, impl)) setattr(AnonymousInterface, method, staticmethod(impl)) found.add(method) @@ -734,11 +729,11 @@ class importlater(object): def _resolve(self): importlater._unresolved.discard(self) if self._il_addtl: - self._initial_import = __import__( + self._initial_import = compat.import_( self._il_path, globals(), locals(), [self._il_addtl]) else: - self._initial_import = __import__(self._il_path) + self._initial_import = compat.import_(self._il_path) def __getattr__(self, key): if key == 'module': @@ -757,7 +752,7 @@ class importlater(object): # from paste.deploy.converters def asbool(obj): - if isinstance(obj, str): + if isinstance(obj, compat.string_types): obj = obj.strip().lower() if obj in ['true', 'yes', 'on', 'y', 't', '1']: return True @@ -817,7 +812,7 @@ def constructor_copy(obj, cls, **kw): def counter(): """Return a threadsafe counter function.""" - lock = threading.Lock() + lock = compat.threading.Lock() counter = itertools.count(1) # avoid the 2to3 "next" transformation... @@ -880,16 +875,14 @@ def assert_arg_type(arg, argtype, name): def dictlike_iteritems(dictlike): """Return a (key, value) iterator for almost any dict-like object.""" -# start Py3K - if hasattr(dictlike, 'items'): - return list(dictlike.items()) -# end Py3K -# start Py2K -# if hasattr(dictlike, 'iteritems'): -# return dictlike.iteritems() -# elif hasattr(dictlike, 'items'): -# return iter(dictlike.items()) -# end Py2K + if compat.py3k: + if hasattr(dictlike, 'items'): + return list(dictlike.items()) + else: + if hasattr(dictlike, 'iteritems'): + return dictlike.iteritems() + elif hasattr(dictlike, 'items'): + return iter(dictlike.items()) getter = getattr(dictlike, '__getitem__', getattr(dictlike, 'get', None)) if getter is None: @@ -902,7 +895,7 @@ def dictlike_iteritems(dictlike): yield key, getter(key) return iterator() elif hasattr(dictlike, 'keys'): - return iter((key, getter(key)) for key in list(dictlike.keys())) + return iter((key, getter(key)) for key in dictlike.keys()) else: raise TypeError( "Object '%r' is not dict-like" % dictlike) @@ -942,7 +935,7 @@ class hybridmethod(object): class _symbol(int): def __new__(self, name, doc=None, canonical=None): """Construct a new named symbol.""" - assert isinstance(name, str) + assert isinstance(name, compat.string_types) if canonical is None: canonical = hash(name) v = int.__new__(_symbol, canonical) @@ -985,7 +978,7 @@ class symbol(object): """ symbols = {} - _lock = threading.Lock() + _lock = compat.threading.Lock() def __new__(cls, name, doc=None, canonical=None): cls._lock.acquire() @@ -1039,7 +1032,7 @@ def warn(msg, stacklevel=3): be controlled. """ - if isinstance(msg, str): + if isinstance(msg, compat.string_types): warnings.warn(msg, exc.SAWarning, stacklevel=stacklevel) else: warnings.warn(msg, stacklevel=stacklevel) -- cgit v1.2.1 From fc624dcfa40bf765bbfffa2fd964f73422e4dbe8 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 28 Apr 2013 14:44:21 -0400 Subject: - test_types, test_compiler, with sqlite at least --- lib/sqlalchemy/engine/base.py | 4 ++- lib/sqlalchemy/sql/expression.py | 3 +- lib/sqlalchemy/types.py | 31 ++++++++---------- test/sql/test_compiler.py | 3 +- test/sql/test_types.py | 70 +++++++++++++--------------------------- 5 files changed, 43 insertions(+), 68 deletions(-) diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index dbc1ff820..d4ced4cca 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -734,7 +734,9 @@ class Connection(Connectable): distilled_params = _distill_params(multiparams, params) if distilled_params: - keys = list(distilled_params[0]) + # need list() + keys() here to suit + # both dict and RowProxy + keys = list(distilled_params[0].keys()) else: keys = [] diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index aff5512d3..2c7b91fe6 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -2204,7 +2204,7 @@ class _DefaultColumnComparator(operators.ColumnOperators): def _check_literal(self, expr, operator, other): if isinstance(other, (ColumnElement, TextClause)): if isinstance(other, BindParameter) and \ - isinstance(other.type, sqltypes.NullType): + isinstance(other.type, sqltypes.NullType): # TODO: perhaps we should not mutate the incoming # bindparam() here and instead make a copy of it. # this might be the only place that we're mutating @@ -3116,7 +3116,6 @@ class Executable(Generative): def execute(self, *multiparams, **params): """Compile and execute this :class:`.Executable`.""" - e = self.bind if e is None: label = getattr(self, 'description', self.__class__.__name__) diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index 4fbadcb0c..ffcd793c6 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -1115,12 +1115,7 @@ class String(Concatenable, TypeEngine): self.convert_unicode != 'force': if self._warn_on_bytestring: def process(value): -# start Py3K - if isinstance(value, bytes): -# end Py3K -# start Py2K -# if isinstance(value, str): -# end Py2K + if isinstance(value, util.binary_type): util.warn("Unicode type received non-unicode bind " "param value.") return value @@ -1132,7 +1127,7 @@ class String(Concatenable, TypeEngine): warn_on_bytestring = self._warn_on_bytestring def process(value): - if isinstance(value, str): + if isinstance(value, util.text_type): return encoder(value, self.unicode_error)[0] elif warn_on_bytestring and value is not None: util.warn("Unicode type received non-unicode bind " @@ -1173,7 +1168,7 @@ class String(Concatenable, TypeEngine): @property def python_type(self): if self.convert_unicode: - return str + return util.text_type else: return str @@ -1744,7 +1739,7 @@ class _Binary(TypeEngine): def coerce_compared_value(self, op, value): """See :meth:`.TypeEngine.coerce_compared_value` for a description.""" - if isinstance(value, str): + if isinstance(value, util.string_types): return self else: return super(_Binary, self).coerce_compared_value(op, value) @@ -2001,7 +1996,7 @@ class Enum(String, SchemaType): convert_unicode = kw.pop('convert_unicode', None) if convert_unicode is None: for e in enums: - if isinstance(e, str): + if isinstance(e, util.string_types): convert_unicode = True break else: @@ -2454,13 +2449,6 @@ BOOLEANTYPE = Boolean() STRINGTYPE = String() _type_map = { - str: String(), -# start Py3K - bytes: LargeBinary(), -# end Py3K -# start Py2K -# unicode: Unicode(), -# end Py2K int: Integer(), float: Numeric(), bool: BOOLEANTYPE, @@ -2471,3 +2459,12 @@ _type_map = { dt.timedelta: Interval(), NoneType: NULLTYPE } + +if util.py3k: + _type_map[bytes] = LargeBinary() + _type_map[str] = Unicode() +else: + _type_map[unicode] = Unicode() + _type_map[str] = String() + + diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index 329d7543e..e3f7df702 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -734,13 +734,14 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): 'JOIN myothertable ON mytable.myid = ' 'myothertable.otherid') - def test_label_comparison(self): + def test_label_comparison_one(self): x = func.lala(table1.c.myid).label('foo') self.assert_compile(select([x], x == 5), 'SELECT lala(mytable.myid) AS foo FROM ' 'mytable WHERE lala(mytable.myid) = ' ':param_1') + def test_label_comparison_two(self): self.assert_compile( label('bar', column('foo', type_=String)) + 'foo', 'foo || :param_1') diff --git a/test/sql/test_types.py b/test/sql/test_types.py index f44ee9286..a47bff3ab 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -141,24 +141,14 @@ class AdaptTest(fixtures.TestBase): eq_(types.Integer().python_type, int) eq_(types.Numeric().python_type, decimal.Decimal) eq_(types.Numeric(asdecimal=False).python_type, float) -# start Py3K - eq_(types.LargeBinary().python_type, bytes) -# end Py3K -# start Py2K -# eq_(types.LargeBinary().python_type, str) -# end Py2K + eq_(types.LargeBinary().python_type, util.binary_type) eq_(types.Float().python_type, float) eq_(types.Interval().python_type, datetime.timedelta) eq_(types.Date().python_type, datetime.date) eq_(types.DateTime().python_type, datetime.datetime) -# start Py3K eq_(types.String().python_type, str) -# end Py3K -# start Py2K -# eq_(types.String().python_type, str) -# end Py2K - eq_(types.Unicode().python_type, str) - eq_(types.String(convert_unicode=True).python_type, str) + eq_(types.Unicode().python_type, util.text_type) + eq_(types.String(convert_unicode=True).python_type, util.text_type) assert_raises( NotImplementedError, @@ -259,14 +249,14 @@ class UserDefinedTest(fixtures.TablesTest, AssertsCompiledSQL): def test_processing(self): users = self.tables.users users.insert().execute( - user_id=2, goofy='jack', goofy2='jack', goofy4='jack', - goofy7='jack', goofy8=12, goofy9=12) + user_id=2, goofy='jack', goofy2='jack', goofy4=util.u('jack'), + goofy7=util.u('jack'), goofy8=12, goofy9=12) users.insert().execute( - user_id=3, goofy='lala', goofy2='lala', goofy4='lala', - goofy7='lala', goofy8=15, goofy9=15) + user_id=3, goofy='lala', goofy2='lala', goofy4=util.u('lala'), + goofy7=util.u('lala'), goofy8=15, goofy9=15) users.insert().execute( - user_id=4, goofy='fred', goofy2='fred', goofy4='fred', - goofy7='fred', goofy8=9, goofy9=9) + user_id=4, goofy='fred', goofy2='fred', goofy4=util.u('fred'), + goofy7=util.u('fred'), goofy8=9, goofy9=9) l = users.select().order_by(users.c.user_id).execute().fetchall() for assertstr, assertint, assertint2, row in zip( @@ -280,7 +270,7 @@ class UserDefinedTest(fixtures.TablesTest, AssertsCompiledSQL): eq_(row[5], assertint) eq_(row[6], assertint2) for col in row[3], row[4]: - assert isinstance(col, str) + assert isinstance(col, util.text_type) def test_typedecorator_impl(self): for impl_, exp, kw in [ @@ -717,9 +707,9 @@ class UnicodeTest(fixtures.TestBase): expected ) - data = "Alors vous imaginez ma surprise, au lever du jour, quand "\ + data = util.u("Alors vous imaginez ma surprise, au lever du jour, quand "\ "une drôle de petite voix m’a réveillé. "\ - "Elle disait: « S’il vous plaît… dessine-moi un mouton! »" + "Elle disait: « S’il vous plaît… dessine-moi un mouton! »") def test_unicode_warnings_typelevel_native_unicode(self): @@ -728,14 +718,12 @@ class UnicodeTest(fixtures.TestBase): dialect = default.DefaultDialect() dialect.supports_unicode_binds = True uni = u.dialect_impl(dialect).bind_processor(dialect) -# start Py3K - assert_raises(exc.SAWarning, uni, b'x') - assert isinstance(uni(unicodedata), str) -# end Py3K -# start Py2K -# assert_raises(exc.SAWarning, uni, 'x') -# assert isinstance(uni(unicodedata), unicode) -# end Py2K + if util.py3k: + assert_raises(exc.SAWarning, uni, b'x') + assert isinstance(uni(unicodedata), str) + else: + assert_raises(exc.SAWarning, uni, 'x') + assert isinstance(uni(unicodedata), unicode) def test_unicode_warnings_typelevel_sqla_unicode(self): unicodedata = self.data @@ -743,14 +731,8 @@ class UnicodeTest(fixtures.TestBase): dialect = default.DefaultDialect() dialect.supports_unicode_binds = False uni = u.dialect_impl(dialect).bind_processor(dialect) -# start Py3K - assert_raises(exc.SAWarning, uni, b'x') - assert isinstance(uni(unicodedata), bytes) -# end Py3K -# start Py2K -# assert_raises(exc.SAWarning, uni, 'x') -# assert isinstance(uni(unicodedata), str) -# end Py2K + assert_raises(exc.SAWarning, uni, util.b('x')) + assert isinstance(uni(unicodedata), util.binary_type) eq_(uni(unicodedata), unicodedata.encode('utf-8')) @@ -763,15 +745,9 @@ class UnicodeTest(fixtures.TestBase): s = String() uni = s.dialect_impl(dialect).bind_processor(dialect) - # this is not the unicode type - no warning -# start Py3K - uni(b'x') - assert isinstance(uni(unicodedata), bytes) -# end Py3K -# start Py2K -# uni('x') -# assert isinstance(uni(unicodedata), str) -# end Py2K + + uni(util.b('x')) + assert isinstance(uni(unicodedata), util.binary_type) eq_(uni(unicodedata), unicodedata.encode('utf-8')) -- cgit v1.2.1 From a5c9907d40b4846175106c098bc0aef9801c786b Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 28 Apr 2013 15:01:26 -0400 Subject: don't need 2to3 --- README.py3k | 50 ++---------------------------------------- sa2to3.py | 72 ------------------------------------------------------------- setup.py | 72 +++++++++++++++++-------------------------------------------- 3 files changed, 22 insertions(+), 172 deletions(-) delete mode 100644 sa2to3.py diff --git a/README.py3k b/README.py3k index 1cf9c3588..2afaeb688 100644 --- a/README.py3k +++ b/README.py3k @@ -2,51 +2,5 @@ PYTHON 3 SUPPORT ================= -Current Python 3k support in SQLAlchemy is provided by a customized -2to3 script which wraps Python's 2to3 tool. - -Installing Distribute ---------------------- - -Distribute should be installed with the Python3 installation. The -distribute bootloader is included. - -Running as a user with permission to modify the Python distribution, -install Distribute: - - python3 distribute_setup.py - - -Installing SQLAlchemy in Python 3 ---------------------------------- - -Once Distribute is installed, SQLAlchemy can be installed directly. -The 2to3 process will kick in which takes several minutes: - - python3 setup.py install - -Converting Tests, Examples, Source to Python 3 ----------------------------------------------- - -To convert all files in the source distribution, run -SQLAlchemys "sa2to3.py" script, which monkeypatches a preprocessor -onto the 2to3 tool: - - python3 sa2to3.py --no-diffs -w lib test examples - -The above will rewrite all files in-place in Python 3 format. - -Running Tests -------------- - -To run unit tests in Py3k, Nose 1.0 is required, or a development -version of Nose that supports Python 3. The tests are run -using ./sqla_nose.py as described in README.unittests. - -Current 3k Issues ------------------ - -Current bugs and tickets related to Py3k are on the Py3k milestone in trac: - -http://www.sqlalchemy.org/trac/query?status=new&status=assigned&status=reopened&milestone=py3k - +As of SQLAlchemy 0.9, SQLAlchemy installs and runs with +Python 3 directly, with no code changes. diff --git a/sa2to3.py b/sa2to3.py deleted file mode 100644 index 8c09540a1..000000000 --- a/sa2to3.py +++ /dev/null @@ -1,72 +0,0 @@ -"""SQLAlchemy 2to3 tool. - -This tool monkeypatches a preprocessor onto -lib2to3.refactor.RefactoringTool, so that conditional -sections can replace non-fixable Python 2 code sections -for the appropriate Python 3 version before 2to3 is run. - -""" - -from lib2to3 import main, refactor - -import re - -py3k_pattern = re.compile(r'\s*# Py3K') -comment_pattern = re.compile(r'(\s*)#(?! ?Py2K)(.*)') -py2k_pattern = re.compile(r'\s*# Py2K') -end_py2k_pattern = re.compile(r'\s*# end Py2K') - -def preprocess(data): - lines = data.split('\n') - def consume_normal(): - while lines: - line = lines.pop(0) - if py3k_pattern.match(line): - for line in consume_py3k(): - yield line - elif py2k_pattern.match(line): - for line in consume_py2k(): - yield line - else: - yield line - - def consume_py3k(): - yield "# start Py3K" - while lines: - line = lines.pop(0) - m = comment_pattern.match(line) - if m: - yield "%s%s" % m.group(1, 2) - else: - # pushback - lines.insert(0, line) - break - yield "# end Py3K" - - def consume_py2k(): - yield "# start Py2K" - while lines: - line = lines.pop(0) - if not end_py2k_pattern.match(line): - yield "#%s" % line - else: - break - yield "# end Py2K" - - return "\n".join(consume_normal()) - -old_refactor_string = refactor.RefactoringTool.refactor_string - -def refactor_string(self, data, name): - newdata = preprocess(data) - tree = old_refactor_string(self, newdata, name) - if tree: - if newdata != data: - tree.was_changed = True - return tree - -if __name__ == '__main__': - refactor.RefactoringTool.refactor_string = refactor_string - main.main("lib2to3.fixes") - - diff --git a/setup.py b/setup.py index 2950a12d4..97212b55e 100644 --- a/setup.py +++ b/setup.py @@ -17,26 +17,16 @@ except ImportError: has_setuptools = False from distutils.core import setup, Extension Feature = None - try: # Python 3 - from distutils.command.build_py import build_py_2to3 as build_py - except ImportError: # Python 2 - from distutils.command.build_py import build_py cmdclass = {} pypy = hasattr(sys, 'pypy_version_info') jython = sys.platform.startswith('java') py3k = False extra = {} -if sys.version_info < (2, 4): - raise Exception("SQLAlchemy requires Python 2.4 or higher.") +if sys.version_info < (2, 6): + raise Exception("SQLAlchemy requires Python 2.6 or higher.") elif sys.version_info >= (3, 0): py3k = True - if has_setuptools: - extra.update( - use_2to3=True, - ) - else: - cmdclass['build_py'] = build_py ext_modules = [ Extension('sqlalchemy.cprocessors', @@ -48,7 +38,7 @@ ext_modules = [ ] ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError) -if sys.platform == 'win32' and sys.version_info > (2, 6): +if sys.platform == 'win32': # 2.6's distutils.msvc9compiler can raise an IOError when failing to # find the compiler ext_errors += (IOError,) @@ -90,8 +80,7 @@ def find_packages(location): packages = [] for pkg in ['sqlalchemy']: for _dir, subdirectories, files in ( - os.walk(os.path.join(location, pkg)) - ): + os.walk(os.path.join(location, pkg))): if '__init__.py' in files: tokens = _dir.split(os.sep)[len(location.split(os.sep)):] packages.append(".".join(tokens)) @@ -121,20 +110,20 @@ def run_setup(with_cext): kwargs['ext_modules'] = ext_modules setup(name="SQLAlchemy", - version=VERSION, - description="Database Abstraction Library", - author="Mike Bayer", - author_email="mike_mp@zzzcomputing.com", - url="http://www.sqlalchemy.org", - packages=find_packages('lib'), - package_dir={'': 'lib'}, - license="MIT License", - cmdclass=cmdclass, - - tests_require=['nose >= 0.11'], - test_suite="sqla_nose", - long_description=readme, - classifiers=[ + version=VERSION, + description="Database Abstraction Library", + author="Mike Bayer", + author_email="mike_mp@zzzcomputing.com", + url="http://www.sqlalchemy.org", + packages=find_packages('lib'), + package_dir={'': 'lib'}, + license="MIT License", + cmdclass=cmdclass, + + tests_require=['nose >= 0.11'], + test_suite="sqla_nose", + long_description=readme, + classifiers=[ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", @@ -149,28 +138,8 @@ def run_setup(with_cext): **kwargs ) -def monkeypatch2to3(): - from sa2to3 import refactor_string - from lib2to3.refactor import RefactoringTool - RefactoringTool.old_refactor_string = RefactoringTool.refactor_string - RefactoringTool.refactor_string = refactor_string - -def unmonkeypatch2to3(): - from lib2to3.refactor import RefactoringTool - if hasattr(RefactoringTool, 'old_refactor_string'): - RefactoringTool.refactor_string = RefactoringTool.old_refactor_string - if pypy or jython or py3k: - if py3k: - # monkeypatch our preprocessor onto the 2to3 tool. - monkeypatch2to3() - try: - run_setup(False) - finally: - if py3k: - # unmonkeypatch to not stomp other setup.py's that are compiled - # and exec'd and which also require 2to3 fixing - unmonkeypatch2to3() + run_setup(False) status_msgs( "WARNING: C extensions are not supported on " + "this Python platform, speedups are not enabled.", @@ -179,8 +148,7 @@ if pypy or jython or py3k: else: try: run_setup(True) - except BuildFailed: - exc = sys.exc_info()[1] # work around py 2/3 different syntax + except BuildFailed as exc: status_msgs( exc.cause, "WARNING: The C extension could not be compiled, " + -- cgit v1.2.1 From 1321088644c8d845e6e8d96f24c5f841c3bc9e28 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 28 Apr 2013 15:02:44 -0400 Subject: no need for all these scripts, not worth maintaining --- test/perf/README | 17 ---- test/perf/insertspeed.py | 109 -------------------- test/perf/large_flush.py | 84 ---------------- test/perf/objselectspeed.py | 146 --------------------------- test/perf/objupdatespeed.py | 94 ------------------ test/perf/ormsession.py | 225 ----------------------------------------- test/perf/sessions.py | 95 ------------------ test/perf/stress_all.py | 226 ------------------------------------------ test/perf/stresstest.py | 174 -------------------------------- test/perf/threaded_compile.py | 75 -------------- 10 files changed, 1245 deletions(-) delete mode 100644 test/perf/README delete mode 100644 test/perf/insertspeed.py delete mode 100644 test/perf/large_flush.py delete mode 100644 test/perf/objselectspeed.py delete mode 100644 test/perf/objupdatespeed.py delete mode 100644 test/perf/ormsession.py delete mode 100644 test/perf/sessions.py delete mode 100644 test/perf/stress_all.py delete mode 100644 test/perf/stresstest.py delete mode 100644 test/perf/threaded_compile.py diff --git a/test/perf/README b/test/perf/README deleted file mode 100644 index 1d03cb5ce..000000000 --- a/test/perf/README +++ /dev/null @@ -1,17 +0,0 @@ -This directory contains informal scripts used to stress test various -library subsections over the years, including testing of memory usage, -function call count, threading behavior. - -The scripts here are *not* part of the automated test suite, and instead -were used at the time of development for particular features or -performance enhancements in an ad-hoc fashion. Ideally -the various functionality tested within would be brought under the -umbrella of controlled, automated tests. Many of the scripts here -are out of date and are possibly covered by formal performance tests -elsewhere. - -Current automated stress and performance tests are in test/aaa_profiling/, -which test either for expected function call count, or flat growth in memory -usage over time. These tests are part of the automated test suite -and are maintained for 100% success rate along Python versions from 2.4 through -current 3 versions. \ No newline at end of file diff --git a/test/perf/insertspeed.py b/test/perf/insertspeed.py deleted file mode 100644 index 88e73fef9..000000000 --- a/test/perf/insertspeed.py +++ /dev/null @@ -1,109 +0,0 @@ -import sys, time -from sqlalchemy import * -from sqlalchemy.orm import * -from sqlalchemy.testing import profiling - -db = create_engine('sqlite://') -metadata = MetaData(db) -Person_table = Table('Person', metadata, - Column('name', String(40)), - Column('sex', Integer), - Column('age', Integer)) - - -def sa_unprofiled_insertmany(n): - i = Person_table.insert() - i.execute([{'name':'John Doe','sex':1,'age':35} for j in range(n)]) - -def sqlite_unprofiled_insertmany(n): - conn = db.connect().connection - c = conn.cursor() - persons = [('john doe', 1, 35) for i in range(n)] - c.executemany("insert into Person(name, sex, age) values (?,?,?)", persons) - -@profiling.profiled('sa_profiled_insert_many', always=True) -def sa_profiled_insert_many(n): - i = Person_table.insert() - i.execute([{'name':'John Doe','sex':1,'age':35} for j in range(n)]) - s = Person_table.select() - r = s.execute() - res = [[value for value in row] for row in r.fetchall()] - -def sqlite_unprofiled_insert(n): - conn = db.connect().connection - c = conn.cursor() - for j in range(n): - c.execute("insert into Person(name, sex, age) values (?,?,?)", - ('john doe', 1, 35)) - -def sa_unprofiled_insert(n): - # Another option is to build Person_table.insert() outside of the - # loop. But it doesn't make much of a difference, so might as well - # use the worst-case/naive version here. - for j in range(n): - Person_table.insert().execute({'name':'John Doe','sex':1,'age':35}) - -@profiling.profiled('sa_profiled_insert', always=True) -def sa_profiled_insert(n): - i = Person_table.insert() - for j in range(n): - i.execute({'name':'John Doe','sex':1,'age':35}) - s = Person_table.select() - r = s.execute() - res = [[value for value in row] for row in r.fetchall()] - -def run_timed(fn, label, *args, **kw): - metadata.drop_all() - metadata.create_all() - - sys.stdout.write("%s (%s): " % (label, ', '.join([str(a) for a in args]))) - sys.stdout.flush() - - t = time.clock() - fn(*args, **kw) - t2 = time.clock() - - sys.stdout.write("%0.2f seconds\n" % (t2 - t)) - -def run_profiled(fn, label, *args, **kw): - metadata.drop_all() - metadata.create_all() - - print("%s (%s)" % (label, ', '.join([str(a) for a in args]))) - fn(*args, **kw) - -def all(): - try: - print("Bulk INSERTS via executemany():\n") - - run_timed(sqlite_unprofiled_insertmany, - 'pysqlite bulk insert', - 50000) - - run_timed(sa_unprofiled_insertmany, - 'SQLAlchemy bulk insert', - 50000) - - run_profiled(sa_profiled_insert_many, - 'SQLAlchemy bulk insert/select, profiled', - 50000) - - print("\nIndividual INSERTS via execute():\n") - - run_timed(sqlite_unprofiled_insert, - "pysqlite individual insert", - 50000) - - run_timed(sa_unprofiled_insert, - "SQLAlchemy individual insert", - 50000) - - run_profiled(sa_profiled_insert, - 'SQLAlchemy individual insert/select, profiled', - 50000) - - finally: - metadata.drop_all() - -if __name__ == '__main__': - all() diff --git a/test/perf/large_flush.py b/test/perf/large_flush.py deleted file mode 100644 index b1ecce852..000000000 --- a/test/perf/large_flush.py +++ /dev/null @@ -1,84 +0,0 @@ -import sqlalchemy as sa -from sqlalchemy import create_engine, MetaData, orm -from sqlalchemy import Column, ForeignKey -from sqlalchemy import Integer, String -from sqlalchemy.orm import mapper -from sqlalchemy.testing import profiling - -class Object(object): - pass - -class Q(Object): - pass - -class A(Object): - pass - -class C(Object): - pass - -class WC(C): - pass - -engine = create_engine('sqlite:///:memory:', echo=True) - -sm = orm.sessionmaker(bind=engine) - -SA_Session = orm.scoped_session(sm) - -SA_Metadata = MetaData() - -object_table = sa.Table('Object', - SA_Metadata, - Column('ObjectID', Integer,primary_key=True), - Column('Type', String(1), nullable=False)) - -q_table = sa.Table('Q', - SA_Metadata, - Column('QID', Integer, ForeignKey('Object.ObjectID'),primary_key=True)) - -c_table = sa.Table('C', - SA_Metadata, - Column('CID', Integer, ForeignKey('Object.ObjectID'),primary_key=True)) - -wc_table = sa.Table('WC', - SA_Metadata, - Column('WCID', Integer, ForeignKey('C.CID'), primary_key=True)) - -a_table = sa.Table('A', - SA_Metadata, - Column('AID', Integer, ForeignKey('Object.ObjectID'),primary_key=True), - Column('QID', Integer, ForeignKey('Q.QID')), - Column('CID', Integer, ForeignKey('C.CID'))) - -mapper(Object, object_table, polymorphic_on=object_table.c.Type, polymorphic_identity='O') - -mapper(Q, q_table, inherits=Object, polymorphic_identity='Q') -mapper(C, c_table, inherits=Object, polymorphic_identity='C') -mapper(WC, wc_table, inherits=C, polymorphic_identity='W') - -mapper(A, a_table, inherits=Object, polymorphic_identity='A', - properties = { - 'Q' : orm.relation(Q,primaryjoin=a_table.c.QID==q_table.c.QID, - backref='As' - ), - 'C' : orm.relation(C,primaryjoin=a_table.c.CID==c_table.c.CID, - backref='A', - uselist=False) - } - ) - -SA_Metadata.create_all(engine) - -@profiling.profiled('large_flush', always=True, sort=['file']) -def generate_error(): - q = Q() - for j in range(100): #at 306 the error does not pop out (depending on recursion depth) - a = A() - a.Q = q - a.C = WC() - - SA_Session.add(q) - SA_Session.commit() #here the error pops out - -generate_error() \ No newline at end of file diff --git a/test/perf/objselectspeed.py b/test/perf/objselectspeed.py deleted file mode 100644 index dc790ab17..000000000 --- a/test/perf/objselectspeed.py +++ /dev/null @@ -1,146 +0,0 @@ -import time, resource -from sqlalchemy import * -from sqlalchemy.orm import * -from sqlalchemy.testing.util import gc_collect -from sqlalchemy.testing import profiling - -db = create_engine('sqlite://') -metadata = MetaData(db) -Person_table = Table('Person', metadata, - Column('id', Integer, primary_key=True), - Column('type', String(10)), - Column('name', String(40)), - Column('sex', Integer), - Column('age', Integer)) - - -Employee_table = Table('Employee', metadata, - Column('id', Integer, ForeignKey('Person.id'), primary_key=True), - Column('foo', String(40)), - Column('bar', Integer), - Column('bat', Integer)) - -class RawPerson(object): pass -class Person(object): pass -mapper(Person, Person_table) - -class JoinedPerson(object):pass -class Employee(JoinedPerson):pass -mapper(JoinedPerson, Person_table, \ - polymorphic_on=Person_table.c.type, polymorphic_identity='person') -mapper(Employee, Employee_table, \ - inherits=JoinedPerson, polymorphic_identity='employee') -compile_mappers() - -def setup(): - metadata.create_all() - i = Person_table.insert() - data = [{'name':'John Doe','sex':1,'age':35, 'type':'employee'}] * 100 - for j in range(500): - i.execute(data) - - # note we arent fetching from employee_table, - # so we can leave it empty even though its "incorrect" - #i = Employee_table.insert() - #data = [{'foo':'foo', 'bar':'bar':'bat':'bat'}] * 100 - #for j in xrange(500): - # i.execute(data) - - print("Inserted 50,000 rows") - -def sqlite_select(entity_cls): - conn = db.connect().connection - cr = conn.cursor() - cr.execute("SELECT id, name, sex, age FROM Person") - people = [] - for row in cr.fetchall(): - person = entity_cls() - person.id = row[0] - person.name = row[1] - person.sex = row[2] - person.age = row[3] - people.append(person) - cr.close() - conn.close() - -def sql_select(entity_cls): - people = [] - for row in Person_table.select().execute().fetchall(): - person = entity_cls() - person.id = row['id'] - person.name = row['name'] - person.sex = row['sex'] - person.age = row['age'] - people.append(person) - -#@profiling.profiled(report=True, always=True) -def orm_select(): - session = create_session() - people = session.query(Person).all() - -#@profiling.profiled(report=True, always=True) -def joined_orm_select(): - session = create_session() - people = session.query(JoinedPerson).all() - -def all(): - setup() - try: - t, t2 = 0, 0 - def usage(label): - now = resource.getrusage(resource.RUSAGE_SELF) - print("%s: %0.3fs real, %0.3fs user, %0.3fs sys" % ( - label, t2 - t, - now.ru_utime - usage.last.ru_utime, - now.ru_stime - usage.last.ru_stime)) - usage.snap(now) - usage.snap = lambda stats=None: setattr( - usage, 'last', stats or resource.getrusage(resource.RUSAGE_SELF)) - - gc_collect() - usage.snap() - t = time.clock() - sqlite_select(RawPerson) - t2 = time.clock() - usage('sqlite select/native') - - gc_collect() - usage.snap() - t = time.clock() - sqlite_select(Person) - t2 = time.clock() - usage('sqlite select/instrumented') - - gc_collect() - usage.snap() - t = time.clock() - sql_select(RawPerson) - t2 = time.clock() - usage('sqlalchemy.sql select/native') - - gc_collect() - usage.snap() - t = time.clock() - sql_select(Person) - t2 = time.clock() - usage('sqlalchemy.sql select/instrumented') - - gc_collect() - usage.snap() - t = time.clock() - orm_select() - t2 = time.clock() - usage('sqlalchemy.orm fetch') - - gc_collect() - usage.snap() - t = time.clock() - joined_orm_select() - t2 = time.clock() - usage('sqlalchemy.orm "joined" fetch') - finally: - metadata.drop_all() - - -if __name__ == '__main__': - all() diff --git a/test/perf/objupdatespeed.py b/test/perf/objupdatespeed.py deleted file mode 100644 index 95a5fbc9b..000000000 --- a/test/perf/objupdatespeed.py +++ /dev/null @@ -1,94 +0,0 @@ -import time, resource -from sqlalchemy import * -from sqlalchemy.orm import * -from sqlalchemy.testing import * -from sqlalchemy.testing.util import gc_collect - - -NUM = 100 - -metadata = MetaData(testing.db) -Person_table = Table('Person', metadata, - Column('id', Integer, primary_key=True), - Column('name', String(40)), - Column('sex', Integer), - Column('age', Integer)) - -Email_table = Table('Email', metadata, - Column('id', Integer, primary_key=True), - Column('person_id', Integer, ForeignKey('Person.id')), - Column('address', String(300))) - -class Person(object): - pass -class Email(object): - def __repr__(self): - return '' % (getattr(self, 'id', None), - getattr(self, 'address', None)) - -mapper(Person, Person_table, properties={ - 'emails': relationship(Email, backref='owner', lazy='joined') - }) -mapper(Email, Email_table) -compile_mappers() - -def setup(): - metadata.create_all() - i = Person_table.insert() - data = [{'name':'John Doe','sex':1,'age':35}] * NUM - i.execute(data) - - i = Email_table.insert() - for j in range(1, NUM + 1): - i.execute(address='foo@bar', person_id=j) - if j % 2: - i.execute(address='baz@quux', person_id=j) - - print("Inserted %d rows." % (NUM + NUM + (NUM // 2))) - -def orm_select(session): - return session.query(Person).all() - -@profiling.profiled('update_and_flush') -def update_and_flush(session, people): - for p in people: - p.name = 'Exene Cervenka' - p.sex = 2 - p.emails[0].address = 'hoho@lala' - session.flush() - -def all(): - setup() - try: - t, t2 = 0, 0 - def usage(label): - now = resource.getrusage(resource.RUSAGE_SELF) - print("%s: %0.3fs real, %0.3fs user, %0.3fs sys" % ( - label, t2 - t, - now.ru_utime - usage.last.ru_utime, - now.ru_stime - usage.last.ru_stime)) - usage.snap(now) - usage.snap = lambda stats=None: setattr( - usage, 'last', stats or resource.getrusage(resource.RUSAGE_SELF)) - - session = create_session() - - gc_collect() - usage.snap() - t = time.clock() - people = orm_select(session) - t2 = time.clock() - usage('load objects') - - gc_collect() - usage.snap() - t = time.clock() - update_and_flush(session, people) - t2 = time.clock() - usage('update and flush') - finally: - metadata.drop_all() - - -if __name__ == '__main__': - all() diff --git a/test/perf/ormsession.py b/test/perf/ormsession.py deleted file mode 100644 index 2fc656117..000000000 --- a/test/perf/ormsession.py +++ /dev/null @@ -1,225 +0,0 @@ -import time -from datetime import datetime - -from sqlalchemy import * -from sqlalchemy.orm import * -from sqlalchemy.testing import * -from sqlalchemy.testing.profiling import profiled - -class Item(object): - def __repr__(self): - return 'Item<#%s "%s">' % (self.id, self.name) -class SubItem(object): - def __repr__(self): - return 'SubItem<#%s "%s">' % (self.id, self.name) -class Customer(object): - def __repr__(self): - return 'Customer<#%s "%s">' % (self.id, self.name) -class Purchase(object): - def __repr__(self): - return 'Purchase<#%s "%s">' % (self.id, self.purchase_date) - -items, subitems, customers, purchases, purchaseitems = \ - None, None, None, None, None - -metadata = MetaData() - -@profiled('table') -def define_tables(): - global items, subitems, customers, purchases, purchaseitems - items = Table('items', metadata, - Column('id', Integer, primary_key=True), - Column('name', String(100)), - test_needs_acid=True) - subitems = Table('subitems', metadata, - Column('id', Integer, primary_key=True), - Column('item_id', Integer, ForeignKey('items.id'), - nullable=False), - Column('name', String(100), server_default='no name'), - test_needs_acid=True) - customers = Table('customers', metadata, - Column('id', Integer, primary_key=True), - Column('name', String(100)), - *[Column("col_%s" % chr(i), String(64), default=str(i)) - for i in range(97,117)], - **dict(test_needs_acid=True)) - purchases = Table('purchases', metadata, - Column('id', Integer, primary_key=True), - Column('customer_id', Integer, - ForeignKey('customers.id'), nullable=False), - Column('purchase_date', DateTime, - default=datetime.now), - test_needs_acid=True) - purchaseitems = Table('purchaseitems', metadata, - Column('purchase_id', Integer, - ForeignKey('purchases.id'), - nullable=False, primary_key=True), - Column('item_id', Integer, ForeignKey('items.id'), - nullable=False, primary_key=True), - test_needs_acid=True) - -@profiled('mapper') -def setup_mappers(): - mapper(Item, items, properties={ - 'subitems': relationship(SubItem, backref='item', lazy='select') - }) - mapper(SubItem, subitems) - mapper(Customer, customers, properties={ - 'purchases': relationship(Purchase, lazy='select', backref='customer') - }) - mapper(Purchase, purchases, properties={ - 'items': relationship(Item, lazy='select', secondary=purchaseitems) - }) - -@profiled('inserts') -def insert_data(): - q_items = 1000 - q_sub_per_item = 10 - q_customers = 1000 - - con = testing.db.connect() - - transaction = con.begin() - data, subdata = [], [] - for item_id in range(1, q_items + 1): - data.append({'name': "item number %s" % item_id}) - for subitem_id in range(1, (item_id % q_sub_per_item) + 1): - subdata.append({'item_id': item_id, - 'name': "subitem number %s" % subitem_id}) - if item_id % 100 == 0: - items.insert().execute(*data) - subitems.insert().execute(*subdata) - del data[:] - del subdata[:] - if data: - items.insert().execute(*data) - if subdata: - subitems.insert().execute(*subdata) - transaction.commit() - - transaction = con.begin() - data = [] - for customer_id in range(1, q_customers): - data.append({'name': "customer number %s" % customer_id}) - if customer_id % 100 == 0: - customers.insert().execute(*data) - del data[:] - if data: - customers.insert().execute(*data) - transaction.commit() - - transaction = con.begin() - data, subdata = [], [] - order_t = int(time.time()) - (5000 * 5 * 60) - current = range(1, q_customers) - step, purchase_id = 1, 0 - while current: - next = [] - for customer_id in current: - order_t += 300 - data.append({'customer_id': customer_id, - 'purchase_date': datetime.fromtimestamp(order_t)}) - purchase_id += 1 - for item_id in range(customer_id % 200, customer_id + 1, 200): - if item_id != 0: - subdata.append({'purchase_id': purchase_id, - 'item_id': item_id}) - if customer_id % 10 > step: - next.append(customer_id) - - if len(data) >= 100: - purchases.insert().execute(*data) - if subdata: - purchaseitems.insert().execute(*subdata) - del data[:] - del subdata[:] - step, current = step + 1, next - - if data: - purchases.insert().execute(*data) - if subdata: - purchaseitems.insert().execute(*subdata) - transaction.commit() - -@profiled('queries') -def run_queries(): - session = create_session() - # no explicit transaction here. - - # build a report of summarizing the last 50 purchases and - # the top 20 items from all purchases - - q = session.query(Purchase). \ - order_by(desc(Purchase.purchase_date)). \ - limit(50).\ - options(joinedload('items'), joinedload('items.subitems'), - joinedload('customer')) - - report = [] - # "write" the report. pretend it's going to a web template or something, - # the point is to actually pull data through attributes and collections. - for purchase in q: - report.append(purchase.customer.name) - report.append(purchase.customer.col_a) - report.append(purchase.purchase_date) - for item in purchase.items: - report.append(item.name) - report.extend([s.name for s in item.subitems]) - - # mix a little low-level with orm - # pull a report of the top 20 items of all time - _item_id = purchaseitems.c.item_id - top_20_q = select([func.distinct(_item_id).label('id')], - group_by=[purchaseitems.c.purchase_id, _item_id], - order_by=[desc(func.count(_item_id)), _item_id], - limit=20) - ids = [r.id for r in top_20_q.execute().fetchall()] - q2 = session.query(Item).filter(Item.id.in_(ids)) - - for num, item in enumerate(q2): - report.append("number %s: %s" % (num + 1, item.name)) - -@profiled('creating') -def create_purchase(): - # commit a purchase - customer_id = 100 - item_ids = (10,22,34,46,58) - - session = create_session() - session.begin() - - customer = session.query(Customer).get(customer_id) - items = session.query(Item).filter(Item.id.in_(item_ids)) - - purchase = Purchase() - purchase.customer = customer - purchase.items.extend(items) - - session.flush() - session.commit() - session.expire(customer) - -def setup_db(): - metadata.drop_all() - metadata.create_all() -def cleanup_db(): - metadata.drop_all() - -@profiled('default') -def default(): - run_queries() - create_purchase() - -@profiled('all') -def main(): - metadata.bind = testing.db - try: - define_tables() - setup_mappers() - setup_db() - insert_data() - default() - finally: - cleanup_db() - -main() diff --git a/test/perf/sessions.py b/test/perf/sessions.py deleted file mode 100644 index 80553fe48..000000000 --- a/test/perf/sessions.py +++ /dev/null @@ -1,95 +0,0 @@ -from sqlalchemy import * -from sqlalchemy.orm import * - -from sqlalchemy.testing.compat import gc_collect -from sqlalchemy.testing import AssertsExecutionResults, profiling, testing -from test.orm import _fixtures - -# in this test we are specifically looking for time spent in the attributes.InstanceState.__cleanup() method. - -ITERATIONS = 100 - -class SessionTest(fixtures.TestBase, AssertsExecutionResults): - @classmethod - def setup_class(cls): - global t1, t2, metadata,T1, T2 - metadata = MetaData(testing.db) - t1 = Table('t1', metadata, - Column('c1', Integer, primary_key=True), - Column('c2', String(30))) - - t2 = Table('t2', metadata, - Column('c1', Integer, primary_key=True), - Column('c2', String(30)), - Column('t1id', Integer, ForeignKey('t1.c1')) - ) - - metadata.create_all() - - l = [] - for x in range(1,51): - l.append({'c2':'this is t1 #%d' % x}) - t1.insert().execute(*l) - for x in range(1, 51): - l = [] - for y in range(1, 100): - l.append({'c2':'this is t2 #%d' % y, 't1id':x}) - t2.insert().execute(*l) - - class T1(fixtures.ComparableEntity): - pass - class T2(fixtures.ComparableEntity): - pass - - mapper(T1, t1, properties={ - 't2s':relationship(T2, backref='t1') - }) - mapper(T2, t2) - - @classmethod - def teardown_class(cls): - metadata.drop_all() - clear_mappers() - - @profiling.profiled('clean', report=True) - def test_session_clean(self): - for x in range(0, ITERATIONS): - sess = create_session() - t1s = sess.query(T1).filter(T1.c1.between(15, 48)).all() - for index in [2, 7, 12, 15, 18, 20]: - t1s[index].t2s - - sess.close() - del sess - gc_collect() - - @profiling.profiled('dirty', report=True) - def test_session_dirty(self): - for x in range(0, ITERATIONS): - sess = create_session() - t1s = sess.query(T1).filter(T1.c1.between(15, 48)).all() - - for index in [2, 7, 12, 15, 18, 20]: - t1s[index].c2 = 'this is some modified text' - for t2 in t1s[index].t2s: - t2.c2 = 'this is some modified text' - - del t1s - gc_collect() - - sess.close() - del sess - gc_collect() - - @profiling.profiled('noclose', report=True) - def test_session_noclose(self): - for x in range(0, ITERATIONS): - sess = create_session() - t1s = sess.query(T1).filter(T1.c1.between(15, 48)).all() - for index in [2, 7, 12, 15, 18, 20]: - t1s[index].t2s - - del sess - gc_collect() - - diff --git a/test/perf/stress_all.py b/test/perf/stress_all.py deleted file mode 100644 index b2e034e7d..000000000 --- a/test/perf/stress_all.py +++ /dev/null @@ -1,226 +0,0 @@ -# -*- encoding: utf8 -*- -from datetime import * -import decimal -#from fastdec import mpd as Decimal -from pickle import dumps, loads - -#from sqlalchemy.dialects.postgresql.base import ARRAY - -from stresstest import * - -# --- -test_types = False -test_methods = True -test_pickle = False -test_orm = False -# --- -verbose = True - -def values_results(raw_results): - return [tuple(r.values()) for r in raw_results] - -def getitem_str_results(raw_results): - return [ - (r['id'], - r['field0'], r['field1'], r['field2'], r['field3'], r['field4'], - r['field5'], r['field6'], r['field7'], r['field8'], r['field9']) - for r in raw_results] - -def getitem_fallback_results(raw_results): - return [ - (r['ID'], - r['FIELD0'], r['FIELD1'], r['FIELD2'], r['FIELD3'], r['FIELD4'], - r['FIELD5'], r['FIELD6'], r['FIELD7'], r['FIELD8'], r['FIELD9']) - for r in raw_results] - -def getitem_int_results(raw_results): - return [ - (r[0], - r[1], r[2], r[3], r[4], r[5], - r[6], r[7], r[8], r[9], r[10]) - for r in raw_results] - -def getitem_long_results(raw_results): - return [ - (r[0], - r[1], r[2], r[3], r[4], r[5], - r[6], r[7], r[8], r[9], r[10]) - for r in raw_results] - -def getitem_obj_results(raw_results): - c = test_table.c - fid, f0, f1, f2, f3, f4, f5, f6, f7, f8, f9 = ( - c.id, c.field0, c.field1, c.field2, c.field3, c.field4, - c.field5, c.field6, c.field7, c.field8, c.field9) - return [ - (r[fid], - r[f0], r[f1], r[f2], r[f3], r[f4], - r[f5], r[f6], r[f7], r[f8], r[f9]) - for r in raw_results] - -def slice_results(raw_results): - return [row[0:6] + row[6:11] for row in raw_results] - -# ---------- # -# Test types # -# ---------- # - -# Array -#def genarrayvalue(rnum, fnum): -# return [fnum, fnum + 1, fnum + 2] -#arraytest = (ARRAY(Integer), genarrayvalue, -# dict(num_fields=100, num_records=1000, -# engineurl='postgresql:///test')) - -# Boolean -def genbooleanvalue(rnum, fnum): - if rnum % 4: - return bool(fnum % 2) - else: - return None -booleantest = (Boolean, genbooleanvalue, dict(num_records=100000)) - -# Datetime -def gendatetimevalue(rnum, fnum): - return (rnum % 4) and datetime(2005, 3, 3) or None -datetimetest = (DateTime, gendatetimevalue, dict(num_records=10000)) - -# Decimal -def gendecimalvalue(rnum, fnum): - if rnum % 4: - return Decimal(str(0.25 * fnum)) - else: - return None -decimaltest = (Numeric(10, 2), gendecimalvalue, dict(num_records=10000)) - -# Interval - -# no microseconds because Postgres does not seem to support it -from_epoch = timedelta(14643, 70235) -def genintervalvalue(rnum, fnum): - return from_epoch -intervaltest = (Interval, genintervalvalue, - dict(num_fields=2, num_records=100000)) - -# PickleType -def genpicklevalue(rnum, fnum): - return (rnum % 4) and {'str': "value%d" % fnum, 'int': rnum} or None -pickletypetest = (PickleType, genpicklevalue, - dict(num_fields=1, num_records=100000)) - -# TypeDecorator -class MyIntType(TypeDecorator): - impl = Integer - - def process_bind_param(self, value, dialect): - return value * 10 - - def process_result_value(self, value, dialect): - return value / 10 - - def copy(self): - return MyIntType() - -def genmyintvalue(rnum, fnum): - return rnum + fnum -typedecoratortest = (MyIntType, genmyintvalue, - dict(num_records=100000)) - -# Unicode -def genunicodevalue(rnum, fnum): - return (rnum % 4) and ("value%d" % fnum) or None -unicodetest = (Unicode(20, ), genunicodevalue, - dict(num_records=100000)) -# dict(engineurl='mysql:///test', freshdata=False)) - -# do the tests -if test_types: - tests = [booleantest, datetimetest, decimaltest, intervaltest, - pickletypetest, typedecoratortest, unicodetest] - for engineurl in ('postgresql://scott:tiger@localhost/test', - 'sqlite://', 'mysql://scott:tiger@localhost/test'): - print("\n%s\n" % engineurl) - for datatype, genvalue, kwargs in tests: - print("%s:" % getattr(datatype, '__name__', - datatype.__class__.__name__), end=' ') - profile_and_time_dbfunc(iter_results, datatype, genvalue, - profile=False, engineurl=engineurl, - verbose=verbose, **kwargs) - -# ---------------------- # -# test row proxy methods # -# ---------------------- # - -if test_methods: - methods = [iter_results, values_results, getattr_results, - getitem_str_results, getitem_fallback_results, - getitem_int_results, getitem_long_results, getitem_obj_results, - slice_results] - for engineurl in ('postgresql://scott:tiger@localhost/test', - 'sqlite://', 'mysql://scott:tiger@localhost/test'): - print("\n%s\n" % engineurl) - test_table = prepare(Unicode(20,), - genunicodevalue, - num_fields=10, num_records=100000, - verbose=verbose, engineurl=engineurl) - for method in methods: - print("%s:" % method.__name__, end=' ') - time_dbfunc(test_table, method, genunicodevalue, - num_fields=10, num_records=100000, profile=False, - verbose=verbose) - -# -------------------------------- -# test pickling Rowproxy instances -# -------------------------------- - -def pickletofile_results(raw_results): - from pickle import dump, load - for protocol in (0, 1, 2): - print("dumping protocol %d..." % protocol) - f = file('noext.pickle%d' % protocol, 'wb') - dump(raw_results, f, protocol) - f.close() - return raw_results - -def pickle_results(raw_results): - return loads(dumps(raw_results, 2)) - -def pickle_meta(raw_results): - pickled = dumps(raw_results[0]._parent, 2) - metadata = loads(pickled) - return raw_results - -def pickle_rows(raw_results): - return [loads(dumps(row, 2)) for row in raw_results] - -if test_pickle: - test_table = prepare(Unicode, genunicodevalue, - num_fields=10, num_records=10000) - funcs = [pickle_rows, pickle_results] - for func in funcs: - print("%s:" % func.__name__, end=' ') - time_dbfunc(test_table, func, genunicodevalue, - num_records=10000, profile=False, verbose=verbose) - -# -------------------------------- -# test ORM -# -------------------------------- - -if test_orm: - from sqlalchemy.orm import * - - class Test(object): - pass - - Session = sessionmaker() - session = Session() - - def get_results(): - return session.query(Test).all() - print("ORM:", end=' ') - for engineurl in ('postgresql:///test', 'sqlite://', 'mysql:///test'): - print("\n%s\n" % engineurl) - profile_and_time_dbfunc(getattr_results, Unicode(20), genunicodevalue, - class_=Test, getresults_func=get_results, - engineurl=engineurl, #freshdata=False, - num_records=10000, verbose=verbose) diff --git a/test/perf/stresstest.py b/test/perf/stresstest.py deleted file mode 100644 index ca7c1da4f..000000000 --- a/test/perf/stresstest.py +++ /dev/null @@ -1,174 +0,0 @@ -import gc -import sys -import timeit -import cProfile - -from sqlalchemy import MetaData, Table, Column -from sqlalchemy.types import * -from sqlalchemy.orm import mapper, clear_mappers - -metadata = MetaData() - -def gen_table(num_fields, field_type, metadata): - return Table('test', metadata, - Column('id', Integer, primary_key=True), - *[Column("field%d" % fnum, field_type) - for fnum in range(num_fields)]) - -def insert(test_table, num_fields, num_records, genvalue, verbose=True): - if verbose: - print("building insert values...", end=' ') - sys.stdout.flush() - values = [dict(("field%d" % fnum, genvalue(rnum, fnum)) - for fnum in range(num_fields)) - for rnum in range(num_records)] - if verbose: - print("inserting...", end=' ') - sys.stdout.flush() - def db_insert(): - test_table.insert().execute(values) - sys.modules['__main__'].db_insert = db_insert - timing = timeit.timeit("db_insert()", - "from __main__ import db_insert", - number=1) - if verbose: - print("%s" % round(timing, 3)) - -def check_result(results, num_fields, genvalue, verbose=True): - if verbose: - print("checking...", end=' ') - sys.stdout.flush() - for rnum, row in enumerate(results): - expected = tuple([rnum + 1] + - [genvalue(rnum, fnum) for fnum in range(num_fields)]) - assert row == expected, "got: %s\nexpected: %s" % (row, expected) - return True - -def avgdev(values, comparison): - return sum(value - comparison for value in values) / len(values) - -def nicer_res(values, printvalues=False): - if printvalues: - print(values) - min_time = min(values) - return round(min_time, 3), round(avgdev(values, min_time), 2) - -def profile_func(func_name, verbose=True): - if verbose: - print("profiling...", end=' ') - sys.stdout.flush() - cProfile.run('%s()' % func_name, 'prof') - -def time_func(func_name, num_tests=1, verbose=True): - if verbose: - print("timing...", end=' ') - sys.stdout.flush() - timings = timeit.repeat('%s()' % func_name, - "from __main__ import %s" % func_name, - number=num_tests, repeat=5) - avg, dev = nicer_res(timings) - if verbose: - print("%s (%s)" % (avg, dev)) - else: - print(avg) - -def profile_and_time(func_name, num_tests=1): - profile_func(func_name) - time_func(func_name, num_tests) - -def iter_results(raw_results): - return [tuple(row) for row in raw_results] - -def getattr_results(raw_results): - return [ - (r.id, - r.field0, r.field1, r.field2, r.field3, r.field4, - r.field5, r.field6, r.field7, r.field8, r.field9) - for r in raw_results] - -def fetchall(test_table): - def results(): - return test_table.select().order_by(test_table.c.id).execute() \ - .fetchall() - return results - -def hashable_set(l): - hashables = [] - for o in l: - try: - hash(o) - hashables.append(o) - except: - pass - return set(hashables) - -def prepare(field_type, genvalue, engineurl='sqlite://', - num_fields=10, num_records=1000, freshdata=True, verbose=True): - global metadata - metadata.clear() - metadata.bind = engineurl - test_table = gen_table(num_fields, field_type, metadata) - if freshdata: - metadata.drop_all() - metadata.create_all() - insert(test_table, num_fields, num_records, genvalue, verbose) - return test_table - -def time_dbfunc(test_table, test_func, genvalue, - class_=None, - getresults_func=None, - num_fields=10, num_records=1000, num_tests=1, - check_results=check_result, profile=True, - check_leaks=True, print_leaks=False, verbose=True): - if verbose: - print("testing '%s'..." % test_func.__name__, end=' ') - sys.stdout.flush() - if class_ is not None: - clear_mappers() - mapper(class_, test_table) - if getresults_func is None: - getresults_func = fetchall(test_table) - def test(): - return test_func(getresults_func()) - sys.modules['__main__'].test = test - if check_leaks: - gc.collect() - objects_before = gc.get_objects() - num_objects_before = len(objects_before) - hashable_objects_before = hashable_set(objects_before) -# gc.set_debug(gc.DEBUG_LEAK) - if check_results: - check_results(test(), num_fields, genvalue, verbose) - if check_leaks: - gc.collect() - objects_after = gc.get_objects() - num_objects_after = len(objects_after) - num_leaks = num_objects_after - num_objects_before - hashable_objects_after = hashable_set(objects_after) - diff = hashable_objects_after - hashable_objects_before - ldiff = len(diff) - if print_leaks and ldiff < num_records: - print("\n*** hashable objects leaked (%d) ***" % ldiff) - print('\n'.join(map(str, diff))) - print("***\n") - - if num_leaks > num_records: - print("(leaked: %d !)" % num_leaks, end=' ') - if profile: - profile_func('test', verbose) - time_func('test', num_tests, verbose) - -def profile_and_time_dbfunc(test_func, field_type, genvalue, - class_=None, - getresults_func=None, - engineurl='sqlite://', freshdata=True, - num_fields=10, num_records=1000, num_tests=1, - check_results=check_result, profile=True, - check_leaks=True, print_leaks=False, verbose=True): - test_table = prepare(field_type, genvalue, engineurl, - num_fields, num_records, freshdata, verbose) - time_dbfunc(test_table, test_func, genvalue, class_, - getresults_func, - num_fields, num_records, num_tests, - check_results, profile, - check_leaks, print_leaks, verbose) diff --git a/test/perf/threaded_compile.py b/test/perf/threaded_compile.py deleted file mode 100644 index 23474a1c6..000000000 --- a/test/perf/threaded_compile.py +++ /dev/null @@ -1,75 +0,0 @@ -"""test that mapper compilation is threadsafe, including -when additional mappers are created while the existing -collection is being compiled.""" - -from sqlalchemy import * -from sqlalchemy.orm import * -import _thread, time -from sqlalchemy.orm import mapperlib - - -meta = MetaData('sqlite:///foo.db') - -t1 = Table('t1', meta, - Column('c1', Integer, primary_key=True), - Column('c2', String(30)) - ) - -t2 = Table('t2', meta, - Column('c1', Integer, primary_key=True), - Column('c2', String(30)), - Column('t1c1', None, ForeignKey('t1.c1')) -) -t3 = Table('t3', meta, - Column('c1', Integer, primary_key=True), - Column('c2', String(30)), -) -meta.create_all() - -class T1(object): - pass - -class T2(object): - pass - -class FakeLock(object): - def acquire(self):pass - def release(self):pass - -# uncomment this to disable the mutex in mapper compilation; -# should produce thread collisions -#mapperlib._COMPILE_MUTEX = FakeLock() - -def run1(): - for i in range(50): - print("T1", _thread.get_ident()) - class_mapper(T1) - time.sleep(.05) - -def run2(): - for i in range(50): - print("T2", _thread.get_ident()) - class_mapper(T2) - time.sleep(.057) - -def run3(): - for i in range(50): - def foo(): - print("FOO", _thread.get_ident()) - class Foo(object):pass - mapper(Foo, t3) - class_mapper(Foo).compile() - foo() - time.sleep(.05) - -mapper(T1, t1, properties={'t2':relationship(T2, backref="t1")}) -mapper(T2, t2) -print("START") -for j in range(0, 5): - _thread.start_new_thread(run1, ()) - _thread.start_new_thread(run2, ()) - _thread.start_new_thread(run3, ()) - _thread.start_new_thread(run3, ()) - _thread.start_new_thread(run3, ()) -print("WAIT") -time.sleep(5) -- cgit v1.2.1 From 734376130f01d17acc0d6c2d34c1e0f94a1cd1da Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 28 Apr 2013 16:27:23 -0400 Subject: postgresql dialect tests --- lib/sqlalchemy/dialects/postgresql/base.py | 25 ++++++----- lib/sqlalchemy/dialects/postgresql/psycopg2.py | 27 ++++++------ lib/sqlalchemy/types.py | 2 +- lib/sqlalchemy/util/__init__.py | 3 +- test/dialect/test_postgresql.py | 59 +++++++++++++------------- 5 files changed, 58 insertions(+), 58 deletions(-) diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 992995434..cd5d9772d 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -188,7 +188,6 @@ underlying CREATE INDEX command, so it *must* be a valid index type for your version of PostgreSQL. """ - import re from ... import sql, schema, exc, util @@ -333,7 +332,7 @@ class UUID(sqltypes.TypeEngine): if self.as_uuid: def process(value): if value is not None: - value = str(value) + value = util.text_type(value) return value return process else: @@ -1419,7 +1418,7 @@ class PGDialect(default.DefaultDialect): query, bindparams=[ sql.bindparam( - 'schema', str(schema.lower()), + 'schema', util.text_type(schema.lower()), type_=sqltypes.Unicode)] ) ) @@ -1435,7 +1434,7 @@ class PGDialect(default.DefaultDialect): "n.oid=c.relnamespace where n.nspname=current_schema() and " "relname=:name", bindparams=[ - sql.bindparam('name', str(table_name), + sql.bindparam('name', util.text_type(table_name), type_=sqltypes.Unicode)] ) ) @@ -1447,9 +1446,9 @@ class PGDialect(default.DefaultDialect): "relname=:name", bindparams=[ sql.bindparam('name', - str(table_name), type_=sqltypes.Unicode), + util.text_type(table_name), type_=sqltypes.Unicode), sql.bindparam('schema', - str(schema), type_=sqltypes.Unicode)] + util.text_type(schema), type_=sqltypes.Unicode)] ) ) return bool(cursor.first()) @@ -1463,7 +1462,7 @@ class PGDialect(default.DefaultDialect): "n.nspname=current_schema() " "and relname=:name", bindparams=[ - sql.bindparam('name', str(sequence_name), + sql.bindparam('name', util.text_type(sequence_name), type_=sqltypes.Unicode) ] ) @@ -1475,10 +1474,10 @@ class PGDialect(default.DefaultDialect): "n.oid=c.relnamespace where relkind='S' and " "n.nspname=:schema and relname=:name", bindparams=[ - sql.bindparam('name', str(sequence_name), + sql.bindparam('name', util.text_type(sequence_name), type_=sqltypes.Unicode), sql.bindparam('schema', - str(schema), type_=sqltypes.Unicode) + util.text_type(schema), type_=sqltypes.Unicode) ] ) ) @@ -1488,9 +1487,9 @@ class PGDialect(default.DefaultDialect): def has_type(self, connection, type_name, schema=None): bindparams = [ sql.bindparam('typname', - str(type_name), type_=sqltypes.Unicode), + util.text_type(type_name), type_=sqltypes.Unicode), sql.bindparam('nspname', - str(schema), type_=sqltypes.Unicode), + util.text_type(schema), type_=sqltypes.Unicode), ] if schema is not None: query = """ @@ -1546,9 +1545,9 @@ class PGDialect(default.DefaultDialect): """ % schema_where_clause # Since we're binding to unicode, table_name and schema_name must be # unicode. - table_name = str(table_name) + table_name = util.text_type(table_name) if schema is not None: - schema = str(schema) + schema = util.text_type(schema) s = sql.text(query, bindparams=[ sql.bindparam('table_name', type_=sqltypes.Unicode), sql.bindparam('schema', type_=sqltypes.Unicode) diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index 2893a3872..ce06aab05 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -142,6 +142,7 @@ type. This replaces SQLAlchemy's pure-Python HSTORE coercion which takes effect for other DBAPIs. """ +from __future__ import absolute_import import re import logging @@ -190,22 +191,20 @@ class _PGNumeric(sqltypes.Numeric): class _PGEnum(ENUM): def __init__(self, *arg, **kw): super(_PGEnum, self).__init__(*arg, **kw) -# start Py2K -# if self.convert_unicode: -# self.convert_unicode = "force" -# end Py2K + if util.py2k: + if self.convert_unicode: + self.convert_unicode = "force" class _PGArray(ARRAY): def __init__(self, *arg, **kw): super(_PGArray, self).__init__(*arg, **kw) -# start Py2K -# # FIXME: this check won't work for setups that -# # have convert_unicode only on their create_engine(). -# if isinstance(self.item_type, sqltypes.String) and \ -# self.item_type.convert_unicode: -# self.item_type.convert_unicode = "force" -# end Py2K + if util.py2k: + # FIXME: this check won't work for setups that + # have convert_unicode only on their create_engine(). + if isinstance(self.item_type, sqltypes.String) and \ + self.item_type.convert_unicode: + self.item_type.convert_unicode = "force" class _PGHStore(HSTORE): @@ -294,9 +293,9 @@ class PGIdentifierPreparer_psycopg2(PGIdentifierPreparer): class PGDialect_psycopg2(PGDialect): driver = 'psycopg2' -# start Py2K -# supports_unicode_statements = False -# end Py2K + if util.py2k: + supports_unicode_statements = False + default_paramstyle = 'pyformat' supports_sane_multi_rowcount = False execution_ctx_cls = PGExecutionContext_psycopg2 diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index ffcd793c6..c601dc306 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -1153,7 +1153,7 @@ class String(Concatenable, TypeEngine): # habits. since we will be getting back unicode # in most cases, we check for it (decode will fail). def process(value): - if isinstance(value, str): + if isinstance(value, util.text_type): return value else: return to_unicode(value) diff --git a/lib/sqlalchemy/util/__init__.py b/lib/sqlalchemy/util/__init__.py index 25dcce335..72baa9f36 100644 --- a/lib/sqlalchemy/util/__init__.py +++ b/lib/sqlalchemy/util/__init__.py @@ -8,7 +8,8 @@ from .compat import callable, cmp, reduce, \ threading, py3k, py2k, jython, pypy, cpython, win32, \ pickle, dottedgetter, parse_qsl, namedtuple, next, WeakSet, reraise, \ raise_from_cause, text_type, string_types, int_types, binary_type, \ - quote_plus, with_metaclass, print_, itertools_filterfalse, u, b + quote_plus, with_metaclass, print_, itertools_filterfalse, u, b,\ + unquote_plus from ._collections import KeyedTuple, ImmutableContainer, immutabledict, \ Properties, OrderedProperties, ImmutableProperties, OrderedDict, \ diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py index 43ac7d7ae..90a09d362 100644 --- a/test/dialect/test_postgresql.py +++ b/test/dialect/test_postgresql.py @@ -554,28 +554,29 @@ class EnumTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL): @testing.fails_on('postgresql+pg8000', 'zxjdbc fails on ENUM: column "XXX" is of type ' 'XXX but expression is of type text') + @testing.provide_metadata def test_unicode_labels(self): - metadata = MetaData(testing.db) + metadata = self.metadata t1 = Table('table', metadata, Column('id', Integer, primary_key=True), Column('value', - Enum('réveillé', 'drôle', 'S’il', + Enum(util.u('réveillé'), util.u('drôle'), util.u('S’il'), name='onetwothreetype')) ) - metadata.create_all() - try: - t1.insert().execute(value='drôle') - t1.insert().execute(value='réveillé') - t1.insert().execute(value='S’il') - eq_(t1.select().order_by(t1.c.id).execute().fetchall(), - [(1, 'drôle'), (2, 'réveillé'), (3, 'S’il')] - ) - m2 = MetaData(testing.db) - t2 = Table('table', m2, autoload=True) - assert t2.c.value.type.enums == ('réveillé', 'drôle', 'S’il') - finally: - metadata.drop_all() + t1.insert().execute(value=util.u('drôle')) + t1.insert().execute(value=util.u('réveillé')) + t1.insert().execute(value=util.u('S’il')) + eq_(t1.select().order_by(t1.c.id).execute().fetchall(), + [(1, util.u('drôle')), (2, util.u('réveillé')), + (3, util.u('S’il'))] + ) + m2 = MetaData(testing.db) + t2 = Table('table', m2, autoload=True) + eq_( + t2.c.value.type.enums, + (util.u('réveillé'), util.u('drôle'), util.u('S’il')) + ) def test_non_native_type(self): metadata = MetaData() @@ -2174,18 +2175,18 @@ class ArrayTest(fixtures.TablesTest, AssertsExecutionResults): def test_insert_array(self): arrtable = self.tables.arrtable - arrtable.insert().execute(intarr=[1, 2, 3], strarr=['abc', - 'def']) + arrtable.insert().execute(intarr=[1, 2, 3], strarr=[util.u('abc'), + util.u('def')]) results = arrtable.select().execute().fetchall() eq_(len(results), 1) eq_(results[0]['intarr'], [1, 2, 3]) - eq_(results[0]['strarr'], ['abc', 'def']) + eq_(results[0]['strarr'], [util.u('abc'), util.u('def')]) def test_array_where(self): arrtable = self.tables.arrtable - arrtable.insert().execute(intarr=[1, 2, 3], strarr=['abc', - 'def']) - arrtable.insert().execute(intarr=[4, 5, 6], strarr='ABC') + arrtable.insert().execute(intarr=[1, 2, 3], strarr=[util.u('abc'), + util.u('def')]) + arrtable.insert().execute(intarr=[4, 5, 6], strarr=util.u('ABC')) results = arrtable.select().where(arrtable.c.intarr == [1, 2, 3]).execute().fetchall() eq_(len(results), 1) @@ -2194,7 +2195,7 @@ class ArrayTest(fixtures.TablesTest, AssertsExecutionResults): def test_array_concat(self): arrtable = self.tables.arrtable arrtable.insert().execute(intarr=[1, 2, 3], - strarr=['abc', 'def']) + strarr=[util.u('abc'), util.u('def')]) results = select([arrtable.c.intarr + [4, 5, 6]]).execute().fetchall() eq_(len(results), 1) @@ -2203,15 +2204,15 @@ class ArrayTest(fixtures.TablesTest, AssertsExecutionResults): def test_array_subtype_resultprocessor(self): arrtable = self.tables.arrtable arrtable.insert().execute(intarr=[4, 5, 6], - strarr=[['m\xe4\xe4'], ['m\xf6\xf6' - ]]) - arrtable.insert().execute(intarr=[1, 2, 3], strarr=['m\xe4\xe4' - , 'm\xf6\xf6']) + strarr=[[util.u('m\xe4\xe4')], [ + util.u('m\xf6\xf6')]]) + arrtable.insert().execute(intarr=[1, 2, 3], strarr=[ + util.u('m\xe4\xe4'), util.u('m\xf6\xf6')]) results = \ arrtable.select(order_by=[arrtable.c.intarr]).execute().fetchall() eq_(len(results), 2) - eq_(results[0]['strarr'], ['m\xe4\xe4', 'm\xf6\xf6']) - eq_(results[1]['strarr'], [['m\xe4\xe4'], ['m\xf6\xf6']]) + eq_(results[0]['strarr'], [util.u('m\xe4\xe4'), util.u('m\xf6\xf6')]) + eq_(results[1]['strarr'], [[util.u('m\xe4\xe4')], [util.u('m\xf6\xf6')]]) def test_array_literal(self): eq_( @@ -2263,7 +2264,7 @@ class ArrayTest(fixtures.TablesTest, AssertsExecutionResults): testing.db.execute( arrtable.insert(), intarr=[4, 5, 6], - strarr=['abc', 'def'] + strarr=[util.u('abc'), util.u('def')] ) eq_( testing.db.scalar(select([arrtable.c.intarr[2:3]])), -- cgit v1.2.1 From 8f9b7ad31f0c91b9e2d4ff49e4f5fc6be90c9e6d Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 4 May 2013 14:23:29 -0400 Subject: formatting stuff --- test/sql/test_types.py | 100 +++++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 49 deletions(-) diff --git a/test/sql/test_types.py b/test/sql/test_types.py index a47bff3ab..a1845778e 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -74,7 +74,7 @@ class AdaptTest(fixtures.TestBase): (DATE, "DATE"), (TIME, ("TIME", "TIME WITHOUT TIME ZONE")), (CLOB, "CLOB"), - (VARCHAR(10), ("VARCHAR(10)","VARCHAR(10 CHAR)")), + (VARCHAR(10), ("VARCHAR(10)", "VARCHAR(10 CHAR)")), (NVARCHAR(10), ("NVARCHAR(10)", "NATIONAL VARCHAR(10)", "NVARCHAR2(10)")), (CHAR, "CHAR"), @@ -122,7 +122,7 @@ class AdaptTest(fixtures.TestBase): t1 = typ() for cls in [typ] + typ.__subclasses__(): if not issubclass(typ, types.Enum) and \ - issubclass(cls, types.Enum): + issubclass(cls, types.Enum): continue t2 = t1.adapt(cls) assert t1 is not t2 @@ -275,8 +275,8 @@ class UserDefinedTest(fixtures.TablesTest, AssertsCompiledSQL): def test_typedecorator_impl(self): for impl_, exp, kw in [ (Float, "FLOAT", {}), - (Float, "FLOAT(2)", {'precision':2}), - (Float(2), "FLOAT(2)", {'precision':4}), + (Float, "FLOAT(2)", {'precision': 2}), + (Float(2), "FLOAT(2)", {'precision': 4}), (Numeric(19, 2), "NUMERIC(19, 2)", {}), ]: for dialect_ in (dialects.postgresql, dialects.mssql, dialects.mysql): @@ -458,7 +458,7 @@ class UserDefinedTest(fixtures.TablesTest, AssertsCompiledSQL): return "VARCHAR(100)" def bind_processor(self, dialect): def process(value): - return "BIND_IN"+ value + return "BIND_IN" + value return process def result_processor(self, dialect, coltype): def process(value): @@ -471,13 +471,13 @@ class UserDefinedTest(fixtures.TablesTest, AssertsCompiledSQL): impl = String def bind_processor(self, dialect): impl_processor = super(MyDecoratedType, self).bind_processor(dialect)\ - or (lambda value:value) + or (lambda value: value) def process(value): - return "BIND_IN"+ impl_processor(value) + return "BIND_IN" + impl_processor(value) return process def result_processor(self, dialect, coltype): impl_processor = super(MyDecoratedType, self).result_processor(dialect, coltype)\ - or (lambda value:value) + or (lambda value: value) def process(value): return impl_processor(value) + "BIND_OUT" return process @@ -520,15 +520,15 @@ class UserDefinedTest(fixtures.TablesTest, AssertsCompiledSQL): def bind_processor(self, dialect): impl_processor = super(MyUnicodeType, self).bind_processor(dialect)\ - or (lambda value:value) + or (lambda value: value) def process(value): - return "BIND_IN"+ impl_processor(value) + return "BIND_IN" + impl_processor(value) return process def result_processor(self, dialect, coltype): impl_processor = super(MyUnicodeType, self).result_processor(dialect, coltype)\ - or (lambda value:value) + or (lambda value: value) def process(value): return impl_processor(value) + "BIND_OUT" return process @@ -537,17 +537,17 @@ class UserDefinedTest(fixtures.TablesTest, AssertsCompiledSQL): return MyUnicodeType(self.impl.length) Table('users', metadata, - Column('user_id', Integer, primary_key = True), + Column('user_id', Integer, primary_key=True), # totall custom type - Column('goofy', MyType, nullable = False), + Column('goofy', MyType, nullable=False), # decorated type with an argument, so its a String - Column('goofy2', MyDecoratedType(50), nullable = False), + Column('goofy2', MyDecoratedType(50), nullable=False), - Column('goofy4', MyUnicodeType(50), nullable = False), - Column('goofy7', MyNewUnicodeType(50), nullable = False), - Column('goofy8', MyNewIntType, nullable = False), - Column('goofy9', MyNewIntSubClass, nullable = False), + Column('goofy4', MyUnicodeType(50), nullable=False), + Column('goofy7', MyNewUnicodeType(50), nullable=False), + Column('goofy8', MyNewIntType, nullable=False), + Column('goofy9', MyNewIntSubClass, nullable=False), ) class VariantTest(fixtures.TestBase, AssertsCompiledSQL): @@ -801,9 +801,9 @@ class EnumTest(fixtures.TestBase): 'but expression is of type text') def test_round_trip(self): enum_table.insert().execute([ - {'id':1, 'someenum':'two'}, - {'id':2, 'someenum':'two'}, - {'id':3, 'someenum':'one'}, + {'id': 1, 'someenum': 'two'}, + {'id': 2, 'someenum': 'two'}, + {'id': 3, 'someenum': 'one'}, ]) eq_( @@ -817,9 +817,9 @@ class EnumTest(fixtures.TestBase): def test_non_native_round_trip(self): non_native_enum_table.insert().execute([ - {'id':1, 'someenum':'two'}, - {'id':2, 'someenum':'two'}, - {'id':3, 'someenum':'one'}, + {'id': 1, 'someenum': 'two'}, + {'id': 2, 'someenum': 'two'}, + {'id': 3, 'someenum': 'one'}, ]) eq_( @@ -834,11 +834,11 @@ class EnumTest(fixtures.TestBase): def test_adapt(self): from sqlalchemy.dialects.postgresql import ENUM - e1 = Enum('one','two','three', native_enum=False) + e1 = Enum('one', 'two', 'three', native_enum=False) eq_(e1.adapt(ENUM).native_enum, False) - e1 = Enum('one','two','three', native_enum=True) + e1 = Enum('one', 'two', 'three', native_enum=True) eq_(e1.adapt(ENUM).native_enum, True) - e1 = Enum('one','two','three', name='foo', schema='bar') + e1 = Enum('one', 'two', 'three', name='foo', schema='bar') eq_(e1.adapt(ENUM).name, 'foo') eq_(e1.adapt(ENUM).schema, 'bar') @@ -848,7 +848,7 @@ class EnumTest(fixtures.TestBase): def test_constraint(self): assert_raises(exc.DBAPIError, enum_table.insert().execute, - {'id':4, 'someenum':'four'} + {'id': 4, 'someenum': 'four'} ) @testing.fails_on('mysql', @@ -856,7 +856,7 @@ class EnumTest(fixtures.TestBase): def test_non_native_constraint(self): assert_raises(exc.DBAPIError, non_native_enum_table.insert().execute, - {'id':4, 'someenum':'four'} + {'id': 4, 'someenum': 'four'} ) def test_mock_engine_no_prob(self): @@ -919,8 +919,8 @@ class BinaryTest(fixtures.TestBase, AssertsExecutionResults): testobj2 = pickleable.Foo('im foo 2') testobj3 = pickleable.Foo('im foo 3') - stream1 =self.load_stream('binary_data_one.dat') - stream2 =self.load_stream('binary_data_two.dat') + stream1 = self.load_stream('binary_data_one.dat') + stream2 = self.load_stream('binary_data_two.dat') binary_table.insert().execute( primary_id=1, misc='binary_data_one.dat', @@ -945,9 +945,9 @@ class BinaryTest(fixtures.TestBase, AssertsExecutionResults): binary_table.select(order_by=binary_table.c.primary_id), text( "select * from binary_table order by binary_table.primary_id", - typemap={'pickled':PickleType, - 'mypickle':MyPickleType, - 'data':LargeBinary, 'data_slice':LargeBinary}, + typemap={'pickled': PickleType, + 'mypickle': MyPickleType, + 'data': LargeBinary, 'data_slice': LargeBinary}, bind=testing.db) ): l = stmt.execute().fetchall() @@ -968,7 +968,9 @@ class BinaryTest(fixtures.TestBase, AssertsExecutionResults): data = os.urandom(32) binary_table.insert().execute(data=data) - eq_(binary_table.select().where(binary_table.c.data==data).alias().count().scalar(), 1) + eq_(binary_table.select(). + where(binary_table.c.data == data).alias(). + count().scalar(), 1) def load_stream(self, name): @@ -994,8 +996,8 @@ class ExpressionTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiled return value / 10 return process def adapt_operator(self, op): - return {operators.add:operators.sub, - operators.sub:operators.add}.get(op, op) + return {operators.add: operators.sub, + operators.sub: operators.add}.get(op, op) class MyTypeDec(types.TypeDecorator): impl = String @@ -1018,10 +1020,10 @@ class ExpressionTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiled meta.create_all() test_table.insert().execute({ - 'id':1, - 'data':'somedata', - 'atimestamp':datetime.date(2007, 10, 15), - 'avalue':25, 'bvalue':'foo'}) + 'id': 1, + 'data': 'somedata', + 'atimestamp': datetime.date(2007, 10, 15), + 'avalue': 25, 'bvalue': 'foo'}) @classmethod def teardown_class(cls): @@ -1045,7 +1047,7 @@ class ExpressionTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiled testing.db.execute( select([test_table.c.id, test_table.c.data, test_table.c.atimestamp]) .where(expr), - {"thedate":datetime.date(2007, 10, 15)}).fetchall(), + {"thedate": datetime.date(2007, 10, 15)}).fetchall(), [(1, 'somedata', datetime.date(2007, 10, 15))] ) @@ -1064,7 +1066,7 @@ class ExpressionTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiled eq_( testing.db.execute(test_table.select().where(expr), - {"somevalue":"foo"}).fetchall(), + {"somevalue": "foo"}).fetchall(), [(1, 'somedata', datetime.date(2007, 10, 15), 25, 'BIND_INfooBIND_OUT')] ) @@ -1328,7 +1330,7 @@ class NumericRawSQLTest(fixtures.TestBase): @testing.provide_metadata def test_decimal_fp(self): metadata = self.metadata - t = self._fixture(metadata, Numeric(10, 5), decimal.Decimal("45.5")) + self._fixture(metadata, Numeric(10, 5), decimal.Decimal("45.5")) val = testing.db.execute("select val from t").scalar() assert isinstance(val, decimal.Decimal) eq_(val, decimal.Decimal("45.5")) @@ -1337,7 +1339,7 @@ class NumericRawSQLTest(fixtures.TestBase): @testing.provide_metadata def test_decimal_int(self): metadata = self.metadata - t = self._fixture(metadata, Numeric(10, 5), decimal.Decimal("45")) + self._fixture(metadata, Numeric(10, 5), decimal.Decimal("45")) val = testing.db.execute("select val from t").scalar() assert isinstance(val, decimal.Decimal) eq_(val, decimal.Decimal("45")) @@ -1345,7 +1347,7 @@ class NumericRawSQLTest(fixtures.TestBase): @testing.provide_metadata def test_ints(self): metadata = self.metadata - t = self._fixture(metadata, Integer, 45) + self._fixture(metadata, Integer, 45) val = testing.db.execute("select val from t").scalar() assert isinstance(val, int) eq_(val, 45) @@ -1353,7 +1355,7 @@ class NumericRawSQLTest(fixtures.TestBase): @testing.provide_metadata def test_float(self): metadata = self.metadata - t = self._fixture(metadata, Float, 46.583) + self._fixture(metadata, Float, 46.583) val = testing.db.execute("select val from t").scalar() assert isinstance(val, float) @@ -1486,7 +1488,7 @@ class PickleTest(fixtures.TestBase): p1 = PickleType() for obj in ( - {'1':'2'}, + {'1': '2'}, pickleable.Bar(5, 6), pickleable.OldSchool(10, 11) ): @@ -1501,7 +1503,7 @@ class PickleTest(fixtures.TestBase): p1 = PickleType() for obj in ( - {'1':'2'}, + {'1': '2'}, pickleable.Bar(5, 6), pickleable.OldSchool(10, 11) ): -- cgit v1.2.1 From 6f82c320b8834761fa9606119a4c2cbc6c3312f1 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 4 May 2013 14:24:20 -0400 Subject: use logging to output exc_info here --- lib/sqlalchemy/engine/base.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index d4ced4cca..c2ba0922b 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -956,17 +956,11 @@ class Connection(Connectable): """ try: cursor.close() - except Exception as e: - try: - ex_text = str(e) - except TypeError: - ex_text = repr(e) - if not self.closed: - self.connection._logger.warn( - "Error closing cursor: %s", ex_text) - - if isinstance(e, (SystemExit, KeyboardInterrupt)): - raise + except (SystemExit, KeyboardInterrupt): + raise + except Exception: + self.connection._logger.error( + "Error closing cursor", exc_info=True) _reentrant_error = False _is_disconnect = False -- cgit v1.2.1 From 2a99b770ddf144c279ad8b42ad8593b3439cd2de Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 4 May 2013 14:59:26 -0400 Subject: - unicode literals need to just be handled differently if they have utf-8 encoded in them vs. unicode escaping. not worth figuring out how to combine these right now --- lib/sqlalchemy/dialects/sqlite/base.py | 2 +- lib/sqlalchemy/sql/compiler.py | 6 +-- lib/sqlalchemy/util/__init__.py | 2 +- lib/sqlalchemy/util/compat.py | 10 +++++ test/sql/test_compiler.py | 5 ++- test/sql/test_unicode.py | 81 +++++++++++++++++----------------- 6 files changed, 59 insertions(+), 47 deletions(-) diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index d742a71b5..1ca8f4e64 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -812,7 +812,7 @@ class SQLiteDialect(default.DefaultDialect): coltype = sqltypes.NullType() if default is not None: - default = str(default) + default = util.text_type(default) return { 'name': name, diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index d51dd625a..c3aea159a 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -1868,11 +1868,11 @@ class DDLCompiler(engine.Compiled): first_pk = True except exc.CompileError as ce: util.raise_from_cause( - exc.CompileError(util.u("(in table '%s', column '%s'): %s" % ( + exc.CompileError(util.u("(in table '%s', column '%s'): %s") % ( table.description, column.name, ce.args[0] - )))) + ))) const = self.create_table_constraints(table) if const: @@ -2344,7 +2344,7 @@ class IdentifierPreparer(object): lc_value = value.lower() return (lc_value in self.reserved_words or value[0] in self.illegal_initial_characters - or not self.legal_characters.match(str(value)) + or not self.legal_characters.match(util.text_type(value)) or (lc_value != value)) def quote_schema(self, schema, force): diff --git a/lib/sqlalchemy/util/__init__.py b/lib/sqlalchemy/util/__init__.py index 72baa9f36..b1f1a2db6 100644 --- a/lib/sqlalchemy/util/__init__.py +++ b/lib/sqlalchemy/util/__init__.py @@ -8,7 +8,7 @@ from .compat import callable, cmp, reduce, \ threading, py3k, py2k, jython, pypy, cpython, win32, \ pickle, dottedgetter, parse_qsl, namedtuple, next, WeakSet, reraise, \ raise_from_cause, text_type, string_types, int_types, binary_type, \ - quote_plus, with_metaclass, print_, itertools_filterfalse, u, b,\ + quote_plus, with_metaclass, print_, itertools_filterfalse, u, ue, b,\ unquote_plus from ._collections import KeyedTuple, ImmutableContainer, immutabledict, \ diff --git a/lib/sqlalchemy/util/compat.py b/lib/sqlalchemy/util/compat.py index bc7a0fe21..94b35f019 100644 --- a/lib/sqlalchemy/util/compat.py +++ b/lib/sqlalchemy/util/compat.py @@ -46,6 +46,9 @@ if py3k: def u(s): return s + def ue(s): + return s + def b(s): return s.encode("latin-1") @@ -79,6 +82,13 @@ else: return (ord(byte) for byte in buf) def u(s): + # this differs from what six does, which doesn't support non-ASCII + # strings - we only use u() with + # literal source strings, and all our source files with non-ascii + # in them (all are tests) are utf-8 encoded. + return unicode(s, "utf-8") + + def ue(s): return unicode(s, "unicode_escape") def b(s): diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index e3f7df702..9cb0e6bbe 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -20,6 +20,7 @@ from sqlalchemy import Integer, String, MetaData, Table, Column, select, \ intersect, union_all, Boolean, distinct, join, outerjoin, asc, desc,\ over, subquery, case import decimal +from sqlalchemy.util import u from sqlalchemy import exc, sql, util, types, schema from sqlalchemy.sql import table, column, label from sqlalchemy.sql.expression import ClauseList, _literal_as_text, HasPrefixes @@ -2680,11 +2681,11 @@ class DDLTest(fixtures.TestBase, AssertsCompiledSQL): def test_reraise_of_column_spec_issue_unicode(self): MyType = self._illegal_type_fixture() t1 = Table('t', MetaData(), - Column('méil', MyType()) + Column(u('méil'), MyType()) ) assert_raises_message( exc.CompileError, - r"\(in table 't', column 'méil'\): Couldn't compile type", + u(r"\(in table 't', column 'méil'\): Couldn't compile type"), schema.CreateTable(t1).compile ) diff --git a/test/sql/test_unicode.py b/test/sql/test_unicode.py index 2ab081dad..ffcef903f 100644 --- a/test/sql/test_unicode.py +++ b/test/sql/test_unicode.py @@ -7,6 +7,7 @@ from sqlalchemy import testing from sqlalchemy.testing.engines import utf8_engine from sqlalchemy.sql import column from sqlalchemy.testing.schema import Table, Column +from sqlalchemy.util import u, ue class UnicodeSchemaTest(fixtures.TestBase): __requires__ = ('unicode_ddl',) @@ -18,14 +19,14 @@ class UnicodeSchemaTest(fixtures.TestBase): unicode_bind = utf8_engine() metadata = MetaData(unicode_bind) - t1 = Table('unitable1', metadata, - Column('méil', Integer, primary_key=True), - Column('\u6e2c\u8a66', Integer), + t1 = Table(u('unitable1'), metadata, + Column(u('méil'), Integer, primary_key=True), + Column(ue('\u6e2c\u8a66'), Integer), test_needs_fk=True, ) - t2 = Table('Unitéble2', metadata, - Column('méil', Integer, primary_key=True, key="a"), - Column('\u6e2c\u8a66', Integer, ForeignKey('unitable1.méil'), + t2 = Table(u('Unitéble2'), metadata, + Column(u('méil'), Integer, primary_key=True, key="a"), + Column(ue('\u6e2c\u8a66'), Integer, ForeignKey(u('unitable1.méil')), key="b" ), test_needs_fk=True, @@ -33,27 +34,27 @@ class UnicodeSchemaTest(fixtures.TestBase): # Few DBs support Unicode foreign keys if testing.against('sqlite'): - t3 = Table('\u6e2c\u8a66', metadata, - Column('\u6e2c\u8a66_id', Integer, primary_key=True, + t3 = Table(ue('\u6e2c\u8a66'), metadata, + Column(ue('\u6e2c\u8a66_id'), Integer, primary_key=True, autoincrement=False), - Column('unitable1_\u6e2c\u8a66', Integer, - ForeignKey('unitable1.\u6e2c\u8a66') + Column(ue('unitable1_\u6e2c\u8a66'), Integer, + ForeignKey(ue('unitable1.\u6e2c\u8a66')) ), - Column('Unitéble2_b', Integer, - ForeignKey('Unitéble2.b') + Column(u('Unitéble2_b'), Integer, + ForeignKey(u('Unitéble2.b')) ), - Column('\u6e2c\u8a66_self', Integer, - ForeignKey('\u6e2c\u8a66.\u6e2c\u8a66_id') + Column(ue('\u6e2c\u8a66_self'), Integer, + ForeignKey(ue('\u6e2c\u8a66.\u6e2c\u8a66_id')) ), test_needs_fk=True, ) else: - t3 = Table('\u6e2c\u8a66', metadata, - Column('\u6e2c\u8a66_id', Integer, primary_key=True, + t3 = Table(ue('\u6e2c\u8a66'), metadata, + Column(ue('\u6e2c\u8a66_id'), Integer, primary_key=True, autoincrement=False), - Column('unitable1_\u6e2c\u8a66', Integer), - Column('Unitéble2_b', Integer), - Column('\u6e2c\u8a66_self', Integer), + Column(ue('unitable1_\u6e2c\u8a66'), Integer), + Column(u('Unitéble2_b'), Integer), + Column(ue('\u6e2c\u8a66_self'), Integer), test_needs_fk=True, ) metadata.create_all() @@ -72,42 +73,42 @@ class UnicodeSchemaTest(fixtures.TestBase): del unicode_bind def test_insert(self): - t1.insert().execute({'méil':1, '\u6e2c\u8a66':5}) - t2.insert().execute({'a':1, 'b':1}) - t3.insert().execute({'\u6e2c\u8a66_id': 1, - 'unitable1_\u6e2c\u8a66': 5, - 'Unitéble2_b': 1, - '\u6e2c\u8a66_self': 1}) + t1.insert().execute({u('méil'):1, ue('\u6e2c\u8a66'):5}) + t2.insert().execute({u('a'):1, u('b'):1}) + t3.insert().execute({ue('\u6e2c\u8a66_id'): 1, + ue('unitable1_\u6e2c\u8a66'): 5, + u('Unitéble2_b'): 1, + ue('\u6e2c\u8a66_self'): 1}) assert t1.select().execute().fetchall() == [(1, 5)] assert t2.select().execute().fetchall() == [(1, 1)] assert t3.select().execute().fetchall() == [(1, 5, 1, 1)] def test_reflect(self): - t1.insert().execute({'méil':2, '\u6e2c\u8a66':7}) - t2.insert().execute({'a':2, 'b':2}) - t3.insert().execute({'\u6e2c\u8a66_id': 2, - 'unitable1_\u6e2c\u8a66': 7, - 'Unitéble2_b': 2, - '\u6e2c\u8a66_self': 2}) + t1.insert().execute({u('méil'):2, ue('\u6e2c\u8a66'):7}) + t2.insert().execute({u('a'):2, u('b'):2}) + t3.insert().execute({ue('\u6e2c\u8a66_id'): 2, + ue('unitable1_\u6e2c\u8a66'): 7, + u('Unitéble2_b'): 2, + ue('\u6e2c\u8a66_self'): 2}) meta = MetaData(unicode_bind) tt1 = Table(t1.name, meta, autoload=True) tt2 = Table(t2.name, meta, autoload=True) tt3 = Table(t3.name, meta, autoload=True) - tt1.insert().execute({'méil':1, '\u6e2c\u8a66':5}) - tt2.insert().execute({'méil':1, '\u6e2c\u8a66':1}) - tt3.insert().execute({'\u6e2c\u8a66_id': 1, - 'unitable1_\u6e2c\u8a66': 5, - 'Unitéble2_b': 1, - '\u6e2c\u8a66_self': 1}) + tt1.insert().execute({u('méil'):1, ue('\u6e2c\u8a66'):5}) + tt2.insert().execute({u('méil'):1, ue('\u6e2c\u8a66'):1}) + tt3.insert().execute({ue('\u6e2c\u8a66_id'): 1, + ue('unitable1_\u6e2c\u8a66'): 5, + u('Unitéble2_b'): 1, + ue('\u6e2c\u8a66_self'): 1}) - self.assert_(tt1.select(order_by=desc('méil')).execute().fetchall() == + self.assert_(tt1.select(order_by=desc(u('méil'))).execute().fetchall() == [(2, 7), (1, 5)]) - self.assert_(tt2.select(order_by=desc('méil')).execute().fetchall() == + self.assert_(tt2.select(order_by=desc(u('méil'))).execute().fetchall() == [(2, 2), (1, 1)]) - self.assert_(tt3.select(order_by=desc('\u6e2c\u8a66_id')). + self.assert_(tt3.select(order_by=desc(ue('\u6e2c\u8a66_id'))). execute().fetchall() == [(2, 7, 2, 2), (1, 5, 1, 1)]) meta.drop_all() -- cgit v1.2.1 From 9db36c36aa09d8aa6226020600847f0d68faec0f Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 4 May 2013 15:06:47 -0400 Subject: cleanup and formatting --- test/sql/test_defaults.py | 135 +++++++++++++++++++++++----------------------- 1 file changed, 68 insertions(+), 67 deletions(-) diff --git a/test/sql/test_defaults.py b/test/sql/test_defaults.py index 38c56f8be..2868f59c4 100644 --- a/test/sql/test_defaults.py +++ b/test/sql/test_defaults.py @@ -1,7 +1,7 @@ -from sqlalchemy.testing import eq_, assert_raises, assert_raises_message +from sqlalchemy.testing import eq_, assert_raises_message, assert_raises import datetime from sqlalchemy.schema import CreateSequence, DropSequence -from sqlalchemy.sql import select, text, literal_column +from sqlalchemy.sql import select, text import sqlalchemy as sa from sqlalchemy import testing from sqlalchemy.testing import engines @@ -9,10 +9,11 @@ from sqlalchemy import MetaData, Integer, String, ForeignKey, Boolean, exc,\ Sequence, func, literal, Unicode from sqlalchemy.types import TypeDecorator, TypeEngine from sqlalchemy.testing.schema import Table, Column -from sqlalchemy.testing import eq_ from sqlalchemy.dialects import sqlite from sqlalchemy.testing import fixtures +t = f = f2 = ts = currenttime = metadata = default_generator = None + class DefaultTest(fixtures.TestBase): @classmethod @@ -21,7 +22,7 @@ class DefaultTest(fixtures.TestBase): db = testing.db metadata = MetaData(db) - default_generator = {'x':50} + default_generator = {'x': 50} def mydefault(): default_generator['x'] += 1 @@ -163,10 +164,10 @@ class DefaultTest(fixtures.TestBase): def fn4(x=1, y=2, z=3): eq_(x, 1) fn5 = list - class fn6(object): + class fn6a(object): def __init__(self, x): eq_(x, "context") - class fn6(object): + class fn6b(object): def __init__(self, x, y=3): eq_(x, "context") class FN7(object): @@ -178,7 +179,7 @@ class DefaultTest(fixtures.TestBase): eq_(x, "context") fn8 = FN8() - for fn in fn1, fn2, fn3, fn4, fn5, fn6, fn7, fn8: + for fn in fn1, fn2, fn3, fn4, fn5, fn6a, fn6b, fn7, fn8: c = sa.ColumnDefault(fn) c.arg("context") @@ -288,7 +289,7 @@ class DefaultTest(fixtures.TestBase): eq_(set(r.context.postfetch_cols), set([t.c.col3, t.c.col5, t.c.col4, t.c.col6])) - eq_(t.select(t.c.col1==54).execute().fetchall(), + eq_(t.select(t.c.col1 == 54).execute().fetchall(), [(54, 'imthedefault', f, ts, ts, ctexec, True, False, 12, today, None)]) @@ -296,10 +297,10 @@ class DefaultTest(fixtures.TestBase): def test_insertmany(self): # MySQL-Python 1.2.2 breaks functions in execute_many :( if (testing.against('mysql+mysqldb') and - testing.db.dialect.dbapi.version_info[:3] == (1, 2, 2)): + testing.db.dialect.dbapi.version_info[:3] == (1, 2, 2)): return - r = t.insert().execute({}, {}, {}) + t.insert().execute({}, {}, {}) ctexec = currenttime.scalar() l = t.select().execute() @@ -342,13 +343,13 @@ class DefaultTest(fixtures.TestBase): assert_raises_message(exc.StatementError, "A value is required for bind parameter 'col7', in parameter group 1", t.insert().execute, - {'col4':7, 'col7':12, 'col8':19}, - {'col4':7, 'col8':19}, - {'col4':7, 'col7':12, 'col8':19}, + {'col4': 7, 'col7': 12, 'col8': 19}, + {'col4': 7, 'col8': 19}, + {'col4': 7, 'col7': 12, 'col8': 19}, ) def test_insert_values(self): - t.insert(values={'col3':50}).execute() + t.insert(values={'col3': 50}).execute() l = t.select().execute() eq_(50, l.first()['col3']) @@ -356,18 +357,18 @@ class DefaultTest(fixtures.TestBase): def test_updatemany(self): # MySQL-Python 1.2.2 breaks functions in execute_many :( if (testing.against('mysql+mysqldb') and - testing.db.dialect.dbapi.version_info[:3] == (1, 2, 2)): + testing.db.dialect.dbapi.version_info[:3] == (1, 2, 2)): return t.insert().execute({}, {}, {}) - t.update(t.c.col1==sa.bindparam('pkval')).execute( - {'pkval':51,'col7':None, 'col8':None, 'boolcol1':False}) + t.update(t.c.col1 == sa.bindparam('pkval')).execute( + {'pkval': 51, 'col7': None, 'col8': None, 'boolcol1': False}) - t.update(t.c.col1==sa.bindparam('pkval')).execute( - {'pkval':51,}, - {'pkval':52,}, - {'pkval':53,}) + t.update(t.c.col1 == sa.bindparam('pkval')).execute( + {'pkval': 51}, + {'pkval': 52}, + {'pkval': 53}) l = t.select().execute() ctexec = currenttime.scalar() @@ -384,9 +385,9 @@ class DefaultTest(fixtures.TestBase): def test_update(self): r = t.insert().execute() pk = r.inserted_primary_key[0] - t.update(t.c.col1==pk).execute(col4=None, col5=None) + t.update(t.c.col1 == pk).execute(col4=None, col5=None) ctexec = currenttime.scalar() - l = t.select(t.c.col1==pk).execute() + l = t.select(t.c.col1 == pk).execute() l = l.first() eq_(l, (pk, 'im the update', f2, None, None, ctexec, True, False, @@ -397,8 +398,8 @@ class DefaultTest(fixtures.TestBase): def test_update_values(self): r = t.insert().execute() pk = r.inserted_primary_key[0] - t.update(t.c.col1==pk, values={'col3': 55}).execute() - l = t.select(t.c.col1==pk).execute() + t.update(t.c.col1 == pk, values={'col3': 55}).execute() + l = t.select(t.c.col1 == pk).execute() l = l.first() eq_(55, l['col3']) @@ -429,7 +430,8 @@ class PKDefaultTest(fixtures.TablesTest): if not returning and not testing.db.dialect.implicit_returning: engine = testing.db else: - engine = engines.testing_engine(options={'implicit_returning':returning}) + engine = engines.testing_engine( + options={'implicit_returning': returning}) engine.execute(t2.insert(), nextid=1) r = engine.execute(t1.insert(), data='hi') eq_([1], r.inserted_primary_key) @@ -473,13 +475,13 @@ class PKIncrementTest(fixtures.TablesTest): self.assert_(last not in ids) ids.add(last) - rs = bind.execute(aitable.insert(values={'int1':func.length('four')})) + rs = bind.execute(aitable.insert(values={'int1': func.length('four')})) last = rs.inserted_primary_key[0] self.assert_(last) self.assert_(last not in ids) ids.add(last) - eq_(ids, set([1,2,3,4])) + eq_(ids, set([1, 2, 3, 4])) eq_(list(bind.execute(aitable.select().order_by(aitable.c.id))), [(1, 1, None), (2, None, 'row 2'), (3, 3, 'row 3'), (4, 4, None)]) @@ -508,18 +510,14 @@ class PKIncrementTest(fixtures.TablesTest): class EmptyInsertTest(fixtures.TestBase): @testing.exclude('sqlite', '<', (3, 3, 8), 'no empty insert support') @testing.fails_on('oracle', 'FIXME: unknown') + @testing.provide_metadata def test_empty_insert(self): - metadata = MetaData(testing.db) - t1 = Table('t1', metadata, + t1 = Table('t1', self.metadata, Column('is_true', Boolean, server_default=('1'))) - metadata.create_all() - - try: - result = t1.insert().execute() - eq_(1, select([func.count(text('*'))], from_obj=t1).scalar()) - eq_(True, t1.select().scalar()) - finally: - metadata.drop_all() + self.metadata.create_all() + t1.insert().execute() + eq_(1, select([func.count(text('*'))], from_obj=t1).scalar()) + eq_(True, t1.select().scalar()) class AutoIncrementTest(fixtures.TablesTest): __requires__ = ('identity',) @@ -563,7 +561,7 @@ class AutoIncrementTest(fixtures.TablesTest): def test_autoincrement_ignore_fk(self): m = MetaData() - y = Table('y', m, + Table('y', m, Column('id', Integer(), primary_key=True) ) x = Table('x', m, @@ -575,7 +573,7 @@ class AutoIncrementTest(fixtures.TablesTest): def test_autoincrement_fk_disqualifies(self): m = MetaData() - y = Table('y', m, + Table('y', m, Column('id', Integer(), primary_key=True) ) x = Table('x', m, @@ -593,15 +591,15 @@ class AutoIncrementTest(fixtures.TablesTest): Column('data', String(20))) nonai.create() - - try: + def go(): # postgresql + mysql strict will fail on first row, # mysql in legacy mode fails on second row nonai.insert().execute(data='row 1') nonai.insert().execute(data='row 2') - assert False - except sa.exc.DBAPIError as e: - assert True + assert_raises( + sa.exc.DBAPIError, + go + ) nonai.insert().execute(id=1, data='row 1') @@ -639,7 +637,7 @@ class SequenceExecTest(fixtures.TestBase): @classmethod def setup_class(cls): - cls.seq= Sequence("my_sequence") + cls.seq = Sequence("my_sequence") cls.seq.create(testing.db) @classmethod @@ -702,7 +700,7 @@ class SequenceExecTest(fixtures.TestBase): Column('x', Integer) ) t1.create(testing.db) - testing.db.execute(t1.insert(), [{'x':1}, {'x':300}, {'x':301}]) + testing.db.execute(t1.insert(), [{'x': 1}, {'x': 300}, {'x': 301}]) s = Sequence("my_sequence") eq_( testing.db.execute( @@ -734,7 +732,7 @@ class SequenceExecTest(fixtures.TestBase): pk_col=next_value(), implicit returning is not used.""" metadata = self.metadata - e = engines.testing_engine(options={'implicit_returning':False}) + e = engines.testing_engine(options={'implicit_returning': False}) s = Sequence("my_sequence") metadata.bind = e t1 = Table('t', metadata, @@ -753,7 +751,7 @@ class SequenceExecTest(fixtures.TestBase): pk_col=next_value(), when implicit returning is used.""" metadata = self.metadata - e = engines.testing_engine(options={'implicit_returning':True}) + e = engines.testing_engine(options={'implicit_returning': True}) s = Sequence("my_sequence") metadata.bind = e t1 = Table('t', metadata, @@ -799,10 +797,10 @@ class SequenceTest(fixtures.TestBase, testing.AssertsCompiledSQL): Sequence("my_seq", optional=True)): assert str(s.next_value(). compile(dialect=testing.db.dialect)) in ( - "nextval('my_seq')", - "gen_id(my_seq, 1)", - "my_seq.nextval", - ) + "nextval('my_seq')", + "gen_id(my_seq, 1)", + "my_seq.nextval", + ) def test_nextval_unsupported(self): """test next_value() used on non-sequence platform @@ -828,7 +826,7 @@ class SequenceTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_checkfirst_metadata(self): m = MetaData() - s = Sequence("my_sequence", metadata=m) + Sequence("my_sequence", metadata=m) m.create_all(testing.db, checkfirst=False) assert self._has_sequence('my_sequence') m.create_all(testing.db, checkfirst=True) @@ -850,7 +848,7 @@ class SequenceTest(fixtures.TestBase, testing.AssertsCompiledSQL): @testing.provide_metadata def test_table_overrides_metadata_create(self): metadata = self.metadata - s1 = Sequence("s1", metadata=metadata) + Sequence("s1", metadata=metadata) s2 = Sequence("s2", metadata=metadata) s3 = Sequence("s3") t = Table('t', metadata, @@ -877,7 +875,7 @@ class SequenceTest(fixtures.TestBase, testing.AssertsCompiledSQL): assert not self._has_sequence('s1') assert not self._has_sequence('s2') - +cartitems = sometable = metadata = None class TableBoundSequenceTest(fixtures.TestBase): __requires__ = ('sequences',) @@ -890,10 +888,10 @@ class TableBoundSequenceTest(fixtures.TestBase): Column("description", String(40)), Column("createdate", sa.DateTime()) ) - sometable = Table( 'Manager', metadata, - Column('obj_id', Integer, Sequence('obj_id_seq'), ), - Column('name', String(128)), - Column('id', Integer, Sequence('Manager_id_seq', optional=True), + sometable = Table('Manager', metadata, + Column('obj_id', Integer, Sequence('obj_id_seq')), + Column('name', String(128)), + Column('id', Integer, Sequence('Manager_id_seq', optional=True), primary_key=True), ) @@ -921,7 +919,8 @@ class TableBoundSequenceTest(fixtures.TestBase): def test_seq_nonpk(self): """test sequences fire off as defaults on non-pk columns""" - engine = engines.testing_engine(options={'implicit_returning':False}) + engine = engines.testing_engine( + options={'implicit_returning': False}) result = engine.execute(sometable.insert(), name="somename") assert set(result.postfetch_cols()) == set([sometable.c.obj_id]) @@ -930,8 +929,8 @@ class TableBoundSequenceTest(fixtures.TestBase): assert set(result.postfetch_cols()) == set([sometable.c.obj_id]) sometable.insert().execute( - {'name':'name3'}, - {'name':'name4'}) + {'name': 'name3'}, + {'name': 'name4'}) eq_(sometable.select().order_by(sometable.c.id).execute().fetchall(), [(1, "somename", 1), (2, "someother", 2), @@ -980,7 +979,9 @@ class SpecialTypePKTest(fixtures.TestBase): r = t.insert().values(data=5).execute() # we don't pre-fetch 'server_default'. - if 'server_default' in kw and (not testing.db.dialect.implicit_returning or not implicit_returning): + if 'server_default' in kw and (not + testing.db.dialect.implicit_returning or + not implicit_returning): eq_(r.inserted_primary_key, [None]) else: eq_(r.inserted_primary_key, ['INT_1']) @@ -1109,7 +1110,7 @@ class ServerDefaultsOnPKTest(fixtures.TestBase): @testing.provide_metadata def test_int_default_none_on_insert_reflected(self): metadata = self.metadata - t = Table('x', metadata, + Table('x', metadata, Column('y', Integer, server_default='5', primary_key=True), Column('data', String(10)), @@ -1153,7 +1154,7 @@ class ServerDefaultsOnPKTest(fixtures.TestBase): class UnicodeDefaultsTest(fixtures.TestBase): def test_no_default(self): - c = Column(Unicode(32)) + Column(Unicode(32)) def test_unicode_default(self): # start Py3K @@ -1162,7 +1163,7 @@ class UnicodeDefaultsTest(fixtures.TestBase): # start Py2K # default = u'foo' # end Py2K - c = Column(Unicode(32), default=default) + Column(Unicode(32), default=default) def test_nonunicode_default(self): -- cgit v1.2.1 From 2a8fcfaa42c1ce3ddec9bfdbdf2db61eb293f9b6 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 4 May 2013 15:09:04 -0400 Subject: update test --- test/sql/test_defaults.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/test/sql/test_defaults.py b/test/sql/test_defaults.py index 2868f59c4..ec408e58a 100644 --- a/test/sql/test_defaults.py +++ b/test/sql/test_defaults.py @@ -11,6 +11,7 @@ from sqlalchemy.types import TypeDecorator, TypeEngine from sqlalchemy.testing.schema import Table, Column from sqlalchemy.dialects import sqlite from sqlalchemy.testing import fixtures +from sqlalchemy.util import u, b t = f = f2 = ts = currenttime = metadata = default_generator = None @@ -1157,22 +1158,12 @@ class UnicodeDefaultsTest(fixtures.TestBase): Column(Unicode(32)) def test_unicode_default(self): -# start Py3K - default = 'foo' -# end Py3K -# start Py2K -# default = u'foo' -# end Py2K + default = u('foo') Column(Unicode(32), default=default) def test_nonunicode_default(self): -# start Py3K - default = b'foo' -# end Py3K -# start Py2K -# default = 'foo' -# end Py2K + default = b('foo') assert_raises_message( sa.exc.SAWarning, "Unicode column received non-unicode default value.", -- cgit v1.2.1 From afcbd7419c0708c63e4d71e634296400db1610c1 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 4 May 2013 15:10:41 -0400 Subject: and int types here... --- test/sql/test_defaults.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/sql/test_defaults.py b/test/sql/test_defaults.py index ec408e58a..8d76f74f9 100644 --- a/test/sql/test_defaults.py +++ b/test/sql/test_defaults.py @@ -12,6 +12,7 @@ from sqlalchemy.testing.schema import Table, Column from sqlalchemy.dialects import sqlite from sqlalchemy.testing import fixtures from sqlalchemy.util import u, b +from sqlalchemy import util t = f = f2 = ts = currenttime = metadata = default_generator = None @@ -648,7 +649,7 @@ class SequenceExecTest(fixtures.TestBase): def _assert_seq_result(self, ret): """asserts return of next_value is an int""" - assert isinstance(ret, int) + assert isinstance(ret, util.int_types) assert ret > 0 def test_implicit_connectionless(self): -- cgit v1.2.1 From c7ce62cf65463c7ea6474d0373c56fb3edeb0e2a Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 4 May 2013 15:26:28 -0400 Subject: - OK we have -w sql passing for: sqlite, postgresql, oursql 2.7 + 3.3, mysqldb 2.7 --- lib/sqlalchemy/engine/default.py | 2 +- setup.cfg | 1 + test/sql/test_types.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index e52aac427..e9645f363 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -221,7 +221,7 @@ class DefaultDialect(interfaces.Dialect): ) row = cursor.fetchone() - return isinstance(row[0], util.string_types) + return isinstance(row[0], util.text_type) except self.dbapi.Error as de: util.warn("Exception attempting to " "detect unicode returns: %r" % de) diff --git a/setup.cfg b/setup.cfg index 92bdbc40f..9c53e32ad 100644 --- a/setup.cfg +++ b/setup.cfg @@ -32,6 +32,7 @@ pg8000=postgresql+pg8000://scott:tiger@127.0.0.1:5432/test postgresql_jython=postgresql+zxjdbc://scott:tiger@127.0.0.1:5432/test mysql_jython=mysql+zxjdbc://scott:tiger@127.0.0.1:5432/test mysql=mysql://scott:tiger@127.0.0.1:3306/test +oursql=mysql+oursql://scott:tiger@127.0.0.1:3306/test pymysql=mysql+pymysql://scott:tiger@127.0.0.1:3306/test?use_unicode=0&charset=utf8 oracle=oracle://scott:tiger@127.0.0.1:1521 oracle8=oracle://scott:tiger@127.0.0.1:1521/?use_ansi=0 diff --git a/test/sql/test_types.py b/test/sql/test_types.py index a1845778e..dbb475b98 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -1349,7 +1349,7 @@ class NumericRawSQLTest(fixtures.TestBase): metadata = self.metadata self._fixture(metadata, Integer, 45) val = testing.db.execute("select val from t").scalar() - assert isinstance(val, int) + assert isinstance(val, util.int_types) eq_(val, 45) @testing.provide_metadata -- cgit v1.2.1 From 920e134d53d32c644f0de487d6c40db99977ea4b Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 4 May 2013 15:29:04 -0400 Subject: test_execute up for sqlite, pg, oursql, mysql 2.7 + 3.3 --- lib/sqlalchemy/testing/engines.py | 2 +- test/engine/test_execute.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/sqlalchemy/testing/engines.py b/lib/sqlalchemy/testing/engines.py index 46bf76fad..cfaacc490 100644 --- a/lib/sqlalchemy/testing/engines.py +++ b/lib/sqlalchemy/testing/engines.py @@ -1,4 +1,4 @@ - +from __future__ import absolute_import import types import weakref diff --git a/test/engine/test_execute.py b/test/engine/test_execute.py index e737accdb..8dca2d92a 100644 --- a/test/engine/test_execute.py +++ b/test/engine/test_execute.py @@ -12,6 +12,7 @@ from sqlalchemy.testing.schema import Table, Column import sqlalchemy as tsa from sqlalchemy import testing from sqlalchemy.testing import engines +from sqlalchemy import util from sqlalchemy.testing.engines import testing_engine import logging.handlers from sqlalchemy.dialects.oracle.zxjdbc import ReturningParam @@ -836,7 +837,7 @@ class MockStrategyTest(fixtures.TestBase): def _engine_fixture(self): buf = io.StringIO() def dump(sql, *multiparams, **params): - buf.write(str(sql.compile(dialect=engine.dialect))) + buf.write(util.text_type(sql.compile(dialect=engine.dialect))) engine = create_engine('postgresql://', strategy='mock', executor=dump) return engine, buf -- cgit v1.2.1 From ef629e7b3d8fcac170be36eab45c925ce3582df9 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 4 May 2013 15:35:47 -0400 Subject: cleanup --- test/engine/test_reflection.py | 157 ++++++++++++++++++++--------------------- 1 file changed, 78 insertions(+), 79 deletions(-) diff --git a/test/engine/test_reflection.py b/test/engine/test_reflection.py index c2e3493f3..d8256f2b0 100644 --- a/test/engine/test_reflection.py +++ b/test/engine/test_reflection.py @@ -1,10 +1,7 @@ import unicodedata import sqlalchemy as sa -from sqlalchemy import exc as sa_exc -from sqlalchemy import types as sql_types from sqlalchemy import schema, events, event, inspect from sqlalchemy import MetaData, Integer, String -from sqlalchemy.engine.reflection import Inspector from sqlalchemy.testing import ComparesTables, \ engines, AssertsCompiledSQL, fixtures from sqlalchemy.testing.schema import Table, Column @@ -29,7 +26,7 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): Column('test1', sa.CHAR(5), nullable=False), Column('test2', sa.Float(5), nullable=False), Column('test3', sa.Text), - Column('test4', sa.Numeric(10, 2), nullable = False), + Column('test4', sa.Numeric(10, 2), nullable=False), Column('test5', sa.Date), Column('parent_user_id', sa.Integer, sa.ForeignKey('engine_users.user_id')), @@ -123,7 +120,7 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): def test_extend_existing(self): meta = self.metadata - t1 = Table('t', meta, + Table('t', meta, Column('id', Integer, primary_key=True), Column('x', Integer), Column('y', Integer), @@ -209,8 +206,8 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): establishes the FK not present in the DB. """ - a = Table('a', self.metadata, Column('id', Integer, primary_key=True)) - b = Table('b', self.metadata, Column('id', Integer, primary_key=True), + Table('a', self.metadata, Column('id', Integer, primary_key=True)) + Table('b', self.metadata, Column('id', Integer, primary_key=True), Column('a_id', Integer)) self.metadata.create_all() @@ -232,8 +229,8 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): the in-python one only. """ - a = Table('a', self.metadata, Column('id', Integer, primary_key=True)) - b = Table('b', self.metadata, Column('id', Integer, primary_key=True), + Table('a', self.metadata, Column('id', Integer, primary_key=True)) + Table('b', self.metadata, Column('id', Integer, primary_key=True), Column('a_id', Integer, sa.ForeignKey('a.id'))) self.metadata.create_all() @@ -254,8 +251,8 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): DB means the FK is skipped and doesn't get installed at all. """ - a = Table('a', self.metadata, Column('id', Integer, primary_key=True)) - b = Table('b', self.metadata, Column('id', Integer, primary_key=True), + Table('a', self.metadata, Column('id', Integer, primary_key=True)) + Table('b', self.metadata, Column('id', Integer, primary_key=True), Column('a_id', Integer, sa.ForeignKey('a.id'))) self.metadata.create_all() @@ -272,7 +269,7 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): @testing.provide_metadata def test_autoload_replace_primary_key(self): - a = Table('a', self.metadata, Column('id', Integer)) + Table('a', self.metadata, Column('id', Integer)) self.metadata.create_all() m2 = MetaData() @@ -296,12 +293,12 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): """ meta = self.metadata - t1 = Table('test', meta, + Table('test', meta, Column('id', sa.Integer, primary_key=True), Column('data', sa.String(50)), mysql_engine='MyISAM' ) - t2 = Table('test2', meta, + Table('test2', meta, Column('id', sa.Integer, sa.ForeignKey('test.id'), primary_key=True), Column('id2', sa.Integer, primary_key=True), @@ -366,10 +363,10 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): a primary key column""" meta = self.metadata - users = Table('users', meta, + Table('users', meta, Column('id', sa.Integer, primary_key=True), Column('name', sa.String(30))) - addresses = Table('addresses', meta, + Table('addresses', meta, Column('id', sa.Integer, primary_key=True), Column('street', sa.String(30))) @@ -384,7 +381,7 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): assert list(a2.primary_key) == [a2.c.id] assert list(u2.primary_key) == [u2.c.id] - assert u2.join(a2).onclause.compare(u2.c.id==a2.c.id) + assert u2.join(a2).onclause.compare(u2.c.id == a2.c.id) meta3 = MetaData(testing.db) u3 = Table('users', meta3, autoload=True) @@ -395,7 +392,7 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): assert list(a3.primary_key) == [a3.c.id] assert list(u3.primary_key) == [u3.c.id] - assert u3.join(a3).onclause.compare(u3.c.id==a3.c.id) + assert u3.join(a3).onclause.compare(u3.c.id == a3.c.id) @testing.provide_metadata def test_override_nonexistent_fk(self): @@ -404,10 +401,10 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): is common with MySQL MyISAM tables.""" meta = self.metadata - users = Table('users', meta, + Table('users', meta, Column('id', sa.Integer, primary_key=True), Column('name', sa.String(30))) - addresses = Table('addresses', meta, + Table('addresses', meta, Column('id', sa.Integer, primary_key=True), Column('street', sa.String(30)), Column('user_id', sa.Integer)) @@ -415,7 +412,7 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): meta.create_all() meta2 = MetaData(testing.db) a2 = Table('addresses', meta2, - Column('user_id',sa.Integer, sa.ForeignKey('users.id')), + Column('user_id', sa.Integer, sa.ForeignKey('users.id')), autoload=True) u2 = Table('users', meta2, autoload=True) assert len(a2.c.user_id.foreign_keys) == 1 @@ -464,13 +461,13 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): metadata = self.metadata - a = Table('a', + Table('a', metadata, Column('x', sa.Integer, primary_key=True), Column('y', sa.Integer, primary_key=True), ) - b = Table('b', + Table('b', metadata, Column('x', sa.Integer, primary_key=True), Column('y', sa.Integer, primary_key=True), @@ -503,12 +500,12 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): and that ForeignKey targeting during reflection still works.""" meta = self.metadata - a1 = Table('a', meta, + Table('a', meta, Column('x', sa.Integer, primary_key=True), Column('z', sa.Integer), test_needs_fk=True ) - b1 = Table('b', meta, + Table('b', meta, Column('y', sa.Integer, sa.ForeignKey('a.x')), test_needs_fk=True ) @@ -530,12 +527,12 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): """ meta = self.metadata - a1 = Table('a', meta, + Table('a', meta, Column('x', sa.Integer, primary_key=True), Column('z', sa.Integer), test_needs_fk=True ) - b1 = Table('b', meta, + Table('b', meta, Column('y', sa.Integer, sa.ForeignKey('a.x')), test_needs_fk=True ) @@ -554,11 +551,11 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): have that foreign key, and that the FK is not duped. """ meta = self.metadata - users = Table('users', meta, + Table('users', meta, Column('id', sa.Integer, primary_key=True), Column('name', sa.String(30)), test_needs_fk=True) - addresses = Table('addresses', meta, + Table('addresses', meta, Column('id', sa.Integer, primary_key=True), Column('user_id', sa.Integer, sa.ForeignKey('users.id')), test_needs_fk=True) @@ -566,7 +563,7 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): meta.create_all() meta2 = MetaData(testing.db) a2 = Table('addresses', meta2, - Column('user_id',sa.Integer, sa.ForeignKey('users.id')), + Column('user_id', sa.Integer, sa.ForeignKey('users.id')), autoload=True) u2 = Table('users', meta2, autoload=True) s = sa.select([a2]) @@ -625,7 +622,7 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): def test_fk_error(self): metadata = MetaData(testing.db) - slots_table = Table('slots', metadata, + Table('slots', metadata, Column('slot_id', sa.Integer, primary_key=True), Column('pkg_id', sa.Integer, sa.ForeignKey('pkgs.pkg_id')), Column('slot', sa.String(128)), @@ -730,9 +727,9 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): check_col = 'true' quoter = meta.bind.dialect.identifier_preparer.quote_identifier - table_b = Table('false', meta, + Table('false', meta, Column('create', sa.Integer, primary_key=True), - Column('true', sa.Integer,sa.ForeignKey('select.not')), + Column('true', sa.Integer, sa.ForeignKey('select.not')), sa.CheckConstraint('%s <> 1' % quoter(check_col), name='limit') ) @@ -746,9 +743,9 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): meta.create_all() index_c.drop() meta2 = MetaData(testing.db) - table_a2 = Table('select', meta2, autoload=True) - table_b2 = Table('false', meta2, autoload=True) - table_c2 = Table('is', meta2, autoload=True) + Table('select', meta2, autoload=True) + Table('false', meta2, autoload=True) + Table('is', meta2, autoload=True) @testing.provide_metadata def _test_reflect_uses_bind(self, fn): @@ -781,7 +778,7 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): def test_reflect_all(self): existing = testing.db.table_names() - names = ['rt_%s' % name for name in ('a','b','c','d','e')] + names = ['rt_%s' % name for name in ('a', 'b', 'c', 'd', 'e')] nameset = set(names) for name in names: # be sure our starting environment is sane @@ -847,9 +844,8 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): assert not c.closed def test_inspector_conn_closing(self): - m1 = MetaData() c = testing.db.connect() - i = inspect(testing.db) + inspect(c) assert not c.closed @testing.provide_metadata @@ -859,8 +855,8 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): Column('id', sa.Integer, nullable=False), Column('name', sa.String(20), index=True) ) - i1 = sa.Index('idx1', t1.c.id, unique=True) - i2 = sa.Index('idx2', t1.c.name, t1.c.id, unique=False) + sa.Index('idx1', t1.c.id, unique=True) + sa.Index('idx2', t1.c.name, t1.c.id, unique=False) m1.create_all() m2 = MetaData(testing.db) t2 = Table('party', m2, autoload=True) @@ -938,9 +934,9 @@ class CreateDropTest(fixtures.TestBase): Column('user_id', sa.Integer, sa.Sequence('user_id_seq', optional=True), primary_key=True), - Column('user_name',sa.String(40))) + Column('user_name', sa.String(40))) - addresses = Table('email_addresses', metadata, + Table('email_addresses', metadata, Column('address_id', sa.Integer, sa.Sequence('address_id_seq', optional=True), primary_key=True), @@ -948,7 +944,7 @@ class CreateDropTest(fixtures.TestBase): sa.Integer, sa.ForeignKey(users.c.user_id)), Column('email_address', sa.String(40))) - orders = Table( + Table( 'orders', metadata, Column('order_id', sa.Integer, sa.Sequence('order_id_seq', @@ -958,13 +954,15 @@ class CreateDropTest(fixtures.TestBase): Column('description', sa.String(50)), Column('isopen', sa.Integer), ) - orderitems = Table('items', metadata, Column('item_id', sa.INT, + Table('items', metadata, + Column('item_id', sa.INT, sa.Sequence('items_id_seq', optional=True), - primary_key=True), Column('order_id', + primary_key=True), + Column('order_id', sa.INT, sa.ForeignKey('orders')), Column('item_name', sa.VARCHAR(50))) - def test_sorter( self ): + def test_sorter(self): tables = metadata.sorted_tables table_names = [t.name for t in tables] ua = [n for n in table_names if n in ('users', 'email_addresses')] @@ -990,16 +988,16 @@ class CreateDropTest(fixtures.TestBase): def test_createdrop(self): metadata.create_all(bind=testing.db) - eq_( testing.db.has_table('items'), True ) - eq_( testing.db.has_table('email_addresses'), True ) + eq_(testing.db.has_table('items'), True) + eq_(testing.db.has_table('email_addresses'), True) metadata.create_all(bind=testing.db) - eq_( testing.db.has_table('items'), True ) + eq_(testing.db.has_table('items'), True) metadata.drop_all(bind=testing.db) - eq_( testing.db.has_table('items'), False ) - eq_( testing.db.has_table('email_addresses'), False ) + eq_(testing.db.has_table('items'), False) + eq_(testing.db.has_table('email_addresses'), False) metadata.drop_all(bind=testing.db) - eq_( testing.db.has_table('items'), False ) + eq_(testing.db.has_table('items'), False) def test_tablenames(self): metadata.create_all(bind=testing.db) @@ -1022,7 +1020,7 @@ class SchemaManipulationTest(fixtures.TestBase): Column('id', sa.Integer), Column('user_id', sa.Integer)) - fk = sa.ForeignKeyConstraint(['user_id'],[users.c.id]) + fk = sa.ForeignKeyConstraint(['user_id'], [users.c.id]) addresses.append_constraint(fk) addresses.append_constraint(fk) @@ -1036,7 +1034,7 @@ class UnicodeReflectionTest(fixtures.TestBase): testing.db.connect().close() cls.bind = bind = engines.utf8_engine( - options={'convert_unicode' : True}) + options={'convert_unicode': True}) cls.metadata = metadata = MetaData() @@ -1064,7 +1062,7 @@ class UnicodeReflectionTest(fixtures.TestBase): names = no_multibyte_period # mysql can't handle casing usually elif testing.against("mysql") and \ - not testing.requires._has_mysql_fully_case_sensitive(): + not testing.requires._has_mysql_fully_case_sensitive(): names = no_multibyte_period.union(no_case_sensitivity) # mssql + pyodbc + freetds can't compare multibyte names to # information_schema.tables.table_name @@ -1074,9 +1072,11 @@ class UnicodeReflectionTest(fixtures.TestBase): names = no_multibyte_period.union(full) for tname, cname, ixname in names: - t = Table(tname, metadata, Column('id', sa.Integer, - sa.Sequence(cname + '_id_seq'), primary_key=True), - Column(cname, Integer) + t = Table(tname, metadata, + Column('id', sa.Integer, + sa.Sequence(cname + '_id_seq'), + primary_key=True), + Column(cname, Integer) ) schema.Index(ixname, t.c[cname]) @@ -1169,11 +1169,11 @@ class SchemaTest(fixtures.TestBase): assert bool(schema) metadata = MetaData(engine) - table1 = Table('table1', metadata, + Table('table1', metadata, Column('col1', sa.Integer, primary_key=True), test_needs_fk=True, schema=schema) - table2 = Table('table2', metadata, + Table('table2', metadata, Column('col1', sa.Integer, primary_key=True), Column('col2', sa.Integer, sa.ForeignKey('%s.table1.col1' % schema)), @@ -1185,8 +1185,8 @@ class SchemaTest(fixtures.TestBase): assert len(metadata.tables) == 2 metadata.clear() - table1 = Table('table1', metadata, autoload=True, schema=schema) - table2 = Table('table2', metadata, autoload=True, schema=schema) + Table('table1', metadata, autoload=True, schema=schema) + Table('table2', metadata, autoload=True, schema=schema) assert len(metadata.tables) == 2 finally: metadata.drop_all() @@ -1209,10 +1209,10 @@ class SchemaTest(fixtures.TestBase): assert bool(schema) metadata = MetaData(engine, schema=schema) - table1 = Table('table1', metadata, + Table('table1', metadata, Column('col1', sa.Integer, primary_key=True), test_needs_fk=True) - table2 = Table('table2', metadata, + Table('table2', metadata, Column('col1', sa.Integer, primary_key=True), Column('col2', sa.Integer, sa.ForeignKey('table1.col1')), @@ -1223,8 +1223,8 @@ class SchemaTest(fixtures.TestBase): assert len(metadata.tables) == 2 metadata.clear() - table1 = Table('table1', metadata, autoload=True) - table2 = Table('table2', metadata, autoload=True) + Table('table1', metadata, autoload=True) + Table('table2', metadata, autoload=True) assert len(metadata.tables) == 2 finally: metadata.drop_all() @@ -1261,7 +1261,7 @@ def createTables(meta, schema=None): Column('test1', sa.CHAR(5), nullable=False), Column('test2', sa.Float(5), nullable=False), Column('test3', sa.Text), - Column('test4', sa.Numeric(10, 2), nullable = False), + Column('test4', sa.Numeric(10, 2), nullable=False), Column('test5', sa.Date), Column('test5_1', sa.TIMESTAMP), Column('parent_user_id', sa.Integer, @@ -1276,13 +1276,12 @@ def createTables(meta, schema=None): test_needs_fk=True, ) dingalings = Table("dingalings", meta, - Column('dingaling_id', sa.Integer, primary_key=True), - Column('address_id', sa.Integer, - sa.ForeignKey('%semail_addresses.address_id' % schema_prefix)), - Column('data', sa.String(30)), - schema=schema, - test_needs_fk=True, - ) + Column('dingaling_id', sa.Integer, primary_key=True), + Column('address_id', sa.Integer, + sa.ForeignKey('%semail_addresses.address_id' % schema_prefix)), + Column('data', sa.String(30)), + schema=schema, test_needs_fk=True, + ) addresses = Table('email_addresses', meta, Column('address_id', sa.Integer), Column('remote_user_id', sa.Integer, @@ -1437,7 +1436,7 @@ class ColumnEventsTest(fixtures.TestBase): def test_override_key(self): self._do_test( - "x", {"key":"YXZ"}, + "x", {"key": "YXZ"}, lambda table: eq_(table.c.YXZ.name, "x") ) @@ -1445,12 +1444,12 @@ class ColumnEventsTest(fixtures.TestBase): def assert_(table): assert isinstance(table.c.x.type, sa.String) self._do_test( - "x", {"type":sa.String}, + "x", {"type": sa.String}, assert_ ) def test_override_info(self): self._do_test( - "x", {"info":{"a":"b"}}, - lambda table: eq_(table.c.x.info, {"a":"b"}) + "x", {"info": {"a": "b"}}, + lambda table: eq_(table.c.x.info, {"a": "b"}) ) -- cgit v1.2.1 From 021b5143e65368bb36889dda03e5a4853621ce29 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 4 May 2013 15:57:03 -0400 Subject: that's all of engine --- lib/sqlalchemy/engine/reflection.py | 8 ++++++-- lib/sqlalchemy/util/compat.py | 6 ++++++ test/engine/test_parseconnect.py | 7 +++---- test/engine/test_reflection.py | 14 ++++++++------ 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/lib/sqlalchemy/engine/reflection.py b/lib/sqlalchemy/engine/reflection.py index cf4a1d532..4b2987851 100644 --- a/lib/sqlalchemy/engine/reflection.py +++ b/lib/sqlalchemy/engine/reflection.py @@ -41,8 +41,12 @@ def cache(fn, self, con, *args, **kw): return fn(self, con, *args, **kw) key = ( fn.__name__, - tuple(a for a in args if isinstance(a, str)), - tuple((k, v) for k, v in kw.items() if isinstance(v, (str, int, float))) + tuple(a for a in args if isinstance(a, util.string_types)), + tuple((k, v) for k, v in kw.items() if + isinstance(v, + util.string_types + util.int_types + (float, ) + ) + ) ) ret = info_cache.get(key) if ret is None: diff --git a/lib/sqlalchemy/util/compat.py b/lib/sqlalchemy/util/compat.py index 94b35f019..06bcd30dd 100644 --- a/lib/sqlalchemy/util/compat.py +++ b/lib/sqlalchemy/util/compat.py @@ -37,6 +37,9 @@ if py3k: from inspect import getfullargspec as inspect_getfullargspec from urllib.parse import quote_plus, unquote_plus, parse_qsl + import configparser + from io import StringIO + string_types = str, binary_type = bytes text_type = str @@ -74,6 +77,9 @@ else: from inspect import getargspec as inspect_getfullargspec from urllib import quote_plus, unquote_plus from urlparse import parse_qsl + import ConfigParser as configparser + from StringIO import StringIO + string_types = basestring, binary_type = str text_type = unicode diff --git a/test/engine/test_parseconnect.py b/test/engine/test_parseconnect.py index 3d99fd509..73bdc76c4 100644 --- a/test/engine/test_parseconnect.py +++ b/test/engine/test_parseconnect.py @@ -1,6 +1,5 @@ -from sqlalchemy.testing import assert_raises, assert_raises_message, eq_ -import configparser -import io +from sqlalchemy.testing import assert_raises, eq_ +from sqlalchemy.util.compat import configparser, StringIO import sqlalchemy.engine.url as url from sqlalchemy import create_engine, engine_from_config, exc, pool from sqlalchemy.engine.util import _coerce_config @@ -104,7 +103,7 @@ pool_threadlocal=1 pool_timeout=10 """ ini = configparser.ConfigParser() - ini.readfp(io.StringIO(raw)) + ini.readfp(StringIO(raw)) expected = { 'url': 'postgresql://scott:tiger@somehost/test?fooz=somevalue', diff --git a/test/engine/test_reflection.py b/test/engine/test_reflection.py index d8256f2b0..a562ef73b 100644 --- a/test/engine/test_reflection.py +++ b/test/engine/test_reflection.py @@ -7,6 +7,8 @@ from sqlalchemy.testing import ComparesTables, \ from sqlalchemy.testing.schema import Table, Column from sqlalchemy.testing import eq_, assert_raises, assert_raises_message from sqlalchemy import testing +from sqlalchemy.util import ue + metadata, users = None, None @@ -1042,16 +1044,16 @@ class UnicodeReflectionTest(fixtures.TestBase): ('plain', 'col_plain', 'ix_plain') ]) no_has_table = [ - ('no_has_table_1', 'col_Unit\u00e9ble', 'ix_Unit\u00e9ble'), - ('no_has_table_2', 'col_\u6e2c\u8a66', 'ix_\u6e2c\u8a66'), + ('no_has_table_1', ue('col_Unit\u00e9ble'), ue('ix_Unit\u00e9ble')), + ('no_has_table_2', ue('col_\u6e2c\u8a66'), ue('ix_\u6e2c\u8a66')), ] no_case_sensitivity = [ - ('\u6e2c\u8a66', 'col_\u6e2c\u8a66', 'ix_\u6e2c\u8a66'), - ('unit\u00e9ble', 'col_unit\u00e9ble', 'ix_unit\u00e9ble'), + (ue('\u6e2c\u8a66'), ue('col_\u6e2c\u8a66'), ue('ix_\u6e2c\u8a66')), + (ue('unit\u00e9ble'), ue('col_unit\u00e9ble'), ue('ix_unit\u00e9ble')), ] full = [ - ('Unit\u00e9ble', 'col_Unit\u00e9ble', 'ix_Unit\u00e9ble'), - ('\u6e2c\u8a66', 'col_\u6e2c\u8a66', 'ix_\u6e2c\u8a66'), + (ue('Unit\u00e9ble'), ue('col_Unit\u00e9ble'), ue('ix_Unit\u00e9ble')), + (ue('\u6e2c\u8a66'), ue('col_\u6e2c\u8a66'), ue('ix_\u6e2c\u8a66')), ] # as you can see, our options for this kind of thing -- cgit v1.2.1 From 8be6831f8be70d7946fd8e3e41b18781a1743ea7 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 4 May 2013 16:00:05 -0400 Subject: base --- lib/sqlalchemy/util/_collections.py | 6 +++--- test/base/test_utils.py | 14 ++++++-------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/sqlalchemy/util/_collections.py b/lib/sqlalchemy/util/_collections.py index e505bdd5f..fddedf4f7 100644 --- a/lib/sqlalchemy/util/_collections.py +++ b/lib/sqlalchemy/util/_collections.py @@ -9,7 +9,7 @@ import itertools import weakref import operator -from .compat import threading +from .compat import threading, itertools_filterfalse EMPTY_SET = frozenset() @@ -470,7 +470,7 @@ class IdentitySet(object): if len(self) > len(other): return False - for m in itertools.filterfalse(other._members.__contains__, + for m in itertools_filterfalse(other._members.__contains__, iter(self._members.keys())): return False return True @@ -491,7 +491,7 @@ class IdentitySet(object): if len(self) < len(other): return False - for m in itertools.filterfalse(self._members.__contains__, + for m in itertools_filterfalse(self._members.__contains__, iter(other._members.keys())): return False return True diff --git a/test/base/test_utils.py b/test/base/test_utils.py index 6dcfaf9d1..b9f94c603 100644 --- a/test/base/test_utils.py +++ b/test/base/test_utils.py @@ -843,14 +843,12 @@ class IdentitySetTest(fixtures.TestBase): return super_, sub_, twin1, twin2, unique1, unique2 def _assert_unorderable_types(self, callable_): -# start Py3K - assert_raises_message( - TypeError, 'unorderable types', callable_) -# end Py3K -# start Py2K -# assert_raises_message( -# TypeError, 'cannot compare sets using cmp()', callable_) -# end Py2K + if util.py3k: + assert_raises_message( + TypeError, 'unorderable types', callable_) + else: + assert_raises_message( + TypeError, 'cannot compare sets using cmp()', callable_) def test_basic_sanity(self): IdentitySet = util.IdentitySet -- cgit v1.2.1 From 220fa91337aced11789b23065289203414f2063d Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 4 May 2013 16:23:27 -0400 Subject: most of ORM passing... --- lib/sqlalchemy/event.py | 3 ++ lib/sqlalchemy/ext/associationproxy.py | 2 ++ lib/sqlalchemy/orm/attributes.py | 5 +-- lib/sqlalchemy/orm/collections.py | 57 +++++++++++++++------------------- lib/sqlalchemy/orm/instrumentation.py | 2 ++ lib/sqlalchemy/orm/query.py | 7 +---- lib/sqlalchemy/orm/util.py | 1 + lib/sqlalchemy/sql/expression.py | 1 + lib/sqlalchemy/util/compat.py | 7 +++-- lib/sqlalchemy/util/langhelpers.py | 7 +---- test/orm/inheritance/test_concrete.py | 4 +-- test/orm/test_assorted_eager.py | 8 ++--- test/orm/test_eager_relations.py | 2 +- test/orm/test_generative.py | 24 +++----------- test/orm/test_naturalpks.py | 2 +- 15 files changed, 56 insertions(+), 76 deletions(-) diff --git a/lib/sqlalchemy/event.py b/lib/sqlalchemy/event.py index 79d024f9b..33626cf2a 100644 --- a/lib/sqlalchemy/event.py +++ b/lib/sqlalchemy/event.py @@ -378,6 +378,8 @@ class _EmptyListener(object): def __bool__(self): return bool(self.parent_listeners) + __nonzero__ = __bool__ + class _CompoundListener(object): _exec_once = False @@ -415,6 +417,7 @@ class _CompoundListener(object): def __bool__(self): return bool(self.listeners or self.parent_listeners) + __nonzero__ = __bool__ class _ListenerCollection(_CompoundListener): """Instance-level attributes on instances of :class:`._Dispatch`. diff --git a/lib/sqlalchemy/ext/associationproxy.py b/lib/sqlalchemy/ext/associationproxy.py index ad09db831..e0a867e5a 100644 --- a/lib/sqlalchemy/ext/associationproxy.py +++ b/lib/sqlalchemy/ext/associationproxy.py @@ -478,6 +478,8 @@ class _AssociationCollection(object): def __bool__(self): return bool(self.col) + __nonzero__ = __bool__ + def __getstate__(self): return {'parent': self.parent, 'lazy_collection': self.lazy_collection} diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index 691904bb3..057247047 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -386,8 +386,8 @@ def create_proxied_attribute(descriptor): return getattr(self.comparator, attribute) except AttributeError: raise AttributeError( - 'Neither %r object nor %r object associated with %s ' - 'has an attribute %r' % ( + 'Neither %r object nor %r object associated with %s ' + 'has an attribute %r' % ( type(descriptor).__name__, type(self.comparator).__name__, self, @@ -1216,6 +1216,7 @@ class History(History): def __bool__(self): return self != HISTORY_BLANK + __nonzero__ = __bool__ def empty(self): """Return True if this :class:`.History` has no changes diff --git a/lib/sqlalchemy/orm/collections.py b/lib/sqlalchemy/orm/collections.py index c2a2c23f0..bb7882ee9 100644 --- a/lib/sqlalchemy/orm/collections.py +++ b/lib/sqlalchemy/orm/collections.py @@ -657,12 +657,10 @@ class CollectionAdapter(object): if getattr(obj, '_sa_adapter', None) is not None: return getattr(obj, '_sa_adapter') elif setting_type == dict: -# start Py3K - return list(obj.values()) -# end Py3K -# start Py2K -# return getattr(obj, 'itervalues', getattr(obj, 'values'))() -# end Py2K + if util.py3k: + return obj.values() + else: + return getattr(obj, 'itervalues', getattr(obj, 'values'))() else: return iter(obj) @@ -706,8 +704,6 @@ class CollectionAdapter(object): def __iter__(self): """Iterate over entities in the collection.""" -# start Py3K -# end Py3K return iter(getattr(self._data(), '_sa_iterator')()) def __len__(self): @@ -717,6 +713,8 @@ class CollectionAdapter(object): def __bool__(self): return True + __nonzero__ = __bool__ + def fire_append_event(self, item, initiator=None): """Notify that a entity has entered the collection. @@ -1130,24 +1128,23 @@ def _list_decorators(): _tidy(__delitem__) return __delitem__ -# start Py2K -# def __setslice__(fn): -# def __setslice__(self, start, end, values): -# for value in self[start:end]: -# __del(self, value) -# values = [__set(self, value) for value in values] -# fn(self, start, end, values) -# _tidy(__setslice__) -# return __setslice__ -# -# def __delslice__(fn): -# def __delslice__(self, start, end): -# for value in self[start:end]: -# __del(self, value) -# fn(self, start, end) -# _tidy(__delslice__) -# return __delslice__ -# end Py2K + if util.py2k: + def __setslice__(fn): + def __setslice__(self, start, end, values): + for value in self[start:end]: + __del(self, value) + values = [__set(self, value) for value in values] + fn(self, start, end, values) + _tidy(__setslice__) + return __setslice__ + + def __delslice__(fn): + def __delslice__(self, start, end): + for value in self[start:end]: + __del(self, value) + fn(self, start, end) + _tidy(__delslice__) + return __delslice__ def extend(fn): def extend(self, iterable): @@ -1465,12 +1462,8 @@ __interfaces = { ), # decorators are required for dicts and object collections. -# start Py3K - dict: ({'iterator': 'values'}, _dict_decorators()), -# end Py3K -# start Py2K -# dict: ({'iterator': 'itervalues'}, _dict_decorators()), -# end Py2K + dict: ({'iterator': 'values'}, _dict_decorators()) if util.py3k + else ({'iterator': 'itervalues'}, _dict_decorators()), } diff --git a/lib/sqlalchemy/orm/instrumentation.py b/lib/sqlalchemy/orm/instrumentation.py index ce12acf20..f2d0df43f 100644 --- a/lib/sqlalchemy/orm/instrumentation.py +++ b/lib/sqlalchemy/orm/instrumentation.py @@ -329,6 +329,8 @@ class ClassManager(dict): """All ClassManagers are non-zero regardless of attribute state.""" return True + __nonzero__ = __bool__ + def __repr__(self): return '<%s of %r at %x>' % ( self.__class__.__name__, self.class_, id(self)) diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 80441b976..09f0bedd1 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -981,12 +981,7 @@ class Query(object): """Return a scalar result corresponding to the given column expression.""" try: -# start Py3K - return self.values(column).__next__()[0] -# end Py3K -# start Py2K -# return self.values(column).next()[0] -# end Py2K + return next(self.values(column))[0] except StopIteration: return None diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index 30a8a8084..2a3124f4d 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -413,6 +413,7 @@ class EntityRegistry(PathRegistry, dict): def __bool__(self): return True + __nonzero__ = __bool__ def __getitem__(self, entity): if isinstance(entity, (int, slice)): diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 2c7b91fe6..f0bcd400a 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -3769,6 +3769,7 @@ class BinaryExpression(ColumnElement): return self.operator(hash(self._orig[0]), hash(self._orig[1])) else: raise TypeError("Boolean value of this clause is not defined") + __nonzero__ = __bool__ @property diff --git a/lib/sqlalchemy/util/compat.py b/lib/sqlalchemy/util/compat.py index 06bcd30dd..e8404c2df 100644 --- a/lib/sqlalchemy/util/compat.py +++ b/lib/sqlalchemy/util/compat.py @@ -184,8 +184,11 @@ else: if py3k: exec_ = getattr(builtins, 'exec') else: - def exec_(func_text, globals_, lcl): - exec('exec func_text in globals_, lcl') + def exec_(func_text, globals_, lcl=None): + if lcl is None: + exec('exec func_text in globals_') + else: + exec('exec func_text in globals_, lcl') def with_metaclass(meta, *bases): diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py index 8a6af3758..4cb745c2b 100644 --- a/lib/sqlalchemy/util/langhelpers.py +++ b/lib/sqlalchemy/util/langhelpers.py @@ -499,7 +499,7 @@ def monkeypatch_proxied_specials(into_cls, from_cls, skip=None, only=None, "return %(name)s.%(method)s%(d_args)s" % locals()) env = from_instance is not None and {name: from_instance} or {} - compat.exec_(py, env, {}) + compat.exec_(py, env) try: env[method].__defaults__ = fn.__defaults__ except AttributeError: @@ -510,12 +510,7 @@ def monkeypatch_proxied_specials(into_cls, from_cls, skip=None, only=None, def methods_equivalent(meth1, meth2): """Return True if the two methods are the same implementation.""" -# start Py3K return getattr(meth1, '__func__', meth1) is getattr(meth2, '__func__', meth2) -# end Py3K -# start Py2K -# return getattr(meth1, 'im_func', meth1) is getattr(meth2, 'im_func', meth2) -# end Py2K def as_interface(obj, cls=None, methods=None, required=None): diff --git a/test/orm/inheritance/test_concrete.py b/test/orm/inheritance/test_concrete.py index 5d6b82a15..573913f74 100644 --- a/test/orm/inheritance/test_concrete.py +++ b/test/orm/inheritance/test_concrete.py @@ -711,12 +711,12 @@ class ColKeysTest(fixtures.MappedTest): refugees_table = Table('refugee', metadata, Column('refugee_fid' , Integer, primary_key=True, test_needs_autoincrement=True), - Column('refugee_name', Unicode(30), + Column('refugee_name', String(30), key='name')) offices_table = Table('office', metadata, Column('office_fid', Integer, primary_key=True, test_needs_autoincrement=True), - Column('office_name', Unicode(30), + Column('office_name', String(30), key='name')) @classmethod diff --git a/test/orm/test_assorted_eager.py b/test/orm/test_assorted_eager.py index e650a1bea..83fccbf7a 100644 --- a/test/orm/test_assorted_eager.py +++ b/test/orm/test_assorted_eager.py @@ -723,13 +723,13 @@ class EagerTest8(fixtures.MappedTest): Table('prj', metadata, Column('id', Integer, primary_key=True, test_needs_autoincrement=True), Column('created', sa.DateTime ), - Column('title', sa.Unicode(100))) + Column('title', sa.String(100))) Table('task', metadata, Column('id', Integer, primary_key=True, test_needs_autoincrement=True), Column('status_id', Integer, ForeignKey('task_status.id'), nullable=False), - Column('title', sa.Unicode(100)), + Column('title', sa.String(100)), Column('task_type_id', Integer , ForeignKey('task_type.id'), nullable=False), Column('prj_id', Integer , ForeignKey('prj.id'), nullable=False)) @@ -748,8 +748,8 @@ class EagerTest8(fixtures.MappedTest): Table('msg_type', metadata, Column('id', Integer, primary_key=True, test_needs_autoincrement=True), - Column('name', sa.Unicode(20)), - Column('display_name', sa.Unicode(20))) + Column('name', sa.String(20)), + Column('display_name', sa.String(20))) @classmethod def fixtures(cls): diff --git a/test/orm/test_eager_relations.py b/test/orm/test_eager_relations.py index 20ee693f3..41dd50e83 100644 --- a/test/orm/test_eager_relations.py +++ b/test/orm/test_eager_relations.py @@ -2107,7 +2107,7 @@ class SelfReferentialM2MEagerTest(fixtures.MappedTest): def define_tables(cls, metadata): Table('widget', metadata, Column('id', Integer, primary_key=True, test_needs_autoincrement=True), - Column('name', sa.Unicode(40), nullable=False, unique=True), + Column('name', sa.String(40), nullable=False, unique=True), ) Table('widget_rel', metadata, diff --git a/test/orm/test_generative.py b/test/orm/test_generative.py index 84e60d8ea..52858cc26 100644 --- a/test/orm/test_generative.py +++ b/test/orm/test_generative.py @@ -78,14 +78,8 @@ class GenerativeQueryTest(fixtures.MappedTest): assert sess.query(func.min(foo.c.bar)).filter(foo.c.bar<30).one() == (0,) assert sess.query(func.max(foo.c.bar)).filter(foo.c.bar<30).one() == (29,) -# start Py3K - assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).__next__()[0] == 29 - assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).__next__()[0] == 29 -# end Py3K -# start Py2K -# assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).next()[0] == 29 -# assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).next()[0] == 29 -# end Py2K + assert next(query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)))[0] == 29 + assert next(query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)))[0] == 29 @testing.fails_if(lambda:testing.against('mysql+mysqldb') and testing.db.dialect.dbapi.version_info[:4] == (1, 2, 1, 'gamma'), @@ -112,20 +106,10 @@ class GenerativeQueryTest(fixtures.MappedTest): query = create_session().query(Foo) -# start Py3K - avg_f = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).__next__()[0] -# end Py3K -# start Py2K -# avg_f = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).next()[0] -# end Py2K + avg_f = next(query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)))[0] assert float(round(avg_f, 1)) == 14.5 -# start Py3K - avg_o = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).__next__()[0] -# end Py3K -# start Py2K -# avg_o = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).next()[0] -# end Py2K + avg_o = next(query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)))[0] assert float(round(avg_o, 1)) == 14.5 def test_filter(self): diff --git a/test/orm/test_naturalpks.py b/test/orm/test_naturalpks.py index 7a636a5a9..173408b82 100644 --- a/test/orm/test_naturalpks.py +++ b/test/orm/test_naturalpks.py @@ -499,7 +499,7 @@ class ReversePKsTest(fixtures.MappedTest): 'user', metadata, Column('code', Integer, primary_key=True), Column('status', Integer, primary_key=True), - Column('username', Unicode(50), nullable=False), + Column('username', String(50), nullable=False), ) @classmethod -- cgit v1.2.1 From 4afe25855653709059623c47c8670ea04743da22 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 4 May 2013 16:25:35 -0400 Subject: cleanup --- test/orm/test_instrumentation.py | 96 ++++++++++++++++++++++++++-------------- 1 file changed, 62 insertions(+), 34 deletions(-) diff --git a/test/orm/test_instrumentation.py b/test/orm/test_instrumentation.py index a18f53737..56ad4908b 100644 --- a/test/orm/test_instrumentation.py +++ b/test/orm/test_instrumentation.py @@ -41,7 +41,8 @@ class InitTest(fixtures.ORMTest): def test_A(self): inits = [] - class A(object): pass + class A(object): + pass self.register(A, inits) obj = A() @@ -65,7 +66,8 @@ class InitTest(fixtures.ORMTest): def __init__(self): inits.append((A, '__init__')) - class B(A): pass + class B(A): + pass self.register(B, inits) obj = A() @@ -148,7 +150,8 @@ class InitTest(fixtures.ORMTest): inits.append((A, '__init__')) self.register(A, inits) - class B(A): pass + class B(A): + pass self.register(B, inits) obj = A() @@ -232,7 +235,8 @@ class InitTest(fixtures.ORMTest): inits.append((A, '__init__')) self.register(A, inits) - class B(A): pass + class B(A): + pass class C(B): def __init__(self): @@ -260,7 +264,8 @@ class InitTest(fixtures.ORMTest): inits.append((A, '__init__')) self.register(A, inits) - class B(A): pass + class B(A): + pass self.register(B, inits) class C(B): @@ -289,10 +294,12 @@ class InitTest(fixtures.ORMTest): inits.append((A, '__init__')) self.register(A, inits) - class B(A): pass + class B(A): + pass self.register(B, inits) - class C(B): pass + class C(B): + pass self.register(C, inits) obj = A() @@ -310,7 +317,8 @@ class InitTest(fixtures.ORMTest): def test_A_Bi_C(self): inits = [] - class A(object): pass + class A(object): + pass self.register(A, inits) class B(A): @@ -318,7 +326,8 @@ class InitTest(fixtures.ORMTest): inits.append((B, '__init__')) self.register(B, inits) - class C(B): pass + class C(B): + pass self.register(C, inits) obj = A() @@ -336,10 +345,12 @@ class InitTest(fixtures.ORMTest): def test_A_B_Ci(self): inits = [] - class A(object): pass + class A(object): + pass self.register(A, inits) - class B(A): pass + class B(A): + pass self.register(B, inits) class C(B): @@ -362,13 +373,16 @@ class InitTest(fixtures.ORMTest): def test_A_B_C(self): inits = [] - class A(object): pass + class A(object): + pass self.register(A, inits) - class B(A): pass + class B(A): + pass self.register(B, inits) - class C(B): pass + class C(B): + pass self.register(C, inits) obj = A() @@ -470,7 +484,8 @@ class OnLoadTest(fixtures.ORMTest): class A(object): pass - def canary(instance): assert False + def canary(instance): + assert False try: instrumentation.register_class(A) @@ -486,7 +501,8 @@ class OnLoadTest(fixtures.ORMTest): class NativeInstrumentationTest(fixtures.ORMTest): def test_register_reserved_attribute(self): - class T(object): pass + class T(object): + pass instrumentation.register_class(T) manager = instrumentation.manager_of_class(T) @@ -507,7 +523,8 @@ class NativeInstrumentationTest(fixtures.ORMTest): Column('id', Integer, primary_key=True), Column(instrumentation.ClassManager.STATE_ATTR, Integer)) - class T(object): pass + class T(object): + pass assert_raises(KeyError, mapper, T, t) @@ -516,7 +533,8 @@ class NativeInstrumentationTest(fixtures.ORMTest): Column('id', Integer, primary_key=True), Column(instrumentation.ClassManager.MANAGER_ATTR, Integer)) - class T(object): pass + class T(object): + pass assert_raises(KeyError, mapper, T, t) class Py3KFunctionInstTest(fixtures.ORMTest): @@ -530,7 +548,7 @@ class Py3KFunctionInstTest(fixtures.ORMTest): self.b = b self.c = c return self._instrument(A) - + def _kw_plus_posn_fixture(self): class A(object): def __init__(self, a, *args, b, c): @@ -538,7 +556,7 @@ class Py3KFunctionInstTest(fixtures.ORMTest): self.b = b self.c = c return self._instrument(A) - + def _kw_opt_fixture(self): class A(object): def __init__(self, a, *, b, c="c"): @@ -560,23 +578,23 @@ class Py3KFunctionInstTest(fixtures.ORMTest): cls, canary = self._kw_only_fixture() a = cls("a", b="b", c="c") - eq_(canary, [(('a', ), {'b':'b','c':'c'})]) + eq_(canary, [(('a', ), {'b': 'b', 'c': 'c'})]) def test_kw_plus_posn_args(self): cls, canary = self._kw_plus_posn_fixture() a = cls("a", 1, 2, 3, b="b", c="c") - eq_(canary, [(('a', 1, 2, 3), {'b':'b','c':'c'})]) + eq_(canary, [(('a', 1, 2, 3), {'b': 'b', 'c': 'c'})]) def test_kw_only_args_plus_opt(self): cls, canary = self._kw_opt_fixture() a = cls("a", b="b") - eq_(canary, [(('a', ), {'b':'b','c':'c'})]) + eq_(canary, [(('a', ), {'b': 'b', 'c': 'c'})]) canary[:] = [] a = cls("a", b="b", c="d") - eq_(canary, [(('a', ), {'b':'b','c':'d'})]) + eq_(canary, [(('a', ), {'b': 'b', 'c': 'd'})]) def test_kw_only_sig(self): cls, canary = self._kw_only_fixture() @@ -604,7 +622,8 @@ class MiscTest(fixtures.ORMTest): t = Table('t', MetaData(), Column('id', Integer, primary_key=True), Column('x', Integer)) - class A(object): pass + class A(object): + pass mapper(A, t) a = A() @@ -618,8 +637,10 @@ class MiscTest(fixtures.ORMTest): t2 = Table('t2', m, Column('id', Integer, primary_key=True), Column('t1_id', Integer, ForeignKey('t1.id'))) - class A(object): pass - class B(object): pass + class A(object): + pass + class B(object): + pass mapper(A, t1, properties=dict(bs=relationship(B))) mapper(B, t2) @@ -627,7 +648,8 @@ class MiscTest(fixtures.ORMTest): assert not a.bs def test_uninstrument(self): - class A(object):pass + class A(object): + pass manager = instrumentation.register_class(A) attributes.register_attribute(A, 'x', uselist=False, useobject=False) @@ -655,8 +677,10 @@ class MiscTest(fixtures.ORMTest): pass for base in object, Base: - class A(base): pass - class B(base): pass + class A(base): + pass + class B(base): + pass mapper(A, t1, properties=dict(bs=relationship(B, backref='a'))) mapper(B, t2) @@ -679,13 +703,17 @@ class MiscTest(fixtures.ORMTest): Column('t1_id', Integer, ForeignKey('t1.id'))) class Base(object): - def __init__(self): pass + def __init__(self): + pass class Base_AKW(object): - def __init__(self, *args, **kwargs): pass + def __init__(self, *args, **kwargs): + pass for base in object, Base, Base_AKW: - class A(base): pass - class B(base): pass + class A(base): + pass + class B(base): + pass mapper(A, t1) mapper(B, t2, properties=dict(a=relationship(A, backref='bs'))) -- cgit v1.2.1 From 87ee86514eedad1b3df787f5a3705492d82acbee Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 4 May 2013 16:35:47 -0400 Subject: py3k specific syntax moved into an exec --- test/orm/test_instrumentation.py | 55 ++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/test/orm/test_instrumentation.py b/test/orm/test_instrumentation.py index 56ad4908b..c3d24ebe7 100644 --- a/test/orm/test_instrumentation.py +++ b/test/orm/test_instrumentation.py @@ -540,31 +540,6 @@ class NativeInstrumentationTest(fixtures.ORMTest): class Py3KFunctionInstTest(fixtures.ORMTest): __requires__ = ("python3", ) -# start Py3K - def _kw_only_fixture(self): - class A(object): - def __init__(self, a, *, b, c): - self.a = a - self.b = b - self.c = c - return self._instrument(A) - - def _kw_plus_posn_fixture(self): - class A(object): - def __init__(self, a, *args, b, c): - self.a = a - self.b = b - self.c = c - return self._instrument(A) - - def _kw_opt_fixture(self): - class A(object): - def __init__(self, a, *, b, c="c"): - self.a = a - self.b = b - self.c = c - return self._instrument(A) -# end Py3K def _instrument(self, cls): manager = instrumentation.register_class(cls) @@ -615,6 +590,36 @@ class Py3KFunctionInstTest(fixtures.ORMTest): cls, "a", "b", c="c" ) +if util.py3k: + _locals = {} + exec(""" +def _kw_only_fixture(self): + class A(object): + def __init__(self, a, *, b, c): + self.a = a + self.b = b + self.c = c + return self._instrument(A) + +def _kw_plus_posn_fixture(self): + class A(object): + def __init__(self, a, *args, b, c): + self.a = a + self.b = b + self.c = c + return self._instrument(A) + +def _kw_opt_fixture(self): + class A(object): + def __init__(self, a, *, b, c="c"): + self.a = a + self.b = b + self.c = c + return self._instrument(A) +""", _locals) + for k in _locals: + setattr(Py3KFunctionInstTest, k, _locals[k]) + class MiscTest(fixtures.ORMTest): """Seems basic, but not directly covered elsewhere!""" -- cgit v1.2.1 From cee8418899259e141f0059c86a32844c49f37118 Mon Sep 17 00:00:00 2001 From: diana Date: Sun, 26 May 2013 10:19:26 -0400 Subject: - fixing AbstractConcreteBase import in docstring, 0.9 branch, [ticket:2717] --- lib/sqlalchemy/ext/declarative/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sqlalchemy/ext/declarative/api.py b/lib/sqlalchemy/ext/declarative/api.py index 21fac8534..bc0c5a38c 100644 --- a/lib/sqlalchemy/ext/declarative/api.py +++ b/lib/sqlalchemy/ext/declarative/api.py @@ -308,7 +308,7 @@ class AbstractConcreteBase(ConcreteBase): Example:: - from sqlalchemy.ext.declarative import ConcreteBase + from sqlalchemy.ext.declarative import AbstractConcreteBase class Employee(AbstractConcreteBase, Base): pass -- cgit v1.2.1 From 956c144c7feae68fa957eb62ede4b21cd818c737 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 May 2013 13:08:24 -0400 Subject: fix serializer tests. something is wrong with non-C pickle but for some reason py3k's pickle seems to be OK? not sure why that is, as this is all related to http://bugs.python.org/issue998998 --- lib/sqlalchemy/ext/serializer.py | 21 ++------------------- lib/sqlalchemy/util/__init__.py | 2 +- lib/sqlalchemy/util/compat.py | 17 ++++++++++++++++- test/ext/test_serializer.py | 9 ++++----- test/requirements.py | 9 +++++++++ 5 files changed, 32 insertions(+), 26 deletions(-) diff --git a/lib/sqlalchemy/ext/serializer.py b/lib/sqlalchemy/ext/serializer.py index 759652014..8abd1fdf3 100644 --- a/lib/sqlalchemy/ext/serializer.py +++ b/lib/sqlalchemy/ext/serializer.py @@ -58,26 +58,9 @@ from ..orm.interfaces import MapperProperty from ..orm.attributes import QueryableAttribute from .. import Table, Column from ..engine import Engine -from ..util import pickle +from ..util import pickle, byte_buffer, b64encode, b64decode import re -import base64 -# start Py3K -from io import BytesIO as byte_buffer -# end Py3K -# start Py2K -#from cStringIO import StringIO as byte_buffer -# end Py2K - -# start Py3K -def b64encode(x): - return base64.b64encode(x).decode('ascii') -def b64decode(x): - return base64.b64decode(x.encode('ascii')) -# end Py3K -# start Py2K -#b64encode = base64.b64encode -#b64decode = base64.b64decode -# end Py2K + __all__ = ['Serializer', 'Deserializer', 'dumps', 'loads'] diff --git a/lib/sqlalchemy/util/__init__.py b/lib/sqlalchemy/util/__init__.py index b1f1a2db6..d1fc8e8e5 100644 --- a/lib/sqlalchemy/util/__init__.py +++ b/lib/sqlalchemy/util/__init__.py @@ -9,7 +9,7 @@ from .compat import callable, cmp, reduce, \ pickle, dottedgetter, parse_qsl, namedtuple, next, WeakSet, reraise, \ raise_from_cause, text_type, string_types, int_types, binary_type, \ quote_plus, with_metaclass, print_, itertools_filterfalse, u, ue, b,\ - unquote_plus + unquote_plus, b64decode, b64encode, byte_buffer from ._collections import KeyedTuple, ImmutableContainer, immutabledict, \ Properties, OrderedProperties, ImmutableProperties, OrderedDict, \ diff --git a/lib/sqlalchemy/util/compat.py b/lib/sqlalchemy/util/compat.py index e8404c2df..ea97999cf 100644 --- a/lib/sqlalchemy/util/compat.py +++ b/lib/sqlalchemy/util/compat.py @@ -28,7 +28,7 @@ if py3k: import pickle else: try: - import pickle as pickle + import cPickle as pickle except ImportError: import pickle @@ -40,6 +40,9 @@ if py3k: import configparser from io import StringIO + from io import BytesIO as byte_buffer + + string_types = str, binary_type = bytes text_type = str @@ -73,12 +76,20 @@ if py3k: import itertools itertools_filterfalse = itertools.filterfalse itertools_imap = map + + import base64 + def b64encode(x): + return base64.b64encode(x).decode('ascii') + def b64decode(x): + return base64.b64decode(x.encode('ascii')) + else: from inspect import getargspec as inspect_getfullargspec from urllib import quote_plus, unquote_plus from urlparse import parse_qsl import ConfigParser as configparser from StringIO import StringIO + from cStringIO import StringIO as byte_buffer string_types = basestring, binary_type = str @@ -109,6 +120,10 @@ else: cmp = cmp reduce = reduce + import base64 + b64encode = base64.b64encode + b64decode = base64.b64decode + def print_(*args, **kwargs): fp = kwargs.pop("file", sys.stdout) if fp is None: diff --git a/test/ext/test_serializer.py b/test/ext/test_serializer.py index 0c7298a8b..84fff1304 100644 --- a/test/ext/test_serializer.py +++ b/test/ext/test_serializer.py @@ -114,7 +114,7 @@ class SerializeTest(fixtures.MappedTest): Address(email='ed@lala.com'), Address(email='ed@bettyboop.com')]) - @testing.skip_if(lambda: util.pypy, "problems with pypy pickle reported") + @testing.requires.non_broken_pickle def test_query_two(self): q = \ Session.query(User).join(User.addresses).\ @@ -124,7 +124,7 @@ class SerializeTest(fixtures.MappedTest): eq_(q2.all(), [User(name='fred')]) eq_(list(q2.values(User.id, User.name)), [(9, 'fred')]) - @testing.skip_if(lambda: util.pypy, "problems with pypy pickle reported") + @testing.requires.non_broken_pickle def test_query_three(self): ua = aliased(User) q = \ @@ -138,7 +138,7 @@ class SerializeTest(fixtures.MappedTest): ua_2 = q2._entities[0].entity_zero.entity eq_(list(q2.values(ua_2.id, ua_2.name)), [(9, 'fred')]) - @testing.skip_if(lambda: util.pypy, "problems with pypy pickle reported") + @testing.requires.non_broken_pickle def test_orm_join(self): from sqlalchemy.orm.util import join @@ -165,8 +165,7 @@ class SerializeTest(fixtures.MappedTest): eq_(list(q2.all()), [(u7, u8), (u7, u9), (u7, u10), (u8, u9), (u8, u10)]) - @testing.skip_if(lambda: util.pypy, "pickle sometimes has " - "problems here, sometimes not") + @testing.requires.non_broken_pickle def test_any(self): r = User.addresses.any(Address.email == 'x') ser = serializer.dumps(r, -1) diff --git a/test/requirements.py b/test/requirements.py index c20bcbd0a..c09c0df99 100644 --- a/test/requirements.py +++ b/test/requirements.py @@ -556,6 +556,15 @@ class DefaultRequirements(SuiteRequirements): "cPython interpreter needed" ) + + @property + def non_broken_pickle(self): + from sqlalchemy.util import pickle + return only_if( + lambda: pickle.__name__ == 'cPickle' or sys.version_info >= (3, 2), + "Needs cPickle or newer Python 3 pickle" + ) + @property def predictable_gc(self): """target platform must remove all cycles unconditionally when -- cgit v1.2.1 From 00f2b19a5589436ddd5b1ad908ed1b59e0b97825 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 May 2013 13:09:05 -0400 Subject: extension tests --- lib/sqlalchemy/ext/orderinglist.py | 16 +++++++--------- test/ext/declarative/test_basic.py | 6 +++--- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/sqlalchemy/ext/orderinglist.py b/lib/sqlalchemy/ext/orderinglist.py index 930464d7b..24d405e39 100644 --- a/lib/sqlalchemy/ext/orderinglist.py +++ b/lib/sqlalchemy/ext/orderinglist.py @@ -334,15 +334,13 @@ class OrderingList(list): super(OrderingList, self).__delitem__(index) self._reorder() -# start Py2K -# def __setslice__(self, start, end, values): -# super(OrderingList, self).__setslice__(start, end, values) -# self._reorder() -# -# def __delslice__(self, start, end): -# super(OrderingList, self).__delslice__(start, end) -# self._reorder() -# end Py2K + def __setslice__(self, start, end, values): + super(OrderingList, self).__setslice__(start, end, values) + self._reorder() + + def __delslice__(self, start, end): + super(OrderingList, self).__delslice__(start, end) + self._reorder() def __reduce__(self): return _reconstitute, (self.__class__, self.__dict__, list(self)) diff --git a/test/ext/declarative/test_basic.py b/test/ext/declarative/test_basic.py index 50d40e8fc..ad2970b70 100644 --- a/test/ext/declarative/test_basic.py +++ b/test/ext/declarative/test_basic.py @@ -13,7 +13,7 @@ from sqlalchemy.orm import relationship, create_session, class_mapper, \ deferred, column_property, composite,\ Session from sqlalchemy.testing import eq_ -from sqlalchemy.util import classproperty +from sqlalchemy.util import classproperty, with_metaclass from sqlalchemy.ext.declarative import declared_attr, AbstractConcreteBase, \ ConcreteBase, synonym_for from sqlalchemy.testing import fixtures @@ -133,7 +133,7 @@ class DeclarativeTest(DeclarativeTestBase): # even though this class has an xyzzy attribute, getattr(cls,"xyzzy") # fails - class BrokenParent(object, metaclass=BrokenMeta): + class BrokenParent(with_metaclass(BrokenMeta)): xyzzy = "magic" # _as_declarative() inspects obj.__class__.__bases__ @@ -274,7 +274,7 @@ class DeclarativeTest(DeclarativeTestBase): __tablename__ = 'foo' id = Column(Integer, primary_key=True) - _user_id = Column(Integer) + _user_id = Column(Integer) rel = relationship('User', uselist=False, foreign_keys=[User.id], -- cgit v1.2.1 From 3d75ff22d3e53b7f6b5965d680157b9453fc8154 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 May 2013 13:09:38 -0400 Subject: repair py3kisms in key ORM modules --- lib/sqlalchemy/orm/mapper.py | 12 ++++++------ lib/sqlalchemy/orm/query.py | 22 +++++++++++----------- lib/sqlalchemy/orm/util.py | 10 +++++----- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 645bf86e7..285d338de 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -582,7 +582,7 @@ class Mapper(_InspectionAttr): if with_polymorphic == '*': self.with_polymorphic = ('*', None) elif isinstance(with_polymorphic, (tuple, list)): - if isinstance(with_polymorphic[0], (str, tuple, list)): + if isinstance(with_polymorphic[0], util.string_types + (tuple, list)): self.with_polymorphic = with_polymorphic else: self.with_polymorphic = (with_polymorphic, None) @@ -920,7 +920,7 @@ class Mapper(_InspectionAttr): if self.polymorphic_on is not None: setter = True - if isinstance(self.polymorphic_on, str): + if isinstance(self.polymorphic_on, util.string_types): # polymorphic_on specified as as string - link # it to mapped ColumnProperty try: @@ -1973,7 +1973,7 @@ class Mapper(_InspectionAttr): visited_states = set() prp, mpp = object(), object() - visitables = deque([(deque(list(self._props.values())), prp, + visitables = deque([(deque(self._props.values()), prp, state, state.dict)]) while visitables: @@ -1995,7 +1995,7 @@ class Mapper(_InspectionAttr): corresponding_dict = iterator.popleft() yield instance, instance_mapper, \ corresponding_state, corresponding_dict - visitables.append((deque(list(instance_mapper._props.values())), + visitables.append((deque(instance_mapper._props.values()), prp, corresponding_state, corresponding_dict)) @@ -2012,7 +2012,7 @@ class Mapper(_InspectionAttr): table_to_mapper.setdefault(t, mapper) extra_dependencies = [] - for table, mapper in list(table_to_mapper.items()): + for table, mapper in table_to_mapper.items(): super_ = mapper.inherits if super_: extra_dependencies.extend([ @@ -2041,7 +2041,7 @@ class Mapper(_InspectionAttr): return fk.parent not in cols return False - sorted_ = sql_util.sort_tables(iter(table_to_mapper.keys()), + sorted_ = sql_util.sort_tables(table_to_mapper, skip_fn=skip, extra_dependencies=extra_dependencies) diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 09f0bedd1..cb788e0a4 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -1292,7 +1292,7 @@ class Query(object): """ - if isinstance(criterion, str): + if isinstance(criterion, util.string_types): criterion = sql.text(criterion) if criterion is not None and \ @@ -1651,7 +1651,7 @@ class Query(object): kwargs.pop('from_joinpoint', False) if kwargs: raise TypeError("unknown arguments: %s" % - ','.join(iter(kwargs.keys()))) + ','.join(kwargs.keys)) return self._join(props, outerjoin=False, create_aliases=aliased, from_joinpoint=from_joinpoint) @@ -1667,7 +1667,7 @@ class Query(object): kwargs.pop('from_joinpoint', False) if kwargs: raise TypeError("unknown arguments: %s" % - ','.join(iter(kwargs.keys()))) + ','.join(kwargs)) return self._join(props, outerjoin=True, create_aliases=aliased, from_joinpoint=from_joinpoint) @@ -1717,14 +1717,14 @@ class Query(object): # is a little bit of legacy behavior still at work here # which means they might be in either order. may possibly # lock this down to (right_entity, onclause) in 0.6. - if isinstance(arg1, (interfaces.PropComparator, str)): + if isinstance(arg1, (interfaces.PropComparator, util.string_types)): right_entity, onclause = arg2, arg1 else: right_entity, onclause = arg1, arg2 left_entity = prop = None - if isinstance(onclause, str): + if isinstance(onclause, util.string_types): left_entity = self._joinpoint_zero() descriptor = _entity_descriptor(left_entity, onclause) @@ -2111,7 +2111,7 @@ class Query(object): appropriate to the entity class represented by this ``Query``. """ - if isinstance(statement, str): + if isinstance(statement, util.string_types): statement = sql.text(statement) if not isinstance(statement, @@ -2605,7 +2605,7 @@ class Query(object): use_labels=context.labels) from_clause = inner - for eager_join in list(context.eager_joins.values()): + for eager_join in context.eager_joins.values(): # EagerLoader places a 'stop_on' attribute on the join, # giving us a marker as to where the "splice point" of # the join should be @@ -2670,7 +2670,7 @@ class Query(object): subtypes are selected from the total results. """ - for (ext_info, adapter) in list(self._mapper_adapter_map.values()): + for (ext_info, adapter) in self._mapper_adapter_map.values(): if ext_info in self._join_entities: continue single_crit = ext_info.mapper._single_table_criterion @@ -2693,7 +2693,7 @@ class _QueryEntity(object): def __new__(cls, *args, **kwargs): if cls is _QueryEntity: entity = args[1] - if not isinstance(entity, str) and \ + if not isinstance(entity, util.string_types) and \ _is_mapped_class(entity): cls = _MapperEntity else: @@ -2901,7 +2901,7 @@ class _ColumnEntity(_QueryEntity): self.expr = column self.namespace = namespace - if isinstance(column, str): + if isinstance(column, util.string_types): column = sql.literal_column(column) self._label_name = column.name elif isinstance(column, ( @@ -3076,7 +3076,7 @@ class AliasOption(interfaces.MapperOption): self.alias = alias def process_query(self, query): - if isinstance(self.alias, str): + if isinstance(self.alias, util.string_types): alias = query._mapper_zero().mapped_table.alias(self.alias) else: alias = self.alias diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index 8a26bd834..ddc0dd818 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -120,7 +120,7 @@ def polymorphic_union(table_map, typecolname, colnames = util.OrderedSet() colnamemaps = {} types = {} - for key in list(table_map.keys()): + for key in table_map: table = table_map[key] # mysql doesnt like selecting from a select; @@ -203,7 +203,7 @@ def identity_key(*args, **kwargs): "positional arguments, got %s" % len(args)) if kwargs: raise sa_exc.ArgumentError("unknown keyword arguments: %s" - % ", ".join(list(kwargs.keys()))) + % ", ".join(kwargs)) mapper = class_mapper(class_) if "ident" in locals(): return mapper.identity_key_from_primary_key(util.to_list(ident)) @@ -211,7 +211,7 @@ def identity_key(*args, **kwargs): instance = kwargs.pop("instance") if kwargs: raise sa_exc.ArgumentError("unknown keyword arguments: %s" - % ", ".join(list(kwargs.keys()))) + % ", ".join(kwargs.keys)) mapper = object_mapper(instance) return mapper.identity_key_from_instance(instance) @@ -888,7 +888,7 @@ class _ORMJoin(expression.Join): self._joined_from_info = right_info - if isinstance(onclause, str): + if isinstance(onclause, util.string_types): onclause = getattr(left_orm_info.entity, onclause) if isinstance(onclause, attributes.QueryableAttribute): @@ -1009,7 +1009,7 @@ def with_parent(instance, prop): parent/child relationship. """ - if isinstance(prop, str): + if isinstance(prop, util.string_types): mapper = object_mapper(instance) prop = getattr(mapper.class_, prop).property elif isinstance(prop, attributes.QueryableAttribute): -- cgit v1.2.1 From 62c7e0dbe64a3de27ad7631a11c813f929397c5e Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 May 2013 13:10:00 -0400 Subject: sqlite tests --- lib/sqlalchemy/dialects/sqlite/pysqlite.py | 2 -- lib/sqlalchemy/sql/util.py | 4 ++-- test/dialect/test_sqlite.py | 10 +++++----- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/sqlalchemy/dialects/sqlite/pysqlite.py b/lib/sqlalchemy/dialects/sqlite/pysqlite.py index 4a86d38d2..32ee1299f 100644 --- a/lib/sqlalchemy/dialects/sqlite/pysqlite.py +++ b/lib/sqlalchemy/dialects/sqlite/pysqlite.py @@ -267,9 +267,7 @@ class SQLiteDialect_pysqlite(SQLiteDialect): } ) -# start Py3K description_encoding = None -# end Py3K driver = 'pysqlite' diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index 12edab3e1..91740dc16 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -232,7 +232,7 @@ def bind_values(clause): def _quote_ddl_expr(element): - if isinstance(element, str): + if isinstance(element, util.string_types): element = element.replace("'", "''") return "'%s'" % element else: @@ -765,7 +765,7 @@ class AliasedRow(object): return self.row[self.map[key]] def keys(self): - return list(self.row.keys()) + return self.row.keys() class ClauseAdapter(visitors.ReplacingCloningVisitor): diff --git a/test/dialect/test_sqlite.py b/test/dialect/test_sqlite.py index 440fe1f43..5410a64cb 100644 --- a/test/dialect/test_sqlite.py +++ b/test/dialect/test_sqlite.py @@ -4,7 +4,7 @@ from sqlalchemy.testing import eq_, assert_raises, \ assert_raises_message import datetime from sqlalchemy import * -from sqlalchemy import exc, sql, schema, pool, types as sqltypes +from sqlalchemy import exc, sql, schema, pool, types as sqltypes, util from sqlalchemy.dialects.sqlite import base as sqlite, \ pysqlite as pysqlite_dialect from sqlalchemy.engine.url import make_url @@ -84,7 +84,7 @@ class TestTypes(fixtures.TestBase, AssertsExecutionResults): eq_(row, (1, datetime.date(2010, 5, 10), datetime.datetime( 2010, 5, 10, 12, 15, 25, ))) r = engine.execute(func.current_date()).scalar() - assert isinstance(r, str) + assert isinstance(r, util.string_types) finally: t.drop(engine) engine.dispose() @@ -104,8 +104,8 @@ class TestTypes(fixtures.TestBase, AssertsExecutionResults): UnicodeText(), ): bindproc = t.dialect_impl(dialect).bind_processor(dialect) - assert not bindproc or isinstance(bindproc('some string'), - str) + assert not bindproc or \ + isinstance(bindproc(util.u('some string')), util.text_type) @testing.provide_metadata def test_type_reflection(self): @@ -602,7 +602,7 @@ class SQLTest(fixtures.TestBase, AssertsCompiledSQL): 'dow': '%w', 'week': '%W', } - for field, subst in list(mapping.items()): + for field, subst in mapping.items(): self.assert_compile(select([extract(field, t.c.col1)]), "SELECT CAST(STRFTIME('%s', t.col1) AS " "INTEGER) AS anon_1 FROM t" % subst) -- cgit v1.2.1 From f939abe83034840b6c304df5ea4dfda5e9dc4633 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 May 2013 16:32:55 -0400 Subject: mysql tests --- lib/sqlalchemy/dialects/mysql/base.py | 6 +----- test/dialect/test_mysql.py | 27 ++++++++++++++------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index 0cc89149e..ad4650f6d 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -1139,14 +1139,10 @@ class SET(_StringType): # No ',' quoting issues- commas aren't allowed in SET values # The bad news: # Plenty of driver inconsistencies here. - if isinstance(value, util.set_types): + if isinstance(value, set): # ..some versions convert '' to an empty set if not value: value.add('') - # ..some return sets.Set, even for pythons - # that have __builtin__.set - if not isinstance(value, set): - value = set(value) return value # ...and some versions return strings if value is not None: diff --git a/test/dialect/test_mysql.py b/test/dialect/test_mysql.py index df4eab86a..728098d3a 100644 --- a/test/dialect/test_mysql.py +++ b/test/dialect/test_mysql.py @@ -5,6 +5,7 @@ from sqlalchemy.testing import eq_, assert_raises, assert_raises_message from sqlalchemy import * from sqlalchemy import sql, exc, schema, types as sqltypes +from sqlalchemy.util import u from sqlalchemy.dialects.mysql import base as mysql from sqlalchemy.engine.url import make_url from sqlalchemy.testing import fixtures, AssertsCompiledSQL, AssertsExecutionResults @@ -684,17 +685,17 @@ class EnumTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL): metadata = MetaData(unicode_engine) t1 = Table('table', metadata, Column('id', Integer, primary_key=True), - Column('value', Enum('réveillé', 'drôle', 'S’il')), - Column('value2', mysql.ENUM('réveillé', 'drôle', 'S’il')) + Column('value', Enum(u('réveillé'), u('drôle'), u('S’il'))), + Column('value2', mysql.ENUM(u('réveillé'), u('drôle'), u('S’il'))) ) metadata.create_all() try: - t1.insert().execute(value='drôle', value2='drôle') - t1.insert().execute(value='réveillé', value2='réveillé') - t1.insert().execute(value='S’il', value2='S’il') + t1.insert().execute(value=u('drôle'), value2=u('drôle')) + t1.insert().execute(value=u('réveillé'), value2=u('réveillé')) + t1.insert().execute(value=u('S’il'), value2=u('S’il')) eq_(t1.select().order_by(t1.c.id).execute().fetchall(), - [(1, 'drôle', 'drôle'), (2, 'réveillé', 'réveillé'), - (3, 'S’il', 'S’il')] + [(1, u('drôle'), u('drôle')), (2, u('réveillé'), u('réveillé')), + (3, u('S’il'), u('S’il'))] ) # test reflection of the enum labels @@ -706,10 +707,10 @@ class EnumTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL): # latin-1 stuff forcing its way in ? assert t2.c.value.type.enums[0:2] == \ - ('réveillé', 'drôle') # u'S’il') # eh ? + (u('réveillé'), u('drôle')) # u'S’il') # eh ? assert t2.c.value2.type.enums[0:2] == \ - ('réveillé', 'drôle') # u'S’il') # eh ? + (u('réveillé'), u('drôle')) # u'S’il') # eh ? finally: metadata.drop_all() @@ -877,13 +878,13 @@ class ReflectionTest(fixtures.TestBase, AssertsExecutionResults): reflected = Table('mysql_case', MetaData(testing.db), autoload=True, include_columns=['c1', 'C2']) for t in case_table, reflected: - assert 'c1' in list(t.c.keys()) - assert 'C2' in list(t.c.keys()) + assert 'c1' in t.c.keys() + assert 'C2' in t.c.keys() reflected2 = Table('mysql_case', MetaData(testing.db), autoload=True, include_columns=['c1', 'c2']) - assert 'c1' in list(reflected2.c.keys()) + assert 'c1' in reflected2.c.keys() for c in ['c2', 'C2', 'C3']: - assert c not in list(reflected2.c.keys()) + assert c not in reflected2.c.keys() finally: case_table.drop() -- cgit v1.2.1 From b3654ee37abe7af3d83098cd8de1980369a3fcba Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 May 2013 16:39:50 -0400 Subject: postgresql tests --- lib/sqlalchemy/dialects/postgresql/base.py | 36 +++++++++++++--------------- lib/sqlalchemy/dialects/postgresql/hstore.py | 4 +++- test/dialect/test_postgresql.py | 12 +++++----- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index cd5d9772d..00d0acc2c 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -1569,14 +1569,13 @@ class PGDialect(default.DefaultDialect): """ rp = connection.execute(s) # what about system tables? -# start Py3K - schema_names = [row[0] for row in rp \ + + if util.py2k: + schema_names = [row[0].decode(self.encoding) for row in rp \ + if not row[0].startswith('pg_')] + else: + schema_names = [row[0] for row in rp \ if not row[0].startswith('pg_')] -# end Py3K -# start Py2K -# schema_names = [row[0].decode(self.encoding) for row in rp \ -# if not row[0].startswith('pg_')] -# end Py2K return schema_names @reflection.cache @@ -1610,13 +1609,12 @@ class PGDialect(default.DefaultDialect): AND '%(schema)s' = (select nspname from pg_namespace n where n.oid = c.relnamespace) """ % dict(schema=current_schema) -# start Py3K - view_names = [row[0] for row in connection.execute(s)] -# end Py3K -# start Py2K -# view_names = [row[0].decode(self.encoding) -# for row in connection.execute(s)] -# end Py2K + + if util.py2k: + view_names = [row[0].decode(self.encoding) + for row in connection.execute(s)] + else: + view_names = [row[0] for row in connection.execute(s)] return view_names @reflection.cache @@ -1633,12 +1631,10 @@ class PGDialect(default.DefaultDialect): rp = connection.execute(sql.text(s), view_name=view_name, schema=current_schema) if rp: -# start Py3K - view_def = rp.scalar() -# end Py3K -# start Py2K -# view_def = rp.scalar().decode(self.encoding) -# end Py2K + if util.py2k: + view_def = rp.scalar().decode(self.encoding) + else: + view_def = rp.scalar() return view_def @reflection.cache diff --git a/lib/sqlalchemy/dialects/postgresql/hstore.py b/lib/sqlalchemy/dialects/postgresql/hstore.py index d7fd34d05..adfb82da7 100644 --- a/lib/sqlalchemy/dialects/postgresql/hstore.py +++ b/lib/sqlalchemy/dialects/postgresql/hstore.py @@ -10,6 +10,8 @@ from .base import ARRAY, ischema_names from ... import types as sqltypes from ...sql import functions as sqlfunc from ...sql.operators import custom_op +from ... import util + __all__ = ('HSTORE', 'hstore') @@ -96,7 +98,7 @@ def _serialize_hstore(val): def esc(s, position): if position == 'value' and s is None: return 'NULL' - elif isinstance(s, str): + elif isinstance(s, util.string_types): return '"%s"' % s.replace('"', r'\"') else: raise ValueError("%r in %s position is not a string." % diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py index 8568f6add..286628d5e 100644 --- a/test/dialect/test_postgresql.py +++ b/test/dialect/test_postgresql.py @@ -1478,7 +1478,7 @@ class ReflectionTest(fixtures.TestBase): meta1.create_all() meta2 = MetaData(testing.db) subject = Table('subject', meta2, autoload=True) - eq_(list(subject.primary_key.columns.keys()), ['p2', 'p1']) + eq_(subject.primary_key.columns.keys(), ['p2', 'p1']) @testing.provide_metadata def test_pg_weirdchar_reflection(self): @@ -2205,15 +2205,15 @@ class ArrayTest(fixtures.TablesTest, AssertsExecutionResults): def test_array_subtype_resultprocessor(self): arrtable = self.tables.arrtable arrtable.insert().execute(intarr=[4, 5, 6], - strarr=[[util.u('m\xe4\xe4')], [ - util.u('m\xf6\xf6')]]) + strarr=[[util.ue('m\xe4\xe4')], [ + util.ue('m\xf6\xf6')]]) arrtable.insert().execute(intarr=[1, 2, 3], strarr=[ - util.u('m\xe4\xe4'), util.u('m\xf6\xf6')]) + util.ue('m\xe4\xe4'), util.ue('m\xf6\xf6')]) results = \ arrtable.select(order_by=[arrtable.c.intarr]).execute().fetchall() eq_(len(results), 2) - eq_(results[0]['strarr'], [util.u('m\xe4\xe4'), util.u('m\xf6\xf6')]) - eq_(results[1]['strarr'], [[util.u('m\xe4\xe4')], [util.u('m\xf6\xf6')]]) + eq_(results[0]['strarr'], [util.ue('m\xe4\xe4'), util.ue('m\xf6\xf6')]) + eq_(results[1]['strarr'], [[util.ue('m\xe4\xe4')], [util.ue('m\xf6\xf6')]]) def test_array_literal(self): eq_( -- cgit v1.2.1 From 4e930a7f780f0997e8f7f9ef4efe5c57ad86efd0 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 May 2013 16:58:37 -0400 Subject: - add a test specific to sqlite testing cursor.description encoding (should probably be one in test_query or test_unicode...) - fix up test_unitofwork --- lib/sqlalchemy/dialects/sqlite/pysqlite.py | 3 ++- lib/sqlalchemy/engine/result.py | 2 ++ test/dialect/test_sqlite.py | 23 ++++++++++++++++++++++- test/orm/test_unitofwork.py | 26 ++++++++++---------------- 4 files changed, 36 insertions(+), 18 deletions(-) diff --git a/lib/sqlalchemy/dialects/sqlite/pysqlite.py b/lib/sqlalchemy/dialects/sqlite/pysqlite.py index 32ee1299f..ad0dd5292 100644 --- a/lib/sqlalchemy/dialects/sqlite/pysqlite.py +++ b/lib/sqlalchemy/dialects/sqlite/pysqlite.py @@ -267,7 +267,8 @@ class SQLiteDialect_pysqlite(SQLiteDialect): } ) - description_encoding = None + if not util.py2k: + description_encoding = None driver = 'pysqlite' diff --git a/lib/sqlalchemy/engine/result.py b/lib/sqlalchemy/engine/result.py index 65ce3b742..4261a5877 100644 --- a/lib/sqlalchemy/engine/result.py +++ b/lib/sqlalchemy/engine/result.py @@ -215,6 +215,8 @@ class ResultMetaData(object): processors.append(processor) rec = (processor, obj, i) +# name.encode('ascii') + # indexes as keys. This is only needed for the Python version of # RowProxy (the C version uses a faster path for integer indexes). primary_keymap[i] = rec diff --git a/test/dialect/test_sqlite.py b/test/dialect/test_sqlite.py index 5410a64cb..4ede13ff6 100644 --- a/test/dialect/test_sqlite.py +++ b/test/dialect/test_sqlite.py @@ -1,9 +1,16 @@ +#!coding: utf-8 + """SQLite-specific tests.""" from sqlalchemy.testing import eq_, assert_raises, \ assert_raises_message import datetime -from sqlalchemy import * +from sqlalchemy import Table, String, select, Text, CHAR, bindparam, Column,\ + Unicode, Date, MetaData, UnicodeText, Time, Integer, TIMESTAMP, \ + Boolean, func, NUMERIC, DateTime, extract, ForeignKey, text, Numeric,\ + DefaultClause, and_, DECIMAL, TypeDecorator, create_engine, Float, \ + INTEGER, UniqueConstraint, DATETIME, DATE, TIME, BOOLEAN +from sqlalchemy.util import u, ue from sqlalchemy import exc, sql, schema, pool, types as sqltypes, util from sqlalchemy.dialects.sqlite import base as sqlite, \ pysqlite as pysqlite_dialect @@ -485,6 +492,20 @@ class DialectTest(fixtures.TestBase, AssertsExecutionResults): 'constrained_columns': ['tid'] }]) + @testing.provide_metadata + def test_description_encoding(self): + # amazingly, pysqlite seems to still deliver cursor.description + # as encoded bytes in py2k + + t = Table('x', self.metadata, + Column(u('méil'), Integer, primary_key=True), + Column(ue('\u6e2c\u8a66'), Integer), + ) + self.metadata.create_all(testing.db) + + result = testing.db.execute(t.select()) + assert u('méil') in result.keys() + assert ue('\u6e2c\u8a66') in result.keys() def test_attached_as_schema(self): cx = testing.db.connect() diff --git a/test/orm/test_unitofwork.py b/test/orm/test_unitofwork.py index 1675ed60f..4b9799d47 100644 --- a/test/orm/test_unitofwork.py +++ b/test/orm/test_unitofwork.py @@ -6,6 +6,7 @@ import datetime from sqlalchemy.orm import mapper as orm_mapper import sqlalchemy as sa +from sqlalchemy.util import u, ue, b from sqlalchemy import Integer, String, ForeignKey, literal_column, event from sqlalchemy.testing import engines from sqlalchemy import testing @@ -87,7 +88,7 @@ class UnicodeTest(fixtures.MappedTest): mapper(Test, uni_t1) - txt = "\u0160\u0110\u0106\u010c\u017d" + txt = ue("\u0160\u0110\u0106\u010c\u017d") t1 = Test(id=1, txt=txt) self.assert_(t1.txt == txt) @@ -107,7 +108,7 @@ class UnicodeTest(fixtures.MappedTest): 't2s': relationship(Test2)}) mapper(Test2, uni_t2) - txt = "\u0160\u0110\u0106\u010c\u017d" + txt = ue("\u0160\u0110\u0106\u010c\u017d") t1 = Test(txt=txt) t1.t2s.append(Test2()) t1.t2s.append(Test2()) @@ -132,16 +133,16 @@ class UnicodeSchemaTest(fixtures.MappedTest): @classmethod def define_tables(cls, metadata): t1 = Table('unitable1', metadata, - Column('méil', Integer, primary_key=True, key='a', test_needs_autoincrement=True), - Column('\u6e2c\u8a66', Integer, key='b'), + Column(u('méil'), Integer, primary_key=True, key='a', test_needs_autoincrement=True), + Column(ue('\u6e2c\u8a66'), Integer, key='b'), Column('type', String(20)), test_needs_fk=True, test_needs_autoincrement=True) - t2 = Table('Unitéble2', metadata, - Column('méil', Integer, primary_key=True, key="cc", test_needs_autoincrement=True), - Column('\u6e2c\u8a66', Integer, + t2 = Table(u('Unitéble2'), metadata, + Column(u('méil'), Integer, primary_key=True, key="cc", test_needs_autoincrement=True), + Column(ue('\u6e2c\u8a66'), Integer, ForeignKey('unitable1.a'), key="d"), - Column('\u6e2c\u8a66_2', Integer, key="e"), + Column(ue('\u6e2c\u8a66_2'), Integer, key="e"), test_needs_fk=True, test_needs_autoincrement=True) @@ -237,13 +238,7 @@ class BinaryHistTest(fixtures.MappedTest, testing.AssertsExecutionResults): def test_binary_equality(self): Foo, t1 = self.classes.Foo, self.tables.t1 - -# start Py3K - data = b"this is some data" -# end Py3K -# start Py2K -# data = "this is some data" -# end Py2K + data = b("this is some data") mapper(Foo, t1) @@ -2128,7 +2123,6 @@ class SaveTest3(fixtures.MappedTest): assert assoc.count().scalar() == 2 i.keywords = [] - print(i.keywords) session.flush() assert assoc.count().scalar() == 0 -- cgit v1.2.1 From 46b0b14fde37ed1cacb7b33fe35d2a276a775f81 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 May 2013 17:37:03 -0400 Subject: cleanup for oracle --- lib/sqlalchemy/dialects/oracle/base.py | 22 +++---- lib/sqlalchemy/dialects/oracle/cx_oracle.py | 95 ++++++++++++++--------------- test/dialect/test_oracle.py | 21 ++++--- 3 files changed, 68 insertions(+), 70 deletions(-) diff --git a/lib/sqlalchemy/dialects/oracle/base.py b/lib/sqlalchemy/dialects/oracle/base.py index a45793367..4863b7ba1 100644 --- a/lib/sqlalchemy/dialects/oracle/base.py +++ b/lib/sqlalchemy/dialects/oracle/base.py @@ -437,7 +437,7 @@ class OracleCompiler(compiler.SQLCompiler): def get_select_hint_text(self, byfroms): return " ".join( - "/*+ %s */" % text for table, text in list(byfroms.items()) + "/*+ %s */" % text for table, text in byfroms.items() ) def function_argspec(self, fn, **kw): @@ -661,7 +661,7 @@ class OracleIdentifierPreparer(compiler.IdentifierPreparer): lc_value = value.lower() return (lc_value in self.reserved_words or value[0] in self.illegal_initial_characters - or not self.legal_characters.match(str(value)) + or not self.legal_characters.match(util.text_type(value)) ) def format_savepoint(self, savepoint): @@ -765,10 +765,9 @@ class OracleDialect(default.DefaultDialect): def normalize_name(self, name): if name is None: return None -# start Py2K -# if isinstance(name, str): -# name = name.decode(self.encoding) -# end Py2K + if util.py2k: + if isinstance(name, str): + name = name.decode(self.encoding) if name.upper() == name and \ not self.identifier_preparer._requires_quotes(name.lower()): return name.lower() @@ -780,12 +779,11 @@ class OracleDialect(default.DefaultDialect): return None elif name.lower() == name and not self.identifier_preparer._requires_quotes(name.lower()): name = name.upper() -# start Py2K -# if not self.supports_unicode_binds: -# name = name.encode(self.encoding) -# else: -# name = unicode(name) -# end Py2K + if util.py2k: + if not self.supports_unicode_binds: + name = name.encode(self.encoding) + else: + name = unicode(name) return name def _get_default_schema_name(self, connection): diff --git a/lib/sqlalchemy/dialects/oracle/cx_oracle.py b/lib/sqlalchemy/dialects/oracle/cx_oracle.py index 10ec20dee..99a514776 100644 --- a/lib/sqlalchemy/dialects/oracle/cx_oracle.py +++ b/lib/sqlalchemy/dialects/oracle/cx_oracle.py @@ -268,21 +268,17 @@ class _LOBMixin(object): class _NativeUnicodeMixin(object): -# start Py3K - pass -# end Py3K -# start Py2K -# def bind_processor(self, dialect): -# if dialect._cx_oracle_with_unicode: -# def process(value): -# if value is None: -# return value -# else: -# return unicode(value) -# return process -# else: -# return super(_NativeUnicodeMixin, self).bind_processor(dialect) -# end Py2K + if util.py2k: + def bind_processor(self, dialect): + if dialect._cx_oracle_with_unicode: + def process(value): + if value is None: + return value + else: + return unicode(value) + return process + else: + return super(_NativeUnicodeMixin, self).bind_processor(dialect) # we apply a connection output handler that returns # unicode in all cases, so the "native_unicode" flag @@ -392,10 +388,10 @@ class OracleExecutionContext_cx_oracle(OracleExecutionContext): (fromname.encode(self.dialect.encoding), toname.encode(self.dialect.encoding)) for fromname, toname in - list(quoted_bind_names.items()) + quoted_bind_names.items() ) for param in self.parameters: - for fromname, toname in list(quoted_bind_names.items()): + for fromname, toname in quoted_bind_names.items(): param[toname] = param[fromname] del param[fromname] @@ -409,7 +405,7 @@ class OracleExecutionContext_cx_oracle(OracleExecutionContext): # if a single execute, check for outparams if len(self.compiled_parameters) == 1: - for bindparam in list(self.compiled.binds.values()): + for bindparam in self.compiled.binds.values(): if bindparam.isoutparam: dbtype = bindparam.type.dialect_impl(self.dialect).\ get_dbapi_type(self.dialect.dbapi) @@ -438,7 +434,7 @@ class OracleExecutionContext_cx_oracle(OracleExecutionContext): if hasattr(self, 'out_parameters') and self.compiled.returning: returning_params = dict( (k, v.getvalue()) - for k, v in list(self.out_parameters.items()) + for k, v in self.out_parameters.items() ) return ReturningResultProxy(self, returning_params) @@ -457,7 +453,7 @@ class OracleExecutionContext_cx_oracle(OracleExecutionContext): len(self.compiled_parameters) == 1: result.out_parameters = out_parameters = {} - for bind, name in list(self.compiled.bind_names.items()): + for bind, name in self.compiled.bind_names.items(): if name in self.out_parameters: type = bind.type impl_type = type.dialect_impl(self.dialect) @@ -473,7 +469,7 @@ class OracleExecutionContext_cx_oracle(OracleExecutionContext): else: result.out_parameters = dict( (k, v.getvalue()) - for k, v in list(self.out_parameters.items()) + for k, v in self.out_parameters.items() ) return result @@ -494,11 +490,11 @@ class OracleExecutionContext_cx_oracle_with_unicode(OracleExecutionContext_cx_or """ def __init__(self, *arg, **kw): OracleExecutionContext_cx_oracle.__init__(self, *arg, **kw) - self.statement = str(self.statement) + self.statement = util.text_type(self.statement) def _execute_scalar(self, stmt): return super(OracleExecutionContext_cx_oracle_with_unicode, self).\ - _execute_scalar(str(stmt)) + _execute_scalar(util.text_type(stmt)) class ReturningResultProxy(_result.FullyBufferedResultProxy): @@ -608,19 +604,23 @@ class OracleDialect_cx_oracle(OracleDialect): self.supports_unicode_statements = True self.supports_unicode_binds = True self._cx_oracle_with_unicode = True -# start Py2K -# # There's really no reason to run with WITH_UNICODE under Python 2.x. -# # Give the user a hint. -# util.warn("cx_Oracle is compiled under Python 2.xx using the " -# "WITH_UNICODE flag. Consider recompiling cx_Oracle without " -# "this flag, which is in no way necessary for full support of Unicode. " -# "Otherwise, all string-holding bind parameters must " -# "be explicitly typed using SQLAlchemy's String type or one of its subtypes," -# "or otherwise be passed as Python unicode. Plain Python strings " -# "passed as bind parameters will be silently corrupted by cx_Oracle." -# ) -# self.execution_ctx_cls = OracleExecutionContext_cx_oracle_with_unicode -# end Py2K + + if util.py2k: + # There's really no reason to run with WITH_UNICODE under Python 2.x. + # Give the user a hint. + util.warn( + "cx_Oracle is compiled under Python 2.xx using the " + "WITH_UNICODE flag. Consider recompiling cx_Oracle " + "without this flag, which is in no way necessary for full " + "support of Unicode. Otherwise, all string-holding bind " + "parameters must be explicitly typed using SQLAlchemy's " + "String type or one of its subtypes," + "or otherwise be passed as Python unicode. " + "Plain Python strings passed as bind parameters will be " + "silently corrupted by cx_Oracle." + ) + self.execution_ctx_cls = \ + OracleExecutionContext_cx_oracle_with_unicode else: self._cx_oracle_with_unicode = False @@ -732,7 +732,7 @@ class OracleDialect_cx_oracle(OracleDialect): arraysize=cursor.arraysize) # allow all strings to come back natively as Unicode elif defaultType in (cx_Oracle.STRING, cx_Oracle.FIXED_CHAR): - return cursor.var(str, size, cursor.arraysize) + return cursor.var(util.text_type, size, cursor.arraysize) def on_connect(conn): conn.outputtypehandler = output_type_handler @@ -767,20 +767,19 @@ class OracleDialect_cx_oracle(OracleDialect): twophase=self.allow_twophase, ) -# start Py2K -# if self._cx_oracle_with_unicode: -# for k, v in opts.items(): -# if isinstance(v, str): -# opts[k] = unicode(v) -# else: -# for k, v in opts.items(): -# if isinstance(v, unicode): -# opts[k] = str(v) -# end Py2K + if util.py2k: + if self._cx_oracle_with_unicode: + for k, v in opts.items(): + if isinstance(v, str): + opts[k] = unicode(v) + else: + for k, v in opts.items(): + if isinstance(v, unicode): + opts[k] = str(v) if 'mode' in url.query: opts['mode'] = url.query['mode'] - if isinstance(opts['mode'], str): + if isinstance(opts['mode'], util.string_types): mode = opts['mode'].upper() if mode == 'SYSDBA': opts['mode'] = self.dbapi.SYSDBA diff --git a/test/dialect/test_oracle.py b/test/dialect/test_oracle.py index ea5113c29..00bbbcd7c 100644 --- a/test/dialect/test_oracle.py +++ b/test/dialect/test_oracle.py @@ -7,6 +7,7 @@ from sqlalchemy import types as sqltypes, exc, schema from sqlalchemy.sql import table, column from sqlalchemy.testing import fixtures, AssertsExecutionResults, AssertsCompiledSQL from sqlalchemy import testing +from sqlalchemy.util import u from sqlalchemy.testing import assert_raises, assert_raises_message from sqlalchemy.testing.engines import testing_engine from sqlalchemy.dialects.oracle import cx_oracle, base as oracle @@ -1267,7 +1268,7 @@ class TypesTest(fixtures.TestBase): autoload=True, oracle_resolve_synonyms=True ) for row in types_table.select().execute().fetchall(): - [row[k] for k in list(row.keys())] + [row[k] for k in row.keys()] @testing.provide_metadata def test_raw_roundtrip(self): @@ -1301,11 +1302,11 @@ class TypesTest(fixtures.TestBase): t2.c.data.type.dialect_impl(testing.db.dialect), cx_oracle._OracleNVarChar) - data = 'm’a réveillé.' + data = u('m’a réveillé.') t2.insert().execute(data=data) res = t2.select().execute().first()['data'] eq_(res, data) - assert isinstance(res, str) + assert isinstance(res, util.text_type) def test_char_length(self): @@ -1436,7 +1437,7 @@ class DontReflectIOTTest(fixtures.TestBase): m = MetaData(testing.db) m.reflect() eq_( - set(t.name for t in list(m.tables.values())), + set(t.name for t in m.tables.values()), set(['admin_docindex']) ) @@ -1654,25 +1655,25 @@ class UnicodeSchemaTest(fixtures.TestBase): {'_underscorecolumn': '’é'}, ) result = testing.db.execute( - table.select().where(table.c._underscorecolumn=='’é') + table.select().where(table.c._underscorecolumn==u('’é')) ).scalar() - eq_(result, '’é') + eq_(result, u('’é')) @testing.provide_metadata def test_quoted_column_unicode(self): metadata = self.metadata table=Table("atable", metadata, - Column("méil", Unicode(255), primary_key=True), + Column(u("méil"), Unicode(255), primary_key=True), ) metadata.create_all() table.insert().execute( - {'méil': '’é'}, + {u('méil'): u('’é')}, ) result = testing.db.execute( - table.select().where(table.c['méil']=='’é') + table.select().where(table.c[u('méil')] == u('’é')) ).scalar() - eq_(result, '’é') + eq_(result, u('’é')) class DBLinkReflectionTest(fixtures.TestBase): -- cgit v1.2.1 From abc43312938434ca42b83f79ddb9b16a4f67bffa Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 May 2013 17:39:53 -0400 Subject: a few more oracle fixes --- lib/sqlalchemy/dialects/oracle/cx_oracle.py | 22 +++++++++++----------- test/dialect/test_oracle.py | 3 ++- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/sqlalchemy/dialects/oracle/cx_oracle.py b/lib/sqlalchemy/dialects/oracle/cx_oracle.py index 99a514776..5b0c3edd7 100644 --- a/lib/sqlalchemy/dialects/oracle/cx_oracle.py +++ b/lib/sqlalchemy/dialects/oracle/cx_oracle.py @@ -182,7 +182,7 @@ a period "." as the decimal character. """ - +from __future__ import absolute_import from .base import OracleCompiler, OracleDialect, OracleExecutionContext from . import base as oracle @@ -269,16 +269,16 @@ class _LOBMixin(object): class _NativeUnicodeMixin(object): if util.py2k: - def bind_processor(self, dialect): - if dialect._cx_oracle_with_unicode: - def process(value): - if value is None: - return value - else: - return unicode(value) - return process - else: - return super(_NativeUnicodeMixin, self).bind_processor(dialect) + def bind_processor(self, dialect): + if dialect._cx_oracle_with_unicode: + def process(value): + if value is None: + return value + else: + return unicode(value) + return process + else: + return super(_NativeUnicodeMixin, self).bind_processor(dialect) # we apply a connection output handler that returns # unicode in all cases, so the "native_unicode" flag diff --git a/test/dialect/test_oracle.py b/test/dialect/test_oracle.py index 00bbbcd7c..7c17459d6 100644 --- a/test/dialect/test_oracle.py +++ b/test/dialect/test_oracle.py @@ -8,6 +8,7 @@ from sqlalchemy.sql import table, column from sqlalchemy.testing import fixtures, AssertsExecutionResults, AssertsCompiledSQL from sqlalchemy import testing from sqlalchemy.util import u +from sqlalchemy import util from sqlalchemy.testing import assert_raises, assert_raises_message from sqlalchemy.testing.engines import testing_engine from sqlalchemy.dialects.oracle import cx_oracle, base as oracle @@ -1652,7 +1653,7 @@ class UnicodeSchemaTest(fixtures.TestBase): metadata.create_all() table.insert().execute( - {'_underscorecolumn': '’é'}, + {'_underscorecolumn': u('’é')}, ) result = testing.db.execute( table.select().where(table.c._underscorecolumn==u('’é')) -- cgit v1.2.1 From 38f65baf1895a679aacf9981d60af6cd7782df82 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 May 2013 17:58:07 -0400 Subject: - oracle tests passing in py3k!! --- .gitignore | 1 + test/dialect/test_oracle.py | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index e04e53b46..d85b893ee 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ tox.ini .coverage .*,cover *.so +sqlnet.log diff --git a/test/dialect/test_oracle.py b/test/dialect/test_oracle.py index 7c17459d6..d26ca6c03 100644 --- a/test/dialect/test_oracle.py +++ b/test/dialect/test_oracle.py @@ -7,7 +7,7 @@ from sqlalchemy import types as sqltypes, exc, schema from sqlalchemy.sql import table, column from sqlalchemy.testing import fixtures, AssertsExecutionResults, AssertsCompiledSQL from sqlalchemy import testing -from sqlalchemy.util import u +from sqlalchemy.util import u, b from sqlalchemy import util from sqlalchemy.testing import assert_raises, assert_raises_message from sqlalchemy.testing.engines import testing_engine @@ -1279,10 +1279,10 @@ class TypesTest(fixtures.TestBase): Column('data', oracle.RAW(35)) ) metadata.create_all() - testing.db.execute(raw_table.insert(), id=1, data="ABCDEF") + testing.db.execute(raw_table.insert(), id=1, data=b("ABCDEF")) eq_( testing.db.execute(raw_table.select()).first(), - (1, "ABCDEF") + (1, b("ABCDEF")) ) @testing.provide_metadata @@ -1369,10 +1369,10 @@ class TypesTest(fixtures.TestBase): try: engine.execute(t.insert(), id=1, data='this is text', - bindata='this is binary') + bindata=b('this is binary')) row = engine.execute(t.select()).first() eq_(row['data'].read(), 'this is text') - eq_(row['bindata'].read(), 'this is binary') + eq_(row['bindata'].read(), b('this is binary')) finally: t.drop(engine) @@ -1457,7 +1457,8 @@ class BufferedColumnTest(fixtures.TestBase, AssertsCompiledSQL): stream = os.path.join( os.path.dirname(__file__), "..", 'binary_data_one.dat') - stream = file(stream).read(12000) + with open(stream, "rb") as file_: + stream = file_.read(12000) for i in range(1, 11): binary_table.insert().execute(id=i, data=stream) -- cgit v1.2.1 From ebc03d5e63f41b51a5adf24b9c84978d09b74818 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 May 2013 18:08:03 -0400 Subject: remove this --- clean_2to3.diff | 13522 ------------------------------------------------------ 1 file changed, 13522 deletions(-) delete mode 100644 clean_2to3.diff diff --git a/clean_2to3.diff b/clean_2to3.diff deleted file mode 100644 index 7020fb956..000000000 --- a/clean_2to3.diff +++ /dev/null @@ -1,13522 +0,0 @@ -diff -r 9d0639b9d3be examples/adjacency_list/adjacency_list.py ---- a/examples/adjacency_list/adjacency_list.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/adjacency_list/adjacency_list.py Sat Apr 27 19:42:17 2013 -0400 -@@ -47,7 +47,7 @@ - "\n" + \ - "".join([ - c.dump(_indent +1) -- for c in self.children.values()] -+ for c in list(self.children.values())] - ) - - if __name__ == '__main__': -@@ -55,9 +55,9 @@ - - def msg(msg, *args): - msg = msg % args -- print "\n\n\n" + "-" * len(msg.split("\n")[0]) -- print msg -- print "-" * len(msg.split("\n")[0]) -+ print("\n\n\n" + "-" * len(msg.split("\n")[0])) -+ print(msg) -+ print("-" * len(msg.split("\n")[0])) - - msg("Creating Tree Table:") - -diff -r 9d0639b9d3be examples/association/basic_association.py ---- a/examples/association/basic_association.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/association/basic_association.py Sat Apr 27 19:42:17 2013 -0400 -@@ -83,12 +83,12 @@ - - # query the order, print items - order = session.query(Order).filter_by(customer_name='john smith').one() -- print [(order_item.item.description, order_item.price) -- for order_item in order.order_items] -+ print([(order_item.item.description, order_item.price) -+ for order_item in order.order_items]) - - # print customers who bought 'MySQL Crowbar' on sale - q = session.query(Order).join('order_items', 'item') - q = q.filter(and_(Item.description == 'MySQL Crowbar', - Item.price > OrderItem.price)) - -- print [order.customer_name for order in q] -+ print([order.customer_name for order in q]) -diff -r 9d0639b9d3be examples/association/dict_of_sets_with_default.py ---- a/examples/association/dict_of_sets_with_default.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/association/dict_of_sets_with_default.py Sat Apr 27 19:42:17 2013 -0400 -@@ -75,13 +75,13 @@ - session.commit() - - a1 = session.query(A).first() -- print a1.collections["1"] -+ print(a1.collections["1"]) - a1.collections["1"].add(4) - session.commit() - - a1.collections["2"].update([7, 8, 9]) - session.commit() - -- print a1.collections["2"] -+ print(a1.collections["2"]) - - -diff -r 9d0639b9d3be examples/association/proxied_association.py ---- a/examples/association/proxied_association.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/association/proxied_association.py Sat Apr 27 19:42:17 2013 -0400 -@@ -86,16 +86,16 @@ - order = session.query(Order).filter_by(customer_name='john smith').one() - - # print items based on the OrderItem collection directly -- print [(assoc.item.description, assoc.price, assoc.item.price) -- for assoc in order.order_items] -+ print([(assoc.item.description, assoc.price, assoc.item.price) -+ for assoc in order.order_items]) - - # print items based on the "proxied" items collection -- print [(item.description, item.price) -- for item in order.items] -+ print([(item.description, item.price) -+ for item in order.items]) - - # print customers who bought 'MySQL Crowbar' on sale - orders = session.query(Order).\ - join('order_items', 'item').\ - filter(Item.description == 'MySQL Crowbar').\ - filter(Item.price > OrderItem.price) -- print [o.customer_name for o in orders] -+ print([o.customer_name for o in orders]) -diff -r 9d0639b9d3be examples/custom_attributes/listen_for_events.py ---- a/examples/custom_attributes/listen_for_events.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/custom_attributes/listen_for_events.py Sat Apr 27 19:42:17 2013 -0400 -@@ -34,7 +34,7 @@ - if oldvalue: - s += "which replaced the value '%s', " % oldvalue - s += "on object %s" % self -- print s -+ print(s) - - Base = declarative_base(cls=Base) - -diff -r 9d0639b9d3be examples/dogpile_caching/advanced.py ---- a/examples/dogpile_caching/advanced.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/dogpile_caching/advanced.py Sat Apr 27 19:42:17 2013 -0400 -@@ -6,9 +6,9 @@ - - """ - --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 @@ - - 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 -r 9d0639b9d3be examples/dogpile_caching/caching_query.py ---- a/examples/dogpile_caching/caching_query.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/dogpile_caching/caching_query.py Sat Apr 27 19:42:17 2013 -0400 -@@ -143,8 +143,8 @@ - # 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 -r 9d0639b9d3be examples/dogpile_caching/environment.py ---- a/examples/dogpile_caching/environment.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/dogpile_caching/environment.py Sat Apr 27 19:42:17 2013 -0400 -@@ -4,7 +4,7 @@ - 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 @@ - 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 @@ - - 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 -r 9d0639b9d3be examples/dogpile_caching/fixture_data.py ---- a/examples/dogpile_caching/fixture_data.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/dogpile_caching/fixture_data.py Sat Apr 27 19:42:17 2013 -0400 -@@ -5,8 +5,8 @@ - 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 @@ - 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 -r 9d0639b9d3be examples/dogpile_caching/helloworld.py ---- a/examples/dogpile_caching/helloworld.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/dogpile_caching/helloworld.py Sat Apr 27 19:42:17 2013 -0400 -@@ -4,12 +4,12 @@ - - """ - --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 @@ - - # 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 @@ - # 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 @@ - - - # ... 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 @@ - # 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 -r 9d0639b9d3be examples/dogpile_caching/local_session_caching.py ---- a/examples/dogpile_caching/local_session_caching.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/dogpile_caching/local_session_caching.py Sat Apr 27 19:42:17 2013 -0400 -@@ -53,8 +53,8 @@ - - - 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 @@ - } - ) - -- from model import Person -+ from .model import Person - - # query to load Person by name, with criterion - # of "person 10" -diff -r 9d0639b9d3be examples/dogpile_caching/model.py ---- a/examples/dogpile_caching/model.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/dogpile_caching/model.py Sat Apr 27 19:42:17 2013 -0400 -@@ -10,8 +10,8 @@ - """ - 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 -r 9d0639b9d3be examples/dogpile_caching/relation_caching.py ---- a/examples/dogpile_caching/relation_caching.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/dogpile_caching/relation_caching.py Sat Apr 27 19:42:17 2013 -0400 -@@ -5,16 +5,16 @@ - 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 @@ - "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')) -diff -r 9d0639b9d3be examples/dynamic_dict/dynamic_dict.py ---- a/examples/dynamic_dict/dynamic_dict.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/dynamic_dict/dynamic_dict.py Sat Apr 27 19:42:17 2013 -0400 -@@ -1,88 +1,88 @@ --class ProxyDict(object): -- def __init__(self, parent, collection_name, childclass, keyname): -- self.parent = parent -- self.collection_name = collection_name -- self.childclass = childclass -- self.keyname = keyname -- -- @property -- def collection(self): -- return getattr(self.parent, self.collection_name) -- -- def keys(self): -- descriptor = getattr(self.childclass, self.keyname) -- return [x[0] for x in self.collection.values(descriptor)] -- -- def __getitem__(self, key): -- x = self.collection.filter_by(**{self.keyname:key}).first() -- if x: -- return x -- else: -- raise KeyError(key) -- -- def __setitem__(self, key, value): -- try: -- existing = self[key] -- self.collection.remove(existing) -- except KeyError: -- pass -- self.collection.append(value) -- --from sqlalchemy.ext.declarative import declarative_base --from sqlalchemy import create_engine, Column, Integer, String, ForeignKey --from sqlalchemy.orm import sessionmaker, relationship -- --engine = create_engine('sqlite://', echo=True) --Base = declarative_base(engine) -- --class Parent(Base): -- __tablename__ = 'parent' -- id = Column(Integer, primary_key=True) -- name = Column(String(50)) -- _collection = relationship("Child", lazy="dynamic", -- cascade="all, delete-orphan") -- -- @property -- def child_map(self): -- return ProxyDict(self, '_collection', Child, 'key') -- --class Child(Base): -- __tablename__ = 'child' -- id = Column(Integer, primary_key=True) -- key = Column(String(50)) -- parent_id = Column(Integer, ForeignKey('parent.id')) -- -- def __repr__(self): -- return "Child(key=%r)" % self.key -- --Base.metadata.create_all() -- --sess = sessionmaker()() -- --p1 = Parent(name='p1') --sess.add(p1) -- --print "\n---------begin setting nodes, autoflush occurs\n" --p1.child_map['k1'] = Child(key='k1') --p1.child_map['k2'] = Child(key='k2') -- --# this will autoflush the current map. --# ['k1', 'k2'] --print "\n---------print keys - flushes first\n" --print p1.child_map.keys() -- --# k1 --print "\n---------print 'k1' node\n" --print p1.child_map['k1'] -- --print "\n---------update 'k2' node - must find existing, and replace\n" --p1.child_map['k2'] = Child(key='k2') -- --print "\n---------print 'k2' key - flushes first\n" --# k2 --print p1.child_map['k2'] -- --print "\n---------print all child nodes\n" --# [k1, k2b] --print sess.query(Child).all() -- -+class ProxyDict(object): -+ def __init__(self, parent, collection_name, childclass, keyname): -+ self.parent = parent -+ self.collection_name = collection_name -+ self.childclass = childclass -+ self.keyname = keyname -+ -+ @property -+ def collection(self): -+ return getattr(self.parent, self.collection_name) -+ -+ def keys(self): -+ descriptor = getattr(self.childclass, self.keyname) -+ return [x[0] for x in self.collection.values(descriptor)] -+ -+ def __getitem__(self, key): -+ x = self.collection.filter_by(**{self.keyname:key}).first() -+ if x: -+ return x -+ else: -+ raise KeyError(key) -+ -+ def __setitem__(self, key, value): -+ try: -+ existing = self[key] -+ self.collection.remove(existing) -+ except KeyError: -+ pass -+ self.collection.append(value) -+ -+from sqlalchemy.ext.declarative import declarative_base -+from sqlalchemy import create_engine, Column, Integer, String, ForeignKey -+from sqlalchemy.orm import sessionmaker, relationship -+ -+engine = create_engine('sqlite://', echo=True) -+Base = declarative_base(engine) -+ -+class Parent(Base): -+ __tablename__ = 'parent' -+ id = Column(Integer, primary_key=True) -+ name = Column(String(50)) -+ _collection = relationship("Child", lazy="dynamic", -+ cascade="all, delete-orphan") -+ -+ @property -+ def child_map(self): -+ return ProxyDict(self, '_collection', Child, 'key') -+ -+class Child(Base): -+ __tablename__ = 'child' -+ id = Column(Integer, primary_key=True) -+ key = Column(String(50)) -+ parent_id = Column(Integer, ForeignKey('parent.id')) -+ -+ def __repr__(self): -+ return "Child(key=%r)" % self.key -+ -+Base.metadata.create_all() -+ -+sess = sessionmaker()() -+ -+p1 = Parent(name='p1') -+sess.add(p1) -+ -+print("\n---------begin setting nodes, autoflush occurs\n") -+p1.child_map['k1'] = Child(key='k1') -+p1.child_map['k2'] = Child(key='k2') -+ -+# this will autoflush the current map. -+# ['k1', 'k2'] -+print("\n---------print keys - flushes first\n") -+print(list(p1.child_map.keys())) -+ -+# k1 -+print("\n---------print 'k1' node\n") -+print(p1.child_map['k1']) -+ -+print("\n---------update 'k2' node - must find existing, and replace\n") -+p1.child_map['k2'] = Child(key='k2') -+ -+print("\n---------print 'k2' key - flushes first\n") -+# k2 -+print(p1.child_map['k2']) -+ -+print("\n---------print all child nodes\n") -+# [k1, k2b] -+print(sess.query(Child).all()) -+ -diff -r 9d0639b9d3be examples/elementtree/adjacency_list.py ---- a/examples/elementtree/adjacency_list.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/elementtree/adjacency_list.py Sat Apr 27 19:42:17 2013 -0400 -@@ -11,7 +11,7 @@ - Unicode, and_, create_engine) - from sqlalchemy.orm import mapper, relationship, Session, lazyload - --import sys, os, StringIO, re -+import sys, os, io, re - - from xml.etree import ElementTree - -@@ -56,7 +56,7 @@ - self.element = element - - def __str__(self): -- buf = StringIO.StringIO() -+ buf = io.StringIO() - self.element.write(buf) - return buf.getvalue() - -@@ -120,11 +120,11 @@ - def __set__(self, document, element): - def traverse(node): - n = _Node() -- n.tag = unicode(node.tag) -- n.text = unicode(node.text) -- n.tail = unicode(node.tail) -+ n.tag = str(node.tag) -+ n.text = str(node.text) -+ n.tail = str(node.tail) - n.children = [traverse(n2) for n2 in node] -- n.attributes = [_Attribute(unicode(k), unicode(v)) for k, v in node.attrib.iteritems()] -+ n.attributes = [_Attribute(str(k), str(v)) for k, v in node.attrib.items()] - return n - - document._root = traverse(element.getroot()) -@@ -150,23 +150,23 @@ - doc = ElementTree.parse(filename) - session.add(Document(file, doc)) - --print "\nSaving three documents...", line -+print("\nSaving three documents...", line) - session.commit() --print "Done." -+print("Done.") - --print "\nFull text of document 'text.xml':", line -+print("\nFull text of document 'text.xml':", line) - document = session.query(Document).filter_by(filename="test.xml").first() - --print document -+print(document) - - ############################################ PART VI - Searching for Paths ######################### - - # manually search for a document which contains "/somefile/header/field1:hi" --d = session.query(Document).join('_root', aliased=True).filter(_Node.tag==u'somefile').\ -- join('children', aliased=True, from_joinpoint=True).filter(_Node.tag==u'header').\ -+d = session.query(Document).join('_root', aliased=True).filter(_Node.tag=='somefile').\ -+ join('children', aliased=True, from_joinpoint=True).filter(_Node.tag=='header').\ - join('children', aliased=True, from_joinpoint=True).filter( -- and_(_Node.tag==u'field1', _Node.text==u'hi')).one() --print d -+ and_(_Node.tag=='field1', _Node.text=='hi')).one() -+print(d) - - # generalize the above approach into an extremely impoverished xpath function: - def find_document(path, compareto): -@@ -188,11 +188,11 @@ - return query.options(lazyload('_root')).filter(_Node.text==compareto).all() - - for path, compareto in ( -- (u'/somefile/header/field1', u'hi'), -- (u'/somefile/field1', u'hi'), -- (u'/somefile/header/field2', u'there'), -- (u'/somefile/header/field2[@attr=foo]', u'there') -+ ('/somefile/header/field1', 'hi'), -+ ('/somefile/field1', 'hi'), -+ ('/somefile/header/field2', 'there'), -+ ('/somefile/header/field2[@attr=foo]', 'there') - ): -- print "\nDocuments containing '%s=%s':" % (path, compareto), line -- print [d.filename for d in find_document(path, compareto)] -+ print("\nDocuments containing '%s=%s':" % (path, compareto), line) -+ print([d.filename for d in find_document(path, compareto)]) - -diff -r 9d0639b9d3be examples/elementtree/optimized_al.py ---- a/examples/elementtree/optimized_al.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/elementtree/optimized_al.py Sat Apr 27 19:42:17 2013 -0400 -@@ -10,7 +10,7 @@ - Unicode, and_, create_engine) - from sqlalchemy.orm import mapper, relationship, Session, lazyload - --import sys, os, StringIO, re -+import sys, os, io, re - - from xml.etree import ElementTree - -@@ -55,7 +55,7 @@ - self.element = element - - def __str__(self): -- buf = StringIO.StringIO() -+ buf = io.StringIO() - self.element.write(buf) - return buf.getvalue() - -@@ -127,12 +127,12 @@ - def __set__(self, document, element): - def traverse(node): - n = _Node() -- n.tag = unicode(node.tag) -- n.text = unicode(node.text) -- n.tail = unicode(node.tail) -+ n.tag = str(node.tag) -+ n.text = str(node.text) -+ n.tail = str(node.tail) - document._nodes.append(n) - n.children = [traverse(n2) for n2 in node] -- n.attributes = [_Attribute(unicode(k), unicode(v)) for k, v in node.attrib.iteritems()] -+ n.attributes = [_Attribute(str(k), str(v)) for k, v in node.attrib.items()] - return n - - traverse(element.getroot()) -@@ -158,27 +158,27 @@ - doc = ElementTree.parse(filename) - session.add(Document(file, doc)) - --print "\nSaving three documents...", line -+print("\nSaving three documents...", line) - session.commit() --print "Done." -+print("Done.") - --print "\nFull text of document 'text.xml':", line -+print("\nFull text of document 'text.xml':", line) - document = session.query(Document).filter_by(filename="test.xml").first() - --print document -+print(document) - - ######################## PART VI - Searching for Paths ####################### - - # manually search for a document which contains "/somefile/header/field1:hi" --print "\nManual search for /somefile/header/field1=='hi':", line -+print("\nManual search for /somefile/header/field1=='hi':", line) - d = session.query(Document).join('_nodes', aliased=True).\ -- filter(and_(_Node.parent_id==None, _Node.tag==u'somefile')).\ -+ filter(and_(_Node.parent_id==None, _Node.tag=='somefile')).\ - join('children', aliased=True, from_joinpoint=True).\ -- filter(_Node.tag==u'header').\ -+ filter(_Node.tag=='header').\ - join('children', aliased=True, from_joinpoint=True).\ -- filter(and_(_Node.tag==u'field1', _Node.text==u'hi')).\ -+ filter(and_(_Node.tag=='field1', _Node.text=='hi')).\ - one() --print d -+print(d) - - # generalize the above approach into an extremely impoverished xpath function: - def find_document(path, compareto): -@@ -203,11 +203,11 @@ - return query.options(lazyload('_nodes')).filter(_Node.text==compareto).all() - - for path, compareto in ( -- (u'/somefile/header/field1', u'hi'), -- (u'/somefile/field1', u'hi'), -- (u'/somefile/header/field2', u'there'), -- (u'/somefile/header/field2[@attr=foo]', u'there') -+ ('/somefile/header/field1', 'hi'), -+ ('/somefile/field1', 'hi'), -+ ('/somefile/header/field2', 'there'), -+ ('/somefile/header/field2[@attr=foo]', 'there') - ): -- print "\nDocuments containing '%s=%s':" % (path, compareto), line -- print [d.filename for d in find_document(path, compareto)] -+ print("\nDocuments containing '%s=%s':" % (path, compareto), line) -+ print([d.filename for d in find_document(path, compareto)]) - -diff -r 9d0639b9d3be examples/generic_associations/discriminator_on_association.py ---- a/examples/generic_associations/discriminator_on_association.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/generic_associations/discriminator_on_association.py Sat Apr 27 19:42:17 2013 -0400 -@@ -144,5 +144,5 @@ - - for customer in session.query(Customer): - for address in customer.addresses: -- print address -- print address.parent -\ No newline at end of file -+ print(address) -+ print(address.parent) -\ No newline at end of file -diff -r 9d0639b9d3be examples/generic_associations/table_per_association.py ---- a/examples/generic_associations/table_per_association.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/generic_associations/table_per_association.py Sat Apr 27 19:42:17 2013 -0400 -@@ -102,5 +102,5 @@ - - for customer in session.query(Customer): - for address in customer.addresses: -- print address -+ print(address) - # no parent here -\ No newline at end of file -diff -r 9d0639b9d3be examples/generic_associations/table_per_related.py ---- a/examples/generic_associations/table_per_related.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/generic_associations/table_per_related.py Sat Apr 27 19:42:17 2013 -0400 -@@ -103,5 +103,5 @@ - - for customer in session.query(Customer): - for address in customer.addresses: -- print address -- print address.parent -\ No newline at end of file -+ print(address) -+ print(address.parent) -\ No newline at end of file -diff -r 9d0639b9d3be examples/inheritance/concrete.py ---- a/examples/inheritance/concrete.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/inheritance/concrete.py Sat Apr 27 19:42:17 2013 -0400 -@@ -68,5 +68,5 @@ - session.add(e2) - session.commit() - --print session.query(Employee).all() -+print(session.query(Employee).all()) - -diff -r 9d0639b9d3be examples/inheritance/joined.py ---- a/examples/inheritance/joined.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/inheritance/joined.py Sat Apr 27 19:42:17 2013 -0400 -@@ -92,10 +92,10 @@ - - c = session.query(Company).get(1) - for e in c.employees: -- print e, inspect(e).key, e.company -+ print(e, inspect(e).key, e.company) - assert set([e.name for e in c.employees]) == set(['pointy haired boss', - 'dilbert', 'joesmith', 'wally', 'jsmith']) --print "\n" -+print("\n") - - dilbert = session.query(Person).filter_by(name='dilbert').one() - dilbert2 = session.query(Engineer).filter_by(name='dilbert').one() -@@ -107,29 +107,29 @@ - - c = session.query(Company).get(1) - for e in c.employees: -- print e -+ print(e) - - # query using with_polymorphic. - eng_manager = with_polymorphic(Person, [Engineer, Manager], aliased=True) --print session.query(eng_manager).\ -+print(session.query(eng_manager).\ - filter( - or_(eng_manager.Engineer.engineer_name=='engineer1', - eng_manager.Manager.manager_name=='manager2' - ) -- ).all() -+ ).all()) - - # illustrate join from Company, - # We use aliased=True - # to help when the selectable is used as the target of a join. - eng_manager = with_polymorphic(Person, [Engineer, Manager], aliased=True) --print session.query(Company).\ -+print(session.query(Company).\ - join( - eng_manager, - Company.employees - ).filter( - or_(eng_manager.Engineer.engineer_name=='engineer1', - eng_manager.Manager.manager_name=='manager2') -- ).all() -+ ).all()) - - session.commit() - -diff -r 9d0639b9d3be examples/inheritance/single.py ---- a/examples/inheritance/single.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/inheritance/single.py Sat Apr 27 19:42:17 2013 -0400 -@@ -23,7 +23,7 @@ - - class Person(object): - def __init__(self, **kwargs): -- for key, value in kwargs.iteritems(): -+ for key, value in kwargs.items(): - setattr(self, key, value) - def __repr__(self): - return "Ordinary person %s" % self.name -@@ -39,7 +39,7 @@ - (self.name, self.status, self.manager_name) - class Company(object): - def __init__(self, **kwargs): -- for key, value in kwargs.iteritems(): -+ for key, value in kwargs.items(): - setattr(self, key, value) - def __repr__(self): - return "Company %s" % self.name -@@ -79,9 +79,9 @@ - - c = session.query(Company).get(1) - for e in c.employees: -- print e, e.company -+ print(e, e.company) - --print "\n" -+print("\n") - - dilbert = session.query(Person).filter_by(name='dilbert').one() - dilbert2 = session.query(Engineer).filter_by(name='dilbert').one() -@@ -94,7 +94,7 @@ - - c = session.query(Company).get(1) - for e in c.employees: -- print e -+ print(e) - - session.delete(c) - session.commit() -diff -r 9d0639b9d3be examples/large_collection/large_collection.py ---- a/examples/large_collection/large_collection.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/large_collection/large_collection.py Sat Apr 27 19:42:17 2013 -0400 -@@ -63,14 +63,14 @@ - - sess.add(org) - -- print "-------------------------\nflush one - save org + 3 members\n" -+ print("-------------------------\nflush one - save org + 3 members\n") - sess.commit() - - # the 'members' collection is a Query. it issues - # SQL as needed to load subsets of the collection. -- print "-------------------------\nload subset of members\n" -+ print("-------------------------\nload subset of members\n") - members = org.members.filter(member_table.c.name.like('%member t%')).all() -- print members -+ print(members) - - # new Members can be appended without any - # SQL being emitted to load the full collection -@@ -78,19 +78,19 @@ - org.members.append(Member('member five')) - org.members.append(Member('member six')) - -- print "-------------------------\nflush two - save 3 more members\n" -+ print("-------------------------\nflush two - save 3 more members\n") - sess.commit() - - # delete the object. Using ON DELETE CASCADE - # SQL is only emitted for the head row - the Member rows - # disappear automatically without the need for additional SQL. - sess.delete(org) -- print "-------------------------\nflush three - delete org, delete members in one statement\n" -+ print("-------------------------\nflush three - delete org, delete members in one statement\n") - sess.commit() - -- print "-------------------------\nno Member rows should remain:\n" -- print sess.query(Member).count() -+ print("-------------------------\nno Member rows should remain:\n") -+ print(sess.query(Member).count()) - sess.close() - -- print "------------------------\ndone. dropping tables." -+ print("------------------------\ndone. dropping tables.") - meta.drop_all(engine) -\ No newline at end of file -diff -r 9d0639b9d3be examples/nested_sets/nested_sets.py ---- a/examples/nested_sets/nested_sets.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/nested_sets/nested_sets.py Sat Apr 27 19:42:17 2013 -0400 -@@ -86,19 +86,19 @@ - session.add_all([albert, bert, chuck, donna, eddie, fred]) - session.commit() - --print(session.query(Employee).all()) -+print((session.query(Employee).all())) - - # 1. Find an employee and all his/her supervisors, no matter how deep the tree. - ealias = aliased(Employee) --print(session.query(Employee).\ -+print((session.query(Employee).\ - filter(ealias.left.between(Employee.left, Employee.right)).\ -- filter(ealias.emp == 'Eddie').all()) -+ filter(ealias.emp == 'Eddie').all())) - - #2. Find the employee and all his/her subordinates. - # (This query has a nice symmetry with the first query.) --print(session.query(Employee).\ -+print((session.query(Employee).\ - filter(Employee.left.between(ealias.left, ealias.right)).\ -- filter(ealias.emp == 'Chuck').all()) -+ filter(ealias.emp == 'Chuck').all())) - - #3. Find the level of each node, so you can print the tree - # as an indented listing. -@@ -107,5 +107,5 @@ - filter(ealias.left.between(Employee.left, Employee.right)).\ - group_by(ealias.emp).\ - order_by(ealias.left): -- print(" " * indentation + str(employee)) -+ print((" " * indentation + str(employee))) - -diff -r 9d0639b9d3be examples/postgis/postgis.py ---- a/examples/postgis/postgis.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/postgis/postgis.py Sat Apr 27 19:42:17 2013 -0400 -@@ -251,7 +251,7 @@ - - road_table = Road.__table__ - stmt = select([road_table]).where(road_table.c.road_geom.intersects(r1.road_geom)) -- print session.execute(stmt).fetchall() -+ print(session.execute(stmt).fetchall()) - - # TODO: for some reason the auto-generated labels have the internal replacement - # strings exposed, even though PG doesn't complain -diff -r 9d0639b9d3be examples/versioning/_lib.py ---- a/examples/versioning/_lib.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/versioning/_lib.py Sat Apr 27 19:42:17 2013 -0400 -@@ -17,7 +17,7 @@ - _repr_stack = set() - class BasicEntity(object): - def __init__(self, **kw): -- for key, value in kw.iteritems(): -+ for key, value in kw.items(): - setattr(self, key, value) - - def __repr__(self): -@@ -74,7 +74,7 @@ - a = self - b = other - -- for attr in a.__dict__.keys(): -+ for attr in list(a.__dict__.keys()): - if attr.startswith('_'): - continue - value = getattr(a, attr) -diff -r 9d0639b9d3be examples/versioning/history_meta.py ---- a/examples/versioning/history_meta.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/versioning/history_meta.py Sat Apr 27 19:42:17 2013 -0400 -@@ -49,7 +49,7 @@ - cols.append(Column('version', Integer, primary_key=True)) - - if super_fks: -- cols.append(ForeignKeyConstraint(*zip(*super_fks))) -+ cols.append(ForeignKeyConstraint(*list(zip(*super_fks)))) - - table = Table(local_mapper.local_table.name + '_history', local_mapper.local_table.metadata, - *cols -@@ -166,7 +166,7 @@ - - attr['version'] = obj.version - hist = history_cls() -- for key, value in attr.iteritems(): -+ for key, value in attr.items(): - setattr(hist, key, value) - session.add(hist) - obj.version += 1 -diff -r 9d0639b9d3be examples/versioning/test_versioning.py ---- a/examples/versioning/test_versioning.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/versioning/test_versioning.py Sat Apr 27 19:42:17 2013 -0400 -@@ -1,9 +1,9 @@ - from unittest import TestCase - from sqlalchemy.ext.declarative import declarative_base --from history_meta import Versioned, versioned_session -+from .history_meta import Versioned, versioned_session - from sqlalchemy import create_engine, Column, Integer, String, ForeignKey - from sqlalchemy.orm import clear_mappers, sessionmaker, deferred, relationship --from _lib import ComparableEntity, eq_ -+from ._lib import ComparableEntity, eq_ - - engine = Session = None - -@@ -188,9 +188,9 @@ - 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), -- SubClassSamePkHistory(id=3, name=u'same1', type=u'same', version=1) -+ SubClassSeparatePkHistory(id=1, name='sep1', type='sep', version=1), -+ BaseClassHistory(id=2, name='base1', type='base', version=1), -+ SubClassSamePkHistory(id=3, name='same1', type='same', version=1) - ] - ) - -@@ -199,10 +199,10 @@ - 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), -- SubClassSamePkHistory(id=3, name=u'same1', type=u'same', version=2) -+ SubClassSeparatePkHistory(id=1, name='sep1', type='sep', version=1), -+ BaseClassHistory(id=2, name='base1', type='base', version=1), -+ SubClassSamePkHistory(id=3, name='same1', type='same', version=1), -+ SubClassSamePkHistory(id=3, name='same1', type='same', version=2) - ] - ) - -@@ -210,11 +210,11 @@ - 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), -- SubClassSamePkHistory(id=3, name=u'same1', type=u'same', version=2) -+ SubClassSeparatePkHistory(id=1, name='sep1', type='sep', version=1), -+ BaseClassHistory(id=2, name='base1', type='base', version=1), -+ BaseClassHistory(id=2, name='base1mod', type='base', version=2), -+ SubClassSamePkHistory(id=3, name='same1', type='same', version=1), -+ SubClassSamePkHistory(id=3, name='same1', type='same', version=2) - ] - ) - -@@ -249,7 +249,7 @@ - - eq_( - sess.query(BaseClassHistory).order_by(BaseClassHistory.id, BaseClassHistory.version).all(), -- [BaseClassHistory(id=1, name=u'b1', type=u'base', version=1)] -+ [BaseClassHistory(id=1, name='b1', type='base', version=1)] - ) - - sc.name ='s1modified' -@@ -258,9 +258,9 @@ - eq_( - sess.query(BaseClassHistory).order_by(BaseClassHistory.id, BaseClassHistory.version).all(), - [ -- BaseClassHistory(id=1, name=u'b1', type=u'base', version=1), -- BaseClassHistory(id=1, name=u'b1modified', type=u'base', version=2), -- SubClassHistory(id=2, name=u's1', type=u'sub', version=1) -+ BaseClassHistory(id=1, name='b1', type='base', version=1), -+ BaseClassHistory(id=1, name='b1modified', type='base', version=2), -+ SubClassHistory(id=2, name='s1', type='sub', version=1) - ] - ) - -diff -r 9d0639b9d3be examples/vertical/dictlike-polymorphic.py ---- a/examples/vertical/dictlike-polymorphic.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/vertical/dictlike-polymorphic.py Sat Apr 27 19:42:17 2013 -0400 -@@ -33,7 +33,7 @@ - from sqlalchemy.ext.hybrid import hybrid_property - - # Using the VerticalPropertyDictMixin from the base example --from dictlike import VerticalPropertyDictMixin -+from .dictlike import VerticalPropertyDictMixin - - class PolymorphicVerticalProperty(object): - """A key/value pair with polymorphic value storage. -@@ -80,7 +80,7 @@ - - @hybrid_property - def value(self): -- for discriminator, field in self.type_map.values(): -+ for discriminator, field in list(self.type_map.values()): - if self.type == discriminator: - return getattr(self, field) - return None -@@ -114,7 +114,7 @@ - - def _case(self): - whens = [(text("'%s'" % p[0]), cast(getattr(self.cls, p[1]), String)) -- for p in self.cls.type_map.values() -+ for p in list(self.cls.type_map.values()) - if p[1] is not None] - return case(whens, self.cls.type, null()) - def __eq__(self, other): -@@ -150,9 +150,9 @@ - - class AnimalFact(PolymorphicVerticalProperty): - type_map = { -- int: (u'integer', 'int_value'), -- unicode: (u'char', 'char_value'), -- bool: (u'boolean', 'boolean_value'), -+ int: ('integer', 'int_value'), -+ str: ('char', 'char_value'), -+ bool: ('boolean', 'boolean_value'), - type(None): (None, None), - } - -@@ -190,42 +190,42 @@ - metadata.create_all(engine) - session = Session(engine) - -- stoat = Animal(u'stoat') -- stoat[u'color'] = u'red' -- stoat[u'cuteness'] = 7 -- stoat[u'weasel-like'] = True -+ stoat = Animal('stoat') -+ stoat['color'] = 'red' -+ stoat['cuteness'] = 7 -+ stoat['weasel-like'] = True - - session.add(stoat) - session.commit() - -- critter = session.query(Animal).filter(Animal.name == u'stoat').one() -- print critter[u'color'] -- print critter[u'cuteness'] -+ critter = session.query(Animal).filter(Animal.name == 'stoat').one() -+ print(critter['color']) -+ print(critter['cuteness']) - -- print "changing cuteness value and type:" -- critter[u'cuteness'] = u'very cute' -+ print("changing cuteness value and type:") -+ critter['cuteness'] = 'very cute' - - session.commit() - -- marten = Animal(u'marten') -- marten[u'cuteness'] = 5 -- marten[u'weasel-like'] = True -- marten[u'poisonous'] = False -+ marten = Animal('marten') -+ marten['cuteness'] = 5 -+ marten['weasel-like'] = True -+ marten['poisonous'] = False - session.add(marten) - -- shrew = Animal(u'shrew') -- shrew[u'cuteness'] = 5 -- shrew[u'weasel-like'] = False -- shrew[u'poisonous'] = True -+ shrew = Animal('shrew') -+ shrew['cuteness'] = 5 -+ shrew['weasel-like'] = False -+ shrew['poisonous'] = True - - session.add(shrew) - session.commit() - - q = (session.query(Animal). - filter(Animal.facts.any( -- and_(AnimalFact.key == u'weasel-like', -+ and_(AnimalFact.key == 'weasel-like', - AnimalFact.value == True)))) -- print 'weasel-like animals', q.all() -+ print('weasel-like animals', q.all()) - - # Save some typing by wrapping that up in a function: - with_characteristic = lambda key, value: and_(AnimalFact.key == key, -@@ -233,24 +233,24 @@ - - q = (session.query(Animal). - filter(Animal.facts.any( -- with_characteristic(u'weasel-like', True)))) -- print 'weasel-like animals again', q.all() -+ with_characteristic('weasel-like', True)))) -+ print('weasel-like animals again', q.all()) - - q = (session.query(Animal). -- filter(Animal.facts.any(with_characteristic(u'poisonous', False)))) -- print 'animals with poisonous=False', q.all() -+ filter(Animal.facts.any(with_characteristic('poisonous', False)))) -+ print('animals with poisonous=False', q.all()) - - q = (session.query(Animal). - filter(or_(Animal.facts.any( -- with_characteristic(u'poisonous', False)), -- not_(Animal.facts.any(AnimalFact.key == u'poisonous'))))) -- print 'non-poisonous animals', q.all() -+ with_characteristic('poisonous', False)), -+ not_(Animal.facts.any(AnimalFact.key == 'poisonous'))))) -+ print('non-poisonous animals', q.all()) - - q = (session.query(Animal). - filter(Animal.facts.any(AnimalFact.value == 5))) -- print 'any animal with a .value of 5', q.all() -+ print('any animal with a .value of 5', q.all()) - - # Facts can be queried as well. - q = (session.query(AnimalFact). -- filter(with_characteristic(u'cuteness', u'very cute'))) -- print q.all() -+ filter(with_characteristic('cuteness', 'very cute'))) -+ print(q.all()) -diff -r 9d0639b9d3be examples/vertical/dictlike.py ---- a/examples/vertical/dictlike.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/examples/vertical/dictlike.py Sat Apr 27 19:42:17 2013 -0400 -@@ -110,16 +110,16 @@ - - # Implement other dict methods to taste. Here are some examples: - def keys(self): -- return self.__map.keys() -+ return list(self.__map.keys()) - - def values(self): -- return [prop.value for prop in self.__map.values()] -+ return [prop.value for prop in list(self.__map.values())] - - def items(self): -- return [(key, prop.value) for key, prop in self.__map.items()] -+ return [(key, prop.value) for key, prop in list(self.__map.items())] - - def __iter__(self): -- return iter(self.keys()) -+ return iter(list(self.keys())) - - - if __name__ == '__main__': -@@ -176,49 +176,49 @@ - metadata.create_all(engine) - session = Session(bind=engine) - -- stoat = Animal(u'stoat') -- stoat[u'color'] = u'reddish' -- stoat[u'cuteness'] = u'somewhat' -+ stoat = Animal('stoat') -+ stoat['color'] = 'reddish' -+ stoat['cuteness'] = 'somewhat' - - # dict-like assignment transparently creates entries in the - # stoat.facts collection: -- print stoat.facts[u'color'] -+ print(stoat.facts['color']) - - session.add(stoat) - session.commit() - -- critter = session.query(Animal).filter(Animal.name == u'stoat').one() -- print critter[u'color'] -- print critter[u'cuteness'] -+ critter = session.query(Animal).filter(Animal.name == 'stoat').one() -+ print(critter['color']) -+ print(critter['cuteness']) - -- critter[u'cuteness'] = u'very' -+ critter['cuteness'] = 'very' - -- print 'changing cuteness:' -+ print('changing cuteness:') - engine.echo = True - session.commit() - engine.echo = False - -- marten = Animal(u'marten') -- marten[u'color'] = u'brown' -- marten[u'cuteness'] = u'somewhat' -+ marten = Animal('marten') -+ marten['color'] = 'brown' -+ marten['cuteness'] = 'somewhat' - session.add(marten) - -- shrew = Animal(u'shrew') -- shrew[u'cuteness'] = u'somewhat' -- shrew[u'poisonous-part'] = u'saliva' -+ shrew = Animal('shrew') -+ shrew['cuteness'] = 'somewhat' -+ shrew['poisonous-part'] = 'saliva' - session.add(shrew) - -- loris = Animal(u'slow loris') -- loris[u'cuteness'] = u'fairly' -- loris[u'poisonous-part'] = u'elbows' -+ loris = Animal('slow loris') -+ loris['cuteness'] = 'fairly' -+ loris['poisonous-part'] = 'elbows' - session.add(loris) - session.commit() - - q = (session.query(Animal). - filter(Animal.facts.any( -- and_(AnimalFact.key == u'color', -- AnimalFact.value == u'reddish')))) -- print 'reddish animals', q.all() -+ and_(AnimalFact.key == 'color', -+ AnimalFact.value == 'reddish')))) -+ print('reddish animals', q.all()) - - # Save some typing by wrapping that up in a function: - with_characteristic = lambda key, value: and_(AnimalFact.key == key, -@@ -226,21 +226,21 @@ - - q = (session.query(Animal). - filter(Animal.facts.any( -- with_characteristic(u'color', u'brown')))) -- print 'brown animals', q.all() -+ with_characteristic('color', 'brown')))) -+ print('brown animals', q.all()) - - q = (session.query(Animal). - filter(not_(Animal.facts.any( -- with_characteristic(u'poisonous-part', u'elbows'))))) -- print 'animals without poisonous-part == elbows', q.all() -+ with_characteristic('poisonous-part', 'elbows'))))) -+ print('animals without poisonous-part == elbows', q.all()) - - q = (session.query(Animal). -- filter(Animal.facts.any(AnimalFact.value == u'somewhat'))) -- print 'any animal with any .value of "somewhat"', q.all() -+ filter(Animal.facts.any(AnimalFact.value == 'somewhat'))) -+ print('any animal with any .value of "somewhat"', q.all()) - - # Facts can be queried as well. - q = (session.query(AnimalFact). -- filter(with_characteristic(u'cuteness', u'very'))) -- print 'just the facts', q.all() -+ filter(with_characteristic('cuteness', 'very'))) -+ print('just the facts', q.all()) - - -diff -r 9d0639b9d3be lib/sqlalchemy/__init__.py ---- a/lib/sqlalchemy/__init__.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/__init__.py Sat Apr 27 19:42:17 2013 -0400 -@@ -117,7 +117,7 @@ - from .engine import create_engine, engine_from_config - - --__all__ = sorted(name for name, obj in locals().items() -+__all__ = sorted(name for name, obj in locals().items()) - if not (name.startswith('_') or _inspect.ismodule(obj))) - - __version__ = '0.8.1' -diff -r 9d0639b9d3be lib/sqlalchemy/connectors/mxodbc.py ---- a/lib/sqlalchemy/connectors/mxodbc.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/connectors/mxodbc.py Sat Apr 27 19:42:17 2013 -0400 -@@ -82,7 +82,7 @@ - category=errorclass, - stacklevel=2) - else: -- raise errorclass, errorvalue -+ raise errorclass(errorvalue) - return error_handler - - def create_connect_args(self, url): -diff -r 9d0639b9d3be lib/sqlalchemy/connectors/pyodbc.py ---- a/lib/sqlalchemy/connectors/pyodbc.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/connectors/pyodbc.py Sat Apr 27 19:42:17 2013 -0400 -@@ -9,7 +9,7 @@ - - import sys - import re --import urllib -+import urllib.request, urllib.parse, urllib.error - - - class PyODBCConnector(Connector): -@@ -59,7 +59,7 @@ - connect_args[param] = asbool(keys.pop(param)) - - if 'odbc_connect' in keys: -- connectors = [urllib.unquote_plus(keys.pop('odbc_connect'))] -+ connectors = [urllib.parse.unquote_plus(keys.pop('odbc_connect'))] - else: - dsn_connection = 'dsn' in keys or \ - ('host' in keys and 'database' not in keys) -@@ -91,7 +91,7 @@ - connectors.append("AutoTranslate=%s" % - keys.pop("odbc_autotranslate")) - -- connectors.extend(['%s=%s' % (k, v) for k, v in keys.iteritems()]) -+ connectors.extend(['%s=%s' % (k, v) for k, v in keys.items()]) - return [[";".join(connectors)], connect_args] - - def is_disconnect(self, e, connection, cursor): -@@ -123,16 +123,16 @@ - - # the "Py2K only" part here is theoretical. - # have not tried pyodbc + python3.1 yet. -- # Py2K -- self.supports_unicode_statements = ( -- not self.freetds and not self.easysoft) -- if self._user_supports_unicode_binds is not None: -- self.supports_unicode_binds = self._user_supports_unicode_binds -- else: -- self.supports_unicode_binds = ( -- not self.freetds or self.freetds_driver_version >= '0.91' -- ) and not self.easysoft -- # end Py2K -+# start Py2K -+# self.supports_unicode_statements = ( -+# not self.freetds and not self.easysoft) -+# if self._user_supports_unicode_binds is not None: -+# self.supports_unicode_binds = self._user_supports_unicode_binds -+# else: -+# self.supports_unicode_binds = ( -+# not self.freetds or self.freetds_driver_version >= '0.91' -+# ) and not self.easysoft -+# end Py2K - - # run other initialization which asks for user name, etc. - super(PyODBCConnector, self).initialize(connection) -diff -r 9d0639b9d3be lib/sqlalchemy/dialects/firebird/base.py ---- a/lib/sqlalchemy/dialects/firebird/base.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/dialects/firebird/base.py Sat Apr 27 19:42:17 2013 -0400 -@@ -685,7 +685,7 @@ - self.normalize_name(row['fname'])) - fk['referred_columns'].append( - self.normalize_name(row['targetfname'])) -- return fks.values() -+ return list(fks.values()) - - @reflection.cache - def get_indexes(self, connection, table_name, schema=None, **kw): -@@ -716,7 +716,7 @@ - indexrec['column_names'].append( - self.normalize_name(row['field_name'])) - -- return indexes.values() -+ return list(indexes.values()) - - def do_execute(self, cursor, statement, parameters, context=None): - # kinterbase does not accept a None, but wants an empty list -diff -r 9d0639b9d3be lib/sqlalchemy/dialects/informix/base.py ---- a/lib/sqlalchemy/dialects/informix/base.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/dialects/informix/base.py Sat Apr 27 19:42:17 2013 -0400 -@@ -24,6 +24,7 @@ - from sqlalchemy.sql import compiler, text - from sqlalchemy.engine import default, reflection - from sqlalchemy import types as sqltypes -+from functools import reduce - - RESERVED_WORDS = set( - ["abs", "absolute", "access", "access_method", "acos", "active", "add", -@@ -298,7 +299,7 @@ - - def get_column_default_string(self, column): - if (isinstance(column.server_default, schema.DefaultClause) and -- isinstance(column.server_default.arg, basestring)): -+ isinstance(column.server_default.arg, str)): - if isinstance(column.type, (sqltypes.Integer, sqltypes.Numeric)): - return self.sql_compiler.process(text(column.server_default.arg)) - -@@ -322,10 +323,10 @@ - remote_table = list(constraint._elements.values())[0].column.table - text = "FOREIGN KEY (%s) REFERENCES %s (%s)" % ( - ', '.join(preparer.quote(f.parent.name, f.parent.quote) -- for f in constraint._elements.values()), -+ for f in list(constraint._elements.values())), - preparer.format_table(remote_table), - ', '.join(preparer.quote(f.column.name, f.column.quote) -- for f in constraint._elements.values()) -+ for f in list(constraint._elements.values())) - ) - text += self.define_constraint_cascades(constraint) - text += self.define_constraint_deferrability(constraint) -@@ -506,7 +507,7 @@ - if remote_column not in remote_cols: - remote_cols.append(remote_column) - -- return fkeys.values() -+ return list(fkeys.values()) - - @reflection.cache - def get_pk_constraint(self, connection, table_name, schema=None, **kw): -diff -r 9d0639b9d3be lib/sqlalchemy/dialects/mssql/adodbapi.py ---- a/lib/sqlalchemy/dialects/mssql/adodbapi.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/dialects/mssql/adodbapi.py Sat Apr 27 19:42:17 2013 -0400 -@@ -44,7 +44,7 @@ - - @classmethod - def import_dbapi(cls): -- import adodbapi as module -+ from . import adodbapi as module - return module - - colspecs = util.update_copy( -diff -r 9d0639b9d3be lib/sqlalchemy/dialects/mssql/base.py ---- a/lib/sqlalchemy/dialects/mssql/base.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/dialects/mssql/base.py Sat Apr 27 19:42:17 2013 -0400 -@@ -295,7 +295,7 @@ - def process(value): - if isinstance(value, datetime.datetime): - return value.date() -- elif isinstance(value, basestring): -+ elif isinstance(value, str): - return datetime.date(*[ - int(x or 0) - for x in self._reg.match(value).groups() -@@ -328,7 +328,7 @@ - def process(value): - if isinstance(value, datetime.datetime): - return value.time() -- elif isinstance(value, basestring): -+ elif isinstance(value, str): - return datetime.time(*[ - int(x or 0) - for x in self._reg.match(value).groups()]) -@@ -1002,7 +1002,7 @@ - # handle other included columns - if index.kwargs.get("mssql_include"): - inclusions = [index.table.c[col] -- if isinstance(col, basestring) else col -+ if isinstance(col, str) else col - for col in index.kwargs["mssql_include"]] - - text += " INCLUDE (%s)" \ -@@ -1103,7 +1103,7 @@ - query_timeout=None, - use_scope_identity=True, - max_identifier_length=None, -- schema_name=u"dbo", **opts): -+ schema_name="dbo", **opts): - self.query_timeout = int(query_timeout or 0) - self.schema_name = schema_name - -@@ -1123,7 +1123,7 @@ - - def initialize(self, connection): - super(MSDialect, self).initialize(connection) -- if self.server_version_info[0] not in range(8, 17): -+ if self.server_version_info[0] not in list(range(8, 17)): - # FreeTDS with version 4.2 seems to report here - # a number like "95.10.255". Don't know what - # that is. So emit warning. -@@ -1150,7 +1150,7 @@ - try: - default_schema_name = connection.scalar(query, name=user_name) - if default_schema_name is not None: -- return unicode(default_schema_name) -+ return str(default_schema_name) - except: - pass - return self.schema_name -@@ -1188,7 +1188,7 @@ - s = sql.select([tables.c.table_name], - sql.and_( - tables.c.table_schema == owner, -- tables.c.table_type == u'BASE TABLE' -+ tables.c.table_type == 'BASE TABLE' - ), - order_by=[tables.c.table_name] - ) -@@ -1202,7 +1202,7 @@ - s = sql.select([tables.c.table_name], - sql.and_( - tables.c.table_schema == owner, -- tables.c.table_type == u'VIEW' -+ tables.c.table_type == 'VIEW' - ), - order_by=[tables.c.table_name] - ) -@@ -1267,7 +1267,7 @@ - if row['index_id'] in indexes: - indexes[row['index_id']]['column_names'].append(row['name']) - -- return indexes.values() -+ return list(indexes.values()) - - @reflection.cache - @_db_plus_owner -@@ -1474,4 +1474,4 @@ - local_cols.append(scol) - remote_cols.append(rcol) - -- return fkeys.values() -+ return list(fkeys.values()) -diff -r 9d0639b9d3be lib/sqlalchemy/dialects/mssql/information_schema.py ---- a/lib/sqlalchemy/dialects/mssql/information_schema.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/dialects/mssql/information_schema.py Sat Apr 27 19:42:17 2013 -0400 -@@ -17,10 +17,10 @@ - impl = Unicode - - def process_bind_param(self, value, dialect): -- # Py2K -- if isinstance(value, str): -- value = value.decode(dialect.encoding) -- # end Py2K -+# start Py2K -+# if isinstance(value, str): -+# value = value.decode(dialect.encoding) -+# end Py2K - return value - - def bind_expression(self, bindvalue): -diff -r 9d0639b9d3be lib/sqlalchemy/dialects/mssql/pyodbc.py ---- a/lib/sqlalchemy/dialects/mssql/pyodbc.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/dialects/mssql/pyodbc.py Sat Apr 27 19:42:17 2013 -0400 -@@ -219,7 +219,7 @@ - # without closing it (FreeTDS particularly) - row = self.cursor.fetchall()[0] - break -- except self.dialect.dbapi.Error, e: -+ except self.dialect.dbapi.Error as e: - # no way around this - nextset() consumes the previous set - # so we need to just keep flipping - self.cursor.nextset() -diff -r 9d0639b9d3be lib/sqlalchemy/dialects/mysql/base.py ---- a/lib/sqlalchemy/dialects/mysql/base.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/dialects/mysql/base.py Sat Apr 27 19:42:17 2013 -0400 -@@ -652,7 +652,7 @@ - - def process(value): - if value is not None: -- v = 0L -+ v = 0 - for i in map(ord, value): - v = v << 8 | i - return v -@@ -1171,7 +1171,7 @@ - super_convert = super(SET, self).bind_processor(dialect) - - def process(value): -- if value is None or isinstance(value, (int, long, basestring)): -+ if value is None or isinstance(value, (int, str)): - pass - else: - if None in value: -@@ -1352,7 +1352,7 @@ - of a SELECT. - - """ -- if isinstance(select._distinct, basestring): -+ if isinstance(select._distinct, str): - return select._distinct.upper() + " " - elif select._distinct: - return "DISTINCT " -@@ -1441,7 +1441,7 @@ - MySQLDDLCompiler, self).create_table_constraints(table) - - engine_key = '%s_engine' % self.dialect.name -- is_innodb = table.kwargs.has_key(engine_key) and \ -+ is_innodb = engine_key in table.kwargs and \ - table.kwargs[engine_key].lower() == 'innodb' - - auto_inc_column = table._autoincrement_column -@@ -1494,7 +1494,7 @@ - k[len(self.dialect.name) + 1:].upper(), - v - ) -- for k, v in table.kwargs.items() -+ for k, v in list(table.kwargs.items()) - if k.startswith('%s_' % self.dialect.name) - ) - -@@ -2045,7 +2045,7 @@ - have = rs.fetchone() is not None - rs.close() - return have -- except exc.DBAPIError, e: -+ except exc.DBAPIError as e: - if self._extract_error_code(e.orig) == 1146: - return False - raise -@@ -2328,7 +2328,7 @@ - rp = None - try: - rp = connection.execute(st) -- except exc.DBAPIError, e: -+ except exc.DBAPIError as e: - if self._extract_error_code(e.orig) == 1146: - raise exc.NoSuchTableError(full_name) - else: -@@ -2352,7 +2352,7 @@ - try: - try: - rp = connection.execute(st) -- except exc.DBAPIError, e: -+ except exc.DBAPIError as e: - if self._extract_error_code(e.orig) == 1146: - raise exc.NoSuchTableError(full_name) - else: -@@ -2485,7 +2485,7 @@ - for nope in ('auto_increment', 'data directory', 'index directory'): - options.pop(nope, None) - -- for opt, val in options.items(): -+ for opt, val in list(options.items()): - state.table_options['%s_%s' % (self.dialect.name, opt)] = val - - def _parse_column(self, line, state): -@@ -2626,11 +2626,11 @@ - - _final = self.preparer.final_quote - -- quotes = dict(zip(('iq', 'fq', 'esc_fq'), -+ quotes = dict(list(zip(('iq', 'fq', 'esc_fq'), - [re.escape(s) for s in - (self.preparer.initial_quote, - _final, -- self.preparer._escape_identifier(_final))])) -+ self.preparer._escape_identifier(_final))]))) - - self._pr_name = _pr_compile( - r'^CREATE (?:\w+ +)?TABLE +' -@@ -2802,11 +2802,12 @@ - item = self.rowproxy[index] - if isinstance(item, _array): - item = item.tostring() -- # Py2K -- if self.charset and isinstance(item, str): -- # end Py2K -- # Py3K -- #if self.charset and isinstance(item, bytes): -+# start Py2K -+# if self.charset and isinstance(item, str): -+# end Py2K -+# start Py3K -+ if self.charset and isinstance(item, bytes): -+# end Py3K - return item.decode(self.charset) - else: - return item -@@ -2815,11 +2816,12 @@ - item = getattr(self.rowproxy, attr) - if isinstance(item, _array): - item = item.tostring() -- # Py2K -- if self.charset and isinstance(item, str): -- # end Py2K -- # Py3K -- #if self.charset and isinstance(item, bytes): -+# start Py2K -+# if self.charset and isinstance(item, str): -+# end Py2K -+# start Py3K -+ if self.charset and isinstance(item, bytes): -+# end Py3K - return item.decode(self.charset) - else: - return item -diff -r 9d0639b9d3be lib/sqlalchemy/dialects/mysql/cymysql.py ---- a/lib/sqlalchemy/dialects/mysql/cymysql.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/dialects/mysql/cymysql.py Sat Apr 27 19:42:17 2013 -0400 -@@ -25,15 +25,16 @@ - - def process(value): - if value is not None: -- # Py2K -- v = 0L -- for i in map(ord, value): -+# start Py2K -+# v = 0L -+# for i in map(ord, value): -+# v = v << 8 | i -+# end Py2K -+# start Py3K -+ v = 0 -+ for i in value: - v = v << 8 | i -- # end Py2K -- # Py3K -- #v = 0 -- #for i in value: -- # v = v << 8 | i -+# end Py3K - return v - return value - return process -diff -r 9d0639b9d3be lib/sqlalchemy/dialects/mysql/oursql.py ---- a/lib/sqlalchemy/dialects/mysql/oursql.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/dialects/mysql/oursql.py Sat Apr 27 19:42:17 2013 -0400 -@@ -55,9 +55,9 @@ - - class MySQLDialect_oursql(MySQLDialect): - driver = 'oursql' --# Py2K -- supports_unicode_binds = True -- supports_unicode_statements = True -+# start Py2K -+# supports_unicode_binds = True -+# supports_unicode_statements = True - # end Py2K - - supports_native_decimal = True -@@ -90,12 +90,13 @@ - connection.cursor().execute('BEGIN', plain_query=True) - - def _xa_query(self, connection, query, xid): --# Py2K -- arg = connection.connection._escape_string(xid) -+# start Py2K -+# arg = connection.connection._escape_string(xid) - # end Py2K --# Py3K --# charset = self._connection_charset --# arg = connection.connection._escape_string(xid.encode(charset)).decode(charset) -+# start Py3K -+ charset = self._connection_charset -+ arg = connection.connection._escape_string(xid.encode(charset)).decode(charset) -+# end Py3K - arg = "'%s'" % arg - connection.execution_options(_oursql_plain_query=True).execute(query % arg) - -diff -r 9d0639b9d3be lib/sqlalchemy/dialects/mysql/zxjdbc.py ---- a/lib/sqlalchemy/dialects/mysql/zxjdbc.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/dialects/mysql/zxjdbc.py Sat Apr 27 19:42:17 2013 -0400 -@@ -37,7 +37,7 @@ - return value - if isinstance(value, bool): - return int(value) -- v = 0L -+ v = 0 - for i in value: - v = v << 8 | (i & 0xff) - value = v -diff -r 9d0639b9d3be lib/sqlalchemy/dialects/oracle/base.py ---- a/lib/sqlalchemy/dialects/oracle/base.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/dialects/oracle/base.py Sat Apr 27 19:42:17 2013 -0400 -@@ -437,7 +437,7 @@ - - def get_select_hint_text(self, byfroms): - return " ".join( -- "/*+ %s */" % text for table, text in byfroms.items() -+ "/*+ %s */" % text for table, text in list(byfroms.items()) - ) - - def function_argspec(self, fn, **kw): -@@ -654,14 +654,14 @@ - class OracleIdentifierPreparer(compiler.IdentifierPreparer): - - reserved_words = set([x.lower() for x in RESERVED_WORDS]) -- illegal_initial_characters = set(xrange(0, 10)).union(["_", "$"]) -+ illegal_initial_characters = set(range(0, 10)).union(["_", "$"]) - - def _bindparam_requires_quotes(self, value): - """Return True if the given identifier requires quoting.""" - lc_value = value.lower() - return (lc_value in self.reserved_words - or value[0] in self.illegal_initial_characters -- or not self.legal_characters.match(unicode(value)) -+ or not self.legal_characters.match(str(value)) - ) - - def format_savepoint(self, savepoint): -@@ -765,10 +765,10 @@ - def normalize_name(self, name): - if name is None: - return None -- # Py2K -- if isinstance(name, str): -- name = name.decode(self.encoding) -- # end Py2K -+# start Py2K -+# if isinstance(name, str): -+# name = name.decode(self.encoding) -+# end Py2K - if name.upper() == name and \ - not self.identifier_preparer._requires_quotes(name.lower()): - return name.lower() -@@ -780,16 +780,16 @@ - return None - elif name.lower() == name and not self.identifier_preparer._requires_quotes(name.lower()): - name = name.upper() -- # Py2K -- if not self.supports_unicode_binds: -- name = name.encode(self.encoding) -- else: -- name = unicode(name) -- # end Py2K -+# start Py2K -+# if not self.supports_unicode_binds: -+# name = name.encode(self.encoding) -+# else: -+# name = unicode(name) -+# end Py2K - return name - - def _get_default_schema_name(self, connection): -- return self.normalize_name(connection.execute(u'SELECT USER FROM DUAL').scalar()) -+ return self.normalize_name(connection.execute('SELECT USER FROM DUAL').scalar()) - - def _resolve_synonym(self, connection, desired_owner=None, desired_synonym=None, desired_table=None): - """search for a local synonym matching the given desired owner/name. -@@ -1167,7 +1167,7 @@ - local_cols.append(local_column) - remote_cols.append(remote_column) - -- return fkeys.values() -+ return list(fkeys.values()) - - @reflection.cache - def get_view_definition(self, connection, view_name, schema=None, -diff -r 9d0639b9d3be lib/sqlalchemy/dialects/oracle/cx_oracle.py ---- a/lib/sqlalchemy/dialects/oracle/cx_oracle.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/dialects/oracle/cx_oracle.py Sat Apr 27 19:42:17 2013 -0400 -@@ -182,7 +182,7 @@ - - """ - --from __future__ import absolute_import -+ - - from .base import OracleCompiler, OracleDialect, OracleExecutionContext - from . import base as oracle -@@ -268,20 +268,21 @@ - - - class _NativeUnicodeMixin(object): -- # Py3K -- #pass -- # Py2K -- def bind_processor(self, dialect): -- if dialect._cx_oracle_with_unicode: -- def process(value): -- if value is None: -- return value -- else: -- return unicode(value) -- return process -- else: -- return super(_NativeUnicodeMixin, self).bind_processor(dialect) -- # end Py2K -+# start Py3K -+ pass -+# end Py3K -+# start Py2K -+# def bind_processor(self, dialect): -+# if dialect._cx_oracle_with_unicode: -+# def process(value): -+# if value is None: -+# return value -+# else: -+# return unicode(value) -+# return process -+# else: -+# return super(_NativeUnicodeMixin, self).bind_processor(dialect) -+# end Py2K - - # we apply a connection output handler that returns - # unicode in all cases, so the "native_unicode" flag -@@ -391,10 +392,10 @@ - (fromname.encode(self.dialect.encoding), - toname.encode(self.dialect.encoding)) - for fromname, toname in -- quoted_bind_names.items() -+ list(quoted_bind_names.items()) - ) - for param in self.parameters: -- for fromname, toname in quoted_bind_names.items(): -+ for fromname, toname in list(quoted_bind_names.items()): - param[toname] = param[fromname] - del param[fromname] - -@@ -408,7 +409,7 @@ - - # if a single execute, check for outparams - if len(self.compiled_parameters) == 1: -- for bindparam in self.compiled.binds.values(): -+ for bindparam in list(self.compiled.binds.values()): - if bindparam.isoutparam: - dbtype = bindparam.type.dialect_impl(self.dialect).\ - get_dbapi_type(self.dialect.dbapi) -@@ -437,7 +438,7 @@ - if hasattr(self, 'out_parameters') and self.compiled.returning: - returning_params = dict( - (k, v.getvalue()) -- for k, v in self.out_parameters.items() -+ for k, v in list(self.out_parameters.items()) - ) - return ReturningResultProxy(self, returning_params) - -@@ -456,7 +457,7 @@ - len(self.compiled_parameters) == 1: - result.out_parameters = out_parameters = {} - -- for bind, name in self.compiled.bind_names.items(): -+ for bind, name in list(self.compiled.bind_names.items()): - if name in self.out_parameters: - type = bind.type - impl_type = type.dialect_impl(self.dialect) -@@ -472,7 +473,7 @@ - else: - result.out_parameters = dict( - (k, v.getvalue()) -- for k, v in self.out_parameters.items() -+ for k, v in list(self.out_parameters.items()) - ) - - return result -@@ -493,11 +494,11 @@ - """ - def __init__(self, *arg, **kw): - OracleExecutionContext_cx_oracle.__init__(self, *arg, **kw) -- self.statement = unicode(self.statement) -+ self.statement = str(self.statement) - - def _execute_scalar(self, stmt): - return super(OracleExecutionContext_cx_oracle_with_unicode, self).\ -- _execute_scalar(unicode(stmt)) -+ _execute_scalar(str(stmt)) - - - class ReturningResultProxy(_result.FullyBufferedResultProxy): -@@ -607,19 +608,19 @@ - self.supports_unicode_statements = True - self.supports_unicode_binds = True - self._cx_oracle_with_unicode = True -- # Py2K -- # There's really no reason to run with WITH_UNICODE under Python 2.x. -- # Give the user a hint. -- util.warn("cx_Oracle is compiled under Python 2.xx using the " -- "WITH_UNICODE flag. Consider recompiling cx_Oracle without " -- "this flag, which is in no way necessary for full support of Unicode. " -- "Otherwise, all string-holding bind parameters must " -- "be explicitly typed using SQLAlchemy's String type or one of its subtypes," -- "or otherwise be passed as Python unicode. Plain Python strings " -- "passed as bind parameters will be silently corrupted by cx_Oracle." -- ) -- self.execution_ctx_cls = OracleExecutionContext_cx_oracle_with_unicode -- # end Py2K -+# start Py2K -+# # There's really no reason to run with WITH_UNICODE under Python 2.x. -+# # Give the user a hint. -+# util.warn("cx_Oracle is compiled under Python 2.xx using the " -+# "WITH_UNICODE flag. Consider recompiling cx_Oracle without " -+# "this flag, which is in no way necessary for full support of Unicode. " -+# "Otherwise, all string-holding bind parameters must " -+# "be explicitly typed using SQLAlchemy's String type or one of its subtypes," -+# "or otherwise be passed as Python unicode. Plain Python strings " -+# "passed as bind parameters will be silently corrupted by cx_Oracle." -+# ) -+# self.execution_ctx_cls = OracleExecutionContext_cx_oracle_with_unicode -+# end Py2K - else: - self._cx_oracle_with_unicode = False - -@@ -731,7 +732,7 @@ - arraysize=cursor.arraysize) - # allow all strings to come back natively as Unicode - elif defaultType in (cx_Oracle.STRING, cx_Oracle.FIXED_CHAR): -- return cursor.var(unicode, size, cursor.arraysize) -+ return cursor.var(str, size, cursor.arraysize) - - def on_connect(conn): - conn.outputtypehandler = output_type_handler -@@ -766,20 +767,20 @@ - twophase=self.allow_twophase, - ) - -- # Py2K -- if self._cx_oracle_with_unicode: -- for k, v in opts.items(): -- if isinstance(v, str): -- opts[k] = unicode(v) -- else: -- for k, v in opts.items(): -- if isinstance(v, unicode): -- opts[k] = str(v) -- # end Py2K -+# start Py2K -+# if self._cx_oracle_with_unicode: -+# for k, v in opts.items(): -+# if isinstance(v, str): -+# opts[k] = unicode(v) -+# else: -+# for k, v in opts.items(): -+# if isinstance(v, unicode): -+# opts[k] = str(v) -+# end Py2K - - if 'mode' in url.query: - opts['mode'] = url.query['mode'] -- if isinstance(opts['mode'], basestring): -+ if isinstance(opts['mode'], str): - mode = opts['mode'].upper() - if mode == 'SYSDBA': - opts['mode'] = self.dbapi.SYSDBA -diff -r 9d0639b9d3be lib/sqlalchemy/dialects/oracle/zxjdbc.py ---- a/lib/sqlalchemy/dialects/oracle/zxjdbc.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/dialects/oracle/zxjdbc.py Sat Apr 27 19:42:17 2013 -0400 -@@ -95,8 +95,8 @@ - try: - try: - rrs = self.statement.__statement__.getReturnResultSet() -- rrs.next() -- except SQLException, sqle: -+ next(rrs) -+ except SQLException as sqle: - msg = '%s [SQLCode: %d]' % (sqle.getMessage(), sqle.getErrorCode()) - if sqle.getSQLState() is not None: - msg += ' [SQLState: %s]' % sqle.getSQLState() -diff -r 9d0639b9d3be lib/sqlalchemy/dialects/postgresql/base.py ---- a/lib/sqlalchemy/dialects/postgresql/base.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/dialects/postgresql/base.py Sat Apr 27 19:42:17 2013 -0400 -@@ -1419,7 +1419,7 @@ - query, - bindparams=[ - sql.bindparam( -- 'schema', unicode(schema.lower()), -+ 'schema', str(schema.lower()), - type_=sqltypes.Unicode)] - ) - ) -@@ -1435,7 +1435,7 @@ - "n.oid=c.relnamespace where n.nspname=current_schema() and " - "relname=:name", - bindparams=[ -- sql.bindparam('name', unicode(table_name), -+ sql.bindparam('name', str(table_name), - type_=sqltypes.Unicode)] - ) - ) -@@ -1447,9 +1447,9 @@ - "relname=:name", - bindparams=[ - sql.bindparam('name', -- unicode(table_name), type_=sqltypes.Unicode), -+ str(table_name), type_=sqltypes.Unicode), - sql.bindparam('schema', -- unicode(schema), type_=sqltypes.Unicode)] -+ str(schema), type_=sqltypes.Unicode)] - ) - ) - return bool(cursor.first()) -@@ -1463,7 +1463,7 @@ - "n.nspname=current_schema() " - "and relname=:name", - bindparams=[ -- sql.bindparam('name', unicode(sequence_name), -+ sql.bindparam('name', str(sequence_name), - type_=sqltypes.Unicode) - ] - ) -@@ -1475,10 +1475,10 @@ - "n.oid=c.relnamespace where relkind='S' and " - "n.nspname=:schema and relname=:name", - bindparams=[ -- sql.bindparam('name', unicode(sequence_name), -+ sql.bindparam('name', str(sequence_name), - type_=sqltypes.Unicode), - sql.bindparam('schema', -- unicode(schema), type_=sqltypes.Unicode) -+ str(schema), type_=sqltypes.Unicode) - ] - ) - ) -@@ -1488,9 +1488,9 @@ - def has_type(self, connection, type_name, schema=None): - bindparams = [ - sql.bindparam('typname', -- unicode(type_name), type_=sqltypes.Unicode), -+ str(type_name), type_=sqltypes.Unicode), - sql.bindparam('nspname', -- unicode(schema), type_=sqltypes.Unicode), -+ str(schema), type_=sqltypes.Unicode), - ] - if schema is not None: - query = """ -@@ -1546,9 +1546,9 @@ - """ % schema_where_clause - # Since we're binding to unicode, table_name and schema_name must be - # unicode. -- table_name = unicode(table_name) -+ table_name = str(table_name) - if schema is not None: -- schema = unicode(schema) -+ schema = str(schema) - s = sql.text(query, bindparams=[ - sql.bindparam('table_name', type_=sqltypes.Unicode), - sql.bindparam('schema', type_=sqltypes.Unicode) -@@ -1570,13 +1570,14 @@ - """ - rp = connection.execute(s) - # what about system tables? -- # Py3K -- #schema_names = [row[0] for row in rp \ -- # if not row[0].startswith('pg_')] -- # Py2K -- schema_names = [row[0].decode(self.encoding) for row in rp \ -+# start Py3K -+ schema_names = [row[0] for row in rp \ - if not row[0].startswith('pg_')] -- # end Py2K -+# end Py3K -+# start Py2K -+# schema_names = [row[0].decode(self.encoding) for row in rp \ -+# if not row[0].startswith('pg_')] -+# end Py2K - return schema_names - - @reflection.cache -@@ -1587,7 +1588,7 @@ - current_schema = self.default_schema_name - - result = connection.execute( -- sql.text(u"SELECT relname FROM pg_class c " -+ sql.text("SELECT relname FROM pg_class c " - "WHERE relkind = 'r' " - "AND '%s' = (select nspname from pg_namespace n " - "where n.oid = c.relnamespace) " % -@@ -1610,12 +1611,13 @@ - AND '%(schema)s' = (select nspname from pg_namespace n - where n.oid = c.relnamespace) - """ % dict(schema=current_schema) -- # Py3K -- #view_names = [row[0] for row in connection.execute(s)] -- # Py2K -- view_names = [row[0].decode(self.encoding) -- for row in connection.execute(s)] -- # end Py2K -+# start Py3K -+ view_names = [row[0] for row in connection.execute(s)] -+# end Py3K -+# start Py2K -+# view_names = [row[0].decode(self.encoding) -+# for row in connection.execute(s)] -+# end Py2K - return view_names - - @reflection.cache -@@ -1632,11 +1634,12 @@ - rp = connection.execute(sql.text(s), - view_name=view_name, schema=current_schema) - if rp: -- # Py3K -- #view_def = rp.scalar() -- # Py2K -- view_def = rp.scalar().decode(self.encoding) -- # end Py2K -+# start Py3K -+ view_def = rp.scalar() -+# end Py3K -+# start Py2K -+# view_def = rp.scalar().decode(self.encoding) -+# end Py2K - return view_def - - @reflection.cache -diff -r 9d0639b9d3be lib/sqlalchemy/dialects/postgresql/hstore.py ---- a/lib/sqlalchemy/dialects/postgresql/hstore.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/dialects/postgresql/hstore.py Sat Apr 27 19:42:17 2013 -0400 -@@ -96,14 +96,14 @@ - def esc(s, position): - if position == 'value' and s is None: - return 'NULL' -- elif isinstance(s, basestring): -+ elif isinstance(s, str): - return '"%s"' % s.replace('"', r'\"') - else: - raise ValueError("%r in %s position is not a string." % - (s, position)) - - return ', '.join('%s=>%s' % (esc(k, 'key'), esc(v, 'value')) -- for k, v in val.iteritems()) -+ for k, v in val.items()) - - - class HSTORE(sqltypes.Concatenable, sqltypes.TypeEngine): -diff -r 9d0639b9d3be lib/sqlalchemy/dialects/postgresql/psycopg2.py ---- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py Sat Apr 27 19:42:17 2013 -0400 -@@ -142,7 +142,7 @@ - effect for other DBAPIs. - - """ --from __future__ import absolute_import -+ - import re - import logging - -@@ -190,22 +190,22 @@ - class _PGEnum(ENUM): - def __init__(self, *arg, **kw): - super(_PGEnum, self).__init__(*arg, **kw) -- # Py2K -- if self.convert_unicode: -- self.convert_unicode = "force" -- # end Py2K -+# start Py2K -+# if self.convert_unicode: -+# self.convert_unicode = "force" -+# end Py2K - - - class _PGArray(ARRAY): - def __init__(self, *arg, **kw): - super(_PGArray, self).__init__(*arg, **kw) -- # Py2K -- # FIXME: this check won't work for setups that -- # have convert_unicode only on their create_engine(). -- if isinstance(self.item_type, sqltypes.String) and \ -- self.item_type.convert_unicode: -- self.item_type.convert_unicode = "force" -- # end Py2K -+# start Py2K -+# # FIXME: this check won't work for setups that -+# # have convert_unicode only on their create_engine(). -+# if isinstance(self.item_type, sqltypes.String) and \ -+# self.item_type.convert_unicode: -+# self.item_type.convert_unicode = "force" -+# end Py2K - - - class _PGHStore(HSTORE): -@@ -294,9 +294,9 @@ - - class PGDialect_psycopg2(PGDialect): - driver = 'psycopg2' -- # Py2K -- supports_unicode_statements = False -- # end Py2K -+# start Py2K -+# supports_unicode_statements = False -+# end Py2K - default_paramstyle = 'pyformat' - supports_sane_multi_rowcount = False - execution_ctx_cls = PGExecutionContext_psycopg2 -diff -r 9d0639b9d3be lib/sqlalchemy/dialects/sqlite/base.py ---- a/lib/sqlalchemy/dialects/sqlite/base.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/dialects/sqlite/base.py Sat Apr 27 19:42:17 2013 -0400 -@@ -508,7 +508,7 @@ - - def visit_foreign_key_constraint(self, constraint): - -- local_table = constraint._elements.values()[0].parent.table -+ local_table = list(constraint._elements.values())[0].parent.table - remote_table = list(constraint._elements.values())[0].column.table - - if local_table.schema != remote_table.schema: -@@ -812,7 +812,7 @@ - coltype = sqltypes.NullType() - - if default is not None: -- default = unicode(default) -+ default = str(default) - - return { - 'name': name, -diff -r 9d0639b9d3be lib/sqlalchemy/dialects/sqlite/pysqlite.py ---- a/lib/sqlalchemy/dialects/sqlite/pysqlite.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/dialects/sqlite/pysqlite.py Sat Apr 27 19:42:17 2013 -0400 -@@ -267,8 +267,9 @@ - } - ) - -- # Py3K -- #description_encoding = None -+# start Py3K -+ description_encoding = None -+# end Py3K - - driver = 'pysqlite' - -@@ -288,7 +289,7 @@ - def dbapi(cls): - try: - from pysqlite2 import dbapi2 as sqlite -- except ImportError, e: -+ except ImportError as e: - try: - from sqlite3 import dbapi2 as sqlite # try 2.5+ stdlib name. - except ImportError: -diff -r 9d0639b9d3be lib/sqlalchemy/dialects/sybase/__init__.py ---- a/lib/sqlalchemy/dialects/sybase/__init__.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/dialects/sybase/__init__.py Sat Apr 27 19:42:17 2013 -0400 -@@ -9,7 +9,7 @@ - # default dialect - base.dialect = pyodbc.dialect - --from base import CHAR, VARCHAR, TIME, NCHAR, NVARCHAR,\ -+from .base import CHAR, VARCHAR, TIME, NCHAR, NVARCHAR,\ - TEXT, DATE, DATETIME, FLOAT, NUMERIC,\ - BIGINT, INT, INTEGER, SMALLINT, BINARY,\ - VARBINARY, UNITEXT, UNICHAR, UNIVARCHAR,\ -diff -r 9d0639b9d3be lib/sqlalchemy/dialects/sybase/base.py ---- a/lib/sqlalchemy/dialects/sybase/base.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/dialects/sybase/base.py Sat Apr 27 19:42:17 2013 -0400 -@@ -475,12 +475,12 @@ - AND o.type in ('U', 'V') - """) - -- # Py2K -- if isinstance(schema, unicode): -- schema = schema.encode("ascii") -- if isinstance(table_name, unicode): -- table_name = table_name.encode("ascii") -- # end Py2K -+# start Py2K -+# if isinstance(schema, unicode): -+# schema = schema.encode("ascii") -+# if isinstance(table_name, unicode): -+# table_name = table_name.encode("ascii") -+# end Py2K - result = connection.execute(TABLEID_SQL, - schema_name=schema, - table_name=table_name) -@@ -759,10 +759,10 @@ - AND o.type = 'U' - """) - -- # Py2K -- if isinstance(schema, unicode): -- schema = schema.encode("ascii") -- # end Py2K -+# start Py2K -+# if isinstance(schema, unicode): -+# schema = schema.encode("ascii") -+# end Py2K - tables = connection.execute(TABLE_SQL, schema_name=schema) - - return [t["name"] for t in tables] -@@ -779,10 +779,10 @@ - AND o.type = 'V' - """) - -- # Py2K -- if isinstance(view_name, unicode): -- view_name = view_name.encode("ascii") -- # end Py2K -+# start Py2K -+# if isinstance(view_name, unicode): -+# view_name = view_name.encode("ascii") -+# end Py2K - view = connection.execute(VIEW_DEF_SQL, view_name=view_name) - - return view.scalar() -@@ -799,10 +799,10 @@ - AND o.type = 'V' - """) - -- # Py2K -- if isinstance(schema, unicode): -- schema = schema.encode("ascii") -- # end Py2K -+# start Py2K -+# if isinstance(schema, unicode): -+# schema = schema.encode("ascii") -+# end Py2K - views = connection.execute(VIEW_SQL, schema_name=schema) - - return [v["name"] for v in views] -diff -r 9d0639b9d3be lib/sqlalchemy/engine/base.py ---- a/lib/sqlalchemy/engine/base.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/engine/base.py Sat Apr 27 19:42:17 2013 -0400 -@@ -9,7 +9,7 @@ - - """ - --from __future__ import with_statement -+ - import sys - from .. import exc, schema, util, log, interfaces - from ..sql import expression, util as sql_util -@@ -460,7 +460,7 @@ - - try: - self.engine.dialect.do_begin(self.connection) -- except Exception, e: -+ except Exception as e: - self._handle_dbapi_exception(e, None, None, None, None) - - def _rollback_impl(self): -@@ -473,7 +473,7 @@ - try: - self.engine.dialect.do_rollback(self.connection) - self.__transaction = None -- except Exception, e: -+ except Exception as e: - self._handle_dbapi_exception(e, None, None, None, None) - else: - self.__transaction = None -@@ -487,7 +487,7 @@ - try: - self.engine.dialect.do_commit(self.connection) - self.__transaction = None -- except Exception, e: -+ except Exception as e: - self._handle_dbapi_exception(e, None, None, None, None) - - def _savepoint_impl(self, name=None): -@@ -688,7 +688,7 @@ - dialect = self.dialect - ctx = dialect.execution_ctx_cls._init_default( - dialect, self, conn) -- except Exception, e: -+ except Exception as e: - self._handle_dbapi_exception(e, None, None, None, None) - - ret = ctx._exec_default(default, None) -@@ -734,7 +734,7 @@ - - distilled_params = _distill_params(multiparams, params) - if distilled_params: -- keys = distilled_params[0].keys() -+ keys = list(distilled_params[0].keys()) - else: - keys = [] - -@@ -822,7 +822,7 @@ - conn = self._revalidate_connection() - - context = constructor(dialect, self, conn, *args) -- except Exception, e: -+ except Exception as e: - self._handle_dbapi_exception(e, - str(statement), parameters, - None, None) -@@ -865,7 +865,7 @@ - statement, - parameters, - context) -- except Exception, e: -+ except Exception as e: - self._handle_dbapi_exception( - e, - statement, -@@ -939,7 +939,7 @@ - cursor, - statement, - parameters) -- except Exception, e: -+ except Exception as e: - self._handle_dbapi_exception( - e, - statement, -@@ -954,7 +954,7 @@ - """ - try: - cursor.close() -- except Exception, e: -+ except Exception as e: - try: - ex_text = str(e) - except TypeError: -@@ -1045,7 +1045,7 @@ - Compiled: _execute_compiled, - schema.SchemaItem: _execute_default, - schema.DDLElement: _execute_ddl, -- basestring: _execute_text -+ str: _execute_text - } - - def default_schema_name(self): -diff -r 9d0639b9d3be lib/sqlalchemy/engine/ddl.py ---- a/lib/sqlalchemy/engine/ddl.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/engine/ddl.py Sat Apr 27 19:42:17 2013 -0400 -@@ -52,10 +52,10 @@ - if self.tables is not None: - tables = self.tables - else: -- tables = metadata.tables.values() -+ tables = list(metadata.tables.values()) - collection = [t for t in sql_util.sort_tables(tables) - if self._can_create_table(t)] -- seq_coll = [s for s in metadata._sequences.values() -+ seq_coll = [s for s in list(metadata._sequences.values()) - if s.column is None and self._can_create_sequence(s)] - - metadata.dispatch.before_create(metadata, self.connection, -@@ -120,7 +120,7 @@ - if self.tables is not None: - tables = self.tables - else: -- tables = metadata.tables.values() -+ tables = list(metadata.tables.values()) - - collection = [ - t -@@ -130,7 +130,7 @@ - - seq_coll = [ - s -- for s in metadata._sequences.values() -+ for s in list(metadata._sequences.values()) - if s.column is None and self._can_drop_sequence(s) - ] - -diff -r 9d0639b9d3be lib/sqlalchemy/engine/default.py ---- a/lib/sqlalchemy/engine/default.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/engine/default.py Sat Apr 27 19:42:17 2013 -0400 -@@ -57,17 +57,18 @@ - # *not* the FLOAT type however. - supports_native_decimal = False - -- # Py3K -- #supports_unicode_statements = True -- #supports_unicode_binds = True -- #returns_unicode_strings = True -- #description_encoding = None -- # Py2K -- supports_unicode_statements = False -- supports_unicode_binds = False -- returns_unicode_strings = False -- description_encoding = 'use_encoding' -- # end Py2K -+# start Py3K -+ supports_unicode_statements = True -+ supports_unicode_binds = True -+ returns_unicode_strings = True -+ description_encoding = None -+# end Py3K -+# start Py2K -+# supports_unicode_statements = False -+# supports_unicode_binds = False -+# returns_unicode_strings = False -+# description_encoding = 'use_encoding' -+# end Py2K - - name = 'default' - -@@ -201,14 +202,15 @@ - return None - - def _check_unicode_returns(self, connection): -- # Py2K -- if self.supports_unicode_statements: -- cast_to = unicode -- else: -- cast_to = str -- # end Py2K -- # Py3K -- #cast_to = str -+# start Py2K -+# if self.supports_unicode_statements: -+# cast_to = unicode -+# else: -+# cast_to = str -+# end Py2K -+# start Py3K -+ cast_to = str -+# end Py3K - - def check_unicode(formatstr, type_): - cursor = connection.connection.cursor() -@@ -226,8 +228,8 @@ - ) - row = cursor.fetchone() - -- return isinstance(row[0], unicode) -- except self.dbapi.Error, de: -+ return isinstance(row[0], str) -+ except self.dbapi.Error as de: - util.warn("Exception attempting to " - "detect unicode returns: %r" % de) - return False -@@ -373,10 +375,10 @@ - self.execution_options.update(connection._execution_options) - - if not dialect.supports_unicode_statements: -- self.unicode_statement = unicode(compiled) -+ self.unicode_statement = str(compiled) - self.statement = dialect._encoder(self.unicode_statement)[0] - else: -- self.statement = self.unicode_statement = unicode(compiled) -+ self.statement = self.unicode_statement = str(compiled) - - self.cursor = self.create_cursor() - self.compiled_parameters = [] -@@ -414,7 +416,7 @@ - - self.result_map = compiled.result_map - -- self.unicode_statement = unicode(compiled) -+ self.unicode_statement = str(compiled) - if not dialect.supports_unicode_statements: - self.statement = self.unicode_statement.encode( - self.dialect.encoding) -@@ -519,7 +521,7 @@ - self.executemany = len(parameters) > 1 - - if not dialect.supports_unicode_statements and \ -- isinstance(statement, unicode): -+ isinstance(statement, str): - self.unicode_statement = statement - self.statement = dialect._encoder(statement)[0] - else: -@@ -573,7 +575,7 @@ - """ - - conn = self.root_connection -- if isinstance(stmt, unicode) and \ -+ if isinstance(stmt, str) and \ - not self.dialect.supports_unicode_statements: - stmt = self.dialect._encoder(stmt)[0] - -@@ -734,12 +736,12 @@ - inputsizes.append(dbtype) - try: - self.cursor.setinputsizes(*inputsizes) -- except Exception, e: -+ except Exception as e: - self.root_connection._handle_dbapi_exception( - e, None, None, None, self) - else: - inputsizes = {} -- for key in self.compiled.bind_names.values(): -+ for key in list(self.compiled.bind_names.values()): - typeengine = types[key] - dbtype = typeengine.dialect_impl(self.dialect).\ - get_dbapi_type(self.dialect.dbapi) -@@ -752,7 +754,7 @@ - inputsizes[key] = dbtype - try: - self.cursor.setinputsizes(**inputsizes) -- except Exception, e: -+ except Exception as e: - self.root_connection._handle_dbapi_exception( - e, None, None, None, self) - -diff -r 9d0639b9d3be lib/sqlalchemy/engine/reflection.py ---- a/lib/sqlalchemy/engine/reflection.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/engine/reflection.py Sat Apr 27 19:42:17 2013 -0400 -@@ -41,8 +41,8 @@ - return fn(self, con, *args, **kw) - key = ( - fn.__name__, -- tuple(a for a in args if isinstance(a, basestring)), -- tuple((k, v) for k, v in kw.iteritems() if isinstance(v, (basestring, int, float))) -+ tuple(a for a in args if isinstance(a, str)), -+ tuple((k, v) for k, v in kw.items() if isinstance(v, (str, int, float))) - ) - ret = info_cache.get(key) - if ret is None: -@@ -381,16 +381,16 @@ - # table.kwargs will need to be passed to each reflection method. Make - # sure keywords are strings. - tblkw = table.kwargs.copy() -- for (k, v) in tblkw.items(): -+ for (k, v) in list(tblkw.items()): - del tblkw[k] - tblkw[str(k)] = v - -- # Py2K -- if isinstance(schema, str): -- schema = schema.decode(dialect.encoding) -- if isinstance(table_name, str): -- table_name = table_name.decode(dialect.encoding) -- # end Py2K -+# start Py2K -+# if isinstance(schema, str): -+# schema = schema.decode(dialect.encoding) -+# if isinstance(table_name, str): -+# table_name = table_name.decode(dialect.encoding) -+# end Py2K - - # columns - found_table = False -diff -r 9d0639b9d3be lib/sqlalchemy/engine/result.py ---- a/lib/sqlalchemy/engine/result.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/engine/result.py Sat Apr 27 19:42:17 2013 -0400 -@@ -8,7 +8,7 @@ - and :class:`.RowProxy.""" - - --from itertools import izip -+ - from .. import exc, types, util - from ..sql import expression - import collections -@@ -55,7 +55,7 @@ - return list(self) - - def __iter__(self): -- for processor, value in izip(self._processors, self._row): -+ for processor, value in zip(self._processors, self._row): - if processor is None: - yield value - else: -@@ -72,7 +72,7 @@ - except TypeError: - if isinstance(key, slice): - l = [] -- for processor, value in izip(self._processors[key], -+ for processor, value in zip(self._processors[key], - self._row[key]): - if processor is None: - l.append(value) -@@ -93,7 +93,7 @@ - def __getattr__(self, name): - try: - return self[name] -- except KeyError, e: -+ except KeyError as e: - raise AttributeError(e.args[0]) - - -@@ -142,7 +142,7 @@ - def items(self): - """Return a list of tuples, each tuple containing a key/value pair.""" - # TODO: no coverage here -- return [(key, self[key]) for key in self.iterkeys()] -+ return [(key, self[key]) for key in self.keys()] - - def keys(self): - """Return the list of keys as strings represented by this RowProxy.""" -@@ -274,7 +274,7 @@ - def _key_fallback(self, key, raiseerr=True): - map = self._keymap - result = None -- if isinstance(key, basestring): -+ if isinstance(key, str): - result = map.get(key if self.case_sensitive else key.lower()) - # fallback for targeting a ColumnElement to a textual expression - # this is a rare use case which only occurs when matching text() -@@ -328,8 +328,8 @@ - return { - '_pickled_keymap': dict( - (key, index) -- for key, (processor, obj, index) in self._keymap.iteritems() -- if isinstance(key, (basestring, int)) -+ for key, (processor, obj, index) in self._keymap.items() -+ if isinstance(key, (str, int)) - ), - 'keys': self.keys, - "case_sensitive": self.case_sensitive, -@@ -338,9 +338,9 @@ - def __setstate__(self, state): - # the row has been processed at pickling time so we don't need any - # processor anymore -- self._processors = [None for _ in xrange(len(state['keys']))] -+ self._processors = [None for _ in range(len(state['keys']))] - self._keymap = keymap = {} -- for key, index in state['_pickled_keymap'].iteritems(): -+ for key, index in state['_pickled_keymap'].items(): - # not preserving "obj" here, unfortunately our - # proxy comparison fails with the unpickle - keymap[key] = (None, None, index) -@@ -440,7 +440,7 @@ - """ - try: - return self.context.rowcount -- except Exception, e: -+ except Exception as e: - self.connection._handle_dbapi_exception( - e, None, None, self.cursor, self.context) - -@@ -462,7 +462,7 @@ - """ - try: - return self._saved_cursor.lastrowid -- except Exception, e: -+ except Exception as e: - self.connection._handle_dbapi_exception( - e, None, None, - self._saved_cursor, self.context) -@@ -746,7 +746,7 @@ - l = self.process_rows(self._fetchall_impl()) - self.close() - return l -- except Exception, e: -+ except Exception as e: - self.connection._handle_dbapi_exception( - e, None, None, - self.cursor, self.context) -@@ -765,7 +765,7 @@ - if len(l) == 0: - self.close() - return l -- except Exception, e: -+ except Exception as e: - self.connection._handle_dbapi_exception( - e, None, None, - self.cursor, self.context) -@@ -784,7 +784,7 @@ - else: - self.close() - return None -- except Exception, e: -+ except Exception as e: - self.connection._handle_dbapi_exception( - e, None, None, - self.cursor, self.context) -@@ -800,7 +800,7 @@ - - try: - row = self._fetchone_impl() -- except Exception, e: -+ except Exception as e: - self.connection._handle_dbapi_exception( - e, None, None, - self.cursor, self.context) -@@ -966,9 +966,9 @@ - # constructed. - metadata._orig_processors = metadata._processors - # replace the all type processors by None processors. -- metadata._processors = [None for _ in xrange(len(metadata.keys))] -+ metadata._processors = [None for _ in range(len(metadata.keys))] - keymap = {} -- for k, (func, obj, index) in metadata._keymap.iteritems(): -+ for k, (func, obj, index) in metadata._keymap.items(): - keymap[k] = (None, obj, index) - self._metadata._keymap = keymap - -@@ -989,7 +989,7 @@ - if size is None: - return self.fetchall() - l = [] -- for i in xrange(size): -+ for i in range(size): - row = self.fetchone() - if row is None: - break -diff -r 9d0639b9d3be lib/sqlalchemy/engine/strategies.py ---- a/lib/sqlalchemy/engine/strategies.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/engine/strategies.py Sat Apr 27 19:42:17 2013 -0400 -@@ -78,20 +78,21 @@ - def connect(): - try: - return dialect.connect(*cargs, **cparams) -- except Exception, e: -+ except Exception as e: - invalidated = dialect.is_disconnect(e, None, None) -- # Py3K -- #raise exc.DBAPIError.instance(None, None, -- # e, dialect.dbapi.Error, -- # connection_invalidated=invalidated -- #) from e -- # Py2K -- import sys -- raise exc.DBAPIError.instance( -- None, None, e, dialect.dbapi.Error, -+# start Py3K -+ raise exc.DBAPIError.instance(None, None, -+ e, dialect.dbapi.Error, - connection_invalidated=invalidated -- ), None, sys.exc_info()[2] -- # end Py2K -+ ) from e -+# end Py3K -+# start Py2K -+# import sys -+# raise exc.DBAPIError.instance( -+# None, None, e, dialect.dbapi.Error, -+# connection_invalidated=invalidated -+# ), None, sys.exc_info()[2] -+# end Py2K - - creator = kwargs.pop('creator', connect) - -diff -r 9d0639b9d3be lib/sqlalchemy/engine/url.py ---- a/lib/sqlalchemy/engine/url.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/engine/url.py Sat Apr 27 19:42:17 2013 -0400 -@@ -14,7 +14,7 @@ - """ - - import re --import urllib -+import urllib.request, urllib.parse, urllib.error - from .. import exc, util - from . import Dialect - -@@ -67,7 +67,7 @@ - if self.username is not None: - s += self.username - if self.password is not None: -- s += ':' + urllib.quote_plus(self.password) -+ s += ':' + urllib.parse.quote_plus(self.password) - s += "@" - if self.host is not None: - s += self.host -@@ -76,7 +76,7 @@ - if self.database is not None: - s += '/' + self.database - if self.query: -- keys = self.query.keys() -+ keys = list(self.query.keys()) - keys.sort() - s += '?' + "&".join("%s=%s" % (k, self.query[k]) for k in keys) - return s -@@ -150,7 +150,7 @@ - existing URL object is passed, just returns the object. - """ - -- if isinstance(name_or_url, basestring): -+ if isinstance(name_or_url, str): - return _parse_rfc1738_args(name_or_url) - else: - return name_or_url -@@ -177,17 +177,17 @@ - tokens = components['database'].split('?', 2) - components['database'] = tokens[0] - query = (len(tokens) > 1 and dict(util.parse_qsl(tokens[1]))) or None -- # Py2K -- if query is not None: -- query = dict((k.encode('ascii'), query[k]) for k in query) -- # end Py2K -+# start Py2K -+# if query is not None: -+# query = dict((k.encode('ascii'), query[k]) for k in query) -+# end Py2K - else: - query = None - components['query'] = query - - if components['password'] is not None: - components['password'] = \ -- urllib.unquote_plus(components['password']) -+ urllib.parse.unquote_plus(components['password']) - - name = components.pop('name') - return URL(name, **components) -diff -r 9d0639b9d3be lib/sqlalchemy/event.py ---- a/lib/sqlalchemy/event.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/event.py Sat Apr 27 19:42:17 2013 -0400 -@@ -201,11 +201,9 @@ - del _registrars[k] - - --class Events(object): -+class Events(object, metaclass=_EventMeta): - """Define event listening functions for a particular target type.""" - -- __metaclass__ = _EventMeta -- - @classmethod - def _accept_with(cls, target): - # Mapper, ClassManager, Session override this to -@@ -302,7 +300,7 @@ - def clear(self): - """Clear all class level listeners""" - -- for dispatcher in self._clslevel.values(): -+ for dispatcher in list(self._clslevel.values()): - dispatcher[:] = [] - - def for_modify(self, obj): -@@ -377,7 +375,7 @@ - def __iter__(self): - return iter(self.parent_listeners) - -- def __nonzero__(self): -+ def __bool__(self): - return bool(self.parent_listeners) - - -@@ -414,7 +412,7 @@ - def __iter__(self): - return chain(self.parent_listeners, self.listeners) - -- def __nonzero__(self): -+ def __bool__(self): - return bool(self.listeners or self.parent_listeners) - - -diff -r 9d0639b9d3be lib/sqlalchemy/exc.py ---- a/lib/sqlalchemy/exc.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/exc.py Sat Apr 27 19:42:17 2013 -0400 -@@ -285,7 +285,7 @@ - text = str(orig) - except (KeyboardInterrupt, SystemExit): - raise -- except Exception, e: -+ except Exception as e: - text = 'Error in str() of DB-API-generated exception: ' + str(e) - StatementError.__init__( - self, -diff -r 9d0639b9d3be lib/sqlalchemy/ext/associationproxy.py ---- a/lib/sqlalchemy/ext/associationproxy.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/ext/associationproxy.py Sat Apr 27 19:42:17 2013 -0400 -@@ -475,7 +475,7 @@ - def __len__(self): - return len(self.col) - -- def __nonzero__(self): -+ def __bool__(self): - return bool(self.col) - - def __getstate__(self): -@@ -514,7 +514,7 @@ - stop = index.stop - step = index.step or 1 - -- rng = range(index.start or 0, stop, step) -+ rng = list(range(index.start or 0, stop, step)) - if step == 1: - for i in rng: - del self[index.start] -@@ -569,7 +569,7 @@ - - def count(self, value): - return sum([1 for _ in -- itertools.ifilter(lambda v: v == value, iter(self))]) -+ filter(lambda v: v == value, iter(self))]) - - def extend(self, values): - for v in values: -@@ -668,8 +668,8 @@ - def __hash__(self): - raise TypeError("%s objects are unhashable" % type(self).__name__) - -- for func_name, func in locals().items(): -- if (util.callable(func) and func.func_name == func_name and -+ for func_name, func in list(locals().items()): -+ if (util.callable(func) and func.__name__ == func_name and - not func.__doc__ and hasattr(list, func_name)): - func.__doc__ = getattr(list, func_name).__doc__ - del func_name, func -@@ -711,7 +711,7 @@ - return key in self.col - - def __iter__(self): -- return self.col.iterkeys() -+ return iter(self.col.keys()) - - def clear(self): - self.col.clear() -@@ -738,7 +738,7 @@ - return cmp(dict(self), other) - - def __repr__(self): -- return repr(dict(self.items())) -+ return repr(dict(list(self.items()))) - - def get(self, key, default=None): - try: -@@ -754,13 +754,13 @@ - return self[key] - - def keys(self): -- return self.col.keys() -+ return list(self.col.keys()) - - def iterkeys(self): -- return self.col.iterkeys() -+ return iter(self.col.keys()) - - def values(self): -- return [self._get(member) for member in self.col.values()] -+ return [self._get(member) for member in list(self.col.values())] - - def itervalues(self): - for key in self.col: -@@ -811,13 +811,13 @@ - self[key] = value - - def copy(self): -- return dict(self.items()) -+ return dict(list(self.items())) - - def __hash__(self): - raise TypeError("%s objects are unhashable" % type(self).__name__) - -- for func_name, func in locals().items(): -- if (util.callable(func) and func.func_name == func_name and -+ for func_name, func in list(locals().items()): -+ if (util.callable(func) and func.__name__ == func_name and - not func.__doc__ and hasattr(dict, func_name)): - func.__doc__ = getattr(dict, func_name).__doc__ - del func_name, func -@@ -838,7 +838,7 @@ - def __len__(self): - return len(self.col) - -- def __nonzero__(self): -+ def __bool__(self): - if self.col: - return True - else: -@@ -1014,8 +1014,8 @@ - def __hash__(self): - raise TypeError("%s objects are unhashable" % type(self).__name__) - -- for func_name, func in locals().items(): -- if (util.callable(func) and func.func_name == func_name and -+ for func_name, func in list(locals().items()): -+ if (util.callable(func) and func.__name__ == func_name and - not func.__doc__ and hasattr(set, func_name)): - func.__doc__ = getattr(set, func_name).__doc__ - del func_name, func -diff -r 9d0639b9d3be lib/sqlalchemy/ext/declarative/api.py ---- a/lib/sqlalchemy/ext/declarative/api.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/ext/declarative/api.py Sat Apr 27 19:42:17 2013 -0400 -@@ -424,7 +424,7 @@ - def prepare(cls, engine): - """Reflect all :class:`.Table` objects for all current - :class:`.DeferredReflection` subclasses""" -- to_map = [m for m in _MapperConfig.configs.values() -+ to_map = [m for m in list(_MapperConfig.configs.values()) - if issubclass(m.cls, cls)] - for thingy in to_map: - cls._sa_decl_prepare(thingy.local_table, engine) -diff -r 9d0639b9d3be lib/sqlalchemy/ext/declarative/base.py ---- a/lib/sqlalchemy/ext/declarative/base.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/ext/declarative/base.py Sat Apr 27 19:42:17 2013 -0400 -@@ -57,7 +57,7 @@ - - class_mapped = _declared_mapping_info(base) is not None - -- for name, obj in vars(base).items(): -+ for name, obj in list(vars(base).items()): - if name == '__mapper_args__': - if not mapper_args_fn and ( - not class_mapped or -@@ -129,7 +129,7 @@ - ret.doc = obj.__doc__ - - # apply inherited columns as we should -- for k, v in potential_columns.items(): -+ for k, v in list(potential_columns.items()): - dict_[k] = v - - if inherited_table_args and not tablename: -@@ -173,7 +173,7 @@ - - # extract columns from the class dict - declared_columns = set() -- for key, c in our_stuff.iteritems(): -+ for key, c in our_stuff.items(): - if isinstance(c, (ColumnProperty, CompositeProperty)): - for col in c.columns: - if isinstance(col, Column) and \ -@@ -354,7 +354,7 @@ - # in which case the mapper makes this combination). - # See if the superclass has a similar column property. - # If so, join them together. -- for k, col in properties.items(): -+ for k, col in list(properties.items()): - if not isinstance(col, expression.ColumnElement): - continue - if k in inherited_mapper._props: -diff -r 9d0639b9d3be lib/sqlalchemy/ext/declarative/clsregistry.py ---- a/lib/sqlalchemy/ext/declarative/clsregistry.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/ext/declarative/clsregistry.py Sat Apr 27 19:42:17 2013 -0400 -@@ -255,7 +255,7 @@ - return x.cls - else: - return x -- except NameError, n: -+ except NameError as n: - raise exc.InvalidRequestError( - "When initializing mapper %s, expression %r failed to " - "locate a name (%r). If this is a class name, consider " -@@ -275,14 +275,14 @@ - for attr in ('argument', 'order_by', 'primaryjoin', 'secondaryjoin', - 'secondary', '_user_defined_foreign_keys', 'remote_side'): - v = getattr(prop, attr) -- if isinstance(v, basestring): -+ if isinstance(v, str): - setattr(prop, attr, resolve_arg(v)) - - if prop.backref and isinstance(prop.backref, tuple): - key, kwargs = prop.backref - for attr in ('primaryjoin', 'secondaryjoin', 'secondary', - 'foreign_keys', 'remote_side', 'order_by'): -- if attr in kwargs and isinstance(kwargs[attr], basestring): -+ if attr in kwargs and isinstance(kwargs[attr], str): - kwargs[attr] = resolve_arg(kwargs[attr]) - - return prop -diff -r 9d0639b9d3be lib/sqlalchemy/ext/mutable.py ---- a/lib/sqlalchemy/ext/mutable.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/ext/mutable.py Sat Apr 27 19:42:17 2013 -0400 -@@ -485,7 +485,7 @@ - def changed(self): - """Subclasses should call this method whenever change events occur.""" - -- for parent, key in self._parents.items(): -+ for parent, key in list(self._parents.items()): - flag_modified(parent, key) - - @classmethod -@@ -579,7 +579,7 @@ - def changed(self): - """Subclasses should call this method whenever change events occur.""" - -- for parent, key in self._parents.items(): -+ for parent, key in list(self._parents.items()): - - prop = object_mapper(parent).get_property(key) - for value, attr_name in zip( -diff -r 9d0639b9d3be lib/sqlalchemy/ext/orderinglist.py ---- a/lib/sqlalchemy/ext/orderinglist.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/ext/orderinglist.py Sat Apr 27 19:42:17 2013 -0400 -@@ -324,7 +324,7 @@ - if stop < 0: - stop += len(self) - -- for i in xrange(start, stop, step): -+ for i in range(start, stop, step): - self.__setitem__(i, entity[i]) - else: - self._order_entity(index, entity, True) -@@ -334,21 +334,21 @@ - super(OrderingList, self).__delitem__(index) - self._reorder() - -- # Py2K -- def __setslice__(self, start, end, values): -- super(OrderingList, self).__setslice__(start, end, values) -- self._reorder() -- -- def __delslice__(self, start, end): -- super(OrderingList, self).__delslice__(start, end) -- self._reorder() -- # end Py2K -+# start Py2K -+# def __setslice__(self, start, end, values): -+# super(OrderingList, self).__setslice__(start, end, values) -+# self._reorder() -+# -+# def __delslice__(self, start, end): -+# super(OrderingList, self).__delslice__(start, end) -+# self._reorder() -+# end Py2K - - def __reduce__(self): - return _reconstitute, (self.__class__, self.__dict__, list(self)) - -- for func_name, func in locals().items(): -- if (util.callable(func) and func.func_name == func_name and -+ for func_name, func in list(locals().items()): -+ if (util.callable(func) and func.__name__ == func_name and - not func.__doc__ and hasattr(list, func_name)): - func.__doc__ = getattr(list, func_name).__doc__ - del func_name, func -diff -r 9d0639b9d3be lib/sqlalchemy/ext/serializer.py ---- a/lib/sqlalchemy/ext/serializer.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/ext/serializer.py Sat Apr 27 19:42:17 2013 -0400 -@@ -61,20 +61,22 @@ - from ..util import pickle - import re - import base64 --# Py3K --#from io import BytesIO as byte_buffer --# Py2K --from cStringIO import StringIO as byte_buffer -+# start Py3K -+from io import BytesIO as byte_buffer -+# end Py3K -+# start Py2K -+#from cStringIO import StringIO as byte_buffer - # end Py2K - --# Py3K --#def b64encode(x): --# return base64.b64encode(x).decode('ascii') --#def b64decode(x): --# return base64.b64decode(x.encode('ascii')) --# Py2K --b64encode = base64.b64encode --b64decode = base64.b64decode -+# start Py3K -+def b64encode(x): -+ return base64.b64encode(x).decode('ascii') -+def b64decode(x): -+ return base64.b64decode(x.encode('ascii')) -+# end Py3K -+# start Py2K -+#b64encode = base64.b64encode -+#b64decode = base64.b64decode - # end Py2K - - __all__ = ['Serializer', 'Deserializer', 'dumps', 'loads'] -diff -r 9d0639b9d3be lib/sqlalchemy/orm/__init__.py ---- a/lib/sqlalchemy/orm/__init__.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/orm/__init__.py Sat Apr 27 19:42:17 2013 -0400 -@@ -1628,7 +1628,7 @@ - alias = kwargs.pop('alias', None) - if kwargs: - raise exc.ArgumentError( -- 'Invalid kwargs for contains_eager: %r' % kwargs.keys()) -+ 'Invalid kwargs for contains_eager: %r' % list(kwargs.keys())) - return strategies.EagerLazyOption(keys, lazy='joined', - propagate_to_loaders=False, chained=True), \ - strategies.LoadEagerFromAliasOption(keys, alias=alias, chained=True) -diff -r 9d0639b9d3be lib/sqlalchemy/orm/attributes.py ---- a/lib/sqlalchemy/orm/attributes.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/orm/attributes.py Sat Apr 27 19:42:17 2013 -0400 -@@ -1214,7 +1214,7 @@ - - """ - -- def __nonzero__(self): -+ def __bool__(self): - return self != HISTORY_BLANK - - def empty(self): -diff -r 9d0639b9d3be lib/sqlalchemy/orm/collections.py ---- a/lib/sqlalchemy/orm/collections.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/orm/collections.py Sat Apr 27 19:42:17 2013 -0400 -@@ -657,11 +657,12 @@ - if getattr(obj, '_sa_adapter', None) is not None: - return getattr(obj, '_sa_adapter') - elif setting_type == dict: -- # Py3K -- #return obj.values() -- # Py2K -- return getattr(obj, 'itervalues', getattr(obj, 'values'))() -- # end Py2K -+# start Py3K -+ return list(obj.values()) -+# end Py3K -+# start Py2K -+# return getattr(obj, 'itervalues', getattr(obj, 'values'))() -+# end Py2K - else: - return iter(obj) - -@@ -705,14 +706,15 @@ - def __iter__(self): - """Iterate over entities in the collection.""" - -- # Py3K requires iter() here -+# start Py3K -+# end Py3K - return iter(getattr(self._data(), '_sa_iterator')()) - - def __len__(self): - """Count entities in the collection.""" - return len(list(getattr(self._data(), '_sa_iterator')())) - -- def __nonzero__(self): -+ def __bool__(self): - return True - - def fire_append_event(self, item, initiator=None): -@@ -883,7 +885,7 @@ - # search for _sa_instrument_role-decorated methods in - # method resolution order, assign to roles - for supercls in cls.__mro__: -- for name, method in vars(supercls).items(): -+ for name, method in list(vars(supercls).items()): - if not util.callable(method): - continue - -@@ -917,11 +919,11 @@ - collection_type = util.duck_type_collection(cls) - if collection_type in __interfaces: - canned_roles, decorators = __interfaces[collection_type] -- for role, name in canned_roles.items(): -+ for role, name in list(canned_roles.items()): - roles.setdefault(role, name) - - # apply ABC auto-decoration to methods that need it -- for method, decorator in decorators.items(): -+ for method, decorator in list(decorators.items()): - fn = getattr(cls, method, None) - if (fn and method not in methods and - not hasattr(fn, '_sa_instrumented')): -@@ -952,12 +954,12 @@ - - # apply ad-hoc instrumentation from decorators, class-level defaults - # and implicit role declarations -- for method_name, (before, argument, after) in methods.items(): -+ for method_name, (before, argument, after) in list(methods.items()): - setattr(cls, method_name, - _instrument_membership_mutator(getattr(cls, method_name), - before, argument, after)) - # intern the role map -- for role, method_name in roles.items(): -+ for role, method_name in list(roles.items()): - setattr(cls, '_sa_%s' % role, getattr(cls, method_name)) - - setattr(cls, '_sa_instrumented', id(cls)) -@@ -1094,14 +1096,14 @@ - stop += len(self) - - if step == 1: -- for i in xrange(start, stop, step): -+ for i in range(start, stop, step): - if len(self) > start: - del self[start] - - for i, item in enumerate(value): - self.insert(i + start, item) - else: -- rng = range(start, stop, step) -+ rng = list(range(start, stop, step)) - if len(value) != len(rng): - raise ValueError( - "attempt to assign sequence of size %s to " -@@ -1128,24 +1130,24 @@ - _tidy(__delitem__) - return __delitem__ - -- # Py2K -- def __setslice__(fn): -- def __setslice__(self, start, end, values): -- for value in self[start:end]: -- __del(self, value) -- values = [__set(self, value) for value in values] -- fn(self, start, end, values) -- _tidy(__setslice__) -- return __setslice__ -- -- def __delslice__(fn): -- def __delslice__(self, start, end): -- for value in self[start:end]: -- __del(self, value) -- fn(self, start, end) -- _tidy(__delslice__) -- return __delslice__ -- # end Py2K -+# start Py2K -+# def __setslice__(fn): -+# def __setslice__(self, start, end, values): -+# for value in self[start:end]: -+# __del(self, value) -+# values = [__set(self, value) for value in values] -+# fn(self, start, end, values) -+# _tidy(__setslice__) -+# return __setslice__ -+# -+# def __delslice__(fn): -+# def __delslice__(self, start, end): -+# for value in self[start:end]: -+# __del(self, value) -+# fn(self, start, end) -+# _tidy(__delslice__) -+# return __delslice__ -+# end Py2K - - def extend(fn): - def extend(self, iterable): -@@ -1251,7 +1253,7 @@ - def update(self, __other=Unspecified, **kw): - if __other is not Unspecified: - if hasattr(__other, 'keys'): -- for key in __other.keys(): -+ for key in list(__other.keys()): - if (key not in self or - self[key] is not __other[key]): - self[key] = __other[key] -@@ -1467,11 +1469,12 @@ - ), - - # decorators are required for dicts and object collections. -- # Py3K -- #dict: ({'iterator': 'values'}, _dict_decorators()), -- # Py2K -- dict: ({'iterator': 'itervalues'}, _dict_decorators()), -- # end Py2K -+# start Py3K -+ dict: ({'iterator': 'values'}, _dict_decorators()), -+# end Py3K -+# start Py2K -+# dict: ({'iterator': 'itervalues'}, _dict_decorators()), -+# end Py2K - } - - -diff -r 9d0639b9d3be lib/sqlalchemy/orm/descriptor_props.py ---- a/lib/sqlalchemy/orm/descriptor_props.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/orm/descriptor_props.py Sat Apr 27 19:42:17 2013 -0400 -@@ -184,7 +184,7 @@ - def _init_props(self): - self.props = props = [] - for attr in self.attrs: -- if isinstance(attr, basestring): -+ if isinstance(attr, str): - prop = self.parent.get_property(attr) - elif isinstance(attr, schema.Column): - prop = self.parent._columntoproperty[attr] -diff -r 9d0639b9d3be lib/sqlalchemy/orm/evaluator.py ---- a/lib/sqlalchemy/orm/evaluator.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/orm/evaluator.py Sat Apr 27 19:42:17 2013 -0400 -@@ -13,9 +13,9 @@ - - _straight_ops = set(getattr(operators, op) - for op in ('add', 'mul', 'sub', -- # Py2K -- 'div', -- # end Py2K -+# start Py2K -+# 'div', -+# end Py2K - 'mod', 'truediv', - 'lt', 'le', 'ne', 'gt', 'ge', 'eq')) - -@@ -50,7 +50,7 @@ - return lambda obj: get_corresponding_attr(obj) - - def visit_clauselist(self, clause): -- evaluators = map(self.process, clause.clauses) -+ evaluators = list(map(self.process, clause.clauses)) - if clause.operator is operators.or_: - def evaluate(obj): - has_null = False -@@ -79,8 +79,8 @@ - return evaluate - - def visit_binary(self, clause): -- eval_left, eval_right = map(self.process, -- [clause.left, clause.right]) -+ eval_left, eval_right = list(map(self.process, -+ [clause.left, clause.right])) - operator = clause.operator - if operator is operators.is_: - def evaluate(obj): -diff -r 9d0639b9d3be lib/sqlalchemy/orm/identity.py ---- a/lib/sqlalchemy/orm/identity.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/orm/identity.py Sat Apr 27 19:42:17 2013 -0400 -@@ -75,7 +75,7 @@ - state = dict.__getitem__(self, key) - o = state.obj() - if o is None: -- raise KeyError, key -+ raise KeyError(key) - return o - - def __contains__(self, key): -@@ -152,30 +152,32 @@ - - return result - -- # Py3K -- #def items(self): -- # return iter(self._items()) -- # -- #def values(self): -- # return iter(self._values()) -- # Py2K -- items = _items -- -- def iteritems(self): -- return iter(self.items()) -- -- values = _values -- -- def itervalues(self): -- return iter(self.values()) -- # end Py2K -+# start Py3K -+ def items(self): -+ return iter(self._items()) -+ -+ def values(self): -+ return iter(self._values()) -+# end Py3K -+# start Py2K -+# items = _items -+# -+# def iteritems(self): -+# return iter(self.items()) -+# -+# values = _values -+# -+# def itervalues(self): -+# return iter(self.values()) -+# end Py2K - - def all_states(self): -- # Py3K -- # return list(dict.values(self)) -- # Py2K -- return dict.values(self) -- # end Py2K -+# start Py3K -+ return list(dict.values(self)) -+# end Py3K -+# start Py2K -+# return dict.values(self) -+# end Py2K - - def discard(self, state): - st = dict.get(self, state.key, None) -@@ -189,7 +191,7 @@ - - class StrongInstanceDict(IdentityMap): - def all_states(self): -- return [attributes.instance_state(o) for o in self.itervalues()] -+ return [attributes.instance_state(o) for o in self.values()] - - def contains_state(self, state): - return ( -diff -r 9d0639b9d3be lib/sqlalchemy/orm/instrumentation.py ---- a/lib/sqlalchemy/orm/instrumentation.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/orm/instrumentation.py Sat Apr 27 19:42:17 2013 -0400 -@@ -279,7 +279,7 @@ - - @property - def attributes(self): -- return self.itervalues() -+ return iter(self.values()) - - ## InstanceState management - -@@ -325,7 +325,7 @@ - """TODO""" - return self.get_impl(key).hasparent(state, optimistic=optimistic) - -- def __nonzero__(self): -+ def __bool__(self): - """All ClassManagers are non-zero regardless of attribute state.""" - return True - -@@ -444,21 +444,23 @@ - func_vars = util.format_argspec_init(original__init__, grouped=False) - func_text = func_body % func_vars - -- # Py3K -- #func_defaults = getattr(original__init__, '__defaults__', None) -- #func_kw_defaults = getattr(original__init__, '__kwdefaults__', None) -- # Py2K -- func = getattr(original__init__, 'im_func', original__init__) -- func_defaults = getattr(func, 'func_defaults', None) -- # end Py2K -+# start Py3K -+ func_defaults = getattr(original__init__, '__defaults__', None) -+ func_kw_defaults = getattr(original__init__, '__kwdefaults__', None) -+# end Py3K -+# start Py2K -+# func = getattr(original__init__, 'im_func', original__init__) -+# func_defaults = getattr(func, 'func_defaults', None) -+# end Py2K - - env = locals().copy() -- exec func_text in env -+ exec(func_text, env) - __init__ = env['__init__'] - __init__.__doc__ = original__init__.__doc__ - if func_defaults: -- __init__.func_defaults = func_defaults -- # Py3K -- #if func_kw_defaults: -- # __init__.__kwdefaults__ = func_kw_defaults -+ __init__.__defaults__ = func_defaults -+# start Py3K -+ if func_kw_defaults: -+ __init__.__kwdefaults__ = func_kw_defaults -+# end Py3K - return __init__ -diff -r 9d0639b9d3be lib/sqlalchemy/orm/interfaces.py ---- a/lib/sqlalchemy/orm/interfaces.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/orm/interfaces.py Sat Apr 27 19:42:17 2013 -0400 -@@ -15,7 +15,7 @@ - classes within should be considered mostly private. - - """ --from __future__ import absolute_import -+ - - from .. import exc as sa_exc, util, inspect - from ..sql import operators -@@ -659,7 +659,7 @@ - tokens = deque(self.key) - while tokens: - token = tokens.popleft() -- if isinstance(token, basestring): -+ if isinstance(token, str): - # wildcard token - if token.endswith(':*'): - return [path.token(token)] -diff -r 9d0639b9d3be lib/sqlalchemy/orm/loading.py ---- a/lib/sqlalchemy/orm/loading.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/orm/loading.py Sat Apr 27 19:42:17 2013 -0400 -@@ -11,7 +11,7 @@ - as well as some of the attribute loading strategies. - - """ --from __future__ import absolute_import -+ - - from .. import util - from . import attributes, exc as orm_exc, state as statelib -@@ -47,11 +47,11 @@ - query._entities[0].mapper.dispatch.append_result - - (process, labels) = \ -- zip(*[ -+ list(zip(*[ - query_entity.row_processor(query, - context, custom_rows) - for query_entity in query._entities -- ]) -+ ])) - - while True: - context.progress = {} -@@ -84,11 +84,11 @@ - context.progress.pop(context.refresh_state) - - statelib.InstanceState._commit_all_states( -- context.progress.items(), -+ list(context.progress.items()), - session.identity_map - ) - -- for state, (dict_, attrs) in context.partials.iteritems(): -+ for state, (dict_, attrs) in context.partials.items(): - state._commit(dict_, attrs) - - for row in rows: -@@ -507,7 +507,7 @@ - pops = (new_populators, existing_populators, delayed_populators, - eager_populators) - -- for prop in mapper._props.itervalues(): -+ for prop in mapper._props.values(): - - for i, pop in enumerate(prop.create_row_processor( - context, -diff -r 9d0639b9d3be lib/sqlalchemy/orm/mapper.py ---- a/lib/sqlalchemy/orm/mapper.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/orm/mapper.py Sat Apr 27 19:42:17 2013 -0400 -@@ -13,7 +13,7 @@ - available in :class:`~sqlalchemy.orm.`. - - """ --from __future__ import absolute_import -+ - import types - import weakref - from itertools import chain -@@ -581,7 +581,7 @@ - if with_polymorphic == '*': - self.with_polymorphic = ('*', None) - elif isinstance(with_polymorphic, (tuple, list)): -- if isinstance(with_polymorphic[0], (basestring, tuple, list)): -+ if isinstance(with_polymorphic[0], (str, tuple, list)): - self.with_polymorphic = with_polymorphic - else: - self.with_polymorphic = (with_polymorphic, None) -@@ -626,7 +626,7 @@ - self.inherits._inheriting_mappers.add(self) - self.passive_updates = self.inherits.passive_updates - self._all_tables = self.inherits._all_tables -- for key, prop in mapper._props.iteritems(): -+ for key, prop in mapper._props.items(): - if key not in self._props and \ - not self._should_exclude(key, key, local=False, - column=None): -@@ -866,12 +866,12 @@ - - # load custom properties - if self._init_properties: -- for key, prop in self._init_properties.iteritems(): -+ for key, prop in self._init_properties.items(): - self._configure_property(key, prop, False) - - # pull properties from the inherited mapper if any. - if self.inherits: -- for key, prop in self.inherits._props.iteritems(): -+ for key, prop in self.inherits._props.items(): - if key not in self._props and \ - not self._should_exclude(key, key, local=False, - column=None): -@@ -919,7 +919,7 @@ - if self.polymorphic_on is not None: - setter = True - -- if isinstance(self.polymorphic_on, basestring): -+ if isinstance(self.polymorphic_on, str): - # polymorphic_on specified as as string - link - # it to mapped ColumnProperty - try: -@@ -1235,7 +1235,7 @@ - """ - - self._log("_post_configure_properties() started") -- l = [(key, prop) for key, prop in self._props.iteritems()] -+ l = [(key, prop) for key, prop in self._props.items()] - for key, prop in l: - self._log("initialize prop %s", key) - -@@ -1253,7 +1253,7 @@ - using `add_property`. - - """ -- for key, value in dict_of_properties.iteritems(): -+ for key, value in dict_of_properties.items(): - self.add_property(key, value) - - def add_property(self, key, prop): -@@ -1350,7 +1350,7 @@ - """return an iterator of all MapperProperty objects.""" - if _new_mappers: - configure_mappers() -- return self._props.itervalues() -+ return iter(self._props.values()) - - def _mappers_from_spec(self, spec, selectable): - """given a with_polymorphic() argument, return the set of mappers it -@@ -1623,7 +1623,7 @@ - if _new_mappers: - configure_mappers() - return util.ImmutableProperties(util.OrderedDict( -- (k, v) for k, v in self._props.iteritems() -+ (k, v) for k, v in self._props.items() - if isinstance(v, type_) - )) - -@@ -1972,7 +1972,7 @@ - visited_states = set() - prp, mpp = object(), object() - -- visitables = deque([(deque(self._props.values()), prp, -+ visitables = deque([(deque(list(self._props.values())), prp, - state, state.dict)]) - - while visitables: -@@ -1994,7 +1994,7 @@ - corresponding_dict = iterator.popleft() - yield instance, instance_mapper, \ - corresponding_state, corresponding_dict -- visitables.append((deque(instance_mapper._props.values()), -+ visitables.append((deque(list(instance_mapper._props.values())), - prp, corresponding_state, - corresponding_dict)) - -@@ -2011,7 +2011,7 @@ - table_to_mapper.setdefault(t, mapper) - - extra_dependencies = [] -- for table, mapper in table_to_mapper.items(): -+ for table, mapper in list(table_to_mapper.items()): - super_ = mapper.inherits - if super_: - extra_dependencies.extend([ -@@ -2040,7 +2040,7 @@ - return fk.parent not in cols - return False - -- sorted_ = sql_util.sort_tables(table_to_mapper.iterkeys(), -+ sorted_ = sql_util.sort_tables(iter(table_to_mapper.keys()), - skip_fn=skip, - extra_dependencies=extra_dependencies) - -diff -r 9d0639b9d3be lib/sqlalchemy/orm/persistence.py ---- a/lib/sqlalchemy/orm/persistence.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/orm/persistence.py Sat Apr 27 19:42:17 2013 -0400 -@@ -45,7 +45,7 @@ - - cached_connections = _cached_connection_dict(base_mapper) - -- for table, mapper in base_mapper._sorted_tables.iteritems(): -+ for table, mapper in base_mapper._sorted_tables.items(): - insert = _collect_insert_commands(base_mapper, uowtransaction, - table, states_to_insert) - -@@ -77,7 +77,7 @@ - base_mapper, - states, uowtransaction) - -- for table, mapper in base_mapper._sorted_tables.iteritems(): -+ for table, mapper in base_mapper._sorted_tables.items(): - update = _collect_post_update_commands(base_mapper, uowtransaction, - table, states_to_update, - post_update_cols) -@@ -105,7 +105,7 @@ - - table_to_mapper = base_mapper._sorted_tables - -- for table in reversed(table_to_mapper.keys()): -+ for table in reversed(list(table_to_mapper.keys())): - delete = _collect_delete_commands(base_mapper, uowtransaction, - table, states_to_delete) - -@@ -318,7 +318,7 @@ - # history is only - # in a different table than the one - # where the version_id_col is. -- for prop in mapper._columntoproperty.itervalues(): -+ for prop in mapper._columntoproperty.values(): - history = attributes.get_state_history( - state, prop.key, - attributes.PASSIVE_NO_INITIALIZE) -@@ -526,7 +526,7 @@ - for (connection, pkeys, hasvalue, has_all_pks), \ - records in groupby(insert, - lambda rec: (rec[4], -- rec[2].keys(), -+ list(rec[2].keys()), - bool(rec[5]), - rec[6]) - ): -@@ -612,7 +612,7 @@ - # also group them into common (connection, cols) sets - # to support executemany(). - for key, grouper in groupby( -- update, lambda rec: (rec[4], rec[2].keys()) -+ update, lambda rec: (rec[4], list(rec[2].keys())) - ): - connection = key[0] - multiparams = [params for state, state_dict, -@@ -646,7 +646,7 @@ - - return table.delete(clause) - -- for connection, del_objects in delete.iteritems(): -+ for connection, del_objects in delete.items(): - statement = base_mapper._memo(('delete', table), delete_stmt) - - connection = cached_connections[connection] -@@ -803,7 +803,7 @@ - raise sa_exc.ArgumentError( - "Valid strategies for session synchronization " - "are %s" % (", ".join(sorted(repr(x) -- for x in lookup.keys())))) -+ for x in list(lookup.keys()))))) - else: - return klass(*arg) - -@@ -868,7 +868,7 @@ - #TODO: detect when the where clause is a trivial primary key match - self.matched_objects = [ - obj for (cls, pk), obj in -- query.session.identity_map.iteritems() -+ query.session.identity_map.items() - if issubclass(cls, target_cls) and - eval_condition(obj)] - -@@ -951,7 +951,7 @@ - - def _additional_evaluators(self, evaluator_compiler): - self.value_evaluators = {} -- for key, value in self.values.iteritems(): -+ for key, value in self.values.items(): - key = _attr_as_key(key) - self.value_evaluators[key] = evaluator_compiler.process( - expression._literal_as_binds(value)) -@@ -959,7 +959,7 @@ - def _do_post_synchronize(self): - session = self.query.session - states = set() -- evaluated_keys = self.value_evaluators.keys() -+ evaluated_keys = list(self.value_evaluators.keys()) - for obj in self.matched_objects: - state, dict_ = attributes.instance_state(obj),\ - attributes.instance_dict(obj) -diff -r 9d0639b9d3be lib/sqlalchemy/orm/properties.py ---- a/lib/sqlalchemy/orm/properties.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/orm/properties.py Sat Apr 27 19:42:17 2013 -0400 -@@ -27,7 +27,7 @@ - mapperlib = util.importlater("sqlalchemy.orm", "mapperlib") - NoneType = type(None) - --from descriptor_props import CompositeProperty, SynonymProperty, \ -+from .descriptor_props import CompositeProperty, SynonymProperty, \ - ComparableProperty, ConcreteInheritedProperty - - __all__ = ['ColumnProperty', 'CompositeProperty', 'SynonymProperty', -@@ -1204,7 +1204,7 @@ - if not self.is_primary(): - return - if self.backref is not None and not self.back_populates: -- if isinstance(self.backref, basestring): -+ if isinstance(self.backref, str): - backref_key, kwargs = self.backref, {} - else: - backref_key, kwargs = self.backref -diff -r 9d0639b9d3be lib/sqlalchemy/orm/query.py ---- a/lib/sqlalchemy/orm/query.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/orm/query.py Sat Apr 27 19:42:17 2013 -0400 -@@ -47,7 +47,7 @@ - def generate(fn, *args, **kw): - self = args[0]._clone() - for assertion in assertions: -- assertion(self, fn.func_name) -+ assertion(self, fn.__name__) - fn(self, *args[1:], **kw) - return self - return generate -@@ -981,11 +981,12 @@ - """Return a scalar result corresponding to the given - column expression.""" - try: -- # Py3K -- #return self.values(column).__next__()[0] -- # Py2K -- return self.values(column).next()[0] -- # end Py2K -+# start Py3K -+ return self.values(column).__next__()[0] -+# end Py3K -+# start Py2K -+# return self.values(column).next()[0] -+# end Py2K - except StopIteration: - return None - -@@ -1231,7 +1232,7 @@ - """ - - clauses = [_entity_descriptor(self._joinpoint_zero(), key) == value -- for key, value in kwargs.iteritems()] -+ for key, value in kwargs.items()] - return self.filter(sql.and_(*clauses)) - - @_generative(_no_statement_condition, _no_limit_offset) -@@ -1296,7 +1297,7 @@ - - """ - -- if isinstance(criterion, basestring): -+ if isinstance(criterion, str): - criterion = sql.text(criterion) - - if criterion is not None and \ -@@ -1655,7 +1656,7 @@ - kwargs.pop('from_joinpoint', False) - if kwargs: - raise TypeError("unknown arguments: %s" % -- ','.join(kwargs.iterkeys())) -+ ','.join(iter(kwargs.keys()))) - return self._join(props, - outerjoin=False, create_aliases=aliased, - from_joinpoint=from_joinpoint) -@@ -1671,7 +1672,7 @@ - kwargs.pop('from_joinpoint', False) - if kwargs: - raise TypeError("unknown arguments: %s" % -- ','.join(kwargs.iterkeys())) -+ ','.join(iter(kwargs.keys()))) - return self._join(props, - outerjoin=True, create_aliases=aliased, - from_joinpoint=from_joinpoint) -@@ -1701,7 +1702,7 @@ - if len(keys) == 2 and \ - isinstance(keys[0], (expression.FromClause, - type, AliasedClass)) and \ -- isinstance(keys[1], (basestring, expression.ClauseElement, -+ isinstance(keys[1], (str, expression.ClauseElement, - interfaces.PropComparator)): - # detect 2-arg form of join and - # convert to a tuple. -@@ -1721,14 +1722,14 @@ - # is a little bit of legacy behavior still at work here - # which means they might be in either order. may possibly - # lock this down to (right_entity, onclause) in 0.6. -- if isinstance(arg1, (interfaces.PropComparator, basestring)): -+ if isinstance(arg1, (interfaces.PropComparator, str)): - right_entity, onclause = arg2, arg1 - else: - right_entity, onclause = arg1, arg2 - - left_entity = prop = None - -- if isinstance(onclause, basestring): -+ if isinstance(onclause, str): - left_entity = self._joinpoint_zero() - - descriptor = _entity_descriptor(left_entity, onclause) -@@ -1922,7 +1923,7 @@ - clause = orm_join(clause, - right, - onclause, isouter=outerjoin) -- except sa_exc.ArgumentError, ae: -+ except sa_exc.ArgumentError as ae: - raise sa_exc.InvalidRequestError( - "Could not find a FROM clause to join from. " - "Tried joining to %s, but got: %s" % (right, ae)) -@@ -1947,7 +1948,7 @@ - - try: - clause = orm_join(clause, right, onclause, isouter=outerjoin) -- except sa_exc.ArgumentError, ae: -+ except sa_exc.ArgumentError as ae: - raise sa_exc.InvalidRequestError( - "Could not find a FROM clause to join from. " - "Tried joining to %s, but got: %s" % (right, ae)) -@@ -2115,7 +2116,7 @@ - appropriate to the entity class represented by this ``Query``. - - """ -- if isinstance(statement, basestring): -+ if isinstance(statement, str): - statement = sql.text(statement) - - if not isinstance(statement, -@@ -2609,7 +2610,7 @@ - use_labels=context.labels) - - from_clause = inner -- for eager_join in context.eager_joins.values(): -+ for eager_join in list(context.eager_joins.values()): - # EagerLoader places a 'stop_on' attribute on the join, - # giving us a marker as to where the "splice point" of - # the join should be -@@ -2674,7 +2675,7 @@ - subtypes are selected from the total results. - - """ -- for (ext_info, adapter) in self._mapper_adapter_map.values(): -+ for (ext_info, adapter) in list(self._mapper_adapter_map.values()): - if ext_info in self._join_entities: - continue - single_crit = ext_info.mapper._single_table_criterion -@@ -2697,7 +2698,7 @@ - def __new__(cls, *args, **kwargs): - if cls is _QueryEntity: - entity = args[1] -- if not isinstance(entity, basestring) and \ -+ if not isinstance(entity, str) and \ - _is_mapped_class(entity): - cls = _MapperEntity - else: -@@ -2905,7 +2906,7 @@ - self.expr = column - self.namespace = namespace - -- if isinstance(column, basestring): -+ if isinstance(column, str): - column = sql.literal_column(column) - self._label_name = column.name - elif isinstance(column, ( -@@ -3080,7 +3081,7 @@ - self.alias = alias - - def process_query(self, query): -- if isinstance(self.alias, basestring): -+ if isinstance(self.alias, str): - alias = query._mapper_zero().mapped_table.alias(self.alias) - else: - alias = self.alias -diff -r 9d0639b9d3be lib/sqlalchemy/orm/session.py ---- a/lib/sqlalchemy/orm/session.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/orm/session.py Sat Apr 27 19:42:17 2013 -0400 -@@ -5,7 +5,7 @@ - # the MIT License: http://www.opensource.org/licenses/mit-license.php - """Provides the Session class and related utilities.""" - --from __future__ import with_statement -+ - - import weakref - from .. import util, sql, engine, exc as sa_exc, event -@@ -35,7 +35,7 @@ - def close_all(cls): - """Close *all* sessions in memory.""" - -- for sess in _sessions.values(): -+ for sess in list(_sessions.values()): - sess.close() - - @classmethod -@@ -249,7 +249,7 @@ - if s.key: - del s.key - -- for s, (oldkey, newkey) in self._key_switches.items(): -+ for s, (oldkey, newkey) in list(self._key_switches.items()): - self.session.identity_map.discard(s) - s.key = oldkey - self.session.identity_map.replace(s) -@@ -327,7 +327,7 @@ - subtransaction.commit() - - if not self.session._flushing: -- for _flush_guard in xrange(100): -+ for _flush_guard in range(100): - if self.session._is_clean(): - break - self.session.flush() -@@ -604,7 +604,7 @@ - SessionExtension._adapt_listener(self, ext) - - if binds is not None: -- for mapperortable, bind in binds.iteritems(): -+ for mapperortable, bind in binds.items(): - if isinstance(mapperortable, (type, Mapper)): - self.bind_mapper(mapperortable, bind) - else: -@@ -1775,7 +1775,7 @@ - Session. - - """ -- return iter(list(self._new.values()) + self.identity_map.values()) -+ return iter(list(self._new.values()) + list(self.identity_map.values())) - - def _contains_state(self, state): - return state in self._new or self.identity_map.contains_state(state) -@@ -2138,13 +2138,13 @@ - def deleted(self): - "The set of all instances marked as 'deleted' within this ``Session``" - -- return util.IdentitySet(self._deleted.values()) -+ return util.IdentitySet(list(self._deleted.values())) - - @property - def new(self): - "The set of all instances marked as 'new' within this ``Session``." - -- return util.IdentitySet(self._new.values()) -+ return util.IdentitySet(list(self._new.values())) - - - class sessionmaker(_SessionClassMethods): -@@ -2236,7 +2236,7 @@ - session = Session() # invokes sessionmaker.__call__() - - """ -- for k, v in self.kw.items(): -+ for k, v in list(self.kw.items()): - local_kw.setdefault(k, v) - return self.class_(**local_kw) - -@@ -2255,7 +2255,7 @@ - return "%s(class_=%r%s)" % ( - self.__class__.__name__, - self.class_.__name__, -- ", ".join("%s=%r" % (k, v) for k, v in self.kw.items()) -+ ", ".join("%s=%r" % (k, v) for k, v in list(self.kw.items())) - ) - - _sessions = weakref.WeakValueDictionary() -diff -r 9d0639b9d3be lib/sqlalchemy/orm/state.py ---- a/lib/sqlalchemy/orm/state.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/orm/state.py Sat Apr 27 19:42:17 2013 -0400 -@@ -417,7 +417,7 @@ - against this set when a refresh operation occurs. - - """ -- return set([k for k, v in self.callables.items() if v is self]) -+ return set([k for k, v in list(self.callables.items()) if v is self]) - - def _instance_dict(self): - return None -diff -r 9d0639b9d3be lib/sqlalchemy/orm/strategies.py ---- a/lib/sqlalchemy/orm/strategies.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/orm/strategies.py Sat Apr 27 19:42:17 2013 -0400 -@@ -359,7 +359,7 @@ - ) - - if self.use_get: -- for col in self._equated_columns.keys(): -+ for col in list(self._equated_columns.keys()): - if col in self.mapper._equivalent_columns: - for c in self.mapper._equivalent_columns[col]: - self._equated_columns[c] = self._equated_columns[col] -@@ -1332,7 +1332,7 @@ - def __init__(self, key, lazy=True, chained=False, - propagate_to_loaders=True - ): -- if isinstance(key[0], basestring) and key[0] == '*': -+ if isinstance(key[0], str) and key[0] == '*': - if len(key) != 1: - raise sa_exc.ArgumentError( - "Wildcard identifier '*' must " -@@ -1384,7 +1384,7 @@ - def __init__(self, key, alias=None, chained=False): - super(LoadEagerFromAliasOption, self).__init__(key) - if alias is not None: -- if not isinstance(alias, basestring): -+ if not isinstance(alias, str): - info = inspect(alias) - alias = info.selectable - self.alias = alias -@@ -1401,7 +1401,7 @@ - - root_mapper, prop = paths[-1].path[-2:] - if self.alias is not None: -- if isinstance(self.alias, basestring): -+ if isinstance(self.alias, str): - self.alias = prop.target.alias(self.alias) - paths[-1].set(query, "user_defined_eager_row_processor", - sql_util.ColumnAdapter(self.alias, -diff -r 9d0639b9d3be lib/sqlalchemy/orm/unitofwork.py ---- a/lib/sqlalchemy/orm/unitofwork.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/orm/unitofwork.py Sat Apr 27 19:42:17 2013 -0400 -@@ -315,7 +315,7 @@ - # see if the graph of mapper dependencies has cycles. - self.cycles = cycles = topological.find_cycles( - self.dependencies, -- self.postsort_actions.values()) -+ list(self.postsort_actions.values())) - - if cycles: - # if yes, break the per-mapper actions into -@@ -342,7 +342,7 @@ - for dep in convert[edge[1]]: - self.dependencies.add((edge[0], dep)) - -- return set([a for a in self.postsort_actions.values() -+ return set([a for a in list(self.postsort_actions.values()) - if not a.disabled - ] - ).difference(cycles) -@@ -381,7 +381,7 @@ - """ - states = set(self.states) - isdel = set( -- s for (s, (isdelete, listonly)) in self.states.iteritems() -+ s for (s, (isdelete, listonly)) in self.states.items() - if isdelete - ) - other = states.difference(isdel) -@@ -461,7 +461,7 @@ - def __repr__(self): - return "%s(%s)" % ( - self.__class__.__name__, -- ",".join(str(x) for x in self.__dict__.values()) -+ ",".join(str(x) for x in list(self.__dict__.values())) - ) - - -diff -r 9d0639b9d3be lib/sqlalchemy/orm/util.py ---- a/lib/sqlalchemy/orm/util.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/orm/util.py Sat Apr 27 19:42:17 2013 -0400 -@@ -120,7 +120,7 @@ - colnames = util.OrderedSet() - colnamemaps = {} - types = {} -- for key in table_map.keys(): -+ for key in list(table_map.keys()): - table = table_map[key] - - # mysql doesnt like selecting from a select; -@@ -146,7 +146,7 @@ - return sql.type_coerce(sql.null(), types[name]).label(name) - - result = [] -- for type, table in table_map.iteritems(): -+ for type, table in table_map.items(): - if typecolname is not None: - result.append( - sql.select([col(name, table) for name in colnames] + -@@ -203,7 +203,7 @@ - "positional arguments, got %s" % len(args)) - if kwargs: - raise sa_exc.ArgumentError("unknown keyword arguments: %s" -- % ", ".join(kwargs.keys())) -+ % ", ".join(list(kwargs.keys()))) - mapper = class_mapper(class_) - if "ident" in locals(): - return mapper.identity_key_from_primary_key(util.to_list(ident)) -@@ -211,7 +211,7 @@ - instance = kwargs.pop("instance") - if kwargs: - raise sa_exc.ArgumentError("unknown keyword arguments: %s" -- % ", ".join(kwargs.keys())) -+ % ", ".join(list(kwargs.keys()))) - mapper = object_mapper(instance) - return mapper.identity_key_from_instance(instance) - -@@ -300,7 +300,7 @@ - - def pairs(self): - path = self.path -- for i in xrange(0, len(path), 2): -+ for i in range(0, len(path), 2): - yield path[i], path[i + 1] - - def contains_mapper(self, mapper): -@@ -314,10 +314,10 @@ - - def serialize(self): - path = self.path -- return zip( -+ return list(zip( - [m.class_ for m in [path[i] for i in range(0, len(path), 2)]], - [path[i].key for i in range(1, len(path), 2)] + [None] -- ) -+ )) - - @classmethod - def deserialize(cls, path): -@@ -411,7 +411,7 @@ - - self.path = parent.path + (entity,) - -- def __nonzero__(self): -+ def __bool__(self): - return True - - def __getitem__(self, entity): -@@ -589,8 +589,8 @@ - return self.__adapt_prop(attr, key) - elif hasattr(attr, 'func_code'): - is_method = getattr(self.__target, key, None) -- if is_method and is_method.im_self is not None: -- return util.types.MethodType(attr.im_func, self, self) -+ if is_method and is_method.__self__ is not None: -+ return util.types.MethodType(attr.__func__, self, self) - else: - return None - elif hasattr(attr, '__get__'): -@@ -880,7 +880,7 @@ - - self._joined_from_info = right_info - -- if isinstance(onclause, basestring): -+ if isinstance(onclause, str): - onclause = getattr(left_orm_info.entity, onclause) - - if isinstance(onclause, attributes.QueryableAttribute): -@@ -1001,7 +1001,7 @@ - parent/child relationship. - - """ -- if isinstance(prop, basestring): -+ if isinstance(prop, str): - mapper = object_mapper(instance) - prop = getattr(mapper.class_, prop).property - elif isinstance(prop, attributes.QueryableAttribute): -diff -r 9d0639b9d3be lib/sqlalchemy/pool.py ---- a/lib/sqlalchemy/pool.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/pool.py Sat Apr 27 19:42:17 2013 -0400 -@@ -57,7 +57,7 @@ - All pools and connections are disposed. - """ - -- for manager in proxies.itervalues(): -+ for manager in proxies.values(): - manager.close() - proxies.clear() - -@@ -368,7 +368,7 @@ - connection = self.__pool._creator() - self.__pool.logger.debug("Created new connection %r", connection) - return connection -- except Exception, e: -+ except Exception as e: - self.__pool.logger.debug("Error on connect(): %s", e) - raise - -@@ -391,7 +391,7 @@ - # Immediately close detached instances - if connection_record is None: - pool._close_connection(connection) -- except Exception, e: -+ except Exception as e: - if connection_record is not None: - connection_record.invalidate(e=e) - if isinstance(e, (SystemExit, KeyboardInterrupt)): -@@ -499,7 +499,7 @@ - self._connection_record, - self) - return self -- except exc.DisconnectionError, e: -+ except exc.DisconnectionError as e: - self._pool.logger.info( - "Disconnection detected on checkout: %s", e) - self._connection_record.invalidate(e) -@@ -755,7 +755,7 @@ - wait = self._max_overflow > -1 and \ - self._overflow >= self._max_overflow - return self._pool.get(wait, self._timeout) -- except sqla_queue.SAAbort, aborted: -+ except sqla_queue.SAAbort as aborted: - return aborted.context._do_get() - except sqla_queue.Empty: - if self._max_overflow > -1 and \ -@@ -1004,7 +1004,7 @@ - self._create_pool_mutex = threading.Lock() - - def close(self): -- for key in self.pools.keys(): -+ for key in list(self.pools.keys()): - del self.pools[key] - - def __del__(self): -diff -r 9d0639b9d3be lib/sqlalchemy/processors.py ---- a/lib/sqlalchemy/processors.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/processors.py Sat Apr 27 19:42:17 2013 -0400 -@@ -38,10 +38,10 @@ - "'%s'" % (type_.__name__, value)) - if has_named_groups: - groups = m.groupdict(0) -- return type_(**dict(zip(groups.iterkeys(), -- map(int, groups.itervalues())))) -+ return type_(**dict(list(zip(iter(groups.keys()), -+ list(map(int, iter(groups.values()))))))) - else: -- return type_(*map(int, m.groups(0))) -+ return type_(*list(map(int, m.groups(0)))) - return process - - -diff -r 9d0639b9d3be lib/sqlalchemy/schema.py ---- a/lib/sqlalchemy/schema.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/schema.py Sat Apr 27 19:42:17 2013 -0400 -@@ -27,7 +27,7 @@ - as components in SQL expressions. - - """ --from __future__ import with_statement -+ - import re - import inspect - from . import exc, util, dialects, event, events, inspection -@@ -683,7 +683,7 @@ - continue - Index(index.name, - unique=index.unique, -- *[table.c[col] for col in index.columns.keys()], -+ *[table.c[col] for col in list(index.columns.keys())], - **index.kwargs) - table.dispatch._update(self.dispatch) - return table -@@ -898,7 +898,7 @@ - type_ = kwargs.pop('type_', None) - args = list(args) - if args: -- if isinstance(args[0], basestring): -+ if isinstance(args[0], str): - if name is not None: - raise exc.ArgumentError( - "May not pass name positionally and as a keyword.") -@@ -944,11 +944,12 @@ - args.append(self.default) - else: - if getattr(self.type, '_warn_on_bytestring', False): -- # Py3K -- #if isinstance(self.default, bytes): -- # Py2K -- if isinstance(self.default, str): -- # end Py2K -+# start Py3K -+ if isinstance(self.default, bytes): -+# end Py3K -+# start Py2K -+# if isinstance(self.default, str): -+# end Py2K - util.warn("Unicode column received non-unicode " - "default value.") - args.append(ColumnDefault(self.default)) -@@ -983,7 +984,7 @@ - - if kwargs: - raise exc.ArgumentError( -- "Unknown arguments passed to Column: " + repr(kwargs.keys())) -+ "Unknown arguments passed to Column: " + repr(list(kwargs.keys()))) - - def __str__(self): - if self.name is None: -@@ -1069,7 +1070,7 @@ - self.table = table - - if self.index: -- if isinstance(self.index, basestring): -+ if isinstance(self.index, str): - raise exc.ArgumentError( - "The 'index' keyword argument on Column is boolean only. " - "To create indexes with a specific name, create an " -@@ -1077,7 +1078,7 @@ - Index(expression._truncated_label('ix_%s' % self._label), - self, unique=self.unique) - elif self.unique: -- if isinstance(self.unique, basestring): -+ if isinstance(self.unique, str): - raise exc.ArgumentError( - "The 'unique' keyword argument on Column is boolean " - "only. To create unique constraints or indexes with a " -@@ -1153,23 +1154,24 @@ - nullable=self.nullable, - quote=self.quote, - _proxies=[self], *fk) -- except TypeError, e: -- # Py3K -- #raise TypeError( -- # "Could not create a copy of this %r object. " -- # "Ensure the class includes a _constructor() " -- # "attribute or method which accepts the " -- # "standard Column constructor arguments, or " -- # "references the Column class itself." % self.__class__) from e -- # Py2K -+ except TypeError as e: -+# start Py3K - raise TypeError( - "Could not create a copy of this %r object. " - "Ensure the class includes a _constructor() " - "attribute or method which accepts the " - "standard Column constructor arguments, or " -- "references the Column class itself. " -- "Original error: %s" % (self.__class__, e)) -- # end Py2K -+ "references the Column class itself." % self.__class__) from e -+# end Py3K -+# start Py2K -+# raise TypeError( -+# "Could not create a copy of this %r object. " -+# "Ensure the class includes a _constructor() " -+# "attribute or method which accepts the " -+# "standard Column constructor arguments, or " -+# "references the Column class itself. " -+# "Original error: %s" % (self.__class__, e)) -+# end Py2K - - c.table = selectable - selectable._columns.add(c) -@@ -1345,7 +1347,7 @@ - if schema: - return schema + "." + self.column.table.name + \ - "." + self.column.key -- elif isinstance(self._colspec, basestring): -+ elif isinstance(self._colspec, str): - return self._colspec - elif hasattr(self._colspec, '__clause_element__'): - _column = self._colspec.__clause_element__() -@@ -1390,7 +1392,7 @@ - """ - # ForeignKey inits its remote column as late as possible, so tables - # can be defined without dependencies -- if isinstance(self._colspec, basestring): -+ if isinstance(self._colspec, str): - # locate the parent table this foreign key is attached to. we - # use the "original" column which our parent column represents - # (its a list of columns/other ColumnElements if the parent -@@ -1657,7 +1659,8 @@ - defaulted = argspec[3] is not None and len(argspec[3]) or 0 - positionals = len(argspec[0]) - defaulted - -- # Py3K compat - no unbound methods -+# start Py3K -+# end Py3K - if inspect.ismethod(inspectable) or inspect.isclass(fn): - positionals -= 1 - -@@ -1919,7 +1922,7 @@ - has_argument = True - - def __init__(self, arg, for_update=False, _reflected=False): -- util.assert_arg_type(arg, (basestring, -+ util.assert_arg_type(arg, (str, - expression.ClauseElement, - expression.TextClause), 'arg') - super(DefaultClause, self).__init__(for_update) -@@ -2029,7 +2032,7 @@ - - def _set_parent(self, table): - for col in self._pending_colargs: -- if isinstance(col, basestring): -+ if isinstance(col, str): - col = table.c[col] - self.columns.add(col) - -@@ -2066,7 +2069,7 @@ - - def copy(self, **kw): - c = self.__class__(name=self.name, deferrable=self.deferrable, -- initially=self.initially, *self.columns.keys()) -+ initially=self.initially, *list(self.columns.keys())) - c.dispatch._update(self.dispatch) - return c - -@@ -2256,19 +2259,19 @@ - - @property - def columns(self): -- return self._elements.keys() -+ return list(self._elements.keys()) - - @property - def elements(self): -- return self._elements.values() -+ return list(self._elements.values()) - - def _set_parent(self, table): - super(ForeignKeyConstraint, self)._set_parent(table) - -- for col, fk in self._elements.iteritems(): -+ for col, fk in self._elements.items(): - # string-specified column names now get - # resolved to Column objects -- if isinstance(col, basestring): -+ if isinstance(col, str): - try: - col = table.c[col] - except KeyError: -@@ -2293,8 +2296,8 @@ - - def copy(self, schema=None, **kw): - fkc = ForeignKeyConstraint( -- [x.parent.key for x in self._elements.values()], -- [x._get_colspec(schema=schema) for x in self._elements.values()], -+ [x.parent.key for x in list(self._elements.values())], -+ [x._get_colspec(schema=schema) for x in list(self._elements.values())], - name=self.name, - onupdate=self.onupdate, - ondelete=self.ondelete, -@@ -2569,7 +2572,7 @@ - return 'MetaData(bind=%r)' % self.bind - - def __contains__(self, table_or_key): -- if not isinstance(table_or_key, basestring): -+ if not isinstance(table_or_key, str): - table_or_key = table_or_key.key - return table_or_key in self.tables - -@@ -2584,7 +2587,7 @@ - dict.pop(self.tables, key, None) - if self._schemas: - self._schemas = set([t.schema -- for t in self.tables.values() -+ for t in list(self.tables.values()) - if t.schema is not None]) - - def __getstate__(self): -@@ -2629,7 +2632,7 @@ - def _bind_to(self, bind): - """Bind this MetaData to an Engine, Connection, string or URL.""" - -- if isinstance(bind, (basestring, url.URL)): -+ if isinstance(bind, (str, url.URL)): - from sqlalchemy import create_engine - self._bind = create_engine(bind) - else: -@@ -2662,7 +2665,7 @@ - :meth:`.Inspector.sorted_tables` - - """ -- return sqlutil.sort_tables(self.tables.itervalues()) -+ return sqlutil.sort_tables(iter(self.tables.values())) - - def reflect(self, bind=None, schema=None, views=False, only=None): - """Load all available table definitions from the database. -@@ -2723,7 +2726,7 @@ - bind.dialect.get_view_names(conn, schema) - ) - -- current = set(self.tables.iterkeys()) -+ current = set(self.tables.keys()) - - if only is None: - load = [name for name in available if name not in current] -@@ -2845,7 +2848,7 @@ - def _bind_to(self, bind): - """Bind to a Connectable in the caller's thread.""" - -- if isinstance(bind, (basestring, url.URL)): -+ if isinstance(bind, (str, url.URL)): - try: - self.context._engine = self.__engines[bind] - except KeyError: -@@ -2870,7 +2873,7 @@ - def dispose(self): - """Dispose all bound engines, in all thread contexts.""" - -- for e in self.__engines.itervalues(): -+ for e in self.__engines.values(): - if hasattr(e, 'dispose'): - e.dispose() - -@@ -3075,7 +3078,7 @@ - not self._should_execute_deprecated(None, target, bind, **kw): - return False - -- if isinstance(self.dialect, basestring): -+ if isinstance(self.dialect, str): - if self.dialect != bind.engine.name: - return False - elif isinstance(self.dialect, (tuple, list, set)): -@@ -3090,7 +3093,7 @@ - def _should_execute_deprecated(self, event, target, bind, **kw): - if self.on is None: - return True -- elif isinstance(self.on, basestring): -+ elif isinstance(self.on, str): - return self.on == bind.engine.name - elif isinstance(self.on, (tuple, list, set)): - return bind.engine.name in self.on -@@ -3105,7 +3108,7 @@ - - def _check_ddl_on(self, on): - if (on is not None and -- (not isinstance(on, (basestring, tuple, list, set)) and -+ (not isinstance(on, (str, tuple, list, set)) and - not util.callable(on))): - raise exc.ArgumentError( - "Expected the name of a database dialect, a tuple " -@@ -3230,7 +3233,7 @@ - - """ - -- if not isinstance(statement, basestring): -+ if not isinstance(statement, str): - raise exc.ArgumentError( - "Expected a string or unicode SQL statement, got '%r'" % - statement) -@@ -3262,7 +3265,7 @@ - def _to_schema_column_or_string(element): - if hasattr(element, '__clause_element__'): - element = element.__clause_element__() -- if not isinstance(element, (basestring, expression.ColumnElement)): -+ if not isinstance(element, (str, expression.ColumnElement)): - msg = "Element %r is not a string name or column element" - raise exc.ArgumentError(msg % element) - return element -diff -r 9d0639b9d3be lib/sqlalchemy/sql/__init__.py ---- a/lib/sqlalchemy/sql/__init__.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/sql/__init__.py Sat Apr 27 19:42:17 2013 -0400 -@@ -64,5 +64,5 @@ - - from .visitors import ClauseVisitor - --__tmp = locals().keys() -+__tmp = list(locals().keys()) - __all__ = sorted([i for i in __tmp if not i.startswith('__')]) -diff -r 9d0639b9d3be lib/sqlalchemy/sql/compiler.py ---- a/lib/sqlalchemy/sql/compiler.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/sql/compiler.py Sat Apr 27 19:42:17 2013 -0400 -@@ -51,7 +51,7 @@ - 'using', 'verbose', 'when', 'where']) - - LEGAL_CHARACTERS = re.compile(r'^[A-Z0-9_$]+$', re.I) --ILLEGAL_INITIAL_CHARACTERS = set([str(x) for x in xrange(0, 10)]).union(['$']) -+ILLEGAL_INITIAL_CHARACTERS = set([str(x) for x in range(0, 10)]).union(['$']) - - BIND_PARAMS = re.compile(r'(?> sys.stderr, "Error emptying table %s: %r" % ( -- table, ex) -+ except sa.exc.DBAPIError as ex: -+ print("Error emptying table %s: %r" % ( -+ table, ex), file=sys.stderr) - - def setup(self): - self._setup_each_tables() -@@ -187,10 +187,10 @@ - def _load_fixtures(cls): - """Insert rows as represented by the fixtures() method.""" - headers, rows = {}, {} -- for table, data in cls.fixtures().iteritems(): -+ for table, data in cls.fixtures().items(): - if len(data) < 2: - continue -- if isinstance(table, basestring): -+ if isinstance(table, str): - table = cls.tables[table] - headers[table] = data[0] - rows[table] = data[1:] -@@ -199,7 +199,7 @@ - continue - cls.bind.execute( - table.insert(), -- [dict(zip(headers[table], column_values)) -+ [dict(list(zip(headers[table], column_values))) - for column_values in rows[table]]) - - -@@ -284,8 +284,8 @@ - cls_registry[classname] = cls - return type.__init__(cls, classname, bases, dict_) - -- class _Base(object): -- __metaclass__ = FindFixture -+ class _Base(object, metaclass=FindFixture): -+ pass - - class Basic(BasicEntity, _Base): - pass -diff -r 9d0639b9d3be lib/sqlalchemy/testing/plugin/noseplugin.py ---- a/lib/sqlalchemy/testing/plugin/noseplugin.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/testing/plugin/noseplugin.py Sat Apr 27 19:42:17 2013 -0400 -@@ -9,10 +9,10 @@ - normally as "from sqlalchemy.testing.plugin import noseplugin". - - """ --from __future__ import absolute_import -+ - - import os --import ConfigParser -+import configparser - - from nose.plugins import Plugin - from nose import SkipTest -@@ -55,9 +55,9 @@ - - - def _list_dbs(*args): -- print "Available --db options (use --dburi to override)" -+ print("Available --db options (use --dburi to override)") - for macro in sorted(file_config.options('db')): -- print "%20s\t%s" % (macro, file_config.get('db', macro)) -+ print("%20s\t%s" % (macro, file_config.get('db', macro))) - sys.exit(0) - - -@@ -318,7 +318,7 @@ - opt("--write-profiles", action="store_true", dest="write_profiles", default=False, - help="Write/update profiling data.") - global file_config -- file_config = ConfigParser.ConfigParser() -+ file_config = configparser.ConfigParser() - file_config.read(['setup.cfg', 'test.cfg']) - - def configure(self, options, conf): -diff -r 9d0639b9d3be lib/sqlalchemy/testing/profiling.py ---- a/lib/sqlalchemy/testing/profiling.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/testing/profiling.py Sat Apr 27 19:42:17 2013 -0400 -@@ -60,9 +60,9 @@ - if report: - sort_ = target_opts.get('sort', profile_config['sort']) - limit = target_opts.get('limit', profile_config['limit']) -- print ("Profile report for target '%s' (%s)" % ( -+ print(("Profile report for target '%s' (%s)" % ( - target, filename) -- ) -+ )) - - stats = load_stats() - stats.sort_stats(*sort_) -@@ -198,7 +198,7 @@ - profile_f.close() - - def _write(self): -- print("Writing profile file %s" % self.fname) -+ print(("Writing profile file %s" % self.fname)) - profile_f = open(self.fname, "w") - profile_f.write(self._header()) - for test_key in sorted(self.data): -@@ -253,11 +253,11 @@ - else: - line_no, expected_count = expected - -- print("Pstats calls: %d Expected %s" % ( -+ print(("Pstats calls: %d Expected %s" % ( - callcount, - expected_count - ) -- ) -+ )) - stats.print_stats() - #stats.print_callers() - -diff -r 9d0639b9d3be lib/sqlalchemy/testing/schema.py ---- a/lib/sqlalchemy/testing/schema.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/testing/schema.py Sat Apr 27 19:42:17 2013 -0400 -@@ -11,7 +11,7 @@ - def Table(*args, **kw): - """A schema.Table wrapper/hook for dialect-specific tweaks.""" - -- test_opts = dict([(k, kw.pop(k)) for k in kw.keys() -+ test_opts = dict([(k, kw.pop(k)) for k in list(kw.keys()) - if k.startswith('test_')]) - - kw.update(table_options) -@@ -58,7 +58,7 @@ - def Column(*args, **kw): - """A schema.Column wrapper/hook for dialect-specific tweaks.""" - -- test_opts = dict([(k, kw.pop(k)) for k in kw.keys() -+ test_opts = dict([(k, kw.pop(k)) for k in list(kw.keys()) - if k.startswith('test_')]) - - if not config.requirements.foreign_key_ddl.enabled: -diff -r 9d0639b9d3be lib/sqlalchemy/testing/suite/test_ddl.py ---- a/lib/sqlalchemy/testing/suite/test_ddl.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/testing/suite/test_ddl.py Sat Apr 27 19:42:17 2013 -0400 -@@ -1,4 +1,4 @@ --from __future__ import with_statement -+ - - from .. import fixtures, config, util - from ..config import requirements -diff -r 9d0639b9d3be lib/sqlalchemy/testing/suite/test_reflection.py ---- a/lib/sqlalchemy/testing/suite/test_reflection.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/testing/suite/test_reflection.py Sat Apr 27 19:42:17 2013 -0400 -@@ -1,4 +1,4 @@ --from __future__ import with_statement -+ - - import sqlalchemy as sa - from sqlalchemy import exc as sa_exc -@@ -386,7 +386,7 @@ - self.tables.email_addresses, self.tables.dingalings - insp = inspect(meta.bind) - oid = insp.get_table_oid(table_name, schema) -- self.assert_(isinstance(oid, (int, long))) -+ self.assert_(isinstance(oid, int)) - - def test_get_table_oid(self): - self._test_get_table_oid('users') -diff -r 9d0639b9d3be lib/sqlalchemy/testing/suite/test_types.py ---- a/lib/sqlalchemy/testing/suite/test_types.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/testing/suite/test_types.py Sat Apr 27 19:42:17 2013 -0400 -@@ -15,9 +15,9 @@ - class _UnicodeFixture(object): - __requires__ = 'unicode_data', - -- data = u"Alors vous imaginez ma surprise, au lever du jour, "\ -- u"quand une drôle de petite voix m’a réveillé. Elle "\ -- u"disait: « S’il vous plaît… dessine-moi un mouton! »" -+ data = "Alors vous imaginez ma surprise, au lever du jour, "\ -+ "quand une drôle de petite voix m’a réveillé. Elle "\ -+ "disait: « S’il vous plaît… dessine-moi un mouton! »" - - @classmethod - def define_tables(cls, metadata): -@@ -47,7 +47,7 @@ - row, - (self.data, ) - ) -- assert isinstance(row[0], unicode) -+ assert isinstance(row[0], str) - - def test_round_trip_executemany(self): - unicode_table = self.tables.unicode_table -@@ -58,7 +58,7 @@ - { - 'unicode_data': self.data, - } -- for i in xrange(3) -+ for i in range(3) - ] - ) - -@@ -69,22 +69,22 @@ - ).fetchall() - eq_( - rows, -- [(self.data, ) for i in xrange(3)] -+ [(self.data, ) for i in range(3)] - ) - for row in rows: -- assert isinstance(row[0], unicode) -+ assert isinstance(row[0], str) - - def _test_empty_strings(self): - unicode_table = self.tables.unicode_table - - config.db.execute( - unicode_table.insert(), -- {"unicode_data": u''} -+ {"unicode_data": ''} - ) - row = config.db.execute( - select([unicode_table.c.unicode_data]) - ).first() -- eq_(row, (u'',)) -+ eq_(row, ('',)) - - - class UnicodeVarcharTest(_UnicodeFixture, fixtures.TablesTest): -diff -r 9d0639b9d3be lib/sqlalchemy/testing/util.py ---- a/lib/sqlalchemy/testing/util.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/testing/util.py Sat Apr 27 19:42:17 2013 -0400 -@@ -32,13 +32,13 @@ - - def picklers(): - picklers = set() -- # Py2K -- try: -- import cPickle -- picklers.add(cPickle) -- except ImportError: -- pass -- # end Py2K -+# start Py2K -+# try: -+# import cPickle -+# picklers.add(cPickle) -+# except ImportError: -+# pass -+# end Py2K - import pickle - picklers.add(pickle) - -@@ -130,8 +130,8 @@ - try: - fn.__name__ = name - except TypeError: -- fn = types.FunctionType(fn.func_code, fn.func_globals, name, -- fn.func_defaults, fn.func_closure) -+ fn = types.FunctionType(fn.__code__, fn.__globals__, name, -+ fn.__defaults__, fn.__closure__) - return fn - - -diff -r 9d0639b9d3be lib/sqlalchemy/testing/warnings.py ---- a/lib/sqlalchemy/testing/warnings.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/testing/warnings.py Sat Apr 27 19:42:17 2013 -0400 -@@ -1,4 +1,4 @@ --from __future__ import absolute_import -+ - - import warnings - from .. import exc as sa_exc -@@ -10,7 +10,7 @@ - - filename = "sqlalchemy.testing.warnings" - lineno = 1 -- if isinstance(msg, basestring): -+ if isinstance(msg, str): - warnings.warn_explicit(msg, sa_exc.SAWarning, filename, lineno) - else: - warnings.warn_explicit(msg, filename, lineno) -diff -r 9d0639b9d3be lib/sqlalchemy/types.py ---- a/lib/sqlalchemy/types.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/types.py Sat Apr 27 19:42:17 2013 -0400 -@@ -156,8 +156,8 @@ - - """ - -- return self.__class__.column_expression.func_code \ -- is not TypeEngine.column_expression.func_code -+ return self.__class__.column_expression.__code__ \ -+ is not TypeEngine.column_expression.__code__ - - def bind_expression(self, bindvalue): - """"Given a bind value (i.e. a :class:`.BindParameter` instance), -@@ -194,8 +194,8 @@ - - """ - -- return self.__class__.bind_expression.func_code \ -- is not TypeEngine.bind_expression.func_code -+ return self.__class__.bind_expression.__code__ \ -+ is not TypeEngine.bind_expression.__code__ - - def compare_values(self, x, y): - """Compare two values for equality.""" -@@ -392,12 +392,13 @@ - return default.DefaultDialect() - - def __str__(self): -- # Py3K -- #return unicode(self.compile()) -- # Py2K -- return unicode(self.compile()).\ -- encode('ascii', 'backslashreplace') -- # end Py2K -+# start Py3K -+ return str(self.compile()) -+# end Py3K -+# start Py2K -+# return unicode(self.compile()).\ -+# encode('ascii', 'backslashreplace') -+# end Py2K - - def __init__(self, *args, **kwargs): - """Support implementations that were passing arguments""" -@@ -723,8 +724,8 @@ - - """ - -- return self.__class__.process_bind_param.func_code \ -- is not TypeDecorator.process_bind_param.func_code -+ return self.__class__.process_bind_param.__code__ \ -+ is not TypeDecorator.process_bind_param.__code__ - - def bind_processor(self, dialect): - """Provide a bound value processing function for the -@@ -769,8 +770,8 @@ - exception throw. - - """ -- return self.__class__.process_result_value.func_code \ -- is not TypeDecorator.process_result_value.func_code -+ return self.__class__.process_result_value.__code__ \ -+ is not TypeDecorator.process_result_value.__code__ - - def result_processor(self, dialect, coltype): - """Provide a result value processing function for the given -@@ -1114,11 +1115,12 @@ - self.convert_unicode != 'force': - if self._warn_on_bytestring: - def process(value): -- # Py3K -- #if isinstance(value, bytes): -- # Py2K -- if isinstance(value, str): -- # end Py2K -+# start Py3K -+ if isinstance(value, bytes): -+# end Py3K -+# start Py2K -+# if isinstance(value, str): -+# end Py2K - util.warn("Unicode type received non-unicode bind " - "param value.") - return value -@@ -1130,7 +1132,7 @@ - warn_on_bytestring = self._warn_on_bytestring - - def process(value): -- if isinstance(value, unicode): -+ if isinstance(value, str): - return encoder(value, self.unicode_error)[0] - elif warn_on_bytestring and value is not None: - util.warn("Unicode type received non-unicode bind " -@@ -1156,7 +1158,7 @@ - # habits. since we will be getting back unicode - # in most cases, we check for it (decode will fail). - def process(value): -- if isinstance(value, unicode): -+ if isinstance(value, str): - return value - else: - return to_unicode(value) -@@ -1171,7 +1173,7 @@ - @property - def python_type(self): - if self.convert_unicode: -- return unicode -+ return str - else: - return str - -@@ -1318,12 +1320,12 @@ - Integer: self.__class__, - Numeric: Numeric, - }, -- # Py2K -- operators.div: { -- Integer: self.__class__, -- Numeric: Numeric, -- }, -- # end Py2K -+# start Py2K -+# operators.div: { -+# Integer: self.__class__, -+# Numeric: Numeric, -+# }, -+# end Py2K - operators.truediv: { - Integer: self.__class__, - Numeric: Numeric, -@@ -1488,12 +1490,12 @@ - Numeric: self.__class__, - Integer: self.__class__, - }, -- # Py2K -- operators.div: { -- Numeric: self.__class__, -- Integer: self.__class__, -- }, -- # end Py2K -+# start Py2K -+# operators.div: { -+# Numeric: self.__class__, -+# Integer: self.__class__, -+# }, -+# end Py2K - operators.truediv: { - Numeric: self.__class__, - Integer: self.__class__, -@@ -1558,11 +1560,11 @@ - Interval: Interval, - Numeric: self.__class__, - }, -- # Py2K -- operators.div: { -- Numeric: self.__class__, -- }, -- # end Py2K -+# start Py2K -+# operators.div: { -+# Numeric: self.__class__, -+# }, -+# end Py2K - operators.truediv: { - Numeric: self.__class__, - }, -@@ -1693,11 +1695,12 @@ - - @property - def python_type(self): -- # Py3K -- #return bytes -- # Py2K -- return str -- # end Py2K -+# start Py3K -+ return bytes -+# end Py3K -+# start Py2K -+# return str -+# end Py2K - - # Python 3 - sqlite3 doesn't need the `Binary` conversion - # here, though pg8000 does to indicate "bytea" -@@ -1715,32 +1718,33 @@ - # Python 3 has native bytes() type - # both sqlite3 and pg8000 seem to return it, - # psycopg2 as of 2.5 returns 'memoryview' -- # Py3K -- #def result_processor(self, dialect, coltype): -- # def process(value): -- # if value is not None: -- # value = bytes(value) -- # return value -- # return process -- # Py2K -+# start Py3K - def result_processor(self, dialect, coltype): -- if util.jython: -- def process(value): -- if value is not None: -- if isinstance(value, array.array): -- return value.tostring() -- return str(value) -- else: -- return None -- else: -- process = processors.to_str -+ def process(value): -+ if value is not None: -+ value = bytes(value) -+ return value - return process -- # end Py2K -+# end Py3K -+# start Py2K -+# def result_processor(self, dialect, coltype): -+# if util.jython: -+# def process(value): -+# if value is not None: -+# if isinstance(value, array.array): -+# return value.tostring() -+# return str(value) -+# else: -+# return None -+# else: -+# process = processors.to_str -+# return process -+# end Py2K - - def coerce_compared_value(self, op, value): - """See :meth:`.TypeEngine.coerce_compared_value` for a description.""" - -- if isinstance(value, basestring): -+ if isinstance(value, str): - return self - else: - return super(_Binary, self).coerce_compared_value(op, value) -@@ -1997,7 +2001,7 @@ - convert_unicode = kw.pop('convert_unicode', None) - if convert_unicode is None: - for e in enums: -- if isinstance(e, unicode): -+ if isinstance(e, str): - convert_unicode = True - break - else: -@@ -2296,11 +2300,11 @@ - operators.truediv: { - Numeric: self.__class__ - }, -- # Py2K -- operators.div: { -- Numeric: self.__class__ -- } -- # end Py2K -+# start Py2K -+# operators.div: { -+# Numeric: self.__class__ -+# } -+# end Py2K - } - - @property -@@ -2451,11 +2455,12 @@ - - _type_map = { - str: String(), -- # Py3K -- #bytes: LargeBinary(), -- # Py2K -- unicode: Unicode(), -- # end Py2K -+# start Py3K -+ bytes: LargeBinary(), -+# end Py3K -+# start Py2K -+# unicode: Unicode(), -+# end Py2K - int: Integer(), - float: Numeric(), - bool: BOOLEANTYPE, -diff -r 9d0639b9d3be lib/sqlalchemy/util/_collections.py ---- a/lib/sqlalchemy/util/_collections.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/util/_collections.py Sat Apr 27 19:42:17 2013 -0400 -@@ -55,7 +55,7 @@ - t = tuple.__new__(cls, vals) - t._labels = [] - if labels: -- t.__dict__.update(zip(labels, vals)) -+ t.__dict__.update(list(zip(labels, vals))) - t._labels = labels - return t - -@@ -94,7 +94,7 @@ - .. versionadded:: 0.8 - - """ -- return dict((key, self.__dict__[key]) for key in self.keys()) -+ return dict((key, self.__dict__[key]) for key in list(self.keys())) - - - class ImmutableContainer(object): -@@ -142,7 +142,7 @@ - return len(self._data) - - def __iter__(self): -- return self._data.itervalues() -+ return iter(self._data.values()) - - def __add__(self, other): - return list(self) + list(other) -@@ -189,13 +189,13 @@ - return default - - def keys(self): -- return self._data.keys() -+ return list(self._data.keys()) - - def values(self): -- return self._data.values() -+ return list(self._data.values()) - - def items(self): -- return self._data.items() -+ return list(self._data.items()) - - def has_key(self, key): - return key in self._data -@@ -242,7 +242,7 @@ - def update(self, ____sequence=None, **kwargs): - if ____sequence is not None: - if hasattr(____sequence, 'keys'): -- for key in ____sequence.keys(): -+ for key in list(____sequence.keys()): - self.__setitem__(key, ____sequence[key]) - else: - for key, value in ____sequence: -@@ -270,13 +270,13 @@ - return list(self._list) - - def iterkeys(self): -- return iter(self.keys()) -+ return iter(list(self.keys())) - - def items(self): -- return [(key, self[key]) for key in self.keys()] -+ return [(key, self[key]) for key in list(self.keys())] - - def iteritems(self): -- return iter(self.items()) -+ return iter(list(self.items())) - - def __setitem__(self, key, object): - if key not in self: -@@ -470,8 +470,8 @@ - - if len(self) > len(other): - return False -- for m in itertools.ifilterfalse(other._members.__contains__, -- self._members.iterkeys()): -+ for m in itertools.filterfalse(other._members.__contains__, -+ iter(self._members.keys())): - return False - return True - -@@ -491,8 +491,8 @@ - if len(self) < len(other): - return False - -- for m in itertools.ifilterfalse(self._members.__contains__, -- other._members.iterkeys()): -+ for m in itertools.filterfalse(self._members.__contains__, -+ iter(other._members.keys())): - return False - return True - -@@ -582,7 +582,7 @@ - return result - - def _member_id_tuples(self): -- return ((id(v), v) for v in self._members.itervalues()) -+ return ((id(v), v) for v in self._members.values()) - - def __xor__(self, other): - if not isinstance(other, IdentitySet): -@@ -599,7 +599,7 @@ - return self - - def copy(self): -- return type(self)(self._members.itervalues()) -+ return type(self)(iter(self._members.values())) - - __copy__ = copy - -@@ -607,13 +607,13 @@ - return len(self._members) - - def __iter__(self): -- return self._members.itervalues() -+ return iter(self._members.values()) - - def __hash__(self): - raise TypeError('set objects are unhashable') - - def __repr__(self): -- return '%s(%r)' % (type(self).__name__, self._members.values()) -+ return '%s(%r)' % (type(self).__name__, list(self._members.values())) - - - class WeakSequence(object): -@@ -623,7 +623,7 @@ - ) - - def __iter__(self): -- return self._storage.itervalues() -+ return iter(self._storage.values()) - - def __getitem__(self, index): - try: -@@ -754,7 +754,7 @@ - - """ - for elem in x: -- if not isinstance(elem, basestring) and hasattr(elem, '__iter__'): -+ if not isinstance(elem, str) and hasattr(elem, '__iter__'): - for y in flatten_iterator(elem): - yield y - else: -diff -r 9d0639b9d3be lib/sqlalchemy/util/compat.py ---- a/lib/sqlalchemy/util/compat.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/util/compat.py Sat Apr 27 19:42:17 2013 -0400 -@@ -43,14 +43,14 @@ - - if sys.version_info < (2, 6): - def next(iter): -- return iter.next() -+ return iter.__next__() - else: - next = next - if py3k_warning: - import pickle - else: - try: -- import cPickle as pickle -+ import pickle as pickle - except ImportError: - import pickle - -@@ -59,12 +59,13 @@ - # in newer pythons - from cgi import parse_qsl - else: -- from urlparse import parse_qsl -+ from urllib.parse import parse_qsl - --# Py3K --#from inspect import getfullargspec as inspect_getfullargspec --# Py2K --from inspect import getargspec as inspect_getfullargspec -+# start Py3K -+from inspect import getfullargspec as inspect_getfullargspec -+# end Py3K -+# start Py2K -+#from inspect import getargspec as inspect_getfullargspec - # end Py2K - - if py3k_warning: -diff -r 9d0639b9d3be lib/sqlalchemy/util/deprecations.py ---- a/lib/sqlalchemy/util/deprecations.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/util/deprecations.py Sat Apr 27 19:42:17 2013 -0400 -@@ -10,7 +10,7 @@ - from .. import exc - import warnings - import re --from langhelpers import decorator -+from .langhelpers import decorator - - - def warn_deprecated(msg, stacklevel=3): -diff -r 9d0639b9d3be lib/sqlalchemy/util/langhelpers.py ---- a/lib/sqlalchemy/util/langhelpers.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/lib/sqlalchemy/util/langhelpers.py Sat Apr 27 19:42:17 2013 -0400 -@@ -21,10 +21,12 @@ - from .. import exc - import hashlib - from . import compat -+import collections - - def md5_hex(x): -- # Py3K -- #x = x.encode('utf-8') -+# start Py3K -+ x = x.encode('utf-8') -+# end Py3K - m = hashlib.md5() - m.update(x) - return m.hexdigest() -@@ -77,8 +79,8 @@ - used = set(used) - for base in bases: - pool = itertools.chain((base,), -- itertools.imap(lambda i: base + str(i), -- xrange(1000))) -+ map(lambda i: base + str(i), -+ range(1000))) - for sym in pool: - if sym not in used: - used.add(sym) -@@ -95,7 +97,7 @@ - if not inspect.isfunction(fn): - raise Exception("not a decoratable function") - spec = inspect_getfullargspec(fn) -- names = tuple(spec[0]) + spec[1:3] + (fn.func_name,) -+ names = tuple(spec[0]) + spec[1:3] + (fn.__name__,) - targ_name, fn_name = _unique_symbols(names, 'target', 'fn') - - metadata = dict(target=targ_name, fn=fn_name) -@@ -104,7 +106,7 @@ - code = 'lambda %(args)s: %(target)s(%(fn)s, %(apply_kw)s)' % ( - metadata) - decorated = eval(code, {targ_name: target, fn_name: fn}) -- decorated.func_defaults = getattr(fn, 'im_func', fn).func_defaults -+ decorated.__defaults__ = getattr(fn, 'im_func', fn).__defaults__ - return update_wrapper(decorated, fn) - return update_wrapper(decorate, target) - -@@ -176,7 +178,7 @@ - ctr = class_.__dict__.get('__init__', False) - if (not ctr or - not isinstance(ctr, types.FunctionType) or -- not isinstance(ctr.func_code, types.CodeType)): -+ not isinstance(ctr.__code__, types.CodeType)): - stack.update(class_.__bases__) - continue - -@@ -194,7 +196,7 @@ - from inspect import CO_VARKEYWORDS - - def inspect_func_args(fn): -- co = fn.func_code -+ co = fn.__code__ - nargs = co.co_argcount - names = co.co_varnames - args = list(names[:nargs]) -@@ -250,7 +252,7 @@ - 'apply_pos': '(self, a, b, c, **d)'} - - """ -- if callable(fn): -+ if isinstance(fn, collections.Callable): - spec = inspect_getfullargspec(fn) - else: - # we accept an existing argspec... -@@ -263,22 +265,23 @@ - else: - self_arg = None - -- # Py3K -- #apply_pos = inspect.formatargspec(spec[0], spec[1], -- # spec[2], None, spec[4]) -- #num_defaults = 0 -- #if spec[3]: -- # num_defaults += len(spec[3]) -- #if spec[4]: -- # num_defaults += len(spec[4]) -- #name_args = spec[0] + spec[4] -- # Py2K -- apply_pos = inspect.formatargspec(spec[0], spec[1], spec[2]) -+# start Py3K -+ apply_pos = inspect.formatargspec(spec[0], spec[1], -+ spec[2], None, spec[4]) - num_defaults = 0 - if spec[3]: - num_defaults += len(spec[3]) -- name_args = spec[0] -- # end Py2K -+ if spec[4]: -+ num_defaults += len(spec[4]) -+ name_args = spec[0] + spec[4] -+# end Py3K -+# start Py2K -+# apply_pos = inspect.formatargspec(spec[0], spec[1], spec[2]) -+# num_defaults = 0 -+# if spec[3]: -+# num_defaults += len(spec[3]) -+# name_args = spec[0] -+# end Py2K - - if num_defaults: - defaulted_vals = name_args[0 - num_defaults:] -@@ -341,8 +344,8 @@ - - """ - -- if isinstance(func_or_cls, types.MethodType) and not func_or_cls.im_self: -- return func_or_cls.im_func -+ if isinstance(func_or_cls, types.MethodType) and not func_or_cls.__self__: -+ return func_or_cls.__func__ - else: - return func_or_cls - -@@ -399,7 +402,7 @@ - - """ - def __init__(self, meth): -- self.target = meth.im_self -+ self.target = meth.__self__ - self.name = meth.__name__ - - def __call__(self, *arg, **kw): -@@ -419,32 +422,34 @@ - will not be descended. - - """ -- # Py2K -- if isinstance(cls, types.ClassType): -- return list() -- # end Py2K -+# start Py2K -+# if isinstance(cls, types.ClassType): -+# return list() -+# end Py2K - hier = set([cls]) - process = list(cls.__mro__) - while process: - c = process.pop() -- # Py2K -- if isinstance(c, types.ClassType): -- continue -+# start Py2K -+# if isinstance(c, types.ClassType): -+# continue -+# for b in (_ for _ in c.__bases__ -+# if _ not in hier and not isinstance(_, types.ClassType)): -+# end Py2K -+# start Py3K - for b in (_ for _ in c.__bases__ -- if _ not in hier and not isinstance(_, types.ClassType)): -- # end Py2K -- # Py3K -- #for b in (_ for _ in c.__bases__ -- # if _ not in hier): -+ if _ not in hier): -+# end Py3K - process.append(b) - hier.add(b) -- # Py3K -- #if c.__module__ == 'builtins' or not hasattr(c, '__subclasses__'): -- # continue -- # Py2K -- if c.__module__ == '__builtin__' or not hasattr(c, '__subclasses__'): -+# start Py3K -+ if c.__module__ == 'builtins' or not hasattr(c, '__subclasses__'): - continue -- # end Py2K -+# end Py3K -+# start Py2K -+# if c.__module__ == '__builtin__' or not hasattr(c, '__subclasses__'): -+# continue -+# end Py2K - for s in [_ for _ in c.__subclasses__() if _ not in hier]: - process.append(s) - hier.add(s) -@@ -501,9 +506,9 @@ - "return %(name)s.%(method)s%(d_args)s" % locals()) - - env = from_instance is not None and {name: from_instance} or {} -- exec py in env -+ exec(py, env) - try: -- env[method].func_defaults = fn.func_defaults -+ env[method].__defaults__ = fn.__defaults__ - except AttributeError: - pass - setattr(into_cls, method, env[method]) -@@ -512,11 +517,12 @@ - def methods_equivalent(meth1, meth2): - """Return True if the two methods are the same implementation.""" - -- # Py3K -- #return getattr(meth1, '__func__', meth1) is getattr(meth2, '__func__', meth2) -- # Py2K -- return getattr(meth1, 'im_func', meth1) is getattr(meth2, 'im_func', meth2) -- # end Py2K -+# start Py3K -+ return getattr(meth1, '__func__', meth1) is getattr(meth2, '__func__', meth2) -+# end Py3K -+# start Py2K -+# return getattr(meth1, 'im_func', meth1) is getattr(meth2, 'im_func', meth2) -+# end Py2K - - - def as_interface(obj, cls=None, methods=None, required=None): -@@ -589,7 +595,7 @@ - for method, impl in dictlike_iteritems(obj): - if method not in interface: - raise TypeError("%r: unknown in this interface" % method) -- if not callable(impl): -+ if not isinstance(impl, collections.Callable): - raise TypeError("%r=%r is not callable" % (method, impl)) - setattr(AnonymousInterface, method, staticmethod(impl)) - found.add(method) -@@ -753,7 +759,7 @@ - - # from paste.deploy.converters - def asbool(obj): -- if isinstance(obj, (str, unicode)): -+ if isinstance(obj, str): - obj = obj.strip().lower() - if obj in ['true', 'yes', 'on', 'y', 't', '1']: - return True -@@ -814,13 +820,13 @@ - """Return a threadsafe counter function.""" - - lock = threading.Lock() -- counter = itertools.count(1L) -+ counter = itertools.count(1) - - # avoid the 2to3 "next" transformation... - def _next(): - lock.acquire() - try: -- return counter.next() -+ return next(counter) - finally: - lock.release() - -@@ -876,15 +882,16 @@ - def dictlike_iteritems(dictlike): - """Return a (key, value) iterator for almost any dict-like object.""" - -- # Py3K -- #if hasattr(dictlike, 'items'): -- # return dictlike.items() -- # Py2K -- if hasattr(dictlike, 'iteritems'): -- return dictlike.iteritems() -- elif hasattr(dictlike, 'items'): -- return iter(dictlike.items()) -- # end Py2K -+# start Py3K -+ if hasattr(dictlike, 'items'): -+ return list(dictlike.items()) -+# end Py3K -+# start Py2K -+# if hasattr(dictlike, 'iteritems'): -+# return dictlike.iteritems() -+# elif hasattr(dictlike, 'items'): -+# return iter(dictlike.items()) -+# end Py2K - - getter = getattr(dictlike, '__getitem__', getattr(dictlike, 'get', None)) - if getter is None: -@@ -893,11 +900,11 @@ - - if hasattr(dictlike, 'iterkeys'): - def iterator(): -- for key in dictlike.iterkeys(): -+ for key in dictlike.keys(): - yield key, getter(key) - return iterator() - elif hasattr(dictlike, 'keys'): -- return iter((key, getter(key)) for key in dictlike.keys()) -+ return iter((key, getter(key)) for key in list(dictlike.keys())) - else: - raise TypeError( - "Object '%r' is not dict-like" % dictlike) -@@ -1034,7 +1041,7 @@ - be controlled. - - """ -- if isinstance(msg, basestring): -+ if isinstance(msg, str): - warnings.warn(msg, exc.SAWarning, stacklevel=stacklevel) - else: - warnings.warn(msg, stacklevel=stacklevel) -diff -r 9d0639b9d3be test/aaa_profiling/test_compiler.py ---- a/test/aaa_profiling/test_compiler.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/aaa_profiling/test_compiler.py Sat Apr 27 19:42:17 2013 -0400 -@@ -29,7 +29,7 @@ - for c in t.c: - c.type._type_affinity - from sqlalchemy import types -- for t in types._type_map.values(): -+ for t in list(types._type_map.values()): - t._type_affinity - - cls.dialect = default.DefaultDialect() -diff -r 9d0639b9d3be test/aaa_profiling/test_memusage.py ---- a/test/aaa_profiling/test_memusage.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/aaa_profiling/test_memusage.py Sat Apr 27 19:42:17 2013 -0400 -@@ -47,7 +47,7 @@ - gc_collect() - samples[x] = len(get_objects_skipping_sqlite_issue()) - -- print "sample gc sizes:", samples -+ print("sample gc sizes:", samples) - - assert len(_sessions) == 0 - -diff -r 9d0639b9d3be test/aaa_profiling/test_orm.py ---- a/test/aaa_profiling/test_orm.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/aaa_profiling/test_orm.py Sat Apr 27 19:42:17 2013 -0400 -@@ -144,7 +144,7 @@ - - child.insert().execute([ - {'id':i, 'data':'c%d' % i} -- for i in xrange(1, 251) -+ for i in range(1, 251) - ]) - parent.insert().execute([ - { -@@ -152,7 +152,7 @@ - 'data':'p%dc%d' % (i, (i % 250) + 1), - 'child_id':(i % 250) + 1 - } -- for i in xrange(1, 1000) -+ for i in range(1, 1000) - ]) - - def test_many_to_one_load_no_identity(self): -@@ -234,11 +234,11 @@ - s = Session() - s.add_all([ - A(id=i, -- bs=[B(id=(i * 5) + j) for j in xrange(1, 5)], -+ bs=[B(id=(i * 5) + j) for j in range(1, 5)], - c=C(id=i), -- ds=[D(id=(i * 5) + j) for j in xrange(1, 5)] -+ ds=[D(id=(i * 5) + j) for j in range(1, 5)] - ) -- for i in xrange(1, 5) -+ for i in range(1, 5) - ]) - s.commit() - -@@ -249,11 +249,11 @@ - s = Session() - for a in [ - A(id=i, -- bs=[B(id=(i * 5) + j) for j in xrange(1, 5)], -+ bs=[B(id=(i * 5) + j) for j in range(1, 5)], - c=C(id=i), -- ds=[D(id=(i * 5) + j) for j in xrange(1, 5)] -+ ds=[D(id=(i * 5) + j) for j in range(1, 5)] - ) -- for i in xrange(1, 5) -+ for i in range(1, 5) - ]: - s.merge(a) - -diff -r 9d0639b9d3be test/aaa_profiling/test_resultset.py ---- a/test/aaa_profiling/test_resultset.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/aaa_profiling/test_resultset.py Sat Apr 27 19:42:17 2013 -0400 -@@ -19,10 +19,10 @@ - - def setup(self): - metadata.create_all() -- t.insert().execute([dict(('field%d' % fnum, u'value%d' % fnum) -+ t.insert().execute([dict(('field%d' % fnum, 'value%d' % fnum) - for fnum in range(NUM_FIELDS)) for r_num in - range(NUM_RECORDS)]) -- t2.insert().execute([dict(('field%d' % fnum, u'value%d' % fnum) -+ t2.insert().execute([dict(('field%d' % fnum, 'value%d' % fnum) - for fnum in range(NUM_FIELDS)) for r_num in - range(NUM_RECORDS)]) - -@@ -88,7 +88,7 @@ - - keymap = {} - for index, (keyobjs, processor, values) in \ -- enumerate(zip(keys, processors, row)): -+ enumerate(list(zip(keys, processors, row))): - for key in keyobjs: - keymap[key] = (processor, key, index) - keymap[index] = (processor, key, index) -diff -r 9d0639b9d3be test/aaa_profiling/test_zoomark.py ---- a/test/aaa_profiling/test_zoomark.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/aaa_profiling/test_zoomark.py Sat Apr 27 19:42:17 2013 -0400 -@@ -72,68 +72,68 @@ - Zoo = metadata.tables['Zoo'] - Animal = metadata.tables['Animal'] - engine = metadata.bind -- wap = engine.execute(Zoo.insert(), Name=u'Wild Animal Park', -+ wap = engine.execute(Zoo.insert(), Name='Wild Animal Park', - Founded=datetime.date(2000, 1, 1), - Opens=datetime.time(8, 15, 59), - LastEscape= - datetime.datetime(2004, 7, 29, 5, 6, 7), - Admission=4.95).inserted_primary_key[0] -- sdz = engine.execute(Zoo.insert(), Name=u'San Diego Zoo', -+ sdz = engine.execute(Zoo.insert(), Name='San Diego Zoo', - Founded=datetime.date(1935, 9, 13), - Opens=datetime.time(9, 0, 0), - Admission=0).inserted_primary_key[0] -- engine.execute(Zoo.insert(inline=True), Name=u'Montr\xe9al Biod\xf4me', -+ engine.execute(Zoo.insert(inline=True), Name='Montr\xe9al Biod\xf4me', - Founded=datetime.date(1992, 6, 19), - Opens=datetime.time(9, 0, 0), Admission=11.75) -- seaworld = engine.execute(Zoo.insert(), Name=u'Sea_World', -+ seaworld = engine.execute(Zoo.insert(), Name='Sea_World', - Admission=60).inserted_primary_key[0] - - # Let's add a crazy futuristic Zoo to test large date values. - -- lp = engine.execute(Zoo.insert(), Name=u'Luna Park', -+ lp = engine.execute(Zoo.insert(), Name='Luna Park', - Founded=datetime.date(2072, 7, 17), - Opens=datetime.time(0, 0, 0), - Admission=134.95).inserted_primary_key[0] - - # Animals - -- leopardid = engine.execute(Animal.insert(), Species=u'Leopard', -+ leopardid = engine.execute(Animal.insert(), Species='Leopard', - Lifespan=73.5).inserted_primary_key[0] - engine.execute(Animal.update(Animal.c.ID == leopardid), ZooID=wap, - LastEscape=datetime.datetime( 2004, 12, 21, 8, 15, 0, 999907,) - ) -- lion = engine.execute(Animal.insert(), Species=u'Lion', -+ lion = engine.execute(Animal.insert(), Species='Lion', - ZooID=wap).inserted_primary_key[0] -- engine.execute(Animal.insert(), Species=u'Slug', Legs=1, Lifespan=.75) -- tiger = engine.execute(Animal.insert(), Species=u'Tiger', -+ engine.execute(Animal.insert(), Species='Slug', Legs=1, Lifespan=.75) -+ tiger = engine.execute(Animal.insert(), Species='Tiger', - ZooID=sdz).inserted_primary_key[0] - - # Override Legs.default with itself just to make sure it works. - -- engine.execute(Animal.insert(inline=True), Species=u'Bear', Legs=4) -- engine.execute(Animal.insert(inline=True), Species=u'Ostrich', Legs=2, -+ engine.execute(Animal.insert(inline=True), Species='Bear', Legs=4) -+ engine.execute(Animal.insert(inline=True), Species='Ostrich', Legs=2, - Lifespan=103.2) -- engine.execute(Animal.insert(inline=True), Species=u'Centipede', -+ engine.execute(Animal.insert(inline=True), Species='Centipede', - Legs=100) -- emp = engine.execute(Animal.insert(), Species=u'Emperor Penguin', -+ emp = engine.execute(Animal.insert(), Species='Emperor Penguin', - Legs=2, ZooID=seaworld).inserted_primary_key[0] -- adelie = engine.execute(Animal.insert(), Species=u'Adelie Penguin', -+ adelie = engine.execute(Animal.insert(), Species='Adelie Penguin', - Legs=2, ZooID=seaworld).inserted_primary_key[0] -- engine.execute(Animal.insert(inline=True), Species=u'Millipede', -+ engine.execute(Animal.insert(inline=True), Species='Millipede', - Legs=1000000, ZooID=sdz) - - # Add a mother and child to test relationships - -- bai_yun = engine.execute(Animal.insert(), Species=u'Ape', -- Name=u'Bai Yun', Legs=2).inserted_primary_key[0] -- engine.execute(Animal.insert(inline=True), Species=u'Ape', -- Name=u'Hua Mei', Legs=2, MotherID=bai_yun) -+ bai_yun = engine.execute(Animal.insert(), Species='Ape', -+ Name='Bai Yun', Legs=2).inserted_primary_key[0] -+ engine.execute(Animal.insert(inline=True), Species='Ape', -+ Name='Hua Mei', Legs=2, MotherID=bai_yun) - - def test_baseline_2_insert(self): - Animal = metadata.tables['Animal'] - i = Animal.insert(inline=True) -- for x in xrange(ITERATIONS): -- tick = i.execute(Species=u'Tick', Name=u'Tick %d' % x, -+ for x in range(ITERATIONS): -+ tick = i.execute(Species='Tick', Name='Tick %d' % x, - Legs=8) - - def test_baseline_3_properties(self): -@@ -146,28 +146,28 @@ - - return list(engine.execute(select).first()) - -- for x in xrange(ITERATIONS): -+ for x in range(ITERATIONS): - - # Zoos - - WAP = fullobject(Zoo.select(Zoo.c.Name -- == u'Wild Animal Park')) -+ == 'Wild Animal Park')) - SDZ = fullobject(Zoo.select(Zoo.c.Founded - == datetime.date(1935, 9, 13))) - Biodome = fullobject(Zoo.select(Zoo.c.Name -- == u'Montr\xe9al Biod\xf4me')) -+ == 'Montr\xe9al Biod\xf4me')) - seaworld = fullobject(Zoo.select(Zoo.c.Admission - == float(60))) - - # Animals - - leopard = fullobject(Animal.select(Animal.c.Species -- == u'Leopard')) -+ == 'Leopard')) - ostrich = fullobject(Animal.select(Animal.c.Species -- == u'Ostrich')) -+ == 'Ostrich')) - millipede = fullobject(Animal.select(Animal.c.Legs - == 1000000)) -- ticks = fullobject(Animal.select(Animal.c.Species == u'Tick' -+ ticks = fullobject(Animal.select(Animal.c.Species == 'Tick' - )) - - def test_baseline_4_expressions(self): -@@ -180,7 +180,7 @@ - - return [list(row) for row in engine.execute(select).fetchall()] - -- for x in xrange(ITERATIONS): -+ for x in range(ITERATIONS): - assert len(fulltable(Zoo.select())) == 5 - assert len(fulltable(Animal.select())) == ITERATIONS + 12 - assert len(fulltable(Animal.select(Animal.c.Legs == 4))) \ -@@ -194,9 +194,9 @@ - assert len(fulltable(Animal.select(Animal.c.Lifespan - > 70))) == 2 - assert len(fulltable(Animal.select(Animal.c.Species. -- startswith(u'L')))) == 2 -+ startswith('L')))) == 2 - assert len(fulltable(Animal.select(Animal.c.Species. -- endswith(u'pede')))) == 2 -+ endswith('pede')))) == 2 - assert len(fulltable(Animal.select(Animal.c.LastEscape - != None))) == 1 - assert len(fulltable(Animal.select(None -@@ -204,10 +204,10 @@ - - # In operator (containedby) - -- assert len(fulltable(Animal.select(Animal.c.Species.like(u'%pede%' -+ assert len(fulltable(Animal.select(Animal.c.Species.like('%pede%' - )))) == 2 -- assert len(fulltable(Animal.select(Animal.c.Species.in_([u'Lion' -- , u'Tiger', u'Bear'])))) == 3 -+ assert len(fulltable(Animal.select(Animal.c.Species.in_(['Lion' -+ , 'Tiger', 'Bear'])))) == 3 - - # Try In with cell references - class thing(object): -@@ -215,20 +215,20 @@ - - - pet, pet2 = thing(), thing() -- pet.Name, pet2.Name = u'Slug', u'Ostrich' -+ pet.Name, pet2.Name = 'Slug', 'Ostrich' - assert len(fulltable(Animal.select(Animal.c.Species.in_([pet.Name, - pet2.Name])))) == 2 - - # logic and other functions - -- assert len(fulltable(Animal.select(Animal.c.Species.like(u'Slug' -+ assert len(fulltable(Animal.select(Animal.c.Species.like('Slug' - )))) == 1 -- assert len(fulltable(Animal.select(Animal.c.Species.like(u'%pede%' -+ assert len(fulltable(Animal.select(Animal.c.Species.like('%pede%' - )))) == 2 -- name = u'Lion' -+ name = 'Lion' - assert len(fulltable(Animal.select(func.length(Animal.c.Species) - == len(name)))) == ITERATIONS + 3 -- assert len(fulltable(Animal.select(Animal.c.Species.like(u'%i%' -+ assert len(fulltable(Animal.select(Animal.c.Species.like('%i%' - )))) == ITERATIONS + 7 - - # Test now(), today(), year(), month(), day() -@@ -250,7 +250,7 @@ - Zoo = metadata.tables['Zoo'] - engine = metadata.bind - -- for x in xrange(ITERATIONS): -+ for x in range(ITERATIONS): - - # views - -@@ -274,7 +274,7 @@ - for species, lifespan in engine.execute(select([Animal.c.Species, - Animal.c.Lifespan])).fetchall(): - assert lifespan == expected[species] -- expected = [u'Montr\xe9al Biod\xf4me', 'Wild Animal Park'] -+ expected = ['Montr\xe9al Biod\xf4me', 'Wild Animal Park'] - e = select([Zoo.c.Name], and_(Zoo.c.Founded != None, - Zoo.c.Founded <= func.current_timestamp(), - Zoo.c.Founded >= datetime.date(1990, 1, 1))) -@@ -290,21 +290,21 @@ - def test_baseline_6_editing(self): - Zoo = metadata.tables['Zoo'] - engine = metadata.bind -- for x in xrange(ITERATIONS): -+ for x in range(ITERATIONS): - - # Edit - -- SDZ = engine.execute(Zoo.select(Zoo.c.Name == u'San Diego Zoo' -+ SDZ = engine.execute(Zoo.select(Zoo.c.Name == 'San Diego Zoo' - )).first() - engine.execute(Zoo.update(Zoo.c.ID == SDZ['ID' -- ]), Name=u'The San Diego Zoo', -+ ]), Name='The San Diego Zoo', - Founded=datetime.date(1900, 1, 1), - Opens=datetime.time(7, 30, 0), - Admission='35.00') - - # Test edits - -- SDZ = engine.execute(Zoo.select(Zoo.c.Name == u'The San Diego Zoo' -+ SDZ = engine.execute(Zoo.select(Zoo.c.Name == 'The San Diego Zoo' - )).first() - assert SDZ['Founded'] == datetime.date(1900, 1, 1), \ - SDZ['Founded'] -@@ -312,14 +312,14 @@ - # Change it back - - engine.execute(Zoo.update(Zoo.c.ID == SDZ['ID' -- ]), Name=u'San Diego Zoo', -+ ]), Name='San Diego Zoo', - Founded=datetime.date(1935, 9, 13), - Opens=datetime.time(9, 0, 0), - Admission='0') - - # Test re-edits - -- SDZ = engine.execute(Zoo.select(Zoo.c.Name == u'San Diego Zoo' -+ SDZ = engine.execute(Zoo.select(Zoo.c.Name == 'San Diego Zoo' - )).first() - assert SDZ['Founded'] == datetime.date(1935, 9, 13) - -@@ -333,14 +333,14 @@ - - return [list(row) for row in engine.execute(select).fetchall()] - -- for x in xrange(ITERATIONS): -+ for x in range(ITERATIONS): - za = fulltable(select([Zoo.c.ID] + list(Animal.c), -- Zoo.c.Name == u'San Diego Zoo', -+ Zoo.c.Name == 'San Diego Zoo', - from_obj=[join(Zoo, Animal)])) -- SDZ = Zoo.select(Zoo.c.Name == u'San Diego Zoo') -+ SDZ = Zoo.select(Zoo.c.Name == 'San Diego Zoo') - e = fulltable(select([Zoo.c.ID, Animal.c.ID], -- and_(Zoo.c.Name == u'San Diego Zoo', -- Animal.c.Species == u'Leopard'), -+ and_(Zoo.c.Name == 'San Diego Zoo', -+ Animal.c.Species == 'Leopard'), - from_obj=[join(Zoo, Animal)])) - - # Now try the same query with INNER, LEFT, and RIGHT JOINs. -diff -r 9d0639b9d3be test/aaa_profiling/test_zoomark_orm.py ---- a/test/aaa_profiling/test_zoomark_orm.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/aaa_profiling/test_zoomark_orm.py Sat Apr 27 19:42:17 2013 -0400 -@@ -75,14 +75,14 @@ - class Zoo(object): - - def __init__(self, **kwargs): -- for k, v in kwargs.iteritems(): -+ for k, v in kwargs.items(): - setattr(self, k, v) - - - class Animal(object): - - def __init__(self, **kwargs): -- for k, v in kwargs.iteritems(): -+ for k, v in kwargs.items(): - setattr(self, k, v) - - -@@ -90,93 +90,93 @@ - mapper(Animal, animal) - - def test_baseline_1a_populate(self): -- wap = Zoo(Name=u'Wild Animal Park', Founded=datetime.date(2000, -+ wap = Zoo(Name='Wild Animal Park', Founded=datetime.date(2000, - 1, 1), Opens=datetime.time(8, 15, 59), - LastEscape=datetime.datetime( 2004, 7, 29, 5, 6, 7, ), - Admission=4.95) - session.add(wap) -- sdz = Zoo(Name=u'San Diego Zoo', Founded=datetime.date(1835, 9, -+ sdz = Zoo(Name='San Diego Zoo', Founded=datetime.date(1835, 9, - 13), Opens=datetime.time(9, 0, 0), Admission=0) - session.add(sdz) -- bio = Zoo(Name=u'Montr\xe9al Biod\xf4me', -+ bio = Zoo(Name='Montr\xe9al Biod\xf4me', - Founded=datetime.date(1992, 6, 19), - Opens=datetime.time(9, 0, 0), Admission=11.75) - session.add(bio) -- seaworld = Zoo(Name=u'Sea_World', Admission=60) -+ seaworld = Zoo(Name='Sea_World', Admission=60) - session.add(seaworld) - - # Let's add a crazy futuristic Zoo to test large date values. - -- lp = Zoo(Name=u'Luna Park', Founded=datetime.date(2072, 7, 17), -+ lp = Zoo(Name='Luna Park', Founded=datetime.date(2072, 7, 17), - Opens=datetime.time(0, 0, 0), Admission=134.95) - session.add(lp) - session.flush() - - # Animals - -- leopard = Animal(Species=u'Leopard', Lifespan=73.5) -+ leopard = Animal(Species='Leopard', Lifespan=73.5) - session.add(leopard) - leopard.ZooID = wap.ID - leopard.LastEscape = \ - datetime.datetime(2004, 12, 21, 8, 15, 0, 999907, ) -- session.add(Animal(Species=u'Lion', ZooID=wap.ID)) -- session.add(Animal(Species=u'Slug', Legs=1, Lifespan=.75)) -- session.add(Animal(Species=u'Tiger', ZooID=sdz.ID)) -+ session.add(Animal(Species='Lion', ZooID=wap.ID)) -+ session.add(Animal(Species='Slug', Legs=1, Lifespan=.75)) -+ session.add(Animal(Species='Tiger', ZooID=sdz.ID)) - - # Override Legs.default with itself just to make sure it works. - -- session.add(Animal(Species=u'Bear', Legs=4)) -- session.add(Animal(Species=u'Ostrich', Legs=2, Lifespan=103.2)) -- session.add(Animal(Species=u'Centipede', Legs=100)) -- session.add(Animal(Species=u'Emperor Penguin', Legs=2, -+ session.add(Animal(Species='Bear', Legs=4)) -+ session.add(Animal(Species='Ostrich', Legs=2, Lifespan=103.2)) -+ session.add(Animal(Species='Centipede', Legs=100)) -+ session.add(Animal(Species='Emperor Penguin', Legs=2, - ZooID=seaworld.ID)) -- session.add(Animal(Species=u'Adelie Penguin', Legs=2, -+ session.add(Animal(Species='Adelie Penguin', Legs=2, - ZooID=seaworld.ID)) -- session.add(Animal(Species=u'Millipede', Legs=1000000, -+ session.add(Animal(Species='Millipede', Legs=1000000, - ZooID=sdz.ID)) - - # Add a mother and child to test relationships - -- bai_yun = Animal(Species=u'Ape', Nameu=u'Bai Yun', Legs=2) -+ bai_yun = Animal(Species='Ape', Nameu='Bai Yun', Legs=2) - session.add(bai_yun) -- session.add(Animal(Species=u'Ape', Name=u'Hua Mei', Legs=2, -+ session.add(Animal(Species='Ape', Name='Hua Mei', Legs=2, - MotherID=bai_yun.ID)) - session.flush() - session.commit() - - def test_baseline_2_insert(self): -- for x in xrange(ITERATIONS): -- session.add(Animal(Species=u'Tick', Name=u'Tick %d' % x, -+ for x in range(ITERATIONS): -+ session.add(Animal(Species='Tick', Name='Tick %d' % x, - Legs=8)) - session.flush() - - def test_baseline_3_properties(self): -- for x in xrange(ITERATIONS): -+ for x in range(ITERATIONS): - - # Zoos - - WAP = list(session.query(Zoo).filter(Zoo.Name -- == u'Wild Animal Park')) -+ == 'Wild Animal Park')) - SDZ = list(session.query(Zoo).filter(Zoo.Founded - == datetime.date(1835, 9, 13))) - Biodome = list(session.query(Zoo).filter(Zoo.Name -- == u'Montr\xe9al Biod\xf4me')) -+ == 'Montr\xe9al Biod\xf4me')) - seaworld = list(session.query(Zoo).filter(Zoo.Admission - == float(60))) - - # Animals - - leopard = list(session.query(Animal).filter(Animal.Species -- == u'Leopard')) -+ == 'Leopard')) - ostrich = list(session.query(Animal).filter(Animal.Species -- == u'Ostrich')) -+ == 'Ostrich')) - millipede = list(session.query(Animal).filter(Animal.Legs - == 1000000)) - ticks = list(session.query(Animal).filter(Animal.Species -- == u'Tick')) -+ == 'Tick')) - - def test_baseline_4_expressions(self): -- for x in xrange(ITERATIONS): -+ for x in range(ITERATIONS): - assert len(list(session.query(Zoo))) == 5 - assert len(list(session.query(Animal))) == ITERATIONS + 12 - assert len(list(session.query(Animal).filter(Animal.Legs -@@ -190,9 +190,9 @@ - assert len(list(session.query(Animal).filter(Animal.Lifespan - > 70))) == 2 - assert len(list(session.query(Animal). -- filter(Animal.Species.like(u'L%')))) == 2 -+ filter(Animal.Species.like('L%')))) == 2 - assert len(list(session.query(Animal). -- filter(Animal.Species.like(u'%pede')))) == 2 -+ filter(Animal.Species.like('%pede')))) == 2 - assert len(list(session.query(Animal).filter(Animal.LastEscape - != None))) == 1 - assert len(list(session.query(Animal).filter(Animal.LastEscape -@@ -201,29 +201,29 @@ - # In operator (containedby) - - assert len(list(session.query(Animal).filter( -- Animal.Species.like(u'%pede%')))) == 2 -+ Animal.Species.like('%pede%')))) == 2 - assert len(list(session.query(Animal). -- filter(Animal.Species.in_((u'Lion' -- , u'Tiger', u'Bear'))))) == 3 -+ filter(Animal.Species.in_(('Lion' -+ , 'Tiger', 'Bear'))))) == 3 - - # Try In with cell references - class thing(object): - pass - - pet, pet2 = thing(), thing() -- pet.Name, pet2.Name = u'Slug', u'Ostrich' -+ pet.Name, pet2.Name = 'Slug', 'Ostrich' - assert len(list(session.query(Animal). - filter(Animal.Species.in_((pet.Name, - pet2.Name))))) == 2 - - # logic and other functions - -- name = u'Lion' -+ name = 'Lion' - assert len(list(session.query(Animal). - filter(func.length(Animal.Species) - == len(name)))) == ITERATIONS + 3 - assert len(list(session.query(Animal). -- filter(Animal.Species.like(u'%i%' -+ filter(Animal.Species.like('%i%' - )))) == ITERATIONS + 7 - - # Test now(), today(), year(), month(), day() -@@ -246,7 +246,7 @@ - - # TODO: convert to ORM - engine = metadata.bind -- for x in xrange(ITERATIONS): -+ for x in range(ITERATIONS): - - # views - -@@ -270,7 +270,7 @@ - for species, lifespan in engine.execute(select([Animal.c.Species, - Animal.c.Lifespan])).fetchall(): - assert lifespan == expected[species] -- expected = [u'Montr\xe9al Biod\xf4me', 'Wild Animal Park'] -+ expected = ['Montr\xe9al Biod\xf4me', 'Wild Animal Park'] - e = select([Zoo.c.Name], and_(Zoo.c.Founded != None, - Zoo.c.Founded <= func.current_timestamp(), - Zoo.c.Founded >= datetime.date(1990, 1, 1))) -@@ -284,13 +284,13 @@ - legs.sort() - - def test_baseline_6_editing(self): -- for x in xrange(ITERATIONS): -+ for x in range(ITERATIONS): - - # Edit - -- SDZ = session.query(Zoo).filter(Zoo.Name == u'San Diego Zoo' -+ SDZ = session.query(Zoo).filter(Zoo.Name == 'San Diego Zoo' - ).one() -- SDZ.Name = u'The San Diego Zoo' -+ SDZ.Name = 'The San Diego Zoo' - SDZ.Founded = datetime.date(1900, 1, 1) - SDZ.Opens = datetime.time(7, 30, 0) - SDZ.Admission = 35.00 -@@ -298,19 +298,19 @@ - # Test edits - - SDZ = session.query(Zoo).filter(Zoo.Name -- == u'The San Diego Zoo').one() -+ == 'The San Diego Zoo').one() - assert SDZ.Founded == datetime.date(1900, 1, 1), SDZ.Founded - - # Change it back - -- SDZ.Name = u'San Diego Zoo' -+ SDZ.Name = 'San Diego Zoo' - SDZ.Founded = datetime.date(1835, 9, 13) - SDZ.Opens = datetime.time(9, 0, 0) - SDZ.Admission = 0 - - # Test re-edits - -- SDZ = session.query(Zoo).filter(Zoo.Name == u'San Diego Zoo' -+ SDZ = session.query(Zoo).filter(Zoo.Name == 'San Diego Zoo' - ).one() - assert SDZ.Founded == datetime.date(1835, 9, 13), \ - SDZ.Founded -diff -r 9d0639b9d3be test/base/test_dependency.py ---- a/test/base/test_dependency.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/base/test_dependency.py Sat Apr 27 19:42:17 2013 -0400 -@@ -82,7 +82,7 @@ - try: - list(topological.sort(tuples, allitems)) - assert False -- except exc.CircularDependencyError, err: -+ except exc.CircularDependencyError as err: - eq_(err.cycles, set(['node1', 'node3', 'node2', 'node5', - 'node4'])) - eq_(err.edges, set([('node3', 'node1'), ('node4', 'node1'), -@@ -105,7 +105,7 @@ - try: - list(topological.sort(tuples, allitems)) - assert False -- except exc.CircularDependencyError, err: -+ except exc.CircularDependencyError as err: - eq_(err.cycles, set(['node1', 'node3', 'node2'])) - eq_(err.edges, set([('node3', 'node1'), ('node2', 'node3'), - ('node3', 'node2'), ('node1', 'node2'), -@@ -271,7 +271,7 @@ - ('node4', 'node17'), ('node2', 'node20'), ('node19', 'node10'), - ('node8', 'node4'), ('node11', 'node3'), ('node6', 'node1') - ] -- allnodes = ['node%d' % i for i in xrange(1, 21)] -+ allnodes = ['node%d' % i for i in range(1, 21)] - eq_( - topological.find_cycles(tuples, allnodes), - set(['node11', 'node10', 'node13', 'node15', 'node14', 'node17', -diff -r 9d0639b9d3be test/base/test_events.py ---- a/test/base/test_events.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/base/test_events.py Sat Apr 27 19:42:17 2013 -0400 -@@ -190,7 +190,7 @@ - def test_lis_subcalss_lis(self): - @event.listens_for(self.TargetOne, "event_one") - def handler1(x, y): -- print 'handler1' -+ print('handler1') - - class SubTarget(self.TargetOne): - pass -@@ -207,7 +207,7 @@ - def test_lis_multisub_lis(self): - @event.listens_for(self.TargetOne, "event_one") - def handler1(x, y): -- print 'handler1' -+ print('handler1') - - class SubTarget(self.TargetOne): - pass -diff -r 9d0639b9d3be test/base/test_except.py ---- a/test/base/test_except.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/base/test_except.py Sat Apr 27 19:42:17 2013 -0400 -@@ -5,14 +5,15 @@ - from sqlalchemy.testing import fixtures - from sqlalchemy.testing import eq_ - --# Py3K --#StandardError = BaseException --# Py2K --from exceptions import StandardError, KeyboardInterrupt, SystemExit -+# start Py3K -+Exception = BaseException -+# end Py3K -+# start Py2K -+#from exceptions import StandardError, KeyboardInterrupt, SystemExit - # end Py2K - - --class Error(StandardError): -+class Error(Exception): - """This class will be old-style on <= 2.4 and new-style on >= - 2.5.""" - -@@ -47,7 +48,7 @@ - try: - raise sa_exceptions.DBAPIError.instance('this is a message' - , None, OperationalError(), DatabaseError) -- except sa_exceptions.DBAPIError, exc: -+ except sa_exceptions.DBAPIError as exc: - assert str(exc) \ - == "(OperationalError) 'this is a message' None" - -@@ -58,7 +59,7 @@ - {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': - 8, 'i': 9, 'j': 10, 'k': 11, - }, OperationalError(), DatabaseError) -- except sa_exceptions.DBAPIError, exc: -+ except sa_exceptions.DBAPIError as exc: - assert str(exc).startswith("(OperationalError) 'this is a " - "message' {") - -@@ -67,7 +68,7 @@ - raise sa_exceptions.DBAPIError.instance('this is a message', - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,], - OperationalError(), DatabaseError) -- except sa_exceptions.DBAPIError, exc: -+ except sa_exceptions.DBAPIError as exc: - assert str(exc).startswith("(OperationalError) 'this is a " - "message' [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]") - -@@ -77,7 +78,7 @@ - [{1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, - {1: 1}, {1:1}, {1: 1}, {1: 1},], - OperationalError(), DatabaseError) -- except sa_exceptions.DBAPIError, exc: -+ except sa_exceptions.DBAPIError as exc: - eq_(str(exc) , - "(OperationalError) 'this is a message' [{1: 1}, "\ - "{1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: "\ -@@ -87,7 +88,7 @@ - {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, - {1:1}, {1: 1}, {1: 1}, {1: 1}, - ], OperationalError(), DatabaseError) -- except sa_exceptions.DBAPIError, exc: -+ except sa_exceptions.DBAPIError as exc: - eq_(str(exc) , - "(OperationalError) 'this is a message' [{1: 1}, " - "{1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, " -@@ -100,7 +101,7 @@ - (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), - (1, ), - ], OperationalError(), DatabaseError) -- except sa_exceptions.DBAPIError, exc: -+ except sa_exceptions.DBAPIError as exc: - eq_(str(exc), - "(OperationalError) 'this is a message' [(1,), "\ - "(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,)]") -@@ -109,7 +110,7 @@ - (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), - (1, ), (1, ), - ], OperationalError(), DatabaseError) -- except sa_exceptions.DBAPIError, exc: -+ except sa_exceptions.DBAPIError as exc: - eq_(str(exc), - "(OperationalError) 'this is a message' [(1,), " - "(1,), (1,), (1,), (1,), (1,), (1,), (1,) " -@@ -121,7 +122,7 @@ - try: - raise sa_exceptions.DBAPIError.instance('', [], - ProgrammingError(), DatabaseError) -- except sa_exceptions.DBAPIError, e: -+ except sa_exceptions.DBAPIError as e: - self.assert_(True) - self.assert_('Error in str() of DB-API' in e.args[0]) - -@@ -129,7 +130,7 @@ - try: - raise sa_exceptions.DBAPIError.instance('', [], OutOfSpec(), - DatabaseError) -- except sa_exceptions.DBAPIError, e: -+ except sa_exceptions.DBAPIError as e: - self.assert_(e.__class__ is sa_exceptions.DBAPIError) - except OutOfSpec: - self.assert_(False) -@@ -137,7 +138,7 @@ - try: - raise sa_exceptions.DBAPIError.instance('', [], - sa_exceptions.ArgumentError(), DatabaseError) -- except sa_exceptions.DBAPIError, e: -+ except sa_exceptions.DBAPIError as e: - self.assert_(e.__class__ is sa_exceptions.DBAPIError) - except sa_exceptions.ArgumentError: - self.assert_(False) -diff -r 9d0639b9d3be test/base/test_utils.py ---- a/test/base/test_utils.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/base/test_utils.py Sat Apr 27 19:42:17 2013 -0400 -@@ -16,7 +16,7 @@ - eq_(len(keyed_tuple), 0) - - eq_(keyed_tuple.__dict__, {'_labels': []}) -- eq_(keyed_tuple.keys(), []) -+ eq_(list(keyed_tuple.keys()), []) - eq_(keyed_tuple._fields, ()) - eq_(keyed_tuple._asdict(), {}) - -@@ -27,7 +27,7 @@ - eq_(len(keyed_tuple), 2) - - eq_(keyed_tuple.__dict__, {'_labels': []}) -- eq_(keyed_tuple.keys(), []) -+ eq_(list(keyed_tuple.keys()), []) - eq_(keyed_tuple._fields, ()) - eq_(keyed_tuple._asdict(), {}) - -@@ -37,7 +37,7 @@ - def test_basic_creation(self): - keyed_tuple = util.KeyedTuple([1, 2], ['a', 'b']) - eq_(str(keyed_tuple), '(1, 2)') -- eq_(keyed_tuple.keys(), ['a', 'b']) -+ eq_(list(keyed_tuple.keys()), ['a', 'b']) - eq_(keyed_tuple._fields, ('a', 'b')) - eq_(keyed_tuple._asdict(), {'a': 1, 'b': 2}) - -@@ -66,7 +66,7 @@ - # TODO: consider not allowing None labels - expected = {'a': 1, None: 2, 'b': 3, '_labels': ['a', None, 'b']} - eq_(keyed_tuple.__dict__, expected) -- eq_(keyed_tuple.keys(), ['a', 'b']) -+ eq_(list(keyed_tuple.keys()), ['a', 'b']) - eq_(keyed_tuple._fields, ('a', 'b')) - eq_(keyed_tuple._asdict(), {'a': 1, 'b': 3}) - -@@ -86,7 +86,7 @@ - # TODO: consider not allowing duplicate labels - expected = {'a': 1, 'b': 3, '_labels': ['a', 'b', 'b']} - eq_(keyed_tuple.__dict__, expected) -- eq_(keyed_tuple.keys(), ['a', 'b', 'b']) -+ eq_(list(keyed_tuple.keys()), ['a', 'b', 'b']) - eq_(keyed_tuple._fields, ('a', 'b', 'b')) - eq_(keyed_tuple._asdict(), {'a': 1, 'b': 3}) - -@@ -125,12 +125,12 @@ - o['snack'] = 'attack' - o['c'] = 3 - -- eq_(o.keys(), ['a', 'b', 'snack', 'c']) -- eq_(o.values(), [1, 2, 'attack', 3]) -+ eq_(list(o.keys()), ['a', 'b', 'snack', 'c']) -+ eq_(list(o.values()), [1, 2, 'attack', 3]) - - o.pop('snack') -- eq_(o.keys(), ['a', 'b', 'c']) -- eq_(o.values(), [1, 2, 3]) -+ eq_(list(o.keys()), ['a', 'b', 'c']) -+ eq_(list(o.values()), [1, 2, 3]) - - try: - o.pop('eep') -@@ -146,40 +146,40 @@ - except TypeError: - pass - -- eq_(o.keys(), ['a', 'b', 'c']) -- eq_(o.values(), [1, 2, 3]) -+ eq_(list(o.keys()), ['a', 'b', 'c']) -+ eq_(list(o.values()), [1, 2, 3]) - - o2 = util.OrderedDict(d=4) - o2['e'] = 5 - -- eq_(o2.keys(), ['d', 'e']) -- eq_(o2.values(), [4, 5]) -+ eq_(list(o2.keys()), ['d', 'e']) -+ eq_(list(o2.values()), [4, 5]) - - o.update(o2) -- eq_(o.keys(), ['a', 'b', 'c', 'd', 'e']) -- eq_(o.values(), [1, 2, 3, 4, 5]) -+ eq_(list(o.keys()), ['a', 'b', 'c', 'd', 'e']) -+ eq_(list(o.values()), [1, 2, 3, 4, 5]) - - o.setdefault('c', 'zzz') - o.setdefault('f', 6) -- eq_(o.keys(), ['a', 'b', 'c', 'd', 'e', 'f']) -- eq_(o.values(), [1, 2, 3, 4, 5, 6]) -+ eq_(list(o.keys()), ['a', 'b', 'c', 'd', 'e', 'f']) -+ eq_(list(o.values()), [1, 2, 3, 4, 5, 6]) - - def test_odict_constructor(self): - o = util.OrderedDict([('name', 'jbe'), ('fullname', 'jonathan' - ), ('password', '')]) -- eq_(o.keys(), ['name', 'fullname', 'password']) -+ eq_(list(o.keys()), ['name', 'fullname', 'password']) - - def test_odict_copy(self): - o = util.OrderedDict() - o["zzz"] = 1 - o["aaa"] = 2 -- eq_(o.keys(), ['zzz', 'aaa']) -+ eq_(list(o.keys()), ['zzz', 'aaa']) - - o2 = o.copy() -- eq_(o2.keys(), o.keys()) -+ eq_(list(o2.keys()), list(o.keys())) - - o3 = copy.copy(o) -- eq_(o3.keys(), o.keys()) -+ eq_(list(o3.keys()), list(o.keys())) - - - class OrderedSetTest(fixtures.TestBase): -@@ -198,7 +198,7 @@ - def test_serialize(self): - d = util.immutabledict({1: 2, 3: 4}) - for loads, dumps in picklers(): -- print loads(dumps(d)) -+ print(loads(dumps(d))) - - - class MemoizedAttrTest(fixtures.TestBase): -@@ -252,7 +252,7 @@ - try: - cc['col1'] in cc - assert False -- except exc.ArgumentError, e: -+ except exc.ArgumentError as e: - eq_(str(e), "__contains__ requires a string argument") - - def test_compare(self): -@@ -414,14 +414,14 @@ - for type_ in (object, ImmutableSubclass): - data = [type_(), type_()] - ids = util.IdentitySet() -- for i in range(2) + range(2): -+ for i in list(range(2)) + list(range(2)): - ids.add(data[i]) - self.assert_eq(ids, data) - - for type_ in (EqOverride, HashOverride, HashEqOverride): - data = [type_(1), type_(1), type_(2)] - ids = util.IdentitySet() -- for i in range(3) + range(3): -+ for i in list(range(3)) + list(range(3)): - ids.add(data[i]) - self.assert_eq(ids, data) - -@@ -843,13 +843,14 @@ - return super_, sub_, twin1, twin2, unique1, unique2 - - def _assert_unorderable_types(self, callable_): -- # Py3K -- #assert_raises_message( -- # TypeError, 'unorderable types', callable_) -- # Py2K -+# start Py3K - assert_raises_message( -- TypeError, 'cannot compare sets using cmp()', callable_) -- # end Py2K -+ TypeError, 'unorderable types', callable_) -+# end Py3K -+# start Py2K -+# assert_raises_message( -+# TypeError, 'cannot compare sets using cmp()', callable_) -+# end Py2K - - def test_basic_sanity(self): - IdentitySet = util.IdentitySet -@@ -969,23 +970,23 @@ - d = subdict(a=1, b=2, c=3) - self._ok(d) - -- # Py2K -- def test_UserDict(self): -- import UserDict -- d = UserDict.UserDict(a=1, b=2, c=3) -- self._ok(d) -- # end Py2K -+# start Py2K -+# def test_UserDict(self): -+# import UserDict -+# d = UserDict.UserDict(a=1, b=2, c=3) -+# self._ok(d) -+# end Py2K - - def test_object(self): - self._notok(object()) - -- # Py2K -- def test_duck_1(self): -- class duck1(object): -- def iteritems(duck): -- return iter(self.baseline) -- self._ok(duck1()) -- # end Py2K -+# start Py2K -+# def test_duck_1(self): -+# class duck1(object): -+# def iteritems(duck): -+# return iter(self.baseline) -+# self._ok(duck1()) -+# end Py2K - - def test_duck_2(self): - class duck2(object): -@@ -993,16 +994,16 @@ - return list(self.baseline) - self._ok(duck2()) - -- # Py2K -- def test_duck_3(self): -- class duck3(object): -- def iterkeys(duck): -- return iter(['a', 'b', 'c']) -- -- def __getitem__(duck, key): -- return dict(a=1, b=2, c=3).get(key) -- self._ok(duck3()) -- # end Py2K -+# start Py2K -+# def test_duck_3(self): -+# class duck3(object): -+# def iterkeys(duck): -+# return iter(['a', 'b', 'c']) -+# -+# def __getitem__(duck, key): -+# return dict(a=1, b=2, c=3).get(key) -+# self._ok(duck3()) -+# end Py2K - - def test_duck_4(self): - class duck4(object): -@@ -1029,9 +1030,9 @@ - class DuckTypeCollectionTest(fixtures.TestBase): - - def test_sets(self): -- # Py2K -- import sets -- # end Py2K -+# start Py2K -+# import sets -+# end Py2K - - class SetLike(object): - def add(self): -@@ -1041,9 +1042,9 @@ - __emulates__ = set - - for type_ in (set, -- # Py2K -- sets.Set, -- # end Py2K -+# start Py2K -+# sets.Set, -+# end Py2K - SetLike, - ForcedSet): - eq_(util.duck_type_collection(type_), set) -@@ -1051,9 +1052,9 @@ - eq_(util.duck_type_collection(instance), set) - - for type_ in (frozenset, -- # Py2K -- sets.ImmutableSet -- # end Py2K -+# start Py2K -+# sets.ImmutableSet -+# end Py2K - ): - is_(util.duck_type_collection(type_), None) - instance = type_() -@@ -1175,7 +1176,7 @@ - sym3 = util.pickle.loads(s) - - for protocol in 0, 1, 2: -- print protocol -+ print(protocol) - serial = util.pickle.dumps(sym1) - rt = util.pickle.loads(serial) - assert rt is sym1 -@@ -1550,21 +1551,21 @@ - eq_(set(util.class_hierarchy(A)), set((A, B, C, object))) - eq_(set(util.class_hierarchy(B)), set((A, B, C, object))) - -- # Py2K -- def test_oldstyle_mixin(self): -- class A(object): -- pass -- -- class Mixin: -- pass -- -- class B(A, Mixin): -- pass -- -- eq_(set(util.class_hierarchy(B)), set((A, B, object))) -- eq_(set(util.class_hierarchy(Mixin)), set()) -- eq_(set(util.class_hierarchy(A)), set((A, B, object))) -- # end Py2K -+# start Py2K -+# def test_oldstyle_mixin(self): -+# class A(object): -+# pass -+# -+# class Mixin: -+# pass -+# -+# class B(A, Mixin): -+# pass -+# -+# eq_(set(util.class_hierarchy(B)), set((A, B, object))) -+# eq_(set(util.class_hierarchy(Mixin)), set()) -+# eq_(set(util.class_hierarchy(A)), set((A, B, object))) -+# end Py2K - - - class TestClassProperty(fixtures.TestBase): -diff -r 9d0639b9d3be test/dialect/test_firebird.py ---- a/test/dialect/test_firebird.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/dialect/test_firebird.py Sat Apr 27 19:42:17 2013 -0400 -@@ -28,7 +28,7 @@ - ) - con.execute('CREATE DOMAIN img_domain AS BLOB SUB_TYPE ' - 'BINARY') -- except ProgrammingError, e: -+ except ProgrammingError as e: - if not 'attempt to store duplicate value' in str(e): - raise e - con.execute('''CREATE GENERATOR gen_testtable_id''') -diff -r 9d0639b9d3be test/dialect/test_mssql.py ---- a/test/dialect/test_mssql.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/dialect/test_mssql.py Sat Apr 27 19:42:17 2013 -0400 -@@ -403,7 +403,7 @@ - self.assert_compile( - s, - "SELECT TOP 10 t.x, t.y FROM t WHERE t.x = :x_1 ORDER BY t.y", -- checkparams={u'x_1': 5} -+ checkparams={'x_1': 5} - ) - - def test_limit_zero_using_top(self): -@@ -414,7 +414,7 @@ - self.assert_compile( - s, - "SELECT TOP 0 t.x, t.y FROM t WHERE t.x = :x_1 ORDER BY t.y", -- checkparams={u'x_1': 5} -+ checkparams={'x_1': 5} - ) - - def test_offset_using_window(self): -@@ -424,14 +424,14 @@ - - # test that the select is not altered with subsequent compile - # calls -- for i in xrange(2): -+ for i in range(2): - self.assert_compile( - s, - "SELECT anon_1.x, anon_1.y FROM (SELECT t.x AS x, t.y " - "AS y, ROW_NUMBER() OVER (ORDER BY t.y) AS " - "mssql_rn FROM t WHERE t.x = :x_1) AS " - "anon_1 WHERE mssql_rn > :mssql_rn_1", -- checkparams={u'mssql_rn_1': 20, u'x_1': 5} -+ checkparams={'mssql_rn_1': 20, 'x_1': 5} - ) - - def test_limit_offset_using_window(self): -@@ -447,7 +447,7 @@ - "FROM t " - "WHERE t.x = :x_1) AS anon_1 " - "WHERE mssql_rn > :mssql_rn_1 AND mssql_rn <= :mssql_rn_2", -- checkparams={u'mssql_rn_1': 20, u'mssql_rn_2': 30, u'x_1': 5} -+ checkparams={'mssql_rn_1': 20, 'mssql_rn_2': 30, 'x_1': 5} - ) - - def test_limit_offset_with_correlated_order_by(self): -@@ -468,7 +468,7 @@ - "FROM t1 " - "WHERE t1.x = :x_1) AS anon_1 " - "WHERE mssql_rn > :mssql_rn_1 AND mssql_rn <= :mssql_rn_2", -- checkparams={u'mssql_rn_1': 20, u'mssql_rn_2': 30, u'x_1': 5} -+ checkparams={'mssql_rn_1': 20, 'mssql_rn_2': 30, 'x_1': 5} - ) - - def test_limit_zero_offset_using_window(self): -@@ -482,7 +482,7 @@ - s, - "SELECT TOP 0 t.x, t.y FROM t " - "WHERE t.x = :x_1 ORDER BY t.y", -- checkparams={u'x_1': 5} -+ checkparams={'x_1': 5} - ) - - def test_sequence_start_0(self): -@@ -851,11 +851,11 @@ - # encode in UTF-8 (sting object) because this is the default - # dialect encoding - -- con.execute(u"insert into unitest_table values ('bien u\ -+ con.execute("insert into unitest_table values ('bien u\ - umang\xc3\xa9')".encode('UTF-8')) - try: - r = t1.select().execute().first() -- assert isinstance(r[1], unicode), \ -+ assert isinstance(r[1], str), \ - '%s is %s instead of unicode, working on %s' % (r[1], - type(r[1]), meta.bind) - finally: -@@ -1707,7 +1707,7 @@ - )] - for value in test_items: - float_table.insert().execute(floatcol=value) -- except Exception, e: -+ except Exception as e: - raise e - - -@@ -1953,8 +1953,8 @@ - - def test_unicode(self): - module = __import__('pymssql') -- result = module.Binary(u'foo') -- eq_(result, u'foo') -+ result = module.Binary('foo') -+ eq_(result, 'foo') - - def test_bytes(self): - module = __import__('pymssql') -@@ -2073,7 +2073,7 @@ - - dialect = mssql.dialect() - value = CoerceUnicode().bind_processor(dialect)('a string') -- assert isinstance(value, unicode) -+ assert isinstance(value, str) - - class ReflectHugeViewTest(fixtures.TestBase): - __only_on__ = 'mssql' -@@ -2085,13 +2085,13 @@ - t = Table('base_table', self.metadata, - *[ - Column("long_named_column_number_%d" % i, Integer) -- for i in xrange(self.col_num) -+ for i in range(self.col_num) - ] - ) - self.view_str = view_str = \ - "CREATE VIEW huge_named_view AS SELECT %s FROM base_table" % ( - ",".join("long_named_column_number_%d" % i -- for i in xrange(self.col_num)) -+ for i in range(self.col_num)) - ) - assert len(view_str) > 4000 - -diff -r 9d0639b9d3be test/dialect/test_mysql.py ---- a/test/dialect/test_mysql.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/dialect/test_mysql.py Sat Apr 27 19:42:17 2013 -0400 -@@ -372,9 +372,9 @@ - try: - self.assert_(list(row) == expected) - except: -- print "Storing %s" % store -- print "Expected %s" % expected -- print "Found %s" % list(row) -+ print("Storing %s" % store) -+ print("Expected %s" % expected) -+ print("Found %s" % list(row)) - raise - table.delete().execute().close() - -@@ -684,17 +684,17 @@ - metadata = MetaData(unicode_engine) - t1 = Table('table', metadata, - Column('id', Integer, primary_key=True), -- Column('value', Enum(u'réveillé', u'drôle', u'S’il')), -- Column('value2', mysql.ENUM(u'réveillé', u'drôle', u'S’il')) -+ Column('value', Enum('réveillé', 'drôle', 'S’il')), -+ Column('value2', mysql.ENUM('réveillé', 'drôle', 'S’il')) - ) - metadata.create_all() - try: -- t1.insert().execute(value=u'drôle', value2=u'drôle') -- t1.insert().execute(value=u'réveillé', value2=u'réveillé') -- t1.insert().execute(value=u'S’il', value2=u'S’il') -+ t1.insert().execute(value='drôle', value2='drôle') -+ t1.insert().execute(value='réveillé', value2='réveillé') -+ t1.insert().execute(value='S’il', value2='S’il') - eq_(t1.select().order_by(t1.c.id).execute().fetchall(), -- [(1, u'drôle', u'drôle'), (2, u'réveillé', u'réveillé'), -- (3, u'S’il', u'S’il')] -+ [(1, 'drôle', 'drôle'), (2, 'réveillé', 'réveillé'), -+ (3, 'S’il', 'S’il')] - ) - - # test reflection of the enum labels -@@ -706,10 +706,10 @@ - # latin-1 stuff forcing its way in ? - - assert t2.c.value.type.enums[0:2] == \ -- (u'réveillé', u'drôle') # u'S’il') # eh ? -+ ('réveillé', 'drôle') # u'S’il') # eh ? - - assert t2.c.value2.type.enums[0:2] == \ -- (u'réveillé', u'drôle') # u'S’il') # eh ? -+ ('réveillé', 'drôle') # u'S’il') # eh ? - finally: - metadata.drop_all() - -@@ -877,13 +877,13 @@ - reflected = Table('mysql_case', MetaData(testing.db), - autoload=True, include_columns=['c1', 'C2']) - for t in case_table, reflected: -- assert 'c1' in t.c.keys() -- assert 'C2' in t.c.keys() -+ assert 'c1' in list(t.c.keys()) -+ assert 'C2' in list(t.c.keys()) - reflected2 = Table('mysql_case', MetaData(testing.db), - autoload=True, include_columns=['c1', 'c2']) -- assert 'c1' in reflected2.c.keys() -+ assert 'c1' in list(reflected2.c.keys()) - for c in ['c2', 'C2', 'C3']: -- assert c not in reflected2.c.keys() -+ assert c not in list(reflected2.c.keys()) - finally: - case_table.drop() - -@@ -1370,7 +1370,7 @@ - def _options(self, modes): - def connect(con, record): - cursor = con.cursor() -- print "DOING THiS:", "set sql_mode='%s'" % (",".join(modes)) -+ print("DOING THiS:", "set sql_mode='%s'" % (",".join(modes))) - cursor.execute("set sql_mode='%s'" % (",".join(modes))) - e = engines.testing_engine(options={ - 'pool_events':[ -diff -r 9d0639b9d3be test/dialect/test_oracle.py ---- a/test/dialect/test_oracle.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/dialect/test_oracle.py Sat Apr 27 19:42:17 2013 -0400 -@@ -1,5 +1,5 @@ - # coding: utf-8 --from __future__ import with_statement -+ - - from sqlalchemy.testing import eq_ - from sqlalchemy import * -@@ -807,7 +807,7 @@ - ) - def test_twophase_prepare_false(self): - conn = self._connection() -- for i in xrange(2): -+ for i in range(2): - trans = conn.begin_twophase() - conn.execute("select 1 from dual") - trans.prepare() -@@ -817,7 +817,7 @@ - - def test_twophase_prepare_true(self): - conn = self._connection() -- for i in xrange(2): -+ for i in range(2): - trans = conn.begin_twophase() - conn.execute("insert into datatable (id, data) " - "values (%s, 'somedata')" % i) -@@ -870,7 +870,7 @@ - b = bindparam("foo", "hello world!") - assert b.type.dialect_impl(dialect).get_dbapi_type(dbapi) == 'STRING' - -- b = bindparam("foo", u"hello world!") -+ b = bindparam("foo", "hello world!") - assert b.type.dialect_impl(dialect).get_dbapi_type(dbapi) == 'STRING' - - def test_long(self): -@@ -1257,7 +1257,7 @@ - autoload=True, oracle_resolve_synonyms=True - ) - for row in types_table.select().execute().fetchall(): -- [row[k] for k in row.keys()] -+ [row[k] for k in list(row.keys())] - - @testing.provide_metadata - def test_raw_roundtrip(self): -@@ -1291,11 +1291,11 @@ - t2.c.data.type.dialect_impl(testing.db.dialect), - cx_oracle._OracleNVarChar) - -- data = u'm’a réveillé.' -+ data = 'm’a réveillé.' - t2.insert().execute(data=data) - res = t2.select().execute().first()['data'] - eq_(res, data) -- assert isinstance(res, unicode) -+ assert isinstance(res, str) - - - def test_char_length(self): -@@ -1426,7 +1426,7 @@ - m = MetaData(testing.db) - m.reflect() - eq_( -- set(t.name for t in m.tables.values()), -+ set(t.name for t in list(m.tables.values())), - set(['admin_docindex']) - ) - -@@ -1641,28 +1641,28 @@ - metadata.create_all() - - table.insert().execute( -- {'_underscorecolumn': u'’é'}, -+ {'_underscorecolumn': '’é'}, - ) - result = testing.db.execute( -- table.select().where(table.c._underscorecolumn==u'’é') -+ table.select().where(table.c._underscorecolumn=='’é') - ).scalar() -- eq_(result, u'’é') -+ eq_(result, '’é') - - @testing.provide_metadata - def test_quoted_column_unicode(self): - metadata = self.metadata - table=Table("atable", metadata, -- Column(u"méil", Unicode(255), primary_key=True), -+ Column("méil", Unicode(255), primary_key=True), - ) - metadata.create_all() - - table.insert().execute( -- {u'méil': u'’é'}, -+ {'méil': '’é'}, - ) - result = testing.db.execute( -- table.select().where(table.c[u'méil']==u'’é') -+ table.select().where(table.c['méil']=='’é') - ).scalar() -- eq_(result, u'’é') -+ eq_(result, '’é') - - - class DBLinkReflectionTest(fixtures.TestBase): -@@ -1702,5 +1702,5 @@ - - t = Table('test_table_syn', m, autoload=True, - autoload_with=testing.db, oracle_resolve_synonyms=True) -- eq_(t.c.keys(), ['id', 'data']) -+ eq_(list(t.c.keys()), ['id', 'data']) - eq_(list(t.primary_key), [t.c.id]) -diff -r 9d0639b9d3be test/dialect/test_postgresql.py ---- a/test/dialect/test_postgresql.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/dialect/test_postgresql.py Sat Apr 27 19:42:17 2013 -0400 -@@ -1,6 +1,6 @@ - # coding: utf-8 - --from __future__ import with_statement -+ - - from sqlalchemy.testing.assertions import eq_, assert_raises, \ - assert_raises_message, is_, AssertsExecutionResults, \ -@@ -559,21 +559,21 @@ - t1 = Table('table', metadata, - Column('id', Integer, primary_key=True), - Column('value', -- Enum(u'réveillé', u'drôle', u'S’il', -+ Enum('réveillé', 'drôle', 'S’il', - name='onetwothreetype')) - ) - - metadata.create_all() - try: -- t1.insert().execute(value=u'drôle') -- t1.insert().execute(value=u'réveillé') -- t1.insert().execute(value=u'S’il') -+ t1.insert().execute(value='drôle') -+ t1.insert().execute(value='réveillé') -+ t1.insert().execute(value='S’il') - eq_(t1.select().order_by(t1.c.id).execute().fetchall(), -- [(1, u'drôle'), (2, u'réveillé'), (3, u'S’il')] -+ [(1, 'drôle'), (2, 'réveillé'), (3, 'S’il')] - ) - m2 = MetaData(testing.db) - t2 = Table('table', m2, autoload=True) -- assert t2.c.value.type.enums == (u'réveillé', u'drôle', u'S’il') -+ assert t2.c.value.type.enums == ('réveillé', 'drôle', 'S’il') - finally: - metadata.drop_all() - -@@ -1238,7 +1238,7 @@ - : - try: - con.execute(ddl) -- except exc.DBAPIError, e: -+ except exc.DBAPIError as e: - if not 'already exists' in str(e): - raise e - con.execute('CREATE TABLE testtable (question integer, answer ' -@@ -1476,7 +1476,7 @@ - meta1.create_all() - meta2 = MetaData(testing.db) - subject = Table('subject', meta2, autoload=True) -- eq_(subject.primary_key.columns.keys(), [u'p2', u'p1']) -+ eq_(list(subject.primary_key.columns.keys()), ['p2', 'p1']) - - @testing.provide_metadata - def test_pg_weirdchar_reflection(self): -@@ -1749,7 +1749,7 @@ - conn.execute("ALTER TABLE t RENAME COLUMN x to y") - - ind = testing.db.dialect.get_indexes(conn, "t", None) -- eq_(ind, [{'unique': False, 'column_names': [u'y'], 'name': u'idx1'}]) -+ eq_(ind, [{'unique': False, 'column_names': ['y'], 'name': 'idx1'}]) - conn.close() - - class CustomTypeReflectionTest(fixtures.TestBase): -@@ -2174,8 +2174,8 @@ - - def test_insert_array(self): - arrtable = self.tables.arrtable -- arrtable.insert().execute(intarr=[1, 2, 3], strarr=[u'abc', -- u'def']) -+ arrtable.insert().execute(intarr=[1, 2, 3], strarr=['abc', -+ 'def']) - results = arrtable.select().execute().fetchall() - eq_(len(results), 1) - eq_(results[0]['intarr'], [1, 2, 3]) -@@ -2183,9 +2183,9 @@ - - def test_array_where(self): - arrtable = self.tables.arrtable -- arrtable.insert().execute(intarr=[1, 2, 3], strarr=[u'abc', -- u'def']) -- arrtable.insert().execute(intarr=[4, 5, 6], strarr=u'ABC') -+ arrtable.insert().execute(intarr=[1, 2, 3], strarr=['abc', -+ 'def']) -+ arrtable.insert().execute(intarr=[4, 5, 6], strarr='ABC') - results = arrtable.select().where(arrtable.c.intarr == [1, 2, - 3]).execute().fetchall() - eq_(len(results), 1) -@@ -2194,7 +2194,7 @@ - def test_array_concat(self): - arrtable = self.tables.arrtable - arrtable.insert().execute(intarr=[1, 2, 3], -- strarr=[u'abc', u'def']) -+ strarr=['abc', 'def']) - results = select([arrtable.c.intarr + [4, 5, - 6]]).execute().fetchall() - eq_(len(results), 1) -@@ -2203,15 +2203,15 @@ - def test_array_subtype_resultprocessor(self): - arrtable = self.tables.arrtable - arrtable.insert().execute(intarr=[4, 5, 6], -- strarr=[[u'm\xe4\xe4'], [u'm\xf6\xf6' -+ strarr=[['m\xe4\xe4'], ['m\xf6\xf6' - ]]) -- arrtable.insert().execute(intarr=[1, 2, 3], strarr=[u'm\xe4\xe4' -- , u'm\xf6\xf6']) -+ arrtable.insert().execute(intarr=[1, 2, 3], strarr=['m\xe4\xe4' -+ , 'm\xf6\xf6']) - results = \ - arrtable.select(order_by=[arrtable.c.intarr]).execute().fetchall() - eq_(len(results), 2) -- eq_(results[0]['strarr'], [u'm\xe4\xe4', u'm\xf6\xf6']) -- eq_(results[1]['strarr'], [[u'm\xe4\xe4'], [u'm\xf6\xf6']]) -+ eq_(results[0]['strarr'], ['m\xe4\xe4', 'm\xf6\xf6']) -+ eq_(results[1]['strarr'], [['m\xe4\xe4'], ['m\xf6\xf6']]) - - def test_array_literal(self): - eq_( -@@ -2263,7 +2263,7 @@ - testing.db.execute( - arrtable.insert(), - intarr=[4, 5, 6], -- strarr=[u'abc', u'def'] -+ strarr=['abc', 'def'] - ) - eq_( - testing.db.scalar(select([arrtable.c.intarr[2:3]])), -diff -r 9d0639b9d3be test/dialect/test_sqlite.py ---- a/test/dialect/test_sqlite.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/dialect/test_sqlite.py Sat Apr 27 19:42:17 2013 -0400 -@@ -84,7 +84,7 @@ - eq_(row, (1, datetime.date(2010, 5, 10), - datetime.datetime( 2010, 5, 10, 12, 15, 25, ))) - r = engine.execute(func.current_date()).scalar() -- assert isinstance(r, basestring) -+ assert isinstance(r, str) - finally: - t.drop(engine) - engine.dispose() -@@ -104,8 +104,8 @@ - UnicodeText(), - ): - bindproc = t.dialect_impl(dialect).bind_processor(dialect) -- assert not bindproc or isinstance(bindproc(u'some string'), -- unicode) -+ assert not bindproc or isinstance(bindproc('some string'), -+ str) - - @testing.provide_metadata - def test_type_reflection(self): -@@ -566,7 +566,7 @@ - eq_(inspector.get_indexes('foo'), []) - eq_(inspector.get_indexes('foo', - include_auto_indexes=True), [{'unique': 1, 'name' -- : u'sqlite_autoindex_foo_1', 'column_names': [u'bar']}]) -+ : 'sqlite_autoindex_foo_1', 'column_names': ['bar']}]) - finally: - meta.drop_all() - -@@ -602,7 +602,7 @@ - 'dow': '%w', - 'week': '%W', - } -- for field, subst in mapping.items(): -+ for field, subst in list(mapping.items()): - self.assert_compile(select([extract(field, t.c.col1)]), - "SELECT CAST(STRFTIME('%s', t.col1) AS " - "INTEGER) AS anon_1 FROM t" % subst) -diff -r 9d0639b9d3be test/dialect/test_sybase.py ---- a/test/dialect/test_sybase.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/dialect/test_sybase.py Sat Apr 27 19:42:17 2013 -0400 -@@ -19,7 +19,7 @@ - 'year': 'year', - } - -- for field, subst in mapping.items(): -+ for field, subst in list(mapping.items()): - self.assert_compile( - select([extract(field, t.c.col1)]), - 'SELECT DATEPART("%s", t.col1) AS anon_1 FROM t' % subst) -diff -r 9d0639b9d3be test/engine/test_bind.py ---- a/test/engine/test_bind.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/engine/test_bind.py Sat Apr 27 19:42:17 2013 -0400 -@@ -1,6 +1,6 @@ - """tests the "bind" attribute/argument across schema and SQL, - including the deprecated versions of these arguments""" --from __future__ import with_statement -+ - from sqlalchemy.testing import eq_, assert_raises - from sqlalchemy import engine, exc - from sqlalchemy import MetaData, ThreadLocalMetaData -@@ -61,7 +61,7 @@ - try: - meth() - assert False -- except exc.UnboundExecutionError, e: -+ except exc.UnboundExecutionError as e: - eq_(str(e), - "The MetaData is not bound to an Engine or " - "Connection. Execution can not proceed without a " -@@ -82,7 +82,7 @@ - try: - meth() - assert False -- except exc.UnboundExecutionError, e: -+ except exc.UnboundExecutionError as e: - eq_( - str(e), - "The Table 'test_table' " -diff -r 9d0639b9d3be test/engine/test_ddlemit.py ---- a/test/engine/test_ddlemit.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/engine/test_ddlemit.py Sat Apr 27 19:42:17 2013 -0400 -@@ -47,7 +47,7 @@ - - return (m, ) + tuple( - Table('t%d' % i, m, Column('x', Integer)) -- for i in xrange(1, 6) -+ for i in range(1, 6) - ) - - def _table_seq_fixture(self): -diff -r 9d0639b9d3be test/engine/test_ddlevents.py ---- a/test/engine/test_ddlevents.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/engine/test_ddlevents.py Sat Apr 27 19:42:17 2013 -0400 -@@ -1,4 +1,4 @@ --from __future__ import with_statement -+ - from sqlalchemy.testing import assert_raises, assert_raises_message - from sqlalchemy.schema import DDL, CheckConstraint, AddConstraint, \ - DropConstraint -diff -r 9d0639b9d3be test/engine/test_execute.py ---- a/test/engine/test_execute.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/engine/test_execute.py Sat Apr 27 19:42:17 2013 -0400 -@@ -1,4 +1,4 @@ --from __future__ import with_statement -+ - - from sqlalchemy.testing import eq_, assert_raises, assert_raises_message, \ - config, is_ -@@ -18,7 +18,7 @@ - from sqlalchemy.engine import result as _result, default - from sqlalchemy.engine.base import Connection, Engine - from sqlalchemy.testing import fixtures --import StringIO -+import io - - users, metadata, users_autoinc = None, None, None - class ExecuteTest(fixtures.TestBase): -@@ -256,7 +256,7 @@ - try: - cursor = raw.cursor() - cursor.execute("SELECTINCORRECT") -- except testing.db.dialect.dbapi.DatabaseError, orig: -+ except testing.db.dialect.dbapi.DatabaseError as orig: - # py3k has "orig" in local scope... - the_orig = orig - finally: -@@ -622,7 +622,7 @@ - def test_log_large_dict(self): - self.eng.execute( - "INSERT INTO foo (data) values (:data)", -- [{"data":str(i)} for i in xrange(100)] -+ [{"data":str(i)} for i in range(100)] - ) - eq_( - self.buf.buffer[1].message, -@@ -635,7 +635,7 @@ - def test_log_large_list(self): - self.eng.execute( - "INSERT INTO foo (data) values (?)", -- [(str(i), ) for i in xrange(100)] -+ [(str(i), ) for i in range(100)] - ) - eq_( - self.buf.buffer[1].message, -@@ -654,7 +654,7 @@ - "100 total bound parameter sets ... {'data': '98'}, {'data': '99'}\]", - lambda: self.eng.execute( - "INSERT INTO nonexistent (data) values (:data)", -- [{"data":str(i)} for i in xrange(100)] -+ [{"data":str(i)} for i in range(100)] - ) - ) - -@@ -668,7 +668,7 @@ - "\('98',\), \('99',\)\]", - lambda: self.eng.execute( - "INSERT INTO nonexistent (data) values (?)", -- [(str(i), ) for i in xrange(100)] -+ [(str(i), ) for i in range(100)] - ) - ) - -@@ -834,9 +834,9 @@ - - class MockStrategyTest(fixtures.TestBase): - def _engine_fixture(self): -- buf = StringIO.StringIO() -+ buf = io.StringIO() - def dump(sql, *multiparams, **params): -- buf.write(unicode(sql.compile(dialect=engine.dialect))) -+ buf.write(str(sql.compile(dialect=engine.dialect))) - engine = create_engine('postgresql://', strategy='mock', executor=dump) - return engine, buf - -@@ -939,7 +939,7 @@ - def test_row_c_sequence_check(self): - import csv - import collections -- from StringIO import StringIO -+ from io import StringIO - - metadata = MetaData() - metadata.bind = 'sqlite://' -@@ -1026,7 +1026,7 @@ - ) - m.create_all(engine) - engine.execute(t.insert(), [ -- {'x':i, 'y':"t_%d" % i} for i in xrange(1, 12) -+ {'x':i, 'y':"t_%d" % i} for i in range(1, 12) - ]) - - def _test_proxy(self, cls): -@@ -1039,13 +1039,13 @@ - assert isinstance(r, cls) - for i in range(5): - rows.append(r.fetchone()) -- eq_(rows, [(i, "t_%d" % i) for i in xrange(1, 6)]) -+ eq_(rows, [(i, "t_%d" % i) for i in range(1, 6)]) - - rows = r.fetchmany(3) -- eq_(rows, [(i, "t_%d" % i) for i in xrange(6, 9)]) -+ eq_(rows, [(i, "t_%d" % i) for i in range(6, 9)]) - - rows = r.fetchall() -- eq_(rows, [(i, "t_%d" % i) for i in xrange(9, 12)]) -+ eq_(rows, [(i, "t_%d" % i) for i in range(9, 12)]) - - r = self.engine.execute(select([self.table])) - rows = r.fetchmany(None) -@@ -1059,7 +1059,7 @@ - - r = self.engine.execute(select([self.table]).limit(5)) - rows = r.fetchmany(6) -- eq_(rows, [(i, "t_%d" % i) for i in xrange(1, 6)]) -+ eq_(rows, [(i, "t_%d" % i) for i in range(1, 6)]) - - def test_plain(self): - self._test_proxy(_result.ResultProxy) -@@ -1184,7 +1184,7 @@ - try: - conn.execute("SELECT FOO FROM I_DONT_EXIST") - assert False -- except tsa.exc.DBAPIError, e: -+ except tsa.exc.DBAPIError as e: - assert canary[0][2] is e.orig - assert canary[0][0] == "SELECT FOO FROM I_DONT_EXIST" - -diff -r 9d0639b9d3be test/engine/test_parseconnect.py ---- a/test/engine/test_parseconnect.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/engine/test_parseconnect.py Sat Apr 27 19:42:17 2013 -0400 -@@ -1,6 +1,6 @@ - from sqlalchemy.testing import assert_raises, assert_raises_message, eq_ --import ConfigParser --import StringIO -+import configparser -+import io - import sqlalchemy.engine.url as url - from sqlalchemy import create_engine, engine_from_config, exc, pool - from sqlalchemy.engine.util import _coerce_config -@@ -103,8 +103,8 @@ - pool_threadlocal=1 - pool_timeout=10 - """ -- ini = ConfigParser.ConfigParser() -- ini.readfp(StringIO.StringIO(raw)) -+ ini = configparser.ConfigParser() -+ ini.readfp(io.StringIO(raw)) - - expected = { - 'url': 'postgresql://scott:tiger@somehost/test?fooz=somevalue', -@@ -234,7 +234,7 @@ - : True}, convert_unicode=True) - try: - e.connect() -- except tsa.exc.DBAPIError, de: -+ except tsa.exc.DBAPIError as de: - assert not de.connection_invalidated - - def test_ensure_dialect_does_is_disconnect_no_conn(self): -@@ -266,7 +266,7 @@ - try: - create_engine('sqlite://', module=ThrowOnConnect()).connect() - assert False -- except tsa.exc.DBAPIError, de: -+ except tsa.exc.DBAPIError as de: - assert de.connection_invalidated - - def test_urlattr(self): -diff -r 9d0639b9d3be test/engine/test_pool.py ---- a/test/engine/test_pool.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/engine/test_pool.py Sat Apr 27 19:42:17 2013 -0400 -@@ -525,23 +525,23 @@ - self.assert_((item in innerself.checked_out) == in_cout) - self.assert_((item in innerself.checked_in) == in_cin) - def inst_connect(self, con, record): -- print "connect(%s, %s)" % (con, record) -+ print("connect(%s, %s)" % (con, record)) - assert con is not None - assert record is not None - self.connected.append(con) - def inst_first_connect(self, con, record): -- print "first_connect(%s, %s)" % (con, record) -+ print("first_connect(%s, %s)" % (con, record)) - assert con is not None - assert record is not None - self.first_connected.append(con) - def inst_checkout(self, con, record, proxy): -- print "checkout(%s, %s, %s)" % (con, record, proxy) -+ print("checkout(%s, %s, %s)" % (con, record, proxy)) - assert con is not None - assert record is not None - assert proxy is not None - self.checked_out.append(con) - def inst_checkin(self, con, record): -- print "checkin(%s, %s)" % (con, record) -+ print("checkin(%s, %s)" % (con, record)) - # con can be None if invalidated - assert record is not None - self.checked_in.append(con) -@@ -738,8 +738,8 @@ - def status(pool): - tup = pool.size(), pool.checkedin(), pool.overflow(), \ - pool.checkedout() -- print 'Pool size: %d Connections in pool: %d Current '\ -- 'Overflow: %d Current Checked out connections: %d' % tup -+ print('Pool size: %d Connections in pool: %d Current '\ -+ 'Overflow: %d Current Checked out connections: %d' % tup) - return tup - - c1 = p.connect() -@@ -794,7 +794,7 @@ - try: - c4 = p.connect() - assert False -- except tsa.exc.TimeoutError, e: -+ except tsa.exc.TimeoutError as e: - assert int(time.time() - now) == 2 - - def test_timeout_race(self): -@@ -812,18 +812,18 @@ - max_overflow = 1, use_threadlocal = False, timeout=3) - timeouts = [] - def checkout(): -- for x in xrange(1): -+ for x in range(1): - now = time.time() - try: - c1 = p.connect() -- except tsa.exc.TimeoutError, e: -+ except tsa.exc.TimeoutError as e: - timeouts.append(time.time() - now) - continue - time.sleep(4) - c1.close() - - threads = [] -- for i in xrange(10): -+ for i in range(10): - th = threading.Thread(target=checkout) - th.start() - threads.append(th) -@@ -860,7 +860,7 @@ - except tsa.exc.TimeoutError: - pass - threads = [] -- for i in xrange(thread_count): -+ for i in range(thread_count): - th = threading.Thread(target=whammy) - th.start() - threads.append(th) -@@ -1007,8 +1007,8 @@ - strong_refs.add(c.connection) - return c - -- for j in xrange(5): -- conns = [_conn() for i in xrange(4)] -+ for j in range(5): -+ conns = [_conn() for i in range(4)] - for c in conns: - c.close() - -@@ -1152,7 +1152,7 @@ - return p.connect() - - def checkout(): -- for x in xrange(10): -+ for x in range(10): - c = _conn() - assert c - c.cursor() -@@ -1160,7 +1160,7 @@ - time.sleep(.1) - - threads = [] -- for i in xrange(10): -+ for i in range(10): - th = threading.Thread(target=checkout) - th.start() - threads.append(th) -diff -r 9d0639b9d3be test/engine/test_processors.py ---- a/test/engine/test_processors.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/engine/test_processors.py Sat Apr 27 19:42:17 2013 -0400 -@@ -53,7 +53,7 @@ - cls.module = type("util", (object,), - dict( - (k, staticmethod(v)) -- for k, v in processors.py_fallback().items() -+ for k, v in list(processors.py_fallback().items()) - ) - ) - -@@ -156,7 +156,7 @@ - cls.module = type("util", (object,), - dict( - (k, staticmethod(v)) -- for k, v in util.py_fallback().items() -+ for k, v in list(util.py_fallback().items()) - ) - ) - -diff -r 9d0639b9d3be test/engine/test_reconnect.py ---- a/test/engine/test_reconnect.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/engine/test_reconnect.py Sat Apr 27 19:42:17 2013 -0400 -@@ -173,7 +173,7 @@ - try: - trans.commit() - assert False -- except tsa.exc.InvalidRequestError, e: -+ except tsa.exc.InvalidRequestError as e: - assert str(e) \ - == "Can't reconnect until invalid transaction is "\ - "rolled back" -@@ -370,7 +370,7 @@ - try: - conn.execute(select([1])) - assert False -- except tsa.exc.DBAPIError, e: -+ except tsa.exc.DBAPIError as e: - if not e.connection_invalidated: - raise - -@@ -386,7 +386,7 @@ - try: - conn.execute(select([1])) - assert False -- except tsa.exc.DBAPIError, e: -+ except tsa.exc.DBAPIError as e: - if not e.connection_invalidated: - raise - assert conn.invalidated -@@ -407,7 +407,7 @@ - try: - c1.execute(select([1])) - assert False -- except tsa.exc.DBAPIError, e: -+ except tsa.exc.DBAPIError as e: - assert e.connection_invalidated - - p2 = engine.pool -@@ -415,7 +415,7 @@ - try: - c2.execute(select([1])) - assert False -- except tsa.exc.DBAPIError, e: -+ except tsa.exc.DBAPIError as e: - assert e.connection_invalidated - - # pool isn't replaced -@@ -503,7 +503,7 @@ - try: - conn.execute(select([1])) - assert False -- except tsa.exc.DBAPIError, e: -+ except tsa.exc.DBAPIError as e: - if not e.connection_invalidated: - raise - assert not conn.closed -@@ -523,7 +523,7 @@ - try: - conn.execute(select([1])) - assert False -- except tsa.exc.DBAPIError, e: -+ except tsa.exc.DBAPIError as e: - if not e.connection_invalidated: - raise - -@@ -542,7 +542,7 @@ - try: - conn.execute(select([1])) - assert False -- except tsa.exc.DBAPIError, e: -+ except tsa.exc.DBAPIError as e: - if not e.connection_invalidated: - raise - assert not conn.closed -@@ -558,7 +558,7 @@ - try: - trans.commit() - assert False -- except tsa.exc.InvalidRequestError, e: -+ except tsa.exc.InvalidRequestError as e: - assert str(e) \ - == "Can't reconnect until invalid transaction is "\ - "rolled back" -@@ -634,13 +634,13 @@ - def test_invalidate_on_results(self): - conn = engine.connect() - result = conn.execute('select * from sometable') -- for x in xrange(20): -+ for x in range(20): - result.fetchone() - engine.test_shutdown() - try: -- print 'ghost result: %r' % result.fetchone() -+ print('ghost result: %r' % result.fetchone()) - assert False -- except tsa.exc.DBAPIError, e: -+ except tsa.exc.DBAPIError as e: - if not e.connection_invalidated: - raise - assert conn.invalidated -diff -r 9d0639b9d3be test/engine/test_reflection.py ---- a/test/engine/test_reflection.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/engine/test_reflection.py Sat Apr 27 19:42:17 2013 -0400 -@@ -811,7 +811,7 @@ - try: - m4.reflect(only=['rt_a', 'rt_f']) - self.assert_(False) -- except sa.exc.InvalidRequestError, e: -+ except sa.exc.InvalidRequestError as e: - self.assert_(e.args[0].endswith('(rt_f)')) - - m5 = MetaData(testing.db) -@@ -833,7 +833,7 @@ - ) - - if existing: -- print "Other tables present in database, skipping some checks." -+ print("Other tables present in database, skipping some checks.") - else: - baseline.drop_all() - m9 = MetaData(testing.db) -@@ -1041,19 +1041,19 @@ - cls.metadata = metadata = MetaData() - - no_multibyte_period = set([ -- (u'plain', u'col_plain', u'ix_plain') -+ ('plain', 'col_plain', 'ix_plain') - ]) - no_has_table = [ -- (u'no_has_table_1', u'col_Unit\u00e9ble', u'ix_Unit\u00e9ble'), -- (u'no_has_table_2', u'col_\u6e2c\u8a66', u'ix_\u6e2c\u8a66'), -+ ('no_has_table_1', 'col_Unit\u00e9ble', 'ix_Unit\u00e9ble'), -+ ('no_has_table_2', 'col_\u6e2c\u8a66', 'ix_\u6e2c\u8a66'), - ] - no_case_sensitivity = [ -- (u'\u6e2c\u8a66', u'col_\u6e2c\u8a66', u'ix_\u6e2c\u8a66'), -- (u'unit\u00e9ble', u'col_unit\u00e9ble', u'ix_unit\u00e9ble'), -+ ('\u6e2c\u8a66', 'col_\u6e2c\u8a66', 'ix_\u6e2c\u8a66'), -+ ('unit\u00e9ble', 'col_unit\u00e9ble', 'ix_unit\u00e9ble'), - ] - full = [ -- (u'Unit\u00e9ble', u'col_Unit\u00e9ble', u'ix_Unit\u00e9ble'), -- (u'\u6e2c\u8a66', u'col_\u6e2c\u8a66', u'ix_\u6e2c\u8a66'), -+ ('Unit\u00e9ble', 'col_Unit\u00e9ble', 'ix_Unit\u00e9ble'), -+ ('\u6e2c\u8a66', 'col_\u6e2c\u8a66', 'ix_\u6e2c\u8a66'), - ] - - # as you can see, our options for this kind of thing -diff -r 9d0639b9d3be test/engine/test_transaction.py ---- a/test/engine/test_transaction.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/engine/test_transaction.py Sat Apr 27 19:42:17 2013 -0400 -@@ -74,8 +74,8 @@ - connection.execute(users.insert(), user_id=1, user_name='user3') - transaction.commit() - assert False -- except Exception , e: -- print "Exception: ", e -+ except Exception as e: -+ print("Exception: ", e) - transaction.rollback() - - result = connection.execute("select * from query_users") -@@ -121,10 +121,10 @@ - trans2.rollback() - raise - transaction.rollback() -- except Exception, e: -+ except Exception as e: - transaction.rollback() - raise -- except Exception, e: -+ except Exception as e: - try: - assert str(e) == 'uh oh' # and not "This transaction is - # inactive" -@@ -167,7 +167,7 @@ - connection.execute(users.insert(), user_id=2, user_name='user2') - try: - connection.execute(users.insert(), user_id=2, user_name='user2.5') -- except Exception, e: -+ except Exception as e: - trans.__exit__(*sys.exc_info()) - - assert not trans.is_active -@@ -1019,7 +1019,7 @@ - con = testing.db.connect() - sel = counters.select(for_update=update_style, - whereclause=counters.c.counter_id == 1) -- for i in xrange(count): -+ for i in range(count): - trans = con.begin() - try: - existing = con.execute(sel).first() -@@ -1033,7 +1033,7 @@ - raise AssertionError('Got %s post-update, expected ' - '%s' % (readback['counter_value'], incr)) - trans.commit() -- except Exception, e: -+ except Exception as e: - trans.rollback() - errors.append(e) - break -@@ -1057,7 +1057,7 @@ - db.execute(counters.insert(), counter_id=1, counter_value=0) - iterations, thread_count = 10, 5 - threads, errors = [], [] -- for i in xrange(thread_count): -+ for i in range(thread_count): - thrd = threading.Thread(target=self.increment, - args=(iterations, ), - kwargs={'errors': errors, -@@ -1088,7 +1088,7 @@ - rows = con.execute(sel).fetchall() - time.sleep(0.25) - trans.commit() -- except Exception, e: -+ except Exception as e: - trans.rollback() - errors.append(e) - con.close() -@@ -1105,7 +1105,7 @@ - db.execute(counters.insert(), counter_id=cid + 1, - counter_value=0) - errors, threads = [], [] -- for i in xrange(thread_count): -+ for i in range(thread_count): - thrd = threading.Thread(target=self.overlap, - args=(groups.pop(0), errors, - update_style)) -diff -r 9d0639b9d3be test/ext/declarative/test_basic.py ---- a/test/ext/declarative/test_basic.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/ext/declarative/test_basic.py Sat Apr 27 19:42:17 2013 -0400 -@@ -127,14 +127,13 @@ - class BrokenMeta(type): - def __getattribute__(self, attr): - if attr == 'xyzzy': -- raise AttributeError, 'xyzzy' -+ raise AttributeError('xyzzy') - else: - return object.__getattribute__(self,attr) - - # even though this class has an xyzzy attribute, getattr(cls,"xyzzy") - # fails -- class BrokenParent(object): -- __metaclass__ = BrokenMeta -+ class BrokenParent(object, metaclass=BrokenMeta): - xyzzy = "magic" - - # _as_declarative() inspects obj.__class__.__bases__ -@@ -1458,12 +1457,12 @@ - - @classmethod - def insert_data(cls): -- params = [dict(zip(('id', 'name'), column_values)) -+ params = [dict(list(zip(('id', 'name'), column_values))) - for column_values in [(7, 'jack'), (8, 'ed'), (9, - 'fred'), (10, 'chuck')]] - User.__table__.insert().execute(params) -- Address.__table__.insert().execute([dict(zip(('id', -- 'user_id', 'email'), column_values)) -+ Address.__table__.insert().execute([dict(list(zip(('id', -+ 'user_id', 'email'), column_values))) - for column_values in [(1, 7, 'jack@bean.com'), (2, - 8, 'ed@wood.com'), (3, 8, 'ed@bettyboop.com'), (4, - 8, 'ed@lala.com'), (5, 9, 'fred@fred.com')]]) -@@ -1492,6 +1491,6 @@ - for inline in True, False: - for stringbased in True, False: - testclass = _produce_test(inline, stringbased) -- exec '%s = testclass' % testclass.__name__ -+ exec('%s = testclass' % testclass.__name__) - del testclass - -diff -r 9d0639b9d3be test/ext/declarative/test_clsregistry.py ---- a/test/ext/declarative/test_clsregistry.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/ext/declarative/test_clsregistry.py Sat Apr 27 19:42:17 2013 -0400 -@@ -124,7 +124,7 @@ - - base = weakref.WeakValueDictionary() - -- for i in xrange(3): -+ for i in range(3): - f1 = MockClass(base, "foo.bar.Foo") - f2 = MockClass(base, "foo.alt.Foo") - clsregistry.add_class("Foo", f1) -diff -r 9d0639b9d3be test/ext/declarative/test_inheritance.py ---- a/test/ext/declarative/test_inheritance.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/ext/declarative/test_inheritance.py Sat Apr 27 19:42:17 2013 -0400 -@@ -573,7 +573,7 @@ - primary_language = Column(String(50)) - - assert Person.__table__.c.golf_swing is not None -- assert not Person.__table__.c.has_key('primary_language') -+ assert 'primary_language' not in Person.__table__.c - assert Engineer.__table__.c.primary_language is not None - assert Engineer.primary_language is not None - assert Manager.golf_swing is not None -diff -r 9d0639b9d3be test/ext/declarative/test_mixin.py ---- a/test/ext/declarative/test_mixin.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/ext/declarative/test_mixin.py Sat Apr 27 19:42:17 2013 -0400 -@@ -685,7 +685,7 @@ - __mapper_args__ = dict(polymorphic_identity='specific') - - assert Specific.__table__ is Generic.__table__ -- eq_(Generic.__table__.c.keys(), ['id', 'type', 'value']) -+ eq_(list(Generic.__table__.c.keys()), ['id', 'type', 'value']) - assert class_mapper(Specific).polymorphic_on \ - is Generic.__table__.c.type - eq_(class_mapper(Specific).polymorphic_identity, 'specific') -@@ -714,9 +714,9 @@ - - eq_(Generic.__table__.name, 'generic') - eq_(Specific.__table__.name, 'specific') -- eq_(Generic.__table__.c.keys(), ['timestamp', 'id', -+ eq_(list(Generic.__table__.c.keys()), ['timestamp', 'id', - 'python_type']) -- eq_(Specific.__table__.c.keys(), ['id']) -+ eq_(list(Specific.__table__.c.keys()), ['id']) - eq_(Generic.__table__.kwargs, {'mysql_engine': 'InnoDB'}) - eq_(Specific.__table__.kwargs, {'mysql_engine': 'InnoDB'}) - -@@ -749,12 +749,12 @@ - primary_key=True) - - eq_(BaseType.__table__.name, 'basetype') -- eq_(BaseType.__table__.c.keys(), ['timestamp', 'type', 'id', -+ eq_(list(BaseType.__table__.c.keys()), ['timestamp', 'type', 'id', - 'value']) - eq_(BaseType.__table__.kwargs, {'mysql_engine': 'InnoDB'}) - assert Single.__table__ is BaseType.__table__ - eq_(Joined.__table__.name, 'joined') -- eq_(Joined.__table__.c.keys(), ['id']) -+ eq_(list(Joined.__table__.c.keys()), ['id']) - eq_(Joined.__table__.kwargs, {'mysql_engine': 'InnoDB'}) - - def test_col_copy_vs_declared_attr_joined_propagation(self): -@@ -839,7 +839,7 @@ - __mapper_args__ = dict(polymorphic_identity='specific') - - eq_(BaseType.__table__.name, 'basetype') -- eq_(BaseType.__table__.c.keys(), ['type', 'id', 'value']) -+ eq_(list(BaseType.__table__.c.keys()), ['type', 'id', 'value']) - assert Specific.__table__ is BaseType.__table__ - assert class_mapper(Specific).polymorphic_on \ - is BaseType.__table__.c.type -@@ -870,9 +870,9 @@ - primary_key=True) - - eq_(BaseType.__table__.name, 'basetype') -- eq_(BaseType.__table__.c.keys(), ['type', 'id', 'value']) -+ eq_(list(BaseType.__table__.c.keys()), ['type', 'id', 'value']) - eq_(Specific.__table__.name, 'specific') -- eq_(Specific.__table__.c.keys(), ['id']) -+ eq_(list(Specific.__table__.c.keys()), ['id']) - - def test_single_back_propagate(self): - -@@ -891,7 +891,7 @@ - - __mapper_args__ = dict(polymorphic_identity='specific') - -- eq_(BaseType.__table__.c.keys(), ['type', 'id', 'timestamp']) -+ eq_(list(BaseType.__table__.c.keys()), ['type', 'id', 'timestamp']) - - def test_table_in_model_and_same_column_in_mixin(self): - -@@ -987,7 +987,7 @@ - id = Column(Integer, primary_key=True) - __tablename__ = 'model' - -- eq_(Model.__table__.c.keys(), ['col1', 'col3', 'col2', 'col4', -+ eq_(list(Model.__table__.c.keys()), ['col1', 'col3', 'col2', 'col4', - 'id']) - - def test_honor_class_mro_one(self): -@@ -1078,8 +1078,8 @@ - filter_class = FilterB - id = Column(Integer(), primary_key=True) - -- TypeA(filters=[u'foo']) -- TypeB(filters=[u'foo']) -+ TypeA(filters=['foo']) -+ TypeB(filters=['foo']) - - class DeclarativeMixinPropertyTest(DeclarativeTestBase): - -diff -r 9d0639b9d3be test/ext/test_associationproxy.py ---- a/test/ext/test_associationproxy.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/ext/test_associationproxy.py Sat Apr 27 19:42:17 2013 -0400 -@@ -288,7 +288,7 @@ - ch = Child('a', 'regular') - p1._children.append(ch) - -- self.assert_(ch in p1._children.values()) -+ self.assert_(ch in list(p1._children.values())) - self.assert_(len(p1._children) == 1) - - self.assert_(p1.children) -@@ -300,7 +300,7 @@ - - p1.children['b'] = 'proxied' - -- self.assert_('proxied' in p1.children.values()) -+ self.assert_('proxied' in list(p1.children.values())) - self.assert_('b' in p1.children) - self.assert_('proxied' not in p1._children) - self.assert_(len(p1.children) == 2) -@@ -526,9 +526,9 @@ - try: - self.assert_(p.children == control) - except: -- print 'Test %s.%s(%s):' % (set(base), op, other) -- print 'want', repr(control) -- print 'got', repr(p.children) -+ print('Test %s.%s(%s):' % (set(base), op, other)) -+ print('want', repr(control)) -+ print('got', repr(p.children)) - raise - - p = self.roundtrip(p) -@@ -536,9 +536,9 @@ - try: - self.assert_(p.children == control) - except: -- print 'Test %s.%s(%s):' % (base, op, other) -- print 'want', repr(control) -- print 'got', repr(p.children) -+ print('Test %s.%s(%s):' % (base, op, other)) -+ print('want', repr(control)) -+ print('got', repr(p.children)) - raise - - # in-place mutations -@@ -553,15 +553,15 @@ - p.children = base[:] - control = set(base[:]) - -- exec "p.children %s other" % op -- exec "control %s other" % op -+ exec("p.children %s other" % op) -+ exec("control %s other" % op) - - try: - self.assert_(p.children == control) - except: -- print 'Test %s %s %s:' % (set(base), op, other) -- print 'want', repr(control) -- print 'got', repr(p.children) -+ print('Test %s %s %s:' % (set(base), op, other)) -+ print('want', repr(control)) -+ print('got', repr(p.children)) - raise - - p = self.roundtrip(p) -@@ -569,9 +569,9 @@ - try: - self.assert_(p.children == control) - except: -- print 'Test %s %s %s:' % (base, op, other) -- print 'want', repr(control) -- print 'got', repr(p.children) -+ print('Test %s %s %s:' % (base, op, other)) -+ print('want', repr(control)) -+ print('got', repr(p.children)) - raise - - -diff -r 9d0639b9d3be test/ext/test_serializer.py ---- a/test/ext/test_serializer.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/ext/test_serializer.py Sat Apr 27 19:42:17 2013 -0400 -@@ -47,12 +47,12 @@ - - @classmethod - def insert_data(cls): -- params = [dict(zip(('id', 'name'), column_values)) -+ params = [dict(list(zip(('id', 'name'), column_values))) - for column_values in [(7, 'jack'), (8, 'ed'), (9, - 'fred'), (10, 'chuck')]] - users.insert().execute(params) -- addresses.insert().execute([dict(zip(('id', 'user_id', 'email' -- ), column_values)) -+ addresses.insert().execute([dict(list(zip(('id', 'user_id', 'email' -+ ), column_values))) - for column_values in [(1, 7, - 'jack@bean.com'), (2, 8, - 'ed@wood.com'), (3, 8, -@@ -85,8 +85,8 @@ - users.metadata, None) - eq_(str(expr), str(re_expr)) - assert re_expr.bind is testing.db -- eq_(re_expr.execute().fetchall(), [(7, u'jack'), (8, u'ed'), -- (8, u'ed'), (8, u'ed'), (9, u'fred')]) -+ eq_(re_expr.execute().fetchall(), [(7, 'jack'), (8, 'ed'), -+ (8, 'ed'), (8, 'ed'), (9, 'fred')]) - - def test_query_one(self): - q = Session.query(User).\ -@@ -121,7 +121,7 @@ - q2 = serializer.loads(serializer.dumps(q, -1), users.metadata, - Session) - eq_(q2.all(), [User(name='fred')]) -- eq_(list(q2.values(User.id, User.name)), [(9, u'fred')]) -+ eq_(list(q2.values(User.id, User.name)), [(9, 'fred')]) - - def test_query_three(self): - ua = aliased(User) -@@ -134,7 +134,7 @@ - - # try to pull out the aliased entity here... - ua_2 = q2._entities[0].entity_zero.entity -- eq_(list(q2.values(ua_2.id, ua_2.name)), [(9, u'fred')]) -+ eq_(list(q2.values(ua_2.id, ua_2.name)), [(9, 'fred')]) - - def test_orm_join(self): - from sqlalchemy.orm.util import join -diff -r 9d0639b9d3be test/orm/inheritance/test_assorted_poly.py ---- a/test/orm/inheritance/test_assorted_poly.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/inheritance/test_assorted_poly.py Sat Apr 27 19:42:17 2013 -0400 -@@ -18,7 +18,7 @@ - - class AttrSettable(object): - def __init__(self, **kwargs): -- [setattr(self, k, v) for k, v in kwargs.iteritems()] -+ [setattr(self, k, v) for k, v in kwargs.items()] - def __repr__(self): - return self.__class__.__name__ + "(%s)" % (hex(id(self))) - -@@ -386,7 +386,7 @@ - # class definitions - class Person(object): - def __init__(self, **kwargs): -- for key, value in kwargs.iteritems(): -+ for key, value in kwargs.items(): - setattr(self, key, value) - def __repr__(self): - return "Ordinary person %s" % self.name -@@ -400,7 +400,7 @@ - (self.name, self.longer_status) - class Car(object): - def __init__(self, **kwargs): -- for key, value in kwargs.iteritems(): -+ for key, value in kwargs.items(): - setattr(self, key, value) - def __repr__(self): - return "Car number %d" % self.car_id -@@ -512,7 +512,7 @@ - - class Person(object): - def __init__(self, **kwargs): -- for key, value in kwargs.iteritems(): -+ for key, value in kwargs.items(): - setattr(self, key, value) - def __repr__(self): - return "Ordinary person %s" % self.name -@@ -526,7 +526,7 @@ - (self.name, self.longer_status) - class Car(object): - def __init__(self, **kwargs): -- for key, value in kwargs.iteritems(): -+ for key, value in kwargs.items(): - setattr(self, key, value) - def __repr__(self): - return "Car number %d" % self.car_id -@@ -646,7 +646,7 @@ - - class PersistentObject(object): - def __init__(self, **kwargs): -- for key, value in kwargs.iteritems(): -+ for key, value in kwargs.items(): - setattr(self, key, value) - - class Status(PersistentObject): -@@ -838,7 +838,7 @@ - # class definitions - class PersistentObject(object): - def __init__(self, **kwargs): -- for key, value in kwargs.iteritems(): -+ for key, value in kwargs.items(): - setattr(self, key, value) - class Status(PersistentObject): - def __repr__(self): -@@ -968,7 +968,7 @@ - def test_threelevels(self): - class Employee( object): - def set( me, **kargs): -- for k,v in kargs.iteritems(): setattr( me, k, v) -+ for k,v in kargs.items(): setattr( me, k, v) - return me - def __str__(me): - return str(me.__class__.__name__)+':'+str(me.name) -diff -r 9d0639b9d3be test/orm/inheritance/test_basic.py ---- a/test/orm/inheritance/test_basic.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/inheritance/test_basic.py Sat Apr 27 19:42:17 2013 -0400 -@@ -1355,7 +1355,7 @@ - def _do_test(self, j1, j2): - class A(object): - def __init__(self, **kwargs): -- for key, value in kwargs.items(): -+ for key, value in list(kwargs.items()): - setattr(self, key, value) - - class B(A): -@@ -1830,7 +1830,7 @@ - "SELECT sub.counter AS sub_counter, base.counter AS base_counter, " - "sub.counter2 AS sub_counter2 FROM base JOIN sub ON " - "base.id = sub.id WHERE base.id = :param_1", -- lambda ctx:{u'param_1': s1.id} -+ lambda ctx:{'param_1': s1.id} - ), - ) - -@@ -1910,7 +1910,7 @@ - "SELECT subsub.counter2 AS subsub_counter2, " - "sub.counter2 AS sub_counter2 FROM subsub, sub " - "WHERE :param_1 = sub.id AND sub.id = subsub.id", -- lambda ctx:{u'param_1': s1.id} -+ lambda ctx:{'param_1': s1.id} - ), - ) - -@@ -2409,9 +2409,9 @@ - polymorphic_identity='foo') - sess = create_session() - f = Foo() -- f.content_type = u'bar' -+ f.content_type = 'bar' - sess.add(f) - sess.flush() - f_id = f.id - sess.expunge_all() -- assert sess.query(Content).get(f_id).content_type == u'bar' -+ assert sess.query(Content).get(f_id).content_type == 'bar' -diff -r 9d0639b9d3be test/orm/inheritance/test_concrete.py ---- a/test/orm/inheritance/test_concrete.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/inheritance/test_concrete.py Sat Apr 27 19:42:17 2013 -0400 -@@ -722,10 +722,10 @@ - @classmethod - def insert_data(cls): - refugees_table.insert().execute(dict(refugee_fid=1, -- name=u'refugee1'), dict(refugee_fid=2, name=u'refugee2' -+ name='refugee1'), dict(refugee_fid=2, name='refugee2' - )) - offices_table.insert().execute(dict(office_fid=1, -- name=u'office1'), dict(office_fid=2, name=u'office2')) -+ name='office1'), dict(office_fid=2, name='office2')) - - def test_keys(self): - pjoin = polymorphic_union({'refugee': refugees_table, 'office' -diff -r 9d0639b9d3be test/orm/inheritance/test_magazine.py ---- a/test/orm/inheritance/test_magazine.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/inheritance/test_magazine.py Sat Apr 27 19:42:17 2013 -0400 -@@ -8,7 +8,7 @@ - - class BaseObject(object): - def __init__(self, *args, **kwargs): -- for key, value in kwargs.iteritems(): -+ for key, value in kwargs.items(): - setattr(self, key, value) - class Publication(BaseObject): - pass -@@ -200,15 +200,15 @@ - - - session.flush() -- print [x for x in session] -+ print([x for x in session]) - session.expunge_all() - - session.flush() - session.expunge_all() - p = session.query(Publication).filter(Publication.name=="Test").one() - -- print p.issues[0].locations[0].magazine.pages -- print [page, page2, page3] -+ print(p.issues[0].locations[0].magazine.pages) -+ print([page, page2, page3]) - assert repr(p.issues[0].locations[0].magazine.pages) == repr([page, page2, page3]), repr(p.issues[0].locations[0].magazine.pages) - - test_roundtrip = function_named( -diff -r 9d0639b9d3be test/orm/inheritance/test_manytomany.py ---- a/test/orm/inheritance/test_manytomany.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/inheritance/test_manytomany.py Sat Apr 27 19:42:17 2013 -0400 -@@ -42,7 +42,7 @@ - def testbasic(self): - class Principal(object): - def __init__(self, **kwargs): -- for key, value in kwargs.iteritems(): -+ for key, value in kwargs.items(): - setattr(self, key, value) - - class User(Principal): -@@ -94,8 +94,8 @@ - - mapper(Foo, foo) - mapper(Bar, bar, inherits=Foo) -- print foo.join(bar).primary_key -- print class_mapper(Bar).primary_key -+ print(foo.join(bar).primary_key) -+ print(class_mapper(Bar).primary_key) - b = Bar('somedata') - sess = create_session() - sess.add(b) -@@ -133,8 +133,8 @@ - sess.expunge_all() - - l = sess.query(Bar).all() -- print l[0] -- print l[0].foos -+ print(l[0]) -+ print(l[0].foos) - self.assert_unordered_result(l, Bar, - # {'id':1, 'data':'barfoo', 'bid':1, 'foos':(Foo, [{'id':2,'data':'subfoo1'}, {'id':3,'data':'subfoo2'}])}, - {'id':b.id, 'data':'barfoo', 'foos':(Foo, [{'id':f1.id,'data':'subfoo1'}, {'id':f2.id,'data':'subfoo2'}])}, -@@ -197,7 +197,7 @@ - compare = [repr(b)] + sorted([repr(o) for o in b.foos]) - sess.expunge_all() - l = sess.query(Bar).all() -- print repr(l[0]) + repr(l[0].foos) -+ print(repr(l[0]) + repr(l[0].foos)) - found = [repr(l[0])] + sorted([repr(o) for o in l[0].foos]) - eq_(found, compare) - -@@ -239,11 +239,11 @@ - sess.expunge_all() - - l = sess.query(Blub).all() -- print l -+ print(l) - self.assert_(repr(l[0]) == compare) - sess.expunge_all() - x = sess.query(Blub).filter_by(id=blubid).one() -- print x -+ print(x) - self.assert_(repr(x) == compare) - - -diff -r 9d0639b9d3be test/orm/inheritance/test_polymorphic_rel.py ---- a/test/orm/inheritance/test_polymorphic_rel.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/inheritance/test_polymorphic_rel.py Sat Apr 27 19:42:17 2013 -0400 -@@ -7,7 +7,7 @@ - from sqlalchemy import testing - from sqlalchemy.testing import assert_raises, eq_ - --from _poly_fixtures import Company, Person, Engineer, Manager, Boss, \ -+from ._poly_fixtures import Company, Person, Engineer, Manager, Boss, \ - Machine, Paperwork, _Polymorphic,\ - _PolymorphicPolymorphic, _PolymorphicUnions, _PolymorphicJoins,\ - _PolymorphicAliasedJoins -@@ -118,24 +118,24 @@ - eq_(q.count(), 1) - eq_(q.all(), [ - ( -- Company(company_id=1, name=u'MegaCorp, Inc.'), -+ Company(company_id=1, name='MegaCorp, Inc.'), - Engineer( -- status=u'regular engineer', -- engineer_name=u'dilbert', -- name=u'dilbert', -+ status='regular engineer', -+ engineer_name='dilbert', -+ name='dilbert', - company_id=1, -- primary_language=u'java', -+ primary_language='java', - person_id=1, -- type=u'engineer'), -- Company(company_id=1, name=u'MegaCorp, Inc.'), -+ type='engineer'), -+ Company(company_id=1, name='MegaCorp, Inc.'), - Engineer( -- status=u'regular engineer', -- engineer_name=u'wally', -- name=u'wally', -+ status='regular engineer', -+ engineer_name='wally', -+ name='wally', - company_id=1, -- primary_language=u'c++', -+ primary_language='c++', - person_id=2, -- type=u'engineer') -+ type='engineer') - ) - ]) - -@@ -337,8 +337,8 @@ - sess = create_session() - - expected = [ -- (u'dogbert',), -- (u'pointy haired boss',)] -+ ('dogbert',), -+ ('pointy haired boss',)] - eq_(sess.query(Manager.name) - .order_by(Manager.name).all(), - expected) -@@ -346,9 +346,9 @@ - def test_join_from_columns_or_subclass_two(self): - sess = create_session() - expected = [ -- (u'dogbert',), -- (u'dogbert',), -- (u'pointy haired boss',)] -+ ('dogbert',), -+ ('dogbert',), -+ ('pointy haired boss',)] - eq_(sess.query(Manager.name) - .join(Paperwork, Manager.paperwork) - .order_by(Manager.name).all(), -@@ -357,14 +357,14 @@ - def test_join_from_columns_or_subclass_three(self): - sess = create_session() - expected = [ -- (u'dilbert',), -- (u'dilbert',), -- (u'dogbert',), -- (u'dogbert',), -- (u'pointy haired boss',), -- (u'vlad',), -- (u'wally',), -- (u'wally',)] -+ ('dilbert',), -+ ('dilbert',), -+ ('dogbert',), -+ ('dogbert',), -+ ('pointy haired boss',), -+ ('vlad',), -+ ('wally',), -+ ('wally',)] - eq_(sess.query(Person.name) - .join(Paperwork, Person.paperwork) - .order_by(Person.name).all(), -@@ -375,14 +375,14 @@ - # Load Person.name, joining from Person -> paperwork, get all - # the people. - expected = [ -- (u'dilbert',), -- (u'dilbert',), -- (u'dogbert',), -- (u'dogbert',), -- (u'pointy haired boss',), -- (u'vlad',), -- (u'wally',), -- (u'wally',)] -+ ('dilbert',), -+ ('dilbert',), -+ ('dogbert',), -+ ('dogbert',), -+ ('pointy haired boss',), -+ ('vlad',), -+ ('wally',), -+ ('wally',)] - eq_(sess.query(Person.name) - .join(paperwork, - Person.person_id == paperwork.c.person_id) -@@ -393,9 +393,9 @@ - sess = create_session() - # same, on manager. get only managers. - expected = [ -- (u'dogbert',), -- (u'dogbert',), -- (u'pointy haired boss',)] -+ ('dogbert',), -+ ('dogbert',), -+ ('pointy haired boss',)] - eq_(sess.query(Manager.name) - .join(paperwork, - Manager.person_id == paperwork.c.person_id) -@@ -418,14 +418,14 @@ - # here, it joins to the full result set. This is 0.6's - # behavior and is more or less wrong. - expected = [ -- (u'dilbert',), -- (u'dilbert',), -- (u'dogbert',), -- (u'dogbert',), -- (u'pointy haired boss',), -- (u'vlad',), -- (u'wally',), -- (u'wally',)] -+ ('dilbert',), -+ ('dilbert',), -+ ('dogbert',), -+ ('dogbert',), -+ ('pointy haired boss',), -+ ('vlad',), -+ ('wally',), -+ ('wally',)] - eq_(sess.query(Person.name) - .join(paperwork, - Manager.person_id == paperwork.c.person_id) -@@ -435,9 +435,9 @@ - # when a join is present and managers.person_id is available, - # you get the managers. - expected = [ -- (u'dogbert',), -- (u'dogbert',), -- (u'pointy haired boss',)] -+ ('dogbert',), -+ ('dogbert',), -+ ('pointy haired boss',)] - eq_(sess.query(Person.name) - .join(paperwork, - Manager.person_id == paperwork.c.person_id) -@@ -454,9 +454,9 @@ - def test_join_from_columns_or_subclass_eight(self): - sess = create_session() - expected = [ -- (u'dogbert',), -- (u'dogbert',), -- (u'pointy haired boss',)] -+ ('dogbert',), -+ ('dogbert',), -+ ('pointy haired boss',)] - eq_(sess.query(Manager.name) - .join(paperwork, - Manager.person_id == paperwork.c.person_id) -@@ -474,9 +474,9 @@ - def test_join_from_columns_or_subclass_ten(self): - sess = create_session() - expected = [ -- (u'pointy haired boss', u'review #1'), -- (u'dogbert', u'review #2'), -- (u'dogbert', u'review #3')] -+ ('pointy haired boss', 'review #1'), -+ ('dogbert', 'review #2'), -+ ('dogbert', 'review #3')] - eq_(sess.query(Manager.name, Paperwork.description) - .join(Paperwork, - Manager.person_id == Paperwork.person_id) -@@ -486,9 +486,9 @@ - def test_join_from_columns_or_subclass_eleven(self): - sess = create_session() - expected = [ -- (u'pointy haired boss',), -- (u'dogbert',), -- (u'dogbert',)] -+ ('pointy haired boss',), -+ ('dogbert',), -+ ('dogbert',)] - malias = aliased(Manager) - eq_(sess.query(malias.name) - .join(paperwork, -@@ -977,32 +977,32 @@ - - expected = [ - (Engineer( -- status=u'regular engineer', -- engineer_name=u'dilbert', -- name=u'dilbert', -+ status='regular engineer', -+ engineer_name='dilbert', -+ name='dilbert', - company_id=1, -- primary_language=u'java', -+ primary_language='java', - person_id=1, -- type=u'engineer'), -- u'MegaCorp, Inc.'), -+ type='engineer'), -+ 'MegaCorp, Inc.'), - (Engineer( -- status=u'regular engineer', -- engineer_name=u'wally', -- name=u'wally', -+ status='regular engineer', -+ engineer_name='wally', -+ name='wally', - company_id=1, -- primary_language=u'c++', -+ primary_language='c++', - person_id=2, -- type=u'engineer'), -- u'MegaCorp, Inc.'), -+ type='engineer'), -+ 'MegaCorp, Inc.'), - (Engineer( -- status=u'elbonian engineer', -- engineer_name=u'vlad', -- name=u'vlad', -+ status='elbonian engineer', -+ engineer_name='vlad', -+ name='vlad', - company_id=2, -- primary_language=u'cobol', -+ primary_language='cobol', - person_id=5, -- type=u'engineer'), -- u'Elbonia, Inc.')] -+ type='engineer'), -+ 'Elbonia, Inc.')] - eq_(sess.query(Engineer, Company.name) - .join(Company.employees) - .filter(Person.type == 'engineer').all(), -@@ -1011,9 +1011,9 @@ - def test_mixed_entities_two(self): - sess = create_session() - expected = [ -- (u'java', u'MegaCorp, Inc.'), -- (u'cobol', u'Elbonia, Inc.'), -- (u'c++', u'MegaCorp, Inc.')] -+ ('java', 'MegaCorp, Inc.'), -+ ('cobol', 'Elbonia, Inc.'), -+ ('c++', 'MegaCorp, Inc.')] - eq_(sess.query(Engineer.primary_language, Company.name) - .join(Company.employees) - .filter(Person.type == 'engineer') -@@ -1025,19 +1025,19 @@ - palias = aliased(Person) - expected = [( - Engineer( -- status=u'elbonian engineer', -- engineer_name=u'vlad', -- name=u'vlad', -- primary_language=u'cobol'), -- u'Elbonia, Inc.', -+ status='elbonian engineer', -+ engineer_name='vlad', -+ name='vlad', -+ primary_language='cobol'), -+ 'Elbonia, Inc.', - Engineer( -- status=u'regular engineer', -- engineer_name=u'dilbert', -- name=u'dilbert', -+ status='regular engineer', -+ engineer_name='dilbert', -+ name='dilbert', - company_id=1, -- primary_language=u'java', -+ primary_language='java', - person_id=1, -- type=u'engineer'))] -+ type='engineer'))] - eq_(sess.query(Person, Company.name, palias) - .join(Company.employees) - .filter(Company.name == 'Elbonia, Inc.') -@@ -1049,19 +1049,19 @@ - palias = aliased(Person) - expected = [( - Engineer( -- status=u'regular engineer', -- engineer_name=u'dilbert', -- name=u'dilbert', -+ status='regular engineer', -+ engineer_name='dilbert', -+ name='dilbert', - company_id=1, -- primary_language=u'java', -+ primary_language='java', - person_id=1, -- type=u'engineer'), -- u'Elbonia, Inc.', -+ type='engineer'), -+ 'Elbonia, Inc.', - Engineer( -- status=u'elbonian engineer', -- engineer_name=u'vlad', -- name=u'vlad', -- primary_language=u'cobol'),)] -+ status='elbonian engineer', -+ engineer_name='vlad', -+ name='vlad', -+ primary_language='cobol'),)] - eq_(sess.query(palias, Company.name, Person) - .join(Company.employees) - .filter(Company.name == 'Elbonia, Inc.') -@@ -1071,7 +1071,7 @@ - def test_mixed_entities_five(self): - sess = create_session() - palias = aliased(Person) -- expected = [(u'vlad', u'Elbonia, Inc.', u'dilbert')] -+ expected = [('vlad', 'Elbonia, Inc.', 'dilbert')] - eq_(sess.query(Person.name, Company.name, palias.name) - .join(Company.employees) - .filter(Company.name == 'Elbonia, Inc.') -@@ -1082,9 +1082,9 @@ - sess = create_session() - palias = aliased(Person) - expected = [ -- (u'manager', u'dogbert', u'engineer', u'dilbert'), -- (u'manager', u'dogbert', u'engineer', u'wally'), -- (u'manager', u'dogbert', u'boss', u'pointy haired boss')] -+ ('manager', 'dogbert', 'engineer', 'dilbert'), -+ ('manager', 'dogbert', 'engineer', 'wally'), -+ ('manager', 'dogbert', 'boss', 'pointy haired boss')] - eq_(sess.query(Person.type, Person.name, palias.type, palias.name) - .filter(Person.company_id == palias.company_id) - .filter(Person.name == 'dogbert') -@@ -1095,14 +1095,14 @@ - def test_mixed_entities_seven(self): - sess = create_session() - expected = [ -- (u'dilbert', u'tps report #1'), -- (u'dilbert', u'tps report #2'), -- (u'dogbert', u'review #2'), -- (u'dogbert', u'review #3'), -- (u'pointy haired boss', u'review #1'), -- (u'vlad', u'elbonian missive #3'), -- (u'wally', u'tps report #3'), -- (u'wally', u'tps report #4')] -+ ('dilbert', 'tps report #1'), -+ ('dilbert', 'tps report #2'), -+ ('dogbert', 'review #2'), -+ ('dogbert', 'review #3'), -+ ('pointy haired boss', 'review #1'), -+ ('vlad', 'elbonian missive #3'), -+ ('wally', 'tps report #3'), -+ ('wally', 'tps report #4')] - eq_(sess.query(Person.name, Paperwork.description) - .filter(Person.person_id == Paperwork.person_id) - .order_by(Person.name, Paperwork.description).all(), -@@ -1116,7 +1116,7 @@ - - def test_mixed_entities_nine(self): - sess = create_session() -- expected = [(u'Elbonia, Inc.', 1), (u'MegaCorp, Inc.', 4)] -+ expected = [('Elbonia, Inc.', 1), ('MegaCorp, Inc.', 4)] - eq_(sess.query(Company.name, func.count(Person.person_id)) - .filter(Company.company_id == Person.company_id) - .group_by(Company.name) -@@ -1125,7 +1125,7 @@ - - def test_mixed_entities_ten(self): - sess = create_session() -- expected = [(u'Elbonia, Inc.', 1), (u'MegaCorp, Inc.', 4)] -+ expected = [('Elbonia, Inc.', 1), ('MegaCorp, Inc.', 4)] - eq_(sess.query(Company.name, func.count(Person.person_id)) - .join(Company.employees) - .group_by(Company.name) -@@ -1153,14 +1153,14 @@ - - def test_mixed_entities_eleven(self): - sess = create_session() -- expected = [(u'java',), (u'c++',), (u'cobol',)] -+ expected = [('java',), ('c++',), ('cobol',)] - eq_(sess.query(Engineer.primary_language) - .filter(Person.type == 'engineer').all(), - expected) - - def test_mixed_entities_twelve(self): - sess = create_session() -- expected = [(u'vlad', u'Elbonia, Inc.')] -+ expected = [('vlad', 'Elbonia, Inc.')] - eq_(sess.query(Person.name, Company.name) - .join(Company.employees) - .filter(Company.name == 'Elbonia, Inc.').all(), -@@ -1168,15 +1168,15 @@ - - def test_mixed_entities_thirteen(self): - sess = create_session() -- expected = [(u'pointy haired boss', u'fore')] -+ expected = [('pointy haired boss', 'fore')] - eq_(sess.query(Boss.name, Boss.golf_swing).all(), expected) - - def test_mixed_entities_fourteen(self): - sess = create_session() - expected = [ -- (u'dilbert', u'java'), -- (u'wally', u'c++'), -- (u'vlad', u'cobol')] -+ ('dilbert', 'java'), -+ ('wally', 'c++'), -+ ('vlad', 'cobol')] - eq_(sess.query(Engineer.name, Engineer.primary_language).all(), - expected) - -@@ -1184,12 +1184,12 @@ - sess = create_session() - - expected = [( -- u'Elbonia, Inc.', -+ 'Elbonia, Inc.', - Engineer( -- status=u'elbonian engineer', -- engineer_name=u'vlad', -- name=u'vlad', -- primary_language=u'cobol'))] -+ status='elbonian engineer', -+ engineer_name='vlad', -+ name='vlad', -+ primary_language='cobol'))] - eq_(sess.query(Company.name, Person) - .join(Company.employees) - .filter(Company.name == 'Elbonia, Inc.').all(), -@@ -1199,11 +1199,11 @@ - sess = create_session() - expected = [( - Engineer( -- status=u'elbonian engineer', -- engineer_name=u'vlad', -- name=u'vlad', -- primary_language=u'cobol'), -- u'Elbonia, Inc.')] -+ status='elbonian engineer', -+ engineer_name='vlad', -+ name='vlad', -+ primary_language='cobol'), -+ 'Elbonia, Inc.')] - eq_(sess.query(Person, Company.name) - .join(Company.employees) - .filter(Company.name == 'Elbonia, Inc.').all(), -diff -r 9d0639b9d3be test/orm/inheritance/test_productspec.py ---- a/test/orm/inheritance/test_productspec.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/inheritance/test_productspec.py Sat Apr 27 19:42:17 2013 -0400 -@@ -122,8 +122,8 @@ - - a1 = session.query(Product).filter_by(name='a1').one() - new = repr(a1) -- print orig -- print new -+ print(orig) -+ print(new) - assert orig == new == ' specification=[>, >] documents=None' - - def testtwo(self): -@@ -153,8 +153,8 @@ - session.flush() - session.expunge_all() - new = repr(session.query(SpecLine).all()) -- print orig -- print new -+ print(orig) -+ print(new) - assert orig == new == '[>, >]' - - def testthree(self): -@@ -206,8 +206,8 @@ - - a1 = session.query(Product).filter_by(name='a1').one() - new = repr(a1) -- print orig -- print new -+ print(orig) -+ print(new) - assert orig == new == ' specification=[>] documents=[, ]' - - def testfour(self): -@@ -245,8 +245,8 @@ - - a1 = session.query(Product).filter_by(name='a1').one() - new = repr(a1) -- print orig -- print new -+ print(orig) -+ print(new) - assert orig == new == ' specification=None documents=[]' - - del a1.documents[0] -@@ -312,7 +312,7 @@ - - a1 = session.query(Product).filter_by(name='a1').one() - new = repr(a1) -- print orig -- print new -+ print(orig) -+ print(new) - assert orig == new == ' specification=[>] documents=[, ]' - -diff -r 9d0639b9d3be test/orm/inheritance/test_relationship.py ---- a/test/orm/inheritance/test_relationship.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/inheritance/test_relationship.py Sat Apr 27 19:42:17 2013 -0400 -@@ -287,7 +287,7 @@ - def _five_obj_fixture(self): - sess = Session() - e1, e2, e3, e4, e5 = [ -- Engineer(name='e%d' % (i + 1)) for i in xrange(5) -+ Engineer(name='e%d' % (i + 1)) for i in range(5) - ] - e3.reports_to = e1 - e4.reports_to = e2 -diff -r 9d0639b9d3be test/orm/inheritance/test_with_poly.py ---- a/test/orm/inheritance/test_with_poly.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/inheritance/test_with_poly.py Sat Apr 27 19:42:17 2013 -0400 -@@ -11,7 +11,7 @@ - from sqlalchemy.testing.schema import Table, Column - from sqlalchemy.testing import assert_raises, eq_ - --from _poly_fixtures import Company, Person, Engineer, Manager, Boss, \ -+from ._poly_fixtures import Company, Person, Engineer, Manager, Boss, \ - Machine, Paperwork, _PolymorphicFixtureBase, _Polymorphic,\ - _PolymorphicPolymorphic, _PolymorphicUnions, _PolymorphicJoins,\ - _PolymorphicAliasedJoins -@@ -37,8 +37,8 @@ - pa.Manager.manager_name=='dogbert')).\ - order_by(pa.Engineer.type).all(), - [ -- (u'dilbert', u'java', None), -- (u'dogbert', None, u'dogbert'), -+ ('dilbert', 'java', None), -+ ('dogbert', None, 'dogbert'), - ] - ) - -@@ -63,10 +63,10 @@ - ) - ).order_by(pa.name, pa_alias.name)], - [ -- (u'dilbert', Engineer, u'dilbert', Engineer), -- (u'dogbert', Manager, u'pointy haired boss', Boss), -- (u'vlad', Engineer, u'vlad', Engineer), -- (u'wally', Engineer, u'wally', Engineer) -+ ('dilbert', Engineer, 'dilbert', Engineer), -+ ('dogbert', Manager, 'pointy haired boss', Boss), -+ ('vlad', Engineer, 'vlad', Engineer), -+ ('wally', Engineer, 'wally', Engineer) - ] - ) - -@@ -91,10 +91,10 @@ - ) - ).order_by(pa.name, pa_alias.name)], - [ -- (u'dilbert', u'java', u'dilbert', u'java'), -- (u'dogbert', None, u'pointy haired boss', None), -- (u'vlad', u'cobol', u'vlad', u'cobol'), -- (u'wally', u'c++', u'wally', u'c++') -+ ('dilbert', 'java', 'dilbert', 'java'), -+ ('dogbert', None, 'pointy haired boss', None), -+ ('vlad', 'cobol', 'vlad', 'cobol'), -+ ('wally', 'c++', 'wally', 'c++') - ] - ) - -diff -r 9d0639b9d3be test/orm/test_assorted_eager.py ---- a/test/orm/test_assorted_eager.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_assorted_eager.py Sat Apr 27 19:42:17 2013 -0400 -@@ -129,7 +129,7 @@ - # 3 " - - # not orm style correct query -- print "Obtaining correct results without orm" -+ print("Obtaining correct results without orm") - result = sa.select( - [tests.c.id,categories.c.name], - sa.and_(tests.c.owner_id == 1, -@@ -140,7 +140,7 @@ - tests.c.id == options.c.test_id, - tests.c.owner_id == options.c.owner_id))] - ).execute().fetchall() -- eq_(result, [(1, u'Some Category'), (3, u'Some Category')]) -+ eq_(result, [(1, 'Some Category'), (3, 'Some Category')]) - - def test_withoutjoinedload(self): - Thing, tests, options = (self.classes.Thing, -@@ -158,7 +158,7 @@ - options.c.someoption==False)))) - - result = ["%d %s" % ( t.id,t.category.name ) for t in l] -- eq_(result, [u'1 Some Category', u'3 Some Category']) -+ eq_(result, ['1 Some Category', '3 Some Category']) - - def test_withjoinedload(self): - """ -@@ -185,7 +185,7 @@ - options.c.someoption==False)))) - - result = ["%d %s" % ( t.id,t.category.name ) for t in l] -- eq_(result, [u'1 Some Category', u'3 Some Category']) -+ eq_(result, ['1 Some Category', '3 Some Category']) - - def test_dslish(self): - """test the same as withjoinedload except using generative""" -@@ -203,7 +203,7 @@ - ).outerjoin('owner_option') - - result = ["%d %s" % ( t.id,t.category.name ) for t in l] -- eq_(result, [u'1 Some Category', u'3 Some Category']) -+ eq_(result, ['1 Some Category', '3 Some Category']) - - @testing.crashes('sybase', 'FIXME: unknown, verify not fails_on') - def test_without_outerjoin_literal(self): -@@ -219,7 +219,7 @@ - join('owner_option')) - - result = ["%d %s" % ( t.id,t.category.name ) for t in l] -- eq_(result, [u'3 Some Category']) -+ eq_(result, ['3 Some Category']) - - def test_withoutouterjoin(self): - Thing, tests, options = (self.classes.Thing, -@@ -234,7 +234,7 @@ - ).join('owner_option') - - result = ["%d %s" % ( t.id,t.category.name ) for t in l] -- eq_(result, [u'3 Some Category']) -+ eq_(result, ['3 Some Category']) - - - class EagerTest2(fixtures.MappedTest): -@@ -764,7 +764,7 @@ - (1,),), - - task=(('title', 'task_type_id', 'status_id', 'prj_id'), -- (u'task 1', 1, 1, 1))) -+ ('task 1', 1, 1, 1))) - - @classmethod - def setup_classes(cls): -@@ -804,7 +804,7 @@ - session = create_session() - - eq_(session.query(Joined).limit(10).offset(0).one(), -- Joined(id=1, title=u'task 1', props_cnt=0)) -+ Joined(id=1, title='task 1', props_cnt=0)) - - - class EagerTest9(fixtures.MappedTest): -diff -r 9d0639b9d3be test/orm/test_attributes.py ---- a/test/orm/test_attributes.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_attributes.py Sat Apr 27 19:42:17 2013 -0400 -@@ -838,7 +838,7 @@ - attributes.register_attribute(Foo, 'collection', - uselist=True, typecallable=dict, useobject=True) - assert False -- except sa_exc.ArgumentError, e: -+ except sa_exc.ArgumentError as e: - assert str(e) \ - == 'Type InstrumentedDict must elect an appender '\ - 'method to be a collection class' -@@ -865,7 +865,7 @@ - attributes.register_attribute(Foo, 'collection', - uselist=True, typecallable=MyColl, useobject=True) - assert False -- except sa_exc.ArgumentError, e: -+ except sa_exc.ArgumentError as e: - assert str(e) \ - == 'Type MyColl must elect an appender method to be a '\ - 'collection class' -@@ -889,7 +889,7 @@ - try: - Foo().collection - assert True -- except sa_exc.ArgumentError, e: -+ except sa_exc.ArgumentError as e: - assert False - - class GetNoValueTest(fixtures.ORMTest): -@@ -1410,7 +1410,7 @@ - class Foo(fixtures.BasicEntity): - pass - class Bar(fixtures.BasicEntity): -- def __nonzero__(self): -+ def __bool__(self): - assert False - - instrumentation.register_class(Foo) -diff -r 9d0639b9d3be test/orm/test_collection.py ---- a/test/orm/test_collection.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_collection.py Sat Apr 27 19:42:17 2013 -0400 -@@ -1106,7 +1106,7 @@ - - @collection.converter - def _convert(self, dictlike): -- for key, value in dictlike.iteritems(): -+ for key, value in dictlike.items(): - yield value + 5 - - class Foo(object): -@@ -1145,12 +1145,12 @@ - def __delitem__(self, key): - del self.data[key] - def values(self): -- return self.data.values() -+ return list(self.data.values()) - def __contains__(self, key): - return key in self.data - @collection.iterator - def itervalues(self): -- return self.data.itervalues() -+ return iter(self.data.values()) - __hash__ = object.__hash__ - def __eq__(self, other): - return self.data == other -@@ -1158,7 +1158,7 @@ - return 'DictLike(%s)' % repr(self.data) - - self._test_adapter(DictLike, self.dictable_entity, -- to_set=lambda c: set(c.itervalues())) -+ to_set=lambda c: set(c.values())) - self._test_dict(DictLike) - self._test_dict_bulk(DictLike) - self.assert_(getattr(DictLike, '_sa_instrumented') == id(DictLike)) -@@ -1185,12 +1185,12 @@ - def __delitem__(self, key): - del self.data[key] - def values(self): -- return self.data.values() -+ return list(self.data.values()) - def __contains__(self, key): - return key in self.data - @collection.iterator - def itervalues(self): -- return self.data.itervalues() -+ return iter(self.data.values()) - __hash__ = object.__hash__ - def __eq__(self, other): - return self.data == other -@@ -1198,7 +1198,7 @@ - return 'DictIsh(%s)' % repr(self.data) - - self._test_adapter(DictIsh, self.dictable_entity, -- to_set=lambda c: set(c.itervalues())) -+ to_set=lambda c: set(c.values())) - self._test_dict(DictIsh) - self._test_dict_bulk(DictIsh) - self.assert_(getattr(DictIsh, '_sa_instrumented') == id(DictIsh)) -@@ -1859,7 +1859,7 @@ - f = sess.query(Foo).get(f.col1) - assert len(list(f.bars)) == 2 - -- existing = set([id(b) for b in f.bars.values()]) -+ existing = set([id(b) for b in list(f.bars.values())]) - - col = collections.collection_adapter(f.bars) - col.append_with_event(Bar('b')) -@@ -1869,7 +1869,7 @@ - f = sess.query(Foo).get(f.col1) - assert len(list(f.bars)) == 2 - -- replaced = set([id(b) for b in f.bars.values()]) -+ replaced = set([id(b) for b in list(f.bars.values())]) - self.assert_(existing != replaced) - - def test_list(self): -diff -r 9d0639b9d3be test/orm/test_composites.py ---- a/test/orm/test_composites.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_composites.py Sat Apr 27 19:42:17 2013 -0400 -@@ -510,11 +510,11 @@ - session.commit() - eq_( - testing.db.execute(descriptions.select()).fetchall(), -- [(1, u'Color', u'Number')] -+ [(1, 'Color', 'Number')] - ) - eq_( - testing.db.execute(values.select()).fetchall(), -- [(1, 1, u'Red', u'5'), (2, 1, u'Blue', u'1')] -+ [(1, 1, 'Red', '5'), (2, 1, 'Blue', '1')] - ) - - class ManyToOneTest(fixtures.MappedTest): -diff -r 9d0639b9d3be test/orm/test_deprecations.py ---- a/test/orm/test_deprecations.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_deprecations.py Sat Apr 27 19:42:17 2013 -0400 -@@ -122,7 +122,7 @@ - session = sessionmaker(query_cls=MyQuery)() - - ad1 = session.query(Address).get(1) -- assert ad1 in cache.values() -+ assert ad1 in list(cache.values()) - - def test_load(self): - """x = session.query(Address).load(1) -diff -r 9d0639b9d3be test/orm/test_dynamic.py ---- a/test/orm/test_dynamic.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_dynamic.py Sat Apr 27 19:42:17 2013 -0400 -@@ -119,9 +119,9 @@ - eq_( - list(u.addresses.order_by(desc(Address.email_address))), - [ -- Address(email_address=u'ed@wood.com'), -- Address(email_address=u'ed@lala.com'), -- Address(email_address=u'ed@bettyboop.com') -+ Address(email_address='ed@wood.com'), -+ Address(email_address='ed@lala.com'), -+ Address(email_address='ed@bettyboop.com') - ] - ) - -@@ -137,9 +137,9 @@ - eq_( - list(u.addresses), - [ -- Address(email_address=u'ed@wood.com'), -- Address(email_address=u'ed@lala.com'), -- Address(email_address=u'ed@bettyboop.com') -+ Address(email_address='ed@wood.com'), -+ Address(email_address='ed@lala.com'), -+ Address(email_address='ed@bettyboop.com') - ] - ) - -@@ -147,9 +147,9 @@ - eq_( - list(u.addresses.order_by(None).order_by(Address.email_address)), - [ -- Address(email_address=u'ed@bettyboop.com'), -- Address(email_address=u'ed@lala.com'), -- Address(email_address=u'ed@wood.com') -+ Address(email_address='ed@bettyboop.com'), -+ Address(email_address='ed@lala.com'), -+ Address(email_address='ed@wood.com') - ] - ) - -@@ -157,9 +157,9 @@ - eq_( - set(u.addresses.order_by(None)), - set([ -- Address(email_address=u'ed@bettyboop.com'), -- Address(email_address=u'ed@lala.com'), -- Address(email_address=u'ed@wood.com') -+ Address(email_address='ed@bettyboop.com'), -+ Address(email_address='ed@lala.com'), -+ Address(email_address='ed@wood.com') - ]) - ) - -@@ -529,12 +529,12 @@ - "SELECT addresses.id AS addresses_id, addresses.email_address " - "AS addresses_email_address FROM addresses " - "WHERE addresses.id = :param_1", -- lambda ctx: [{u'param_1': a2_id}] -+ lambda ctx: [{'param_1': a2_id}] - ), - CompiledSQL( - "UPDATE addresses SET user_id=:user_id WHERE addresses.id = " - ":addresses_id", -- lambda ctx: [{u'addresses_id': a2_id, 'user_id': None}] -+ lambda ctx: [{'addresses_id': a2_id, 'user_id': None}] - ) - ) - -diff -r 9d0639b9d3be test/orm/test_eager_relations.py ---- a/test/orm/test_eager_relations.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_eager_relations.py Sat Apr 27 19:42:17 2013 -0400 -@@ -747,11 +747,11 @@ - - sess = create_session() - eq_(sess.query(User).first(), -- User(name=u'jack',orders=[ -- Order(address_id=1,description=u'order 1',isopen=0,user_id=7,id=1), -- Order(address_id=1,description=u'order 3',isopen=1,user_id=7,id=3), -- Order(address_id=None,description=u'order 5',isopen=0,user_id=7,id=5)], -- email_address=u'jack@bean.com',id=7) -+ User(name='jack',orders=[ -+ Order(address_id=1,description='order 1',isopen=0,user_id=7,id=1), -+ Order(address_id=1,description='order 3',isopen=1,user_id=7,id=3), -+ Order(address_id=None,description='order 5',isopen=0,user_id=7,id=5)], -+ email_address='jack@bean.com',id=7) - ) - - def test_useget_cancels_eager(self): -@@ -2131,15 +2131,15 @@ - }) - - sess = create_session() -- w1 = Widget(name=u'w1') -- w2 = Widget(name=u'w2') -+ w1 = Widget(name='w1') -+ w2 = Widget(name='w2') - w1.children.append(w2) - sess.add(w1) - sess.flush() - sess.expunge_all() - - eq_([Widget(name='w1', children=[Widget(name='w2')])], -- sess.query(Widget).filter(Widget.name==u'w1').all()) -+ sess.query(Widget).filter(Widget.name=='w1').all()) - - class MixedEntitiesTest(_fixtures.FixtureTest, testing.AssertsCompiledSQL): - run_setup_mappers = 'once' -@@ -2223,24 +2223,24 @@ - eq_( - [ - ( -- User(addresses=[Address(email_address=u'fred@fred.com')], name=u'fred'), -- Order(description=u'order 2', isopen=0, items=[Item(description=u'item 1'), Item(description=u'item 2'), Item(description=u'item 3')]), -- User(addresses=[Address(email_address=u'jack@bean.com')], name=u'jack'), -- Order(description=u'order 3', isopen=1, items=[Item(description=u'item 3'), Item(description=u'item 4'), Item(description=u'item 5')]) -+ User(addresses=[Address(email_address='fred@fred.com')], name='fred'), -+ Order(description='order 2', isopen=0, items=[Item(description='item 1'), Item(description='item 2'), Item(description='item 3')]), -+ User(addresses=[Address(email_address='jack@bean.com')], name='jack'), -+ Order(description='order 3', isopen=1, items=[Item(description='item 3'), Item(description='item 4'), Item(description='item 5')]) - ), - - ( -- User(addresses=[Address(email_address=u'fred@fred.com')], name=u'fred'), -- Order(description=u'order 2', isopen=0, items=[Item(description=u'item 1'), Item(description=u'item 2'), Item(description=u'item 3')]), -- User(addresses=[Address(email_address=u'jack@bean.com')], name=u'jack'), -- Order(address_id=None, description=u'order 5', isopen=0, items=[Item(description=u'item 5')]) -+ User(addresses=[Address(email_address='fred@fred.com')], name='fred'), -+ Order(description='order 2', isopen=0, items=[Item(description='item 1'), Item(description='item 2'), Item(description='item 3')]), -+ User(addresses=[Address(email_address='jack@bean.com')], name='jack'), -+ Order(address_id=None, description='order 5', isopen=0, items=[Item(description='item 5')]) - ), - - ( -- User(addresses=[Address(email_address=u'fred@fred.com')], name=u'fred'), -- Order(description=u'order 4', isopen=1, items=[Item(description=u'item 1'), Item(description=u'item 5')]), -- User(addresses=[Address(email_address=u'jack@bean.com')], name=u'jack'), -- Order(address_id=None, description=u'order 5', isopen=0, items=[Item(description=u'item 5')]) -+ User(addresses=[Address(email_address='fred@fred.com')], name='fred'), -+ Order(description='order 4', isopen=1, items=[Item(description='item 1'), Item(description='item 5')]), -+ User(addresses=[Address(email_address='jack@bean.com')], name='jack'), -+ Order(address_id=None, description='order 5', isopen=0, items=[Item(description='item 5')]) - ), - ], - sess.query(User, Order, u1, o1).\ -@@ -2651,9 +2651,9 @@ - Movie = self.classes.Movie - - session = Session(testing.db) -- rscott = Director(name=u"Ridley Scott") -- alien = Movie(title=u"Alien") -- brunner = Movie(title=u"Blade Runner") -+ rscott = Director(name="Ridley Scott") -+ alien = Movie(title="Alien") -+ brunner = Movie(title="Blade Runner") - rscott.movies.append(brunner) - rscott.movies.append(alien) - session.add_all([rscott, alien, brunner]) -diff -r 9d0639b9d3be test/orm/test_expire.py ---- a/test/orm/test_expire.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_expire.py Sat Apr 27 19:42:17 2013 -0400 -@@ -850,7 +850,7 @@ - assert len(u.addresses) == 3 - sess.expire(u) - assert 'addresses' not in u.__dict__ -- print "-------------------------------------------" -+ print("-------------------------------------------") - sess.query(User).filter_by(id=8).all() - assert 'addresses' in u.__dict__ - assert len(u.addresses) == 3 -diff -r 9d0639b9d3be test/orm/test_froms.py ---- a/test/orm/test_froms.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_froms.py Sat Apr 27 19:42:17 2013 -0400 -@@ -315,12 +315,12 @@ - from_self(User.name, ualias.name). - order_by(User.name, ualias.name).all(), - [ -- (u'chuck', u'ed'), -- (u'chuck', u'fred'), -- (u'chuck', u'jack'), -- (u'ed', u'jack'), -- (u'fred', u'ed'), -- (u'fred', u'jack') -+ ('chuck', 'ed'), -+ ('chuck', 'fred'), -+ ('chuck', 'jack'), -+ ('ed', 'jack'), -+ ('fred', 'ed'), -+ ('fred', 'jack') - ] - ) - -@@ -330,7 +330,7 @@ - from_self(User.name, ualias.name). - filter(ualias.name=='ed')\ - .order_by(User.name, ualias.name).all(), -- [(u'chuck', u'ed'), (u'fred', u'ed')] -+ [('chuck', 'ed'), ('fred', 'ed')] - ) - - eq_( -@@ -340,11 +340,11 @@ - join(ualias.addresses). - order_by(ualias.name, Address.email_address).all(), - [ -- (u'ed', u'fred@fred.com'), -- (u'jack', u'ed@bettyboop.com'), -- (u'jack', u'ed@lala.com'), -- (u'jack', u'ed@wood.com'), -- (u'jack', u'fred@fred.com')] -+ ('ed', 'fred@fred.com'), -+ ('jack', 'ed@bettyboop.com'), -+ ('jack', 'ed@lala.com'), -+ ('jack', 'ed@wood.com'), -+ ('jack', 'fred@fred.com')] - ) - - -@@ -629,8 +629,8 @@ - eq_( - q.all(), - [( -- A(bid=2, id=1, name=u'a1', type=u'a'), -- C(age=3, id=2, name=u'c1', type=u'c') -+ A(bid=2, id=1, name='a1', type='a'), -+ C(age=3, id=2, name='c1', type='c') - )] - ) - -@@ -642,8 +642,8 @@ - eq_( - q.all(), - [( -- C(age=3, id=2, name=u'c1', type=u'c'), -- A(bid=2, id=1, name=u'a1', type=u'a') -+ C(age=3, id=2, name='c1', type='c'), -+ A(bid=2, id=1, name='a1', type='a') - )] - ) - -@@ -929,12 +929,12 @@ - # have a Dingaling here due to using the inner - # join for the eager load - [ -- User(name=u'ed', addresses=[ -- Address(email_address=u'ed@wood.com', -+ User(name='ed', addresses=[ -+ Address(email_address='ed@wood.com', - dingaling=Dingaling(data='ding 1/2')), - ]), -- User(name=u'fred', addresses=[ -- Address(email_address=u'fred@fred.com', -+ User(name='fred', addresses=[ -+ Address(email_address='fred@fred.com', - dingaling=Dingaling(data='ding 2/5')) - ]) - ] -@@ -965,12 +965,12 @@ - # have a Dingaling here due to using the inner - # join for the eager load - [ -- User(name=u'ed', addresses=[ -- Address(email_address=u'ed@wood.com', -+ User(name='ed', addresses=[ -+ Address(email_address='ed@wood.com', - dingaling=Dingaling(data='ding 1/2')), - ]), -- User(name=u'fred', addresses=[ -- Address(email_address=u'fred@fred.com', -+ User(name='fred', addresses=[ -+ Address(email_address='fred@fred.com', - dingaling=Dingaling(data='ding 2/5')) - ]) - ] -@@ -998,11 +998,11 @@ - contains_eager(User.orders)).order_by(User.id, - Order.id).offset(1).limit(2).all() - eq_(l, [User(id=7, -- addresses=[Address(email_address=u'jack@bean.com', -- user_id=7, id=1)], name=u'jack', -+ addresses=[Address(email_address='jack@bean.com', -+ user_id=7, id=1)], name='jack', - orders=[Order(address_id=1, user_id=7, -- description=u'order 3', isopen=1, id=3), -- Order(address_id=None, user_id=7, description=u'order 5' -+ description='order 3', isopen=1, id=3), -+ Order(address_id=None, user_id=7, description='order 5' - , isopen=0, id=5)])]) - - self.assert_sql_count(testing.db, go, 1) -@@ -1020,11 +1020,11 @@ - order_by(User.id, oalias.id).\ - offset(1).limit(2).all() - eq_(l, [User(id=7, -- addresses=[Address(email_address=u'jack@bean.com', -- user_id=7, id=1)], name=u'jack', -+ addresses=[Address(email_address='jack@bean.com', -+ user_id=7, id=1)], name='jack', - orders=[Order(address_id=1, user_id=7, -- description=u'order 3', isopen=1, id=3), -- Order(address_id=None, user_id=7, description=u'order 5' -+ description='order 3', isopen=1, id=3), -+ Order(address_id=None, user_id=7, description='order 5' - , isopen=0, id=5)])]) - - self.assert_sql_count(testing.db, go, 1) -@@ -1045,15 +1045,15 @@ - sel = users.select(User.id.in_([7, 8])).alias() - q = sess.query(User) - q2 = q.select_from(sel).values(User.name) -- eq_(list(q2), [(u'jack',), (u'ed',)]) -+ eq_(list(q2), [('jack',), ('ed',)]) - - q = sess.query(User) - q2 = q.order_by(User.id).\ - values(User.name, User.name + " " + cast(User.id, String(50))) - eq_( - list(q2), -- [(u'jack', u'jack 7'), (u'ed', u'ed 8'), -- (u'fred', u'fred 9'), (u'chuck', u'chuck 10')] -+ [('jack', 'jack 7'), ('ed', 'ed 8'), -+ ('fred', 'fred 9'), ('chuck', 'chuck 10')] - ) - - q2 = q.join('addresses').\ -@@ -1061,27 +1061,27 @@ - order_by(User.id, Address.id).\ - values(User.name, Address.email_address) - eq_(list(q2), -- [(u'ed', u'ed@wood.com'), (u'ed', u'ed@bettyboop.com'), -- (u'ed', u'ed@lala.com'), (u'fred', u'fred@fred.com')]) -+ [('ed', 'ed@wood.com'), ('ed', 'ed@bettyboop.com'), -+ ('ed', 'ed@lala.com'), ('fred', 'fred@fred.com')]) - - q2 = q.join('addresses').\ - filter(User.name.like('%e%')).\ - order_by(desc(Address.email_address)).\ - slice(1, 3).values(User.name, Address.email_address) -- eq_(list(q2), [(u'ed', u'ed@wood.com'), (u'ed', u'ed@lala.com')]) -+ eq_(list(q2), [('ed', 'ed@wood.com'), ('ed', 'ed@lala.com')]) - - adalias = aliased(Address) - q2 = q.join(adalias, 'addresses').\ - filter(User.name.like('%e%')).order_by(adalias.email_address).\ - values(User.name, adalias.email_address) -- eq_(list(q2), [(u'ed', u'ed@bettyboop.com'), (u'ed', u'ed@lala.com'), -- (u'ed', u'ed@wood.com'), (u'fred', u'fred@fred.com')]) -+ eq_(list(q2), [('ed', 'ed@bettyboop.com'), ('ed', 'ed@lala.com'), -+ ('ed', 'ed@wood.com'), ('fred', 'fred@fred.com')]) - - q2 = q.values(func.count(User.name)) -- assert q2.next() == (4,) -+ assert next(q2) == (4,) - - q2 = q.select_from(sel).filter(User.id==8).values(User.name, sel.c.name, User.name) -- eq_(list(q2), [(u'ed', u'ed', u'ed')]) -+ eq_(list(q2), [('ed', 'ed', 'ed')]) - - # using User.xxx is alised against "sel", so this query returns nothing - q2 = q.select_from(sel).\ -@@ -1093,7 +1093,7 @@ - q2 = q.select_from(sel).\ - filter(users.c.id==8).\ - filter(users.c.id>sel.c.id).values(users.c.name, sel.c.name, User.name) -- eq_(list(q2), [(u'ed', u'jack', u'jack')]) -+ eq_(list(q2), [('ed', 'jack', 'jack')]) - - def test_alias_naming(self): - User = self.classes.User -@@ -1123,10 +1123,10 @@ - filter(u2.id>1).\ - order_by(User.id, sel.c.id, u2.id).\ - values(User.name, sel.c.name, u2.name) -- eq_(list(q2), [(u'jack', u'jack', u'jack'), (u'jack', u'jack', u'ed'), -- (u'jack', u'jack', u'fred'), (u'jack', u'jack', u'chuck'), -- (u'ed', u'ed', u'jack'), (u'ed', u'ed', u'ed'), -- (u'ed', u'ed', u'fred'), (u'ed', u'ed', u'chuck')]) -+ eq_(list(q2), [('jack', 'jack', 'jack'), ('jack', 'jack', 'ed'), -+ ('jack', 'jack', 'fred'), ('jack', 'jack', 'chuck'), -+ ('ed', 'ed', 'jack'), ('ed', 'ed', 'ed'), -+ ('ed', 'ed', 'fred'), ('ed', 'ed', 'chuck')]) - - @testing.fails_on('mssql', 'FIXME: unknown') - @testing.fails_on('oracle', -@@ -1177,8 +1177,8 @@ - # we don't want Address to be outside of the subquery here - eq_( - list(sess.query(User, subq)[0:3]), -- [(User(id=7,name=u'jack'), 1), (User(id=8,name=u'ed'), 3), -- (User(id=9,name=u'fred'), 1)] -+ [(User(id=7,name='jack'), 1), (User(id=8,name='ed'), 3), -+ (User(id=9,name='fred'), 1)] - ) - - # same thing without the correlate, as it should -@@ -1190,8 +1190,8 @@ - # we don't want Address to be outside of the subquery here - eq_( - list(sess.query(User, subq)[0:3]), -- [(User(id=7,name=u'jack'), 1), (User(id=8,name=u'ed'), 3), -- (User(id=9,name=u'fred'), 1)] -+ [(User(id=7,name='jack'), 1), (User(id=8,name='ed'), 3), -+ (User(id=9,name='fred'), 1)] - ) - - -@@ -1202,23 +1202,23 @@ - - sess = create_session() - -- eq_(sess.query(User.name).all(), [(u'jack',), (u'ed',), (u'fred',), (u'chuck',)]) -+ eq_(sess.query(User.name).all(), [('jack',), ('ed',), ('fred',), ('chuck',)]) - - sel = users.select(User.id.in_([7, 8])).alias() - q = sess.query(User.name) - q2 = q.select_from(sel).all() -- eq_(list(q2), [(u'jack',), (u'ed',)]) -+ eq_(list(q2), [('jack',), ('ed',)]) - - eq_(sess.query(User.name, Address.email_address).filter(User.id==Address.user_id).all(), [ -- (u'jack', u'jack@bean.com'), (u'ed', u'ed@wood.com'), -- (u'ed', u'ed@bettyboop.com'), (u'ed', u'ed@lala.com'), -- (u'fred', u'fred@fred.com') -+ ('jack', 'jack@bean.com'), ('ed', 'ed@wood.com'), -+ ('ed', 'ed@bettyboop.com'), ('ed', 'ed@lala.com'), -+ ('fred', 'fred@fred.com') - ]) - - eq_(sess.query(User.name, func.count(Address.email_address)).\ - outerjoin(User.addresses).group_by(User.id, User.name).\ - order_by(User.id).all(), -- [(u'jack', 1), (u'ed', 3), (u'fred', 1), (u'chuck', 0)] -+ [('jack', 1), ('ed', 3), ('fred', 1), ('chuck', 0)] - ) - - eq_(sess.query(User, func.count(Address.email_address)).\ -@@ -1246,8 +1246,8 @@ - eq_(sess.query(func.count(adalias.email_address), User).\ - outerjoin(adalias, User.addresses).group_by(User).\ - order_by(User.id).all(), -- [(1, User(name=u'jack',id=7)), (3, User(name=u'ed',id=8)), -- (1, User(name=u'fred',id=9)), (0, User(name=u'chuck',id=10))] -+ [(1, User(name='jack',id=7)), (3, User(name='ed',id=8)), -+ (1, User(name='fred',id=9)), (0, User(name='chuck',id=10))] - ) - - # select from aliasing + explicit aliasing -@@ -1257,12 +1257,12 @@ - from_self(User, adalias.email_address).\ - order_by(User.id, adalias.id).all(), - [ -- (User(name=u'jack',id=7), u'jack@bean.com'), -- (User(name=u'ed',id=8), u'ed@wood.com'), -- (User(name=u'ed',id=8), u'ed@bettyboop.com'), -- (User(name=u'ed',id=8), u'ed@lala.com'), -- (User(name=u'fred',id=9), u'fred@fred.com'), -- (User(name=u'chuck',id=10), None) -+ (User(name='jack',id=7), 'jack@bean.com'), -+ (User(name='ed',id=8), 'ed@wood.com'), -+ (User(name='ed',id=8), 'ed@bettyboop.com'), -+ (User(name='ed',id=8), 'ed@lala.com'), -+ (User(name='fred',id=9), 'fred@fred.com'), -+ (User(name='chuck',id=10), None) - ] - ) - -@@ -1272,8 +1272,8 @@ - filter(Address.email_address.like('%ed%')).\ - from_self().all(), - [ -- User(name=u'ed',id=8), -- User(name=u'fred',id=9), -+ User(name='ed',id=8), -+ User(name='fred',id=9), - ] - ) - -@@ -1293,27 +1293,27 @@ - - q.all(), - [(User(addresses=[ -- Address(user_id=7,email_address=u'jack@bean.com',id=1)], -- name=u'jack',id=7), u'jack@bean.com'), -+ Address(user_id=7,email_address='jack@bean.com',id=1)], -+ name='jack',id=7), 'jack@bean.com'), - (User(addresses=[ -- Address(user_id=8,email_address=u'ed@wood.com',id=2), -- Address(user_id=8,email_address=u'ed@bettyboop.com',id=3), -- Address(user_id=8,email_address=u'ed@lala.com',id=4)], -- name=u'ed',id=8), u'ed@wood.com'), -+ Address(user_id=8,email_address='ed@wood.com',id=2), -+ Address(user_id=8,email_address='ed@bettyboop.com',id=3), -+ Address(user_id=8,email_address='ed@lala.com',id=4)], -+ name='ed',id=8), 'ed@wood.com'), - (User(addresses=[ -- Address(user_id=8,email_address=u'ed@wood.com',id=2), -- Address(user_id=8,email_address=u'ed@bettyboop.com',id=3), -- Address(user_id=8,email_address=u'ed@lala.com',id=4)],name=u'ed',id=8), -- u'ed@bettyboop.com'), -+ Address(user_id=8,email_address='ed@wood.com',id=2), -+ Address(user_id=8,email_address='ed@bettyboop.com',id=3), -+ Address(user_id=8,email_address='ed@lala.com',id=4)],name='ed',id=8), -+ 'ed@bettyboop.com'), - (User(addresses=[ -- Address(user_id=8,email_address=u'ed@wood.com',id=2), -- Address(user_id=8,email_address=u'ed@bettyboop.com',id=3), -- Address(user_id=8,email_address=u'ed@lala.com',id=4)],name=u'ed',id=8), -- u'ed@lala.com'), -- (User(addresses=[Address(user_id=9,email_address=u'fred@fred.com',id=5)],name=u'fred',id=9), -- u'fred@fred.com'), -+ Address(user_id=8,email_address='ed@wood.com',id=2), -+ Address(user_id=8,email_address='ed@bettyboop.com',id=3), -+ Address(user_id=8,email_address='ed@lala.com',id=4)],name='ed',id=8), -+ 'ed@lala.com'), -+ (User(addresses=[Address(user_id=9,email_address='fred@fred.com',id=5)],name='fred',id=9), -+ 'fred@fred.com'), - -- (User(addresses=[],name=u'chuck',id=10), None)] -+ (User(addresses=[],name='chuck',id=10), None)] - ) - - def test_column_from_limited_joinedload(self): -@@ -1367,19 +1367,19 @@ - eq_( - q.all(), - [ -- (Order(address_id=1,description=u'order 3',isopen=1,user_id=7,id=3), -- Order(address_id=1,description=u'order 1',isopen=0,user_id=7,id=1)), -- (Order(address_id=None,description=u'order 5',isopen=0,user_id=7,id=5), -- Order(address_id=1,description=u'order 1',isopen=0,user_id=7,id=1)), -- (Order(address_id=None,description=u'order 5',isopen=0,user_id=7,id=5), -- Order(address_id=1,description=u'order 3',isopen=1,user_id=7,id=3)) -+ (Order(address_id=1,description='order 3',isopen=1,user_id=7,id=3), -+ Order(address_id=1,description='order 1',isopen=0,user_id=7,id=1)), -+ (Order(address_id=None,description='order 5',isopen=0,user_id=7,id=5), -+ Order(address_id=1,description='order 1',isopen=0,user_id=7,id=1)), -+ (Order(address_id=None,description='order 5',isopen=0,user_id=7,id=5), -+ Order(address_id=1,description='order 3',isopen=1,user_id=7,id=3)) - ] - ) - - - # ensure column expressions are taken from inside the subquery, not restated at the top - q = sess.query(Order.id, Order.description, literal_column("'q'").label('foo')).\ -- filter(Order.description == u'order 3').from_self() -+ filter(Order.description == 'order 3').from_self() - self.assert_compile(q, - "SELECT anon_1.orders_id AS " - "anon_1_orders_id, anon_1.orders_descriptio" -@@ -1392,7 +1392,7 @@ - "anon_1") - eq_( - q.all(), -- [(3, u'order 3', 'q')] -+ [(3, 'order 3', 'q')] - ) - - -@@ -1518,7 +1518,7 @@ - - eq_( - sess.query(User.id).add_column(users).all(), -- [(7, 7, u'jack'), (8, 8, u'ed'), (9, 9, u'fred'), (10, 10, u'chuck')] -+ [(7, 7, 'jack'), (8, 8, 'ed'), (9, 9, 'fred'), (10, 10, 'chuck')] - ) - - def test_multi_columns_2(self): -@@ -1936,7 +1936,7 @@ - filter(Keyword.name.in_(['red', 'big', 'round'])).\ - all(), - [ -- User(name=u'jack',id=7) -+ User(name='jack',id=7) - ]) - - eq_(sess.query(User).select_from(sel).\ -@@ -1944,7 +1944,7 @@ - filter(Keyword.name.in_(['red', 'big', 'round'])).\ - all(), - [ -- User(name=u'jack',id=7) -+ User(name='jack',id=7) - ]) - - def go(): -@@ -1955,39 +1955,39 @@ - filter(Keyword.name.in_(['red', 'big', 'round'])).\ - all(), - [ -- User(name=u'jack',orders=[ -- Order(description=u'order 1',items=[ -- Item(description=u'item 1', -+ User(name='jack',orders=[ -+ Order(description='order 1',items=[ -+ Item(description='item 1', - keywords=[ -- Keyword(name=u'red'), -- Keyword(name=u'big'), -- Keyword(name=u'round') -+ Keyword(name='red'), -+ Keyword(name='big'), -+ Keyword(name='round') - ]), -- Item(description=u'item 2', -+ Item(description='item 2', - keywords=[ -- Keyword(name=u'red',id=2), -- Keyword(name=u'small',id=5), -- Keyword(name=u'square') -+ Keyword(name='red',id=2), -+ Keyword(name='small',id=5), -+ Keyword(name='square') - ]), -- Item(description=u'item 3', -+ Item(description='item 3', - keywords=[ -- Keyword(name=u'green',id=3), -- Keyword(name=u'big',id=4), -- Keyword(name=u'round',id=6)]) -+ Keyword(name='green',id=3), -+ Keyword(name='big',id=4), -+ Keyword(name='round',id=6)]) - ]), -- Order(description=u'order 3',items=[ -- Item(description=u'item 3', -+ Order(description='order 3',items=[ -+ Item(description='item 3', - keywords=[ -- Keyword(name=u'green',id=3), -- Keyword(name=u'big',id=4), -- Keyword(name=u'round',id=6) -+ Keyword(name='green',id=3), -+ Keyword(name='big',id=4), -+ Keyword(name='round',id=6) - ]), -- Item(description=u'item 4',keywords=[],id=4), -- Item(description=u'item 5',keywords=[],id=5) -+ Item(description='item 4',keywords=[],id=4), -+ Item(description='item 5',keywords=[],id=5) - ]), -- Order(description=u'order 5', -+ Order(description='order 5', - items=[ -- Item(description=u'item 5',keywords=[])]) -+ Item(description='item 5',keywords=[])]) - ]) - ]) - self.assert_sql_count(testing.db, go, 1) -@@ -1998,15 +1998,15 @@ - join('items', 'keywords').\ - filter(Keyword.name == 'red').\ - order_by(Order.id).all(), [ -- Order(description=u'order 1',id=1), -- Order(description=u'order 2',id=2), -+ Order(description='order 1',id=1), -+ Order(description='order 2',id=2), - ]) - eq_(sess.query(Order).select_from(sel2).\ - join('items', 'keywords', aliased=True).\ - filter(Keyword.name == 'red').\ - order_by(Order.id).all(), [ -- Order(description=u'order 1',id=1), -- Order(description=u'order 2',id=2), -+ Order(description='order 1',id=1), -+ Order(description='order 2',id=2), - ]) - - -diff -r 9d0639b9d3be test/orm/test_generative.py ---- a/test/orm/test_generative.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_generative.py Sat Apr 27 19:42:17 2013 -0400 -@@ -78,13 +78,14 @@ - assert sess.query(func.min(foo.c.bar)).filter(foo.c.bar<30).one() == (0,) - - assert sess.query(func.max(foo.c.bar)).filter(foo.c.bar<30).one() == (29,) -- # Py3K -- #assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).__next__()[0] == 29 -- #assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).__next__()[0] == 29 -- # Py2K -- assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).next()[0] == 29 -- assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).next()[0] == 29 -- # end Py2K -+# start Py3K -+ assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).__next__()[0] == 29 -+ assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).__next__()[0] == 29 -+# end Py3K -+# start Py2K -+# assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).next()[0] == 29 -+# assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).next()[0] == 29 -+# end Py2K - - @testing.fails_if(lambda:testing.against('mysql+mysqldb') and - testing.db.dialect.dbapi.version_info[:4] == (1, 2, 1, 'gamma'), -@@ -111,18 +112,20 @@ - - query = create_session().query(Foo) - -- # Py3K -- #avg_f = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).__next__()[0] -- # Py2K -- avg_f = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).next()[0] -- # end Py2K -+# start Py3K -+ avg_f = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).__next__()[0] -+# end Py3K -+# start Py2K -+# avg_f = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).next()[0] -+# end Py2K - assert float(round(avg_f, 1)) == 14.5 - -- # Py3K -- #avg_o = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).__next__()[0] -- # Py2K -- avg_o = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).next()[0] -- # end Py2K -+# start Py3K -+ avg_o = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).__next__()[0] -+# end Py3K -+# start Py2K -+# avg_o = query.filter(foo.c.bar<30).values(sa.func.avg(foo.c.bar)).next()[0] -+# end Py2K - assert float(round(avg_o, 1)) == 14.5 - - def test_filter(self): -diff -r 9d0639b9d3be test/orm/test_inspect.py ---- a/test/orm/test_inspect.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_inspect.py Sat Apr 27 19:42:17 2013 -0400 -@@ -142,7 +142,7 @@ - [insp.get_property('id'), insp.get_property('name')] - ) - eq_( -- insp.column_attrs.keys(), -+ list(insp.column_attrs.keys()), - ['id', 'name'] - ) - is_( -@@ -274,7 +274,7 @@ - insp = inspect(SomeSubClass) - eq_( - dict((k, v.extension_type) -- for k, v in insp.all_orm_descriptors.items() -+ for k, v in list(insp.all_orm_descriptors.items()) - ), - { - 'id': NOT_EXTENSION, -diff -r 9d0639b9d3be test/orm/test_instrumentation.py ---- a/test/orm/test_instrumentation.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_instrumentation.py Sat Apr 27 19:42:17 2013 -0400 -@@ -522,30 +522,31 @@ - class Py3KFunctionInstTest(fixtures.ORMTest): - __requires__ = ("python3", ) - -- # Py3K -- #def _kw_only_fixture(self): -- # class A(object): -- # def __init__(self, a, *, b, c): -- # self.a = a -- # self.b = b -- # self.c = c -- # return self._instrument(A) -- # -- #def _kw_plus_posn_fixture(self): -- # class A(object): -- # def __init__(self, a, *args, b, c): -- # self.a = a -- # self.b = b -- # self.c = c -- # return self._instrument(A) -- # -- #def _kw_opt_fixture(self): -- # class A(object): -- # def __init__(self, a, *, b, c="c"): -- # self.a = a -- # self.b = b -- # self.c = c -- # return self._instrument(A) -+# start Py3K -+ def _kw_only_fixture(self): -+ class A(object): -+ def __init__(self, a, *, b, c): -+ self.a = a -+ self.b = b -+ self.c = c -+ return self._instrument(A) -+ -+ def _kw_plus_posn_fixture(self): -+ class A(object): -+ def __init__(self, a, *args, b, c): -+ self.a = a -+ self.b = b -+ self.c = c -+ return self._instrument(A) -+ -+ def _kw_opt_fixture(self): -+ class A(object): -+ def __init__(self, a, *, b, c="c"): -+ self.a = a -+ self.b = b -+ self.c = c -+ return self._instrument(A) -+# end Py3K - - def _instrument(self, cls): - manager = instrumentation.register_class(cls) -diff -r 9d0639b9d3be test/orm/test_joins.py ---- a/test/orm/test_joins.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_joins.py Sat Apr 27 19:42:17 2013 -0400 -@@ -774,14 +774,14 @@ - eq_( - sess.query(User).join(Address.user).\ - filter(Address.email_address=='ed@wood.com').all(), -- [User(id=8,name=u'ed')] -+ [User(id=8,name='ed')] - ) - - # its actually not so controversial if you view it in terms - # of multiple entities. - eq_( - sess.query(User, Address).join(Address.user).filter(Address.email_address=='ed@wood.com').all(), -- [(User(id=8,name=u'ed'), Address(email_address='ed@wood.com'))] -+ [(User(id=8,name='ed'), Address(email_address='ed@wood.com'))] - ) - - # this was the controversial part. now, raise an error if the feature is abused. -@@ -1162,9 +1162,9 @@ - sess.query(OrderAlias).join('items').filter_by(description='item 3').\ - order_by(OrderAlias.id).all(), - [ -- Order(address_id=1,description=u'order 1',isopen=0,user_id=7,id=1), -- Order(address_id=4,description=u'order 2',isopen=0,user_id=9,id=2), -- Order(address_id=1,description=u'order 3',isopen=1,user_id=7,id=3) -+ Order(address_id=1,description='order 1',isopen=0,user_id=7,id=1), -+ Order(address_id=4,description='order 2',isopen=0,user_id=9,id=2), -+ Order(address_id=1,description='order 3',isopen=1,user_id=7,id=3) - ] - ) - -@@ -1175,9 +1175,9 @@ - filter_by(description='item 3').\ - order_by(User.id, OrderAlias.id).all(), - [ -- (User(name=u'jack',id=7), Order(address_id=1,description=u'order 1',isopen=0,user_id=7,id=1), u'item 3'), -- (User(name=u'jack',id=7), Order(address_id=1,description=u'order 3',isopen=1,user_id=7,id=3), u'item 3'), -- (User(name=u'fred',id=9), Order(address_id=4,description=u'order 2',isopen=0,user_id=9,id=2), u'item 3') -+ (User(name='jack',id=7), Order(address_id=1,description='order 1',isopen=0,user_id=7,id=1), 'item 3'), -+ (User(name='jack',id=7), Order(address_id=1,description='order 3',isopen=1,user_id=7,id=3), 'item 3'), -+ (User(name='fred',id=9), Order(address_id=4,description='order 2',isopen=0,user_id=9,id=2), 'item 3') - ] - ) - -@@ -1334,12 +1334,12 @@ - eq_( - sess.query(User, ualias).filter(User.id > ualias.id).order_by(desc(ualias.id), User.name).all(), - [ -- (User(id=10,name=u'chuck'), User(id=9,name=u'fred')), -- (User(id=10,name=u'chuck'), User(id=8,name=u'ed')), -- (User(id=9,name=u'fred'), User(id=8,name=u'ed')), -- (User(id=10,name=u'chuck'), User(id=7,name=u'jack')), -- (User(id=8,name=u'ed'), User(id=7,name=u'jack')), -- (User(id=9,name=u'fred'), User(id=7,name=u'jack')) -+ (User(id=10,name='chuck'), User(id=9,name='fred')), -+ (User(id=10,name='chuck'), User(id=8,name='ed')), -+ (User(id=9,name='fred'), User(id=8,name='ed')), -+ (User(id=10,name='chuck'), User(id=7,name='jack')), -+ (User(id=8,name='ed'), User(id=7,name='jack')), -+ (User(id=9,name='fred'), User(id=7,name='jack')) - ] - ) - -@@ -1351,7 +1351,7 @@ - - eq_( - sess.query(User.name).join(addresses, User.id==addresses.c.user_id).order_by(User.id).all(), -- [(u'jack',), (u'ed',), (u'ed',), (u'ed',), (u'fred',)] -+ [('jack',), ('ed',), ('ed',), ('ed',), ('fred',)] - ) - - def test_no_joinpoint_expr(self): -@@ -2066,13 +2066,13 @@ - # using 'n1.parent' implicitly joins to unaliased Node - eq_( - sess.query(n1).join(n1.parent).filter(Node.data=='n1').all(), -- [Node(parent_id=1,data=u'n11',id=2), Node(parent_id=1,data=u'n12',id=3), Node(parent_id=1,data=u'n13',id=4)] -+ [Node(parent_id=1,data='n11',id=2), Node(parent_id=1,data='n12',id=3), Node(parent_id=1,data='n13',id=4)] - ) - - # explicit (new syntax) - eq_( - sess.query(n1).join(Node, n1.parent).filter(Node.data=='n1').all(), -- [Node(parent_id=1,data=u'n11',id=2), Node(parent_id=1,data=u'n12',id=3), Node(parent_id=1,data=u'n13',id=4)] -+ [Node(parent_id=1,data='n11',id=2), Node(parent_id=1,data='n12',id=3), Node(parent_id=1,data='n13',id=4)] - ) - - -diff -r 9d0639b9d3be test/orm/test_loading.py ---- a/test/orm/test_loading.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_loading.py Sat Apr 27 19:42:17 2013 -0400 -@@ -73,7 +73,7 @@ - [(x.id, y) for x, y in it], - [(1, 1), (2, 2), (7, 7), (8, 8)] - ) -- eq_(it[0].keys(), ['User', 'id']) -+ eq_(list(it[0].keys()), ['User', 'id']) - - def test_entity_col_mix_keyed_tuple(self): - s, (u1, u2, u3, u4) = self._fixture() -@@ -91,7 +91,7 @@ - [(x.id, y) for x, y in it], - [(1, 1), (2, 2), (7, 7), (8, 8)] - ) -- eq_(it[0].keys(), ['User', 'id']) -+ eq_(list(it[0].keys()), ['User', 'id']) - - def test_none_entity(self): - s, (u1, u2, u3, u4) = self._fixture() -diff -r 9d0639b9d3be test/orm/test_mapper.py ---- a/test/orm/test_mapper.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_mapper.py Sat Apr 27 19:42:17 2013 -0400 -@@ -272,13 +272,14 @@ - ) - m = mapper(Foo, foo_t) - class DontCompareMeToString(int): -- # Py3K -- # pass -- # Py2K -- def __lt__(self, other): -- assert not isinstance(other, basestring) -- return int(self) < other -- # end Py2K -+# start Py3K -+ pass -+# end Py3K -+# start Py2K -+# def __lt__(self, other): -+# assert not isinstance(other, basestring) -+# return int(self) < other -+# end Py2K - foos = [Foo(id='f%d' % i) for i in range(5)] - states = [attributes.instance_state(f) for f in foos] - -@@ -847,7 +848,7 @@ - - def test_we_dont_call_bool(self): - class NoBoolAllowed(object): -- def __nonzero__(self): -+ def __bool__(self): - raise Exception("nope") - mapper(NoBoolAllowed, self.tables.users) - u1 = NoBoolAllowed() -@@ -1057,12 +1058,12 @@ - - eq_( - create_session().query(User).all(), -- [User(id=7, name=u'jack'), User(id=9, name=u'fred'), User(id=8, name=u'ed'), User(id=10, name=u'chuck')] -+ [User(id=7, name='jack'), User(id=9, name='fred'), User(id=8, name='ed'), User(id=10, name='chuck')] - ) - - eq_( - create_session().query(User).order_by(User.name).all(), -- [User(id=10, name=u'chuck'), User(id=8, name=u'ed'), User(id=9, name=u'fred'), User(id=7, name=u'jack')] -+ [User(id=10, name='chuck'), User(id=8, name='ed'), User(id=9, name='fred'), User(id=7, name='jack')] - ) - - # 'Raises a "expression evaluation not supported" error at prepare time -@@ -2123,7 +2124,7 @@ - mapper(Address, addresses) - - eq_( -- dict((k, v[0].__name__) for k, v in u_m.validators.items()), -+ dict((k, v[0].__name__) for k, v in list(u_m.validators.items())), - {'name':'validate_name', - 'addresses':'validate_address'} - ) -@@ -2992,29 +2993,29 @@ - Column('ht1b_id', Integer, ForeignKey('ht1.id'), primary_key=True), - Column('value', String(10))) - -- # Py2K -- def test_baseclass(self): -- ht1 = self.tables.ht1 -- -- class OldStyle: -- pass -- -- assert_raises(sa.exc.ArgumentError, mapper, OldStyle, ht1) -- -- assert_raises(sa.exc.ArgumentError, mapper, 123) -- -- class NoWeakrefSupport(str): -- pass -- -- # TODO: is weakref support detectable without an instance? -- #self.assertRaises(sa.exc.ArgumentError, mapper, NoWeakrefSupport, t2) -- # end Py2K -+# start Py2K -+# def test_baseclass(self): -+# ht1 = self.tables.ht1 -+# -+# class OldStyle: -+# pass -+# -+# assert_raises(sa.exc.ArgumentError, mapper, OldStyle, ht1) -+# -+# assert_raises(sa.exc.ArgumentError, mapper, 123) -+# -+# class NoWeakrefSupport(str): -+# pass -+# -+# # TODO: is weakref support detectable without an instance? -+# #self.assertRaises(sa.exc.ArgumentError, mapper, NoWeakrefSupport, t2) -+# end Py2K - - class _ValueBase(object): - def __init__(self, value='abc', id=None): - self.id = id - self.value = value -- def __nonzero__(self): -+ def __bool__(self): - return False - def __hash__(self): - return hash(self.value) -@@ -3173,7 +3174,7 @@ - return self.value - - class H2(object): -- def __nonzero__(self): -+ def __bool__(self): - return bool(self.get_value()) - - def get_value(self): -@@ -3224,7 +3225,7 @@ - self._test("someprop") - - def test_unicode(self): -- self._test(u"someprop") -+ self._test("someprop") - - def test_int(self): - self._test(5) -diff -r 9d0639b9d3be test/orm/test_merge.py ---- a/test/orm/test_merge.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_merge.py Sat Apr 27 19:42:17 2013 -0400 -@@ -346,7 +346,7 @@ - sess = create_session() - sess.merge(u1) - sess.flush() -- assert u1.addresses.keys() == ['foo@bar.com'] -+ assert list(u1.addresses.keys()) == ['foo@bar.com'] - - def test_attribute_cascade(self): - """Merge of a persistent entity with two child -@@ -803,7 +803,7 @@ - try: - sess2.merge(u, load=False) - assert False -- except sa.exc.InvalidRequestError, e: -+ except sa.exc.InvalidRequestError as e: - assert "merge() with load=False option does not support "\ - "objects marked as 'dirty'. flush() all changes on "\ - "mapped instances before merging with load=False." \ -@@ -924,7 +924,7 @@ - sess2.expunge_all() - eq_(sess2.query(User).get(u2.id).addresses[0].email_address, - 'somenewaddress') -- except sa.exc.InvalidRequestError, e: -+ except sa.exc.InvalidRequestError as e: - assert "load=False option does not support" in str(e) - - def test_synonym_comparable(self): -diff -r 9d0639b9d3be test/orm/test_naturalpks.py ---- a/test/orm/test_naturalpks.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_naturalpks.py Sat Apr 27 19:42:17 2013 -0400 -@@ -2,7 +2,7 @@ - Primary key changing capabilities and passive/non-passive cascading updates. - - """ --from __future__ import with_statement -+ - from sqlalchemy.testing import eq_, ne_, \ - assert_raises, assert_raises_message - import sqlalchemy as sa -@@ -519,11 +519,11 @@ - - session = sa.orm.sessionmaker()() - -- a_published = User(1, PUBLISHED, u'a') -+ a_published = User(1, PUBLISHED, 'a') - session.add(a_published) - session.commit() - -- a_editable = User(1, EDITABLE, u'a') -+ a_editable = User(1, EDITABLE, 'a') - - session.add(a_editable) - session.commit() -diff -r 9d0639b9d3be test/orm/test_pickled.py ---- a/test/orm/test_pickled.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_pickled.py Sat Apr 27 19:42:17 2013 -0400 -@@ -443,21 +443,21 @@ - if pickled is not False: - row = pickle.loads(pickle.dumps(row, pickled)) - -- eq_(row.keys(), ['User', 'Address']) -+ eq_(list(row.keys()), ['User', 'Address']) - eq_(row.User, row[0]) - eq_(row.Address, row[1]) - - for row in sess.query(User.name, User.id.label('foobar')): - if pickled is not False: - row = pickle.loads(pickle.dumps(row, pickled)) -- eq_(row.keys(), ['name', 'foobar']) -+ eq_(list(row.keys()), ['name', 'foobar']) - eq_(row.name, row[0]) - eq_(row.foobar, row[1]) - - for row in sess.query(User).values(User.name, User.id.label('foobar')): - if pickled is not False: - row = pickle.loads(pickle.dumps(row, pickled)) -- eq_(row.keys(), ['name', 'foobar']) -+ eq_(list(row.keys()), ['name', 'foobar']) - eq_(row.name, row[0]) - eq_(row.foobar, row[1]) - -@@ -465,21 +465,21 @@ - for row in sess.query(User, oalias).join(User.orders).all(): - if pickled is not False: - row = pickle.loads(pickle.dumps(row, pickled)) -- eq_(row.keys(), ['User']) -+ eq_(list(row.keys()), ['User']) - eq_(row.User, row[0]) - - oalias = aliased(Order, name='orders') - for row in sess.query(User, oalias).join(oalias, User.orders).all(): - if pickled is not False: - row = pickle.loads(pickle.dumps(row, pickled)) -- eq_(row.keys(), ['User', 'orders']) -+ eq_(list(row.keys()), ['User', 'orders']) - eq_(row.User, row[0]) - eq_(row.orders, row[1]) - - # test here that first col is not labeled, only - # one name in keys, matches correctly - for row in sess.query(User.name + 'hoho', User.name): -- eq_(row.keys(), ['name']) -+ eq_(list(row.keys()), ['name']) - eq_(row[0], row.name + 'hoho') - - if pickled is not False: -diff -r 9d0639b9d3be test/orm/test_query.py ---- a/test/orm/test_query.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_query.py Sat Apr 27 19:42:17 2013 -0400 -@@ -407,11 +407,12 @@ - Column('data', Unicode(40))) - try: - metadata.create_all() -- # Py3K -- #ustring = b'petit voix m\xe2\x80\x99a'.decode('utf-8') -- # Py2K -- ustring = 'petit voix m\xe2\x80\x99a'.decode('utf-8') -- # end Py2K -+# start Py3K -+ ustring = b'petit voix m\xe2\x80\x99a'.decode('utf-8') -+# end Py3K -+# start Py2K -+# ustring = 'petit voix m\xe2\x80\x99a'.decode('utf-8') -+# end Py2K - - table.insert().execute(id=ustring, data=ustring) - class LocalFoo(self.classes.Base): -@@ -637,9 +638,9 @@ - (operator.sub, '-'), - # Py3k - #(operator.truediv, '/'), -- # Py2K -- (operator.div, '/'), -- # end Py2K -+# start Py2K -+# (operator.div, '/'), -+# end Py2K - ): - for (lhs, rhs, res) in ( - (5, User.id, ':id_1 %s users.id'), -@@ -1047,7 +1048,7 @@ - adalias = aliased(Address, q1.subquery()) - eq_( - s.query(User, adalias).join(adalias, User.id==adalias.user_id).all(), -- [(User(id=7,name=u'jack'), Address(email_address=u'jack@bean.com',user_id=7,id=1))] -+ [(User(id=7,name='jack'), Address(email_address='jack@bean.com',user_id=7,id=1))] - ) - - # more slice tests are available in test/orm/generative.py -@@ -1196,7 +1197,7 @@ - "users.name AS users_name FROM users WHERE users.id = :param_1 " - "UNION SELECT users.id AS users_id, users.name AS users_name " - "FROM users WHERE users.id = :param_2) AS anon_1", -- checkparams = {u'param_1': 7, u'param_2': 8} -+ checkparams = {'param_1': 7, 'param_2': 8} - ) - - def test_any(self): -@@ -1319,7 +1320,7 @@ - "FROM users JOIN addresses ON users.id = addresses.user_id " - "WHERE users.name = :name_1 AND " - "addresses.email_address = :email_address_1", -- checkparams={u'email_address_1': 'ed@ed.com', u'name_1': 'ed'} -+ checkparams={'email_address_1': 'ed@ed.com', 'name_1': 'ed'} - ) - - def test_filter_by_no_property(self): -@@ -1468,14 +1469,14 @@ - for q in (q3.order_by(User.id, "anon_1_param_1"), q6.order_by(User.id, "foo")): - eq_(q.all(), - [ -- (User(id=7, name=u'jack'), u'x'), -- (User(id=7, name=u'jack'), u'y'), -- (User(id=8, name=u'ed'), u'x'), -- (User(id=8, name=u'ed'), u'y'), -- (User(id=9, name=u'fred'), u'x'), -- (User(id=9, name=u'fred'), u'y'), -- (User(id=10, name=u'chuck'), u'x'), -- (User(id=10, name=u'chuck'), u'y') -+ (User(id=7, name='jack'), 'x'), -+ (User(id=7, name='jack'), 'y'), -+ (User(id=8, name='ed'), 'x'), -+ (User(id=8, name='ed'), 'y'), -+ (User(id=9, name='fred'), 'x'), -+ (User(id=9, name='fred'), 'y'), -+ (User(id=10, name='chuck'), 'x'), -+ (User(id=10, name='chuck'), 'y') - ] - ) - -@@ -1603,7 +1604,7 @@ - - sess = create_session() - orders = sess.query(Order).filter(Order.id.in_([2, 3, 4])) -- eq_(orders.values(func.sum(Order.user_id * Order.address_id)).next(), (79,)) -+ eq_(next(orders.values(func.sum(Order.user_id * Order.address_id))), (79,)) - eq_(orders.value(func.sum(Order.user_id * Order.address_id)), 79) - - def test_apply(self): -@@ -1616,9 +1617,9 @@ - User, Address = self.classes.User, self.classes.Address - - sess = create_session() -- assert [User(name=u'ed',id=8)] == sess.query(User).order_by(User.id).group_by(User).join('addresses').having(func.count(Address.id)> 2).all() -- -- assert [User(name=u'jack',id=7), User(name=u'fred',id=9)] == sess.query(User).order_by(User.id).group_by(User).join('addresses').having(func.count(Address.id)< 2).all() -+ assert [User(name='ed',id=8)] == sess.query(User).order_by(User.id).group_by(User).join('addresses').having(func.count(Address.id)> 2).all() -+ -+ assert [User(name='jack',id=7), User(name='fred',id=9)] == sess.query(User).order_by(User.id).group_by(User).join('addresses').having(func.count(Address.id)< 2).all() - - - class ExistsTest(QueryTest, AssertsCompiledSQL): -@@ -1798,14 +1799,14 @@ - - ret = [] - eq_(len(sess.identity_map), 0) -- ret.append(q.next()) -- ret.append(q.next()) -+ ret.append(next(q)) -+ ret.append(next(q)) - eq_(len(sess.identity_map), 2) -- ret.append(q.next()) -- ret.append(q.next()) -+ ret.append(next(q)) -+ ret.append(next(q)) - eq_(len(sess.identity_map), 4) - try: -- q.next() -+ next(q) - assert False - except StopIteration: - pass -@@ -1915,7 +1916,7 @@ - User.id, text("users.name")) - - eq_(s.query(User.id, "name").order_by(User.id).all(), -- [(7, u'jack'), (8, u'ed'), (9, u'fred'), (10, u'chuck')]) -+ [(7, 'jack'), (8, 'ed'), (9, 'fred'), (10, 'chuck')]) - - def test_via_select(self): - User = self.classes.User -@@ -1973,7 +1974,7 @@ - try: - q = sess.query(Item).with_parent(u1) - assert False -- except sa_exc.InvalidRequestError, e: -+ except sa_exc.InvalidRequestError as e: - assert str(e) \ - == "Could not locate a property which relates "\ - "instances of class 'Item' to instances of class 'User'" -@@ -2058,7 +2059,7 @@ - "addresses.id AS addresses_id, addresses.user_id AS " - "addresses_user_id, addresses.email_address AS addresses_email_address " - "FROM addresses WHERE :param_2 = addresses.user_id) AS anon_1", -- checkparams={u'param_1': 7, u'param_2': 8}, -+ checkparams={'param_1': 7, 'param_2': 8}, - ) - - def test_unique_binds_or(self): -@@ -2075,7 +2076,7 @@ - "addresses_user_id, addresses.email_address AS " - "addresses_email_address FROM addresses WHERE " - ":param_1 = addresses.user_id OR :param_2 = addresses.user_id", -- checkparams={u'param_1': 7, u'param_2': 8}, -+ checkparams={'param_1': 7, 'param_2': 8}, - ) - - class SynonymTest(QueryTest): -@@ -2117,9 +2118,9 @@ - options(joinedload(User.orders_syn)).all() - eq_(result, [ - User(id=7, name='jack', orders=[ -- Order(description=u'order 1'), -- Order(description=u'order 3'), -- Order(description=u'order 5') -+ Order(description='order 1'), -+ Order(description='order 3'), -+ Order(description='order 5') - ]) - ]) - self.assert_sql_count(testing.db, go, 1) -@@ -2133,9 +2134,9 @@ - options(joinedload(User.orders_syn_2)).all() - eq_(result, [ - User(id=7, name='jack', orders=[ -- Order(description=u'order 1'), -- Order(description=u'order 3'), -- Order(description=u'order 5') -+ Order(description='order 1'), -+ Order(description='order 3'), -+ Order(description='order 5') - ]) - ]) - self.assert_sql_count(testing.db, go, 1) -@@ -2149,9 +2150,9 @@ - options(joinedload('orders_syn_2')).all() - eq_(result, [ - User(id=7, name='jack', orders=[ -- Order(description=u'order 1'), -- Order(description=u'order 3'), -- Order(description=u'order 5') -+ Order(description='order 1'), -+ Order(description='order 3'), -+ Order(description='order 5') - ]) - ]) - self.assert_sql_count(testing.db, go, 1) -@@ -2355,7 +2356,7 @@ - if isinstance(item, type): - item = class_mapper(item) - else: -- if isinstance(item, basestring): -+ if isinstance(item, str): - item = inspect(r[-1]).mapper.attrs[item] - r.append(item) - return tuple(r) -diff -r 9d0639b9d3be test/orm/test_relationships.py ---- a/test/orm/test_relationships.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_relationships.py Sat Apr 27 19:42:17 2013 -0400 -@@ -426,13 +426,13 @@ - c1 = Company('c1') - c2 = Company('c2') - -- e1 = Employee(u'emp1', c1, 1) -- e2 = Employee(u'emp2', c1, 2, e1) -- e3 = Employee(u'emp3', c1, 3, e1) -- e4 = Employee(u'emp4', c1, 4, e3) -- e5 = Employee(u'emp5', c2, 1) -- e6 = Employee(u'emp6', c2, 2, e5) -- e7 = Employee(u'emp7', c2, 3, e5) -+ e1 = Employee('emp1', c1, 1) -+ e2 = Employee('emp2', c1, 2, e1) -+ e3 = Employee('emp3', c1, 3, e1) -+ e4 = Employee('emp4', c1, 4, e3) -+ e5 = Employee('emp5', c2, 1) -+ e6 = Employee('emp6', c2, 2, e5) -+ e7 = Employee('emp7', c2, 3, e5) - - sess.add_all((c1, c2)) - sess.commit() -@@ -642,7 +642,7 @@ - try: - sess.flush() - assert False -- except AssertionError, e: -+ except AssertionError as e: - startswith_(str(e), - "Dependency rule tried to blank-out " - "primary key column 'tableB.id' on instance ") -@@ -667,7 +667,7 @@ - try: - sess.flush() - assert False -- except AssertionError, e: -+ except AssertionError as e: - startswith_(str(e), - "Dependency rule tried to blank-out " - "primary key column 'tableB.id' on instance ") -@@ -1106,9 +1106,9 @@ - eq_( - sess.query(Subscriber).order_by(Subscriber.type).all(), - [ -- Subscriber(id=1, type=u'A'), -- Subscriber(id=2, type=u'B'), -- Subscriber(id=2, type=u'C') -+ Subscriber(id=1, type='A'), -+ Subscriber(id=2, type='B'), -+ Subscriber(id=2, type='C') - ] - ) - -@@ -1365,7 +1365,7 @@ - try: - sess.add(a1) - assert False -- except AssertionError, err: -+ except AssertionError as err: - eq_(str(err), - "Attribute 'bs' on class '%s' doesn't handle " - "objects of type '%s'" % (A, C)) -diff -r 9d0639b9d3be test/orm/test_session.py ---- a/test/orm/test_session.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_session.py Sat Apr 27 19:42:17 2013 -0400 -@@ -232,7 +232,7 @@ - # use :bindparam style - eq_(sess.execute("select * from users where id=:id", - {'id': 7}).fetchall(), -- [(7, u'jack')]) -+ [(7, 'jack')]) - - - # use :bindparam style -@@ -733,7 +733,7 @@ - # withstand a change? should this be - # more directly attempting to manipulate the identity_map ? - u1, u2, u3 = sess.query(User).all() -- for i, (key, value) in enumerate(sess.identity_map.iteritems()): -+ for i, (key, value) in enumerate(iter(sess.identity_map.items())): - if i == 2: - del u3 - gc_collect() -@@ -747,7 +747,7 @@ - @event.listens_for(m, "after_update") - def e(mapper, conn, target): - sess = object_session(target) -- for entry in sess.identity_map.values(): -+ for entry in list(sess.identity_map.values()): - entry.name = "5" - - a1, a2 = User(name="1"), User(name="2") -@@ -845,7 +845,7 @@ - u = session.query(User).filter_by(id=7).one() - - # get everything to load in both directions -- print [a.user for a in u.addresses] -+ print([a.user for a in u.addresses]) - - # then see if expunge fails - session.expunge(u) -@@ -1187,7 +1187,7 @@ - s.flush() - user = s.query(User).one() - user = None -- print s.identity_map -+ print(s.identity_map) - gc_collect() - assert len(s.identity_map) == 1 - -@@ -1207,7 +1207,7 @@ - s = create_session(weak_identity_map=False) - mapper(User, users) - -- for o in [User(name='u%s' % x) for x in xrange(10)]: -+ for o in [User(name='u%s' % x) for x in range(10)]: - s.add(o) - # o is still live after this loop... - -diff -r 9d0639b9d3be test/orm/test_subquery_relations.py ---- a/test/orm/test_subquery_relations.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_subquery_relations.py Sat Apr 27 19:42:17 2013 -0400 -@@ -1552,9 +1552,9 @@ - Movie = self.classes.Movie - - session = Session(testing.db) -- rscott = Director(name=u"Ridley Scott") -- alien = Movie(title=u"Alien") -- brunner = Movie(title=u"Blade Runner") -+ rscott = Director(name="Ridley Scott") -+ alien = Movie(title="Alien") -+ brunner = Movie(title="Blade Runner") - rscott.movies.append(brunner) - rscott.movies.append(alien) - session.add_all([rscott, alien, brunner]) -diff -r 9d0639b9d3be test/orm/test_unitofwork.py ---- a/test/orm/test_unitofwork.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_unitofwork.py Sat Apr 27 19:42:17 2013 -0400 -@@ -87,7 +87,7 @@ - - mapper(Test, uni_t1) - -- txt = u"\u0160\u0110\u0106\u010c\u017d" -+ txt = "\u0160\u0110\u0106\u010c\u017d" - t1 = Test(id=1, txt=txt) - self.assert_(t1.txt == txt) - -@@ -107,7 +107,7 @@ - 't2s': relationship(Test2)}) - mapper(Test2, uni_t2) - -- txt = u"\u0160\u0110\u0106\u010c\u017d" -+ txt = "\u0160\u0110\u0106\u010c\u017d" - t1 = Test(txt=txt) - t1.t2s.append(Test2()) - t1.t2s.append(Test2()) -@@ -132,16 +132,16 @@ - @classmethod - def define_tables(cls, metadata): - t1 = Table('unitable1', metadata, -- Column(u'méil', Integer, primary_key=True, key='a', test_needs_autoincrement=True), -- Column(u'\u6e2c\u8a66', Integer, key='b'), -+ Column('méil', Integer, primary_key=True, key='a', test_needs_autoincrement=True), -+ Column('\u6e2c\u8a66', Integer, key='b'), - Column('type', String(20)), - test_needs_fk=True, - test_needs_autoincrement=True) -- t2 = Table(u'Unitéble2', metadata, -- Column(u'méil', Integer, primary_key=True, key="cc", test_needs_autoincrement=True), -- Column(u'\u6e2c\u8a66', Integer, -- ForeignKey(u'unitable1.a'), key="d"), -- Column(u'\u6e2c\u8a66_2', Integer, key="e"), -+ t2 = Table('Unitéble2', metadata, -+ Column('méil', Integer, primary_key=True, key="cc", test_needs_autoincrement=True), -+ Column('\u6e2c\u8a66', Integer, -+ ForeignKey('unitable1.a'), key="d"), -+ Column('\u6e2c\u8a66_2', Integer, key="e"), - test_needs_fk=True, - test_needs_autoincrement=True) - -@@ -238,11 +238,12 @@ - Foo, t1 = self.classes.Foo, self.tables.t1 - - -- # Py3K -- #data = b"this is some data" -- # Py2K -- data = "this is some data" -- # end Py2K -+# start Py3K -+ data = b"this is some data" -+# end Py3K -+# start Py2K -+# data = "this is some data" -+# end Py2K - - mapper(Foo, t1) - -@@ -1054,13 +1055,13 @@ - session.flush() - - user_rows = users.select(users.c.id.in_([u.id])).execute().fetchall() -- eq_(user_rows[0].values(), [u.id, 'one2manytester']) -+ eq_(list(user_rows[0].values()), [u.id, 'one2manytester']) - - address_rows = addresses.select( - addresses.c.id.in_([a.id, a2.id]), - order_by=[addresses.c.email_address]).execute().fetchall() -- eq_(address_rows[0].values(), [a2.id, u.id, 'lala@test.org']) -- eq_(address_rows[1].values(), [a.id, u.id, 'one2many@test.org']) -+ eq_(list(address_rows[0].values()), [a2.id, u.id, 'lala@test.org']) -+ eq_(list(address_rows[1].values()), [a.id, u.id, 'one2many@test.org']) - - userid = u.id - addressid = a2.id -@@ -1071,7 +1072,7 @@ - - address_rows = addresses.select( - addresses.c.id == addressid).execute().fetchall() -- eq_(address_rows[0].values(), -+ eq_(list(address_rows[0].values()), - [addressid, userid, 'somethingnew@foo.com']) - self.assert_(u.id == userid and a2.id == addressid) - -@@ -1501,18 +1502,18 @@ - assert u.name == 'multitester' - - user_rows = users.select(users.c.id.in_([u.foo_id])).execute().fetchall() -- eq_(user_rows[0].values(), [u.foo_id, 'multitester']) -+ eq_(list(user_rows[0].values()), [u.foo_id, 'multitester']) - address_rows = addresses.select(addresses.c.id.in_([u.id])).execute().fetchall() -- eq_(address_rows[0].values(), [u.id, u.foo_id, 'multi@test.org']) -+ eq_(list(address_rows[0].values()), [u.id, u.foo_id, 'multi@test.org']) - - u.email = 'lala@hey.com' - u.name = 'imnew' - session.flush() - - user_rows = users.select(users.c.id.in_([u.foo_id])).execute().fetchall() -- eq_(user_rows[0].values(), [u.foo_id, 'imnew']) -+ eq_(list(user_rows[0].values()), [u.foo_id, 'imnew']) - address_rows = addresses.select(addresses.c.id.in_([u.id])).execute().fetchall() -- eq_(address_rows[0].values(), [u.id, u.foo_id, 'lala@hey.com']) -+ eq_(list(address_rows[0].values()), [u.id, u.foo_id, 'lala@hey.com']) - - session.expunge_all() - u = session.query(User).get(id) -@@ -1650,7 +1651,7 @@ - l = sa.select([users, addresses], - sa.and_(users.c.id==addresses.c.user_id, - addresses.c.id==a.id)).execute() -- eq_(l.first().values(), -+ eq_(list(l.first().values()), - [a.user.id, 'asdf8d', a.id, a.user_id, 'theater@foo.com']) - - def test_many_to_one_1(self): -@@ -2127,7 +2128,7 @@ - - assert assoc.count().scalar() == 2 - i.keywords = [] -- print i.keywords -+ print(i.keywords) - session.flush() - assert assoc.count().scalar() == 0 - -diff -r 9d0639b9d3be test/orm/test_unitofworkv2.py ---- a/test/orm/test_unitofworkv2.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_unitofworkv2.py Sat Apr 27 19:42:17 2013 -0400 -@@ -26,7 +26,7 @@ - def _assert_uow_size(self, session, expected ): - uow = self._get_test_uow(session) - postsort_actions = uow._generate_actions() -- print postsort_actions -+ print(postsort_actions) - eq_(len(postsort_actions), expected, postsort_actions) - - class UOWTest(_fixtures.FixtureTest, -@@ -125,12 +125,12 @@ - CompiledSQL( - "UPDATE addresses SET user_id=:user_id WHERE " - "addresses.id = :addresses_id", -- lambda ctx: [{u'addresses_id': a1.id, 'user_id': None}] -+ lambda ctx: [{'addresses_id': a1.id, 'user_id': None}] - ), - CompiledSQL( - "UPDATE addresses SET user_id=:user_id WHERE " - "addresses.id = :addresses_id", -- lambda ctx: [{u'addresses_id': a2.id, 'user_id': None}] -+ lambda ctx: [{'addresses_id': a2.id, 'user_id': None}] - ), - CompiledSQL( - "DELETE FROM users WHERE users.id = :id", -@@ -235,12 +235,12 @@ - CompiledSQL( - "UPDATE addresses SET user_id=:user_id WHERE " - "addresses.id = :addresses_id", -- lambda ctx: [{u'addresses_id': a1.id, 'user_id': None}] -+ lambda ctx: [{'addresses_id': a1.id, 'user_id': None}] - ), - CompiledSQL( - "UPDATE addresses SET user_id=:user_id WHERE " - "addresses.id = :addresses_id", -- lambda ctx: [{u'addresses_id': a2.id, 'user_id': None}] -+ lambda ctx: [{'addresses_id': a2.id, 'user_id': None}] - ), - CompiledSQL( - "DELETE FROM users WHERE users.id = :id", -@@ -1149,7 +1149,7 @@ - "nodes, node_to_nodes WHERE :param_1 = " - "node_to_nodes.right_node_id AND nodes.id = " - "node_to_nodes.left_node_id" , -- lambda ctx:{u'param_1': n1.id}, -+ lambda ctx:{'param_1': n1.id}, - ), - CompiledSQL( - "DELETE FROM node_to_nodes WHERE " -diff -r 9d0639b9d3be test/orm/test_update_delete.py ---- a/test/orm/test_update_delete.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_update_delete.py Sat Apr 27 19:42:17 2013 -0400 -@@ -188,22 +188,22 @@ - update({'age': User.age - 10}, synchronize_session='evaluate') - - eq_([john.age, jack.age, jill.age, jane.age], [25,37,29,27]) -- eq_(sess.query(User.age).order_by(User.id).all(), zip([25,37,29,27])) -+ eq_(sess.query(User.age).order_by(User.id).all(), list(zip([25,37,29,27]))) - - sess.query(User).filter(User.age > 29).\ - update({User.age: User.age - 10}, synchronize_session='evaluate') - eq_([john.age, jack.age, jill.age, jane.age], [25,27,29,27]) -- eq_(sess.query(User.age).order_by(User.id).all(), zip([25,27,29,27])) -+ eq_(sess.query(User.age).order_by(User.id).all(), list(zip([25,27,29,27]))) - - sess.query(User).filter(User.age > 27).\ - update({users.c.age: User.age - 10}, synchronize_session='evaluate') - eq_([john.age, jack.age, jill.age, jane.age], [25,27,19,27]) -- eq_(sess.query(User.age).order_by(User.id).all(), zip([25,27,19,27])) -+ eq_(sess.query(User.age).order_by(User.id).all(), list(zip([25,27,19,27]))) - - sess.query(User).filter(User.age == 25).\ - update({User.age: User.age - 10}, synchronize_session='fetch') - eq_([john.age, jack.age, jill.age, jane.age], [15,27,19,27]) -- eq_(sess.query(User.age).order_by(User.id).all(), zip([15,27,19,27])) -+ eq_(sess.query(User.age).order_by(User.id).all(), list(zip([15,27,19,27]))) - - def test_update_against_metadata(self): - User, users = self.classes.User, self.tables.users -@@ -211,7 +211,7 @@ - sess = Session() - - sess.query(users).update({users.c.age: 29}, synchronize_session=False) -- eq_(sess.query(User.age).order_by(User.id).all(), zip([29,29,29,29])) -+ eq_(sess.query(User.age).order_by(User.id).all(), list(zip([29,29,29,29]))) - - def test_update_with_bindparams(self): - User = self.classes.User -@@ -224,7 +224,7 @@ - update({'age': User.age - 10}, synchronize_session='fetch') - - eq_([john.age, jack.age, jill.age, jane.age], [25,37,29,27]) -- eq_(sess.query(User.age).order_by(User.id).all(), zip([25,37,29,27])) -+ eq_(sess.query(User.age).order_by(User.id).all(), list(zip([25,37,29,27]))) - - def test_update_without_load(self): - User = self.classes.User -@@ -233,7 +233,7 @@ - - sess.query(User).filter(User.id == 3).\ - update({'age': 44}, synchronize_session='fetch') -- eq_(sess.query(User.age).order_by(User.id).all(), zip([25,47,44,37])) -+ eq_(sess.query(User.age).order_by(User.id).all(), list(zip([25,47,44,37]))) - - def test_update_changes_resets_dirty(self): - User = self.classes.User -@@ -300,7 +300,7 @@ - update({'age': User.age - 10}, synchronize_session='fetch') - - eq_([john.age, jack.age, jill.age, jane.age], [25,37,29,27]) -- eq_(sess.query(User.age).order_by(User.id).all(), zip([25,37,29,27])) -+ eq_(sess.query(User.age).order_by(User.id).all(), list(zip([25,37,29,27]))) - - @testing.fails_if(lambda: not testing.db.dialect.supports_sane_rowcount) - def test_update_returns_rowcount(self): -@@ -334,7 +334,7 @@ - sess.query(User).update({'age': 42}, synchronize_session='evaluate') - - eq_([john.age, jack.age, jill.age, jane.age], [42,42,42,42]) -- eq_(sess.query(User.age).order_by(User.id).all(), zip([42,42,42,42])) -+ eq_(sess.query(User.age).order_by(User.id).all(), list(zip([42,42,42,42]))) - - def test_delete_all(self): - User = self.classes.User -@@ -516,7 +516,7 @@ - - eq_([foo.title, bar.title, baz.title], ['foofoo','barbar', 'baz']) - eq_(sess.query(Document.title).order_by(Document.id).all(), -- zip(['foofoo','barbar', 'baz'])) -+ list(zip(['foofoo','barbar', 'baz']))) - - def test_update_with_explicit_joinedload(self): - User = self.classes.User -@@ -528,7 +528,7 @@ - update({'age': User.age - 10}, synchronize_session='fetch') - - eq_([john.age, jack.age, jill.age, jane.age], [25,37,29,27]) -- eq_(sess.query(User.age).order_by(User.id).all(), zip([25,37,29,27])) -+ eq_(sess.query(User.age).order_by(User.id).all(), list(zip([25,37,29,27]))) - - def test_delete_with_eager_relationships(self): - Document = self.classes.Document -@@ -538,7 +538,7 @@ - sess.query(Document).filter(Document.user_id == 1).\ - delete(synchronize_session=False) - -- eq_(sess.query(Document.title).all(), zip(['baz'])) -+ eq_(sess.query(Document.title).all(), list(zip(['baz']))) - - class UpdateDeleteFromTest(fixtures.MappedTest): - @classmethod -diff -r 9d0639b9d3be test/orm/test_utils.py ---- a/test/orm/test_utils.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/orm/test_utils.py Sat Apr 27 19:42:17 2013 -0400 -@@ -52,10 +52,10 @@ - alias = aliased(Point) - - assert Point.zero -- # Py2K -- # TODO: what is this testing ?? -- assert not getattr(alias, 'zero') -- # end Py2K -+# start Py2K -+# # TODO: what is this testing ?? -+# assert not getattr(alias, 'zero') -+# end Py2K - - def test_classmethods(self): - class Point(object): -@@ -123,17 +123,19 @@ - self.func = func - def __get__(self, instance, owner): - if instance is None: -- # Py3K -- #args = (self.func, owner) -- # Py2K -- args = (self.func, owner, owner.__class__) -- # end Py2K -+# start Py3K -+ args = (self.func, owner) -+# end Py3K -+# start Py2K -+# args = (self.func, owner, owner.__class__) -+# end Py2K - else: -- # Py3K -- #args = (self.func, instance) -- # Py2K -- args = (self.func, instance, owner) -- # end Py2K -+# start Py3K -+ args = (self.func, instance) -+# end Py3K -+# start Py2K -+# args = (self.func, instance, owner) -+# end Py2K - return types.MethodType(*args) - - class PropertyDescriptor(object): -diff -r 9d0639b9d3be test/perf/insertspeed.py ---- a/test/perf/insertspeed.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/perf/insertspeed.py Sat Apr 27 19:42:17 2013 -0400 -@@ -13,18 +13,18 @@ - - def sa_unprofiled_insertmany(n): - i = Person_table.insert() -- i.execute([{'name':'John Doe','sex':1,'age':35} for j in xrange(n)]) -+ i.execute([{'name':'John Doe','sex':1,'age':35} for j in range(n)]) - - def sqlite_unprofiled_insertmany(n): - conn = db.connect().connection - c = conn.cursor() -- persons = [('john doe', 1, 35) for i in xrange(n)] -+ persons = [('john doe', 1, 35) for i in range(n)] - c.executemany("insert into Person(name, sex, age) values (?,?,?)", persons) - - @profiling.profiled('sa_profiled_insert_many', always=True) - def sa_profiled_insert_many(n): - i = Person_table.insert() -- i.execute([{'name':'John Doe','sex':1,'age':35} for j in xrange(n)]) -+ i.execute([{'name':'John Doe','sex':1,'age':35} for j in range(n)]) - s = Person_table.select() - r = s.execute() - res = [[value for value in row] for row in r.fetchall()] -@@ -32,7 +32,7 @@ - def sqlite_unprofiled_insert(n): - conn = db.connect().connection - c = conn.cursor() -- for j in xrange(n): -+ for j in range(n): - c.execute("insert into Person(name, sex, age) values (?,?,?)", - ('john doe', 1, 35)) - -@@ -40,13 +40,13 @@ - # Another option is to build Person_table.insert() outside of the - # loop. But it doesn't make much of a difference, so might as well - # use the worst-case/naive version here. -- for j in xrange(n): -+ for j in range(n): - Person_table.insert().execute({'name':'John Doe','sex':1,'age':35}) - - @profiling.profiled('sa_profiled_insert', always=True) - def sa_profiled_insert(n): - i = Person_table.insert() -- for j in xrange(n): -+ for j in range(n): - i.execute({'name':'John Doe','sex':1,'age':35}) - s = Person_table.select() - r = s.execute() -@@ -69,12 +69,12 @@ - metadata.drop_all() - metadata.create_all() - -- print "%s (%s)" % (label, ', '.join([str(a) for a in args])) -+ print("%s (%s)" % (label, ', '.join([str(a) for a in args]))) - fn(*args, **kw) - - def all(): - try: -- print "Bulk INSERTS via executemany():\n" -+ print("Bulk INSERTS via executemany():\n") - - run_timed(sqlite_unprofiled_insertmany, - 'pysqlite bulk insert', -@@ -88,7 +88,7 @@ - 'SQLAlchemy bulk insert/select, profiled', - 50000) - -- print "\nIndividual INSERTS via execute():\n" -+ print("\nIndividual INSERTS via execute():\n") - - run_timed(sqlite_unprofiled_insert, - "pysqlite individual insert", -diff -r 9d0639b9d3be test/perf/objselectspeed.py ---- a/test/perf/objselectspeed.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/perf/objselectspeed.py Sat Apr 27 19:42:17 2013 -0400 -@@ -36,7 +36,7 @@ - metadata.create_all() - i = Person_table.insert() - data = [{'name':'John Doe','sex':1,'age':35, 'type':'employee'}] * 100 -- for j in xrange(500): -+ for j in range(500): - i.execute(data) - - # note we arent fetching from employee_table, -@@ -46,7 +46,7 @@ - #for j in xrange(500): - # i.execute(data) - -- print "Inserted 50,000 rows" -+ print("Inserted 50,000 rows") - - def sqlite_select(entity_cls): - conn = db.connect().connection -@@ -89,10 +89,10 @@ - t, t2 = 0, 0 - def usage(label): - now = resource.getrusage(resource.RUSAGE_SELF) -- print "%s: %0.3fs real, %0.3fs user, %0.3fs sys" % ( -+ print("%s: %0.3fs real, %0.3fs user, %0.3fs sys" % ( - label, t2 - t, - now.ru_utime - usage.last.ru_utime, -- now.ru_stime - usage.last.ru_stime) -+ now.ru_stime - usage.last.ru_stime)) - usage.snap(now) - usage.snap = lambda stats=None: setattr( - usage, 'last', stats or resource.getrusage(resource.RUSAGE_SELF)) -diff -r 9d0639b9d3be test/perf/objupdatespeed.py ---- a/test/perf/objupdatespeed.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/perf/objupdatespeed.py Sat Apr 27 19:42:17 2013 -0400 -@@ -39,12 +39,12 @@ - i.execute(data) - - i = Email_table.insert() -- for j in xrange(1, NUM + 1): -+ for j in range(1, NUM + 1): - i.execute(address='foo@bar', person_id=j) - if j % 2: - i.execute(address='baz@quux', person_id=j) - -- print "Inserted %d rows." % (NUM + NUM + (NUM // 2)) -+ print("Inserted %d rows." % (NUM + NUM + (NUM // 2))) - - def orm_select(session): - return session.query(Person).all() -@@ -63,10 +63,10 @@ - t, t2 = 0, 0 - def usage(label): - now = resource.getrusage(resource.RUSAGE_SELF) -- print "%s: %0.3fs real, %0.3fs user, %0.3fs sys" % ( -+ print("%s: %0.3fs real, %0.3fs user, %0.3fs sys" % ( - label, t2 - t, - now.ru_utime - usage.last.ru_utime, -- now.ru_stime - usage.last.ru_stime) -+ now.ru_stime - usage.last.ru_stime)) - usage.snap(now) - usage.snap = lambda stats=None: setattr( - usage, 'last', stats or resource.getrusage(resource.RUSAGE_SELF)) -diff -r 9d0639b9d3be test/perf/orm2010.py ---- a/test/perf/orm2010.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/perf/orm2010.py Sat Apr 27 19:42:17 2013 -0400 -@@ -95,7 +95,7 @@ - name="Boss %d" % i, - golf_average=Decimal(random.randint(40, 150)) - ) -- for i in xrange(1000) -+ for i in range(1000) - ] - - sess.add_all(bosses) -@@ -107,7 +107,7 @@ - name="Grunt %d" % i, - savings=Decimal(random.randint(5000000, 15000000) / 100) - ) -- for i in xrange(10000) -+ for i in range(10000) - ] - - # Assign each Grunt a Boss. Look them up in the DB -@@ -149,15 +149,15 @@ - - counts_by_methname = dict((key[2], stats.stats[key][0]) for key in stats.stats) - --print "SQLA Version: %s" % __version__ --print "Total calls %d" % stats.total_calls --print "Total cpu seconds: %.2f" % stats.total_tt --print 'Total execute calls: %d' \ -+print("SQLA Version: %s" % __version__) -+print("Total calls %d" % stats.total_calls) -+print("Total cpu seconds: %.2f" % stats.total_tt) -+print('Total execute calls: %d' \ - % counts_by_methname[""] --print 'Total executemany calls: %d' \ -+ "objects>"]) -+print('Total executemany calls: %d' \ - % counts_by_methname.get("", 0) -+ "objects>", 0)) - - #stats.sort_stats('time', 'calls') - #stats.print_stats() -diff -r 9d0639b9d3be test/perf/ormsession.py ---- a/test/perf/ormsession.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/perf/ormsession.py Sat Apr 27 19:42:17 2013 -0400 -@@ -81,9 +81,9 @@ - - transaction = con.begin() - data, subdata = [], [] -- for item_id in xrange(1, q_items + 1): -+ for item_id in range(1, q_items + 1): - data.append({'name': "item number %s" % item_id}) -- for subitem_id in xrange(1, (item_id % q_sub_per_item) + 1): -+ for subitem_id in range(1, (item_id % q_sub_per_item) + 1): - subdata.append({'item_id': item_id, - 'name': "subitem number %s" % subitem_id}) - if item_id % 100 == 0: -@@ -99,7 +99,7 @@ - - transaction = con.begin() - data = [] -- for customer_id in xrange(1, q_customers): -+ for customer_id in range(1, q_customers): - data.append({'name': "customer number %s" % customer_id}) - if customer_id % 100 == 0: - customers.insert().execute(*data) -@@ -111,7 +111,7 @@ - transaction = con.begin() - data, subdata = [], [] - order_t = int(time.time()) - (5000 * 5 * 60) -- current = xrange(1, q_customers) -+ current = range(1, q_customers) - step, purchase_id = 1, 0 - while current: - next = [] -diff -r 9d0639b9d3be test/perf/stress_all.py ---- a/test/perf/stress_all.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/perf/stress_all.py Sat Apr 27 19:42:17 2013 -0400 -@@ -2,7 +2,7 @@ - from datetime import * - import decimal - #from fastdec import mpd as Decimal --from cPickle import dumps, loads -+from pickle import dumps, loads - - #from sqlalchemy.dialects.postgresql.base import ARRAY - -@@ -42,9 +42,9 @@ - - def getitem_long_results(raw_results): - return [ -- (r[0L], -- r[1L], r[2L], r[3L], r[4L], r[5L], -- r[6L], r[7L], r[8L], r[9L], r[10L]) -+ (r[0], -+ r[1], r[2], r[3], r[4], r[5], -+ r[6], r[7], r[8], r[9], r[10]) - for r in raw_results] - - def getitem_obj_results(raw_results): -@@ -128,7 +128,7 @@ - - # Unicode - def genunicodevalue(rnum, fnum): -- return (rnum % 4) and (u"value%d" % fnum) or None -+ return (rnum % 4) and ("value%d" % fnum) or None - unicodetest = (Unicode(20, ), genunicodevalue, - dict(num_records=100000)) - # dict(engineurl='mysql:///test', freshdata=False)) -@@ -139,10 +139,10 @@ - pickletypetest, typedecoratortest, unicodetest] - for engineurl in ('postgresql://scott:tiger@localhost/test', - 'sqlite://', 'mysql://scott:tiger@localhost/test'): -- print "\n%s\n" % engineurl -+ print("\n%s\n" % engineurl) - for datatype, genvalue, kwargs in tests: -- print "%s:" % getattr(datatype, '__name__', -- datatype.__class__.__name__), -+ print("%s:" % getattr(datatype, '__name__', -+ datatype.__class__.__name__), end=' ') - profile_and_time_dbfunc(iter_results, datatype, genvalue, - profile=False, engineurl=engineurl, - verbose=verbose, **kwargs) -@@ -158,13 +158,13 @@ - slice_results] - for engineurl in ('postgresql://scott:tiger@localhost/test', - 'sqlite://', 'mysql://scott:tiger@localhost/test'): -- print "\n%s\n" % engineurl -+ print("\n%s\n" % engineurl) - test_table = prepare(Unicode(20,), - genunicodevalue, - num_fields=10, num_records=100000, - verbose=verbose, engineurl=engineurl) - for method in methods: -- print "%s:" % method.__name__, -+ print("%s:" % method.__name__, end=' ') - time_dbfunc(test_table, method, genunicodevalue, - num_fields=10, num_records=100000, profile=False, - verbose=verbose) -@@ -174,9 +174,9 @@ - # -------------------------------- - - def pickletofile_results(raw_results): -- from cPickle import dump, load -+ from pickle import dump, load - for protocol in (0, 1, 2): -- print "dumping protocol %d..." % protocol -+ print("dumping protocol %d..." % protocol) - f = file('noext.pickle%d' % protocol, 'wb') - dump(raw_results, f, protocol) - f.close() -@@ -198,7 +198,7 @@ - num_fields=10, num_records=10000) - funcs = [pickle_rows, pickle_results] - for func in funcs: -- print "%s:" % func.__name__, -+ print("%s:" % func.__name__, end=' ') - time_dbfunc(test_table, func, genunicodevalue, - num_records=10000, profile=False, verbose=verbose) - -@@ -217,9 +217,9 @@ - - def get_results(): - return session.query(Test).all() -- print "ORM:", -+ print("ORM:", end=' ') - for engineurl in ('postgresql:///test', 'sqlite://', 'mysql:///test'): -- print "\n%s\n" % engineurl -+ print("\n%s\n" % engineurl) - profile_and_time_dbfunc(getattr_results, Unicode(20), genunicodevalue, - class_=Test, getresults_func=get_results, - engineurl=engineurl, #freshdata=False, -diff -r 9d0639b9d3be test/perf/stresstest.py ---- a/test/perf/stresstest.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/perf/stresstest.py Sat Apr 27 19:42:17 2013 -0400 -@@ -17,13 +17,13 @@ - - def insert(test_table, num_fields, num_records, genvalue, verbose=True): - if verbose: -- print "building insert values...", -+ print("building insert values...", end=' ') - sys.stdout.flush() - values = [dict(("field%d" % fnum, genvalue(rnum, fnum)) - for fnum in range(num_fields)) - for rnum in range(num_records)] - if verbose: -- print "inserting...", -+ print("inserting...", end=' ') - sys.stdout.flush() - def db_insert(): - test_table.insert().execute(values) -@@ -32,11 +32,11 @@ - "from __main__ import db_insert", - number=1) - if verbose: -- print "%s" % round(timing, 3) -+ print("%s" % round(timing, 3)) - - def check_result(results, num_fields, genvalue, verbose=True): - if verbose: -- print "checking...", -+ print("checking...", end=' ') - sys.stdout.flush() - for rnum, row in enumerate(results): - expected = tuple([rnum + 1] + -@@ -49,28 +49,28 @@ - - def nicer_res(values, printvalues=False): - if printvalues: -- print values -+ print(values) - min_time = min(values) - return round(min_time, 3), round(avgdev(values, min_time), 2) - - def profile_func(func_name, verbose=True): - if verbose: -- print "profiling...", -+ print("profiling...", end=' ') - sys.stdout.flush() - cProfile.run('%s()' % func_name, 'prof') - - def time_func(func_name, num_tests=1, verbose=True): - if verbose: -- print "timing...", -+ print("timing...", end=' ') - sys.stdout.flush() - timings = timeit.repeat('%s()' % func_name, - "from __main__ import %s" % func_name, - number=num_tests, repeat=5) - avg, dev = nicer_res(timings) - if verbose: -- print "%s (%s)" % (avg, dev) -+ print("%s (%s)" % (avg, dev)) - else: -- print avg -+ print(avg) - - def profile_and_time(func_name, num_tests=1): - profile_func(func_name) -@@ -121,7 +121,7 @@ - check_results=check_result, profile=True, - check_leaks=True, print_leaks=False, verbose=True): - if verbose: -- print "testing '%s'..." % test_func.__name__, -+ print("testing '%s'..." % test_func.__name__, end=' ') - sys.stdout.flush() - if class_ is not None: - clear_mappers() -@@ -148,12 +148,12 @@ - diff = hashable_objects_after - hashable_objects_before - ldiff = len(diff) - if print_leaks and ldiff < num_records: -- print "\n*** hashable objects leaked (%d) ***" % ldiff -- print '\n'.join(map(str, diff)) -- print "***\n" -+ print("\n*** hashable objects leaked (%d) ***" % ldiff) -+ print('\n'.join(map(str, diff))) -+ print("***\n") - - if num_leaks > num_records: -- print "(leaked: %d !)" % num_leaks, -+ print("(leaked: %d !)" % num_leaks, end=' ') - if profile: - profile_func('test', verbose) - time_func('test', num_tests, verbose) -diff -r 9d0639b9d3be test/perf/threaded_compile.py ---- a/test/perf/threaded_compile.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/perf/threaded_compile.py Sat Apr 27 19:42:17 2013 -0400 -@@ -4,7 +4,7 @@ - - from sqlalchemy import * - from sqlalchemy.orm import * --import thread, time -+import _thread, time - from sqlalchemy.orm import mapperlib - - -@@ -42,20 +42,20 @@ - - def run1(): - for i in range(50): -- print "T1", thread.get_ident() -+ print("T1", _thread.get_ident()) - class_mapper(T1) - time.sleep(.05) - - def run2(): - for i in range(50): -- print "T2", thread.get_ident() -+ print("T2", _thread.get_ident()) - class_mapper(T2) - time.sleep(.057) - - def run3(): - for i in range(50): - def foo(): -- print "FOO", thread.get_ident() -+ print("FOO", _thread.get_ident()) - class Foo(object):pass - mapper(Foo, t3) - class_mapper(Foo).compile() -@@ -64,12 +64,12 @@ - - mapper(T1, t1, properties={'t2':relationship(T2, backref="t1")}) - mapper(T2, t2) --print "START" -+print("START") - for j in range(0, 5): -- thread.start_new_thread(run1, ()) -- thread.start_new_thread(run2, ()) -- thread.start_new_thread(run3, ()) -- thread.start_new_thread(run3, ()) -- thread.start_new_thread(run3, ()) --print "WAIT" -+ _thread.start_new_thread(run1, ()) -+ _thread.start_new_thread(run2, ()) -+ _thread.start_new_thread(run3, ()) -+ _thread.start_new_thread(run3, ()) -+ _thread.start_new_thread(run3, ()) -+print("WAIT") - time.sleep(5) -diff -r 9d0639b9d3be test/sql/test_compiler.py ---- a/test/sql/test_compiler.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/sql/test_compiler.py Sat Apr 27 19:42:17 2013 -0400 -@@ -661,13 +661,13 @@ - s = select([table1.c.myid]).as_scalar() - try: - s.c.foo -- except exc.InvalidRequestError, err: -+ except exc.InvalidRequestError as err: - assert str(err) \ - == 'Scalar Select expression has no columns; use this '\ - 'object directly within a column-level expression.' - try: - s.columns.foo -- except exc.InvalidRequestError, err: -+ except exc.InvalidRequestError as err: - assert str(err) \ - == 'Scalar Select expression has no columns; use this '\ - 'object directly within a column-level expression.' -@@ -1116,9 +1116,9 @@ - - # test unicode - self.assert_compile(select( -- [u"foobar(a)", u"pk_foo_bar(syslaal)"], -- u"a = 12", -- from_obj=[u"foobar left outer join lala on foobar.foo = lala.foo"] -+ ["foobar(a)", "pk_foo_bar(syslaal)"], -+ "a = 12", -+ from_obj=["foobar left outer join lala on foobar.foo = lala.foo"] - ), - "SELECT foobar(a), pk_foo_bar(syslaal) FROM foobar " - "left outer join lala on foobar.foo = lala.foo WHERE a = 12" -@@ -2245,7 +2245,7 @@ - func.lala(table1.c.name).label('gg')]) - - eq_( -- s1.c.keys(), -+ list(s1.c.keys()), - ['myid', 'foobar', str(f1), 'gg'] - ) - -@@ -2273,7 +2273,7 @@ - t = table1 - - s1 = select([col], from_obj=t) -- assert s1.c.keys() == [key], s1.c.keys() -+ assert list(s1.c.keys()) == [key], list(s1.c.keys()) - - if label: - self.assert_compile(s1, -@@ -2679,11 +2679,11 @@ - def test_reraise_of_column_spec_issue_unicode(self): - MyType = self._illegal_type_fixture() - t1 = Table('t', MetaData(), -- Column(u'méil', MyType()) -+ Column('méil', MyType()) - ) - assert_raises_message( - exc.CompileError, -- ur"\(in table 't', column 'méil'\): Couldn't compile type", -+ r"\(in table 't', column 'méil'\): Couldn't compile type", - schema.CreateTable(t1).compile - ) - -diff -r 9d0639b9d3be test/sql/test_defaults.py ---- a/test/sql/test_defaults.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/sql/test_defaults.py Sat Apr 27 19:42:17 2013 -0400 -@@ -600,7 +600,7 @@ - nonai.insert().execute(data='row 1') - nonai.insert().execute(data='row 2') - assert False -- except sa.exc.DBAPIError, e: -+ except sa.exc.DBAPIError as e: - assert True - - nonai.insert().execute(id=1, data='row 1') -@@ -649,7 +649,7 @@ - def _assert_seq_result(self, ret): - """asserts return of next_value is an int""" - -- assert isinstance(ret, (int, long)) -+ assert isinstance(ret, int) - assert ret > 0 - - def test_implicit_connectionless(self): -@@ -781,7 +781,7 @@ - ] - start = seq.start or 1 - inc = seq.increment or 1 -- assert values == list(xrange(start, start + inc * 3, inc)) -+ assert values == list(range(start, start + inc * 3, inc)) - - finally: - seq.drop(testing.db) -@@ -1156,20 +1156,22 @@ - c = Column(Unicode(32)) - - def test_unicode_default(self): -- # Py3K -- #default = 'foo' -- # Py2K -- default = u'foo' -- # end Py2K -+# start Py3K -+ default = 'foo' -+# end Py3K -+# start Py2K -+# default = u'foo' -+# end Py2K - c = Column(Unicode(32), default=default) - - - def test_nonunicode_default(self): -- # Py3K -- #default = b'foo' -- # Py2K -- default = 'foo' -- # end Py2K -+# start Py3K -+ default = b'foo' -+# end Py3K -+# start Py2K -+# default = 'foo' -+# end Py2K - assert_raises_message( - sa.exc.SAWarning, - "Unicode column received non-unicode default value.", -diff -r 9d0639b9d3be test/sql/test_functions.py ---- a/test/sql/test_functions.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/sql/test_functions.py Sat Apr 27 19:42:17 2013 -0400 -@@ -381,7 +381,7 @@ - assert t.select(t.c.id == id).execute().first()['value'] == 9 - t.update(values={t.c.value: func.length("asdf")}).execute() - assert t.select().execute().first()['value'] == 4 -- print "--------------------------" -+ print("--------------------------") - t2.insert().execute() - t2.insert(values=dict(value=func.length("one"))).execute() - t2.insert(values=dict(value=func.length("asfda") + -19)).\ -@@ -409,7 +409,7 @@ - - t2.update(values={t2.c.value: func.length("asfdaasdf"), - t2.c.stuff: "foo"}).execute() -- print "HI", select([t2.c.value, t2.c.stuff]).execute().first() -+ print("HI", select([t2.c.value, t2.c.stuff]).execute().first()) - eq_(select([t2.c.value, t2.c.stuff]).execute().first(), - (9, "foo") - ) -diff -r 9d0639b9d3be test/sql/test_generative.py ---- a/test/sql/test_generative.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/sql/test_generative.py Sat Apr 27 19:42:17 2013 -0400 -@@ -176,7 +176,7 @@ - canary = [] - def visit(binary, l, r): - canary.append((binary.operator, l, r)) -- print binary.operator, l, r -+ print(binary.operator, l, r) - sql_util.visit_binary_product(visit, expr) - eq_( - canary, expected -@@ -433,7 +433,7 @@ - clause2 = Vis().traverse(clause) - assert c1 == str(clause) - assert str(clause2) == c1 + " SOME MODIFIER=:lala" -- assert clause.bindparams.keys() == ['bar'] -+ assert list(clause.bindparams.keys()) == ['bar'] - assert set(clause2.bindparams.keys()) == set(['bar', 'lala']) - - def test_select(self): -@@ -446,8 +446,8 @@ - s3 = Vis().traverse(s2) - assert str(s3) == s3_assert - assert str(s2) == s2_assert -- print str(s2) -- print str(s3) -+ print(str(s2)) -+ print(str(s3)) - class Vis(ClauseVisitor): - def visit_select(self, select): - select.append_whereclause(t1.c.col2 == 7) -@@ -459,8 +459,8 @@ - def visit_select(self, select): - select.append_whereclause(t1.c.col3 == 9) - s4 = Vis().traverse(s3) -- print str(s3) -- print str(s4) -+ print(str(s3)) -+ print(str(s4)) - assert str(s4) == s4_assert - assert str(s3) == s3_assert - -@@ -471,8 +471,8 @@ - binary.left = t1.c.col1 - binary.right = bindparam("col1", unique=True) - s5 = Vis().traverse(s4) -- print str(s4) -- print str(s5) -+ print(str(s4)) -+ print(str(s5)) - assert str(s5) == s5_assert - assert str(s4) == s4_assert - -diff -r 9d0639b9d3be test/sql/test_metadata.py ---- a/test/sql/test_metadata.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/sql/test_metadata.py Sat Apr 27 19:42:17 2013 -0400 -@@ -89,7 +89,7 @@ - msgs.append("attach %s.%s" % (t.name, c.name)) - c1 = Column('foo', String()) - m = MetaData() -- for i in xrange(3): -+ for i in range(3): - cx = c1.copy() - # as of 0.7, these events no longer copy. its expected - # that listeners will be re-established from the -@@ -511,7 +511,7 @@ - def _get_key(i): - return [i.name, i.unique] + \ - sorted(i.kwargs.items()) + \ -- i.columns.keys() -+ list(i.columns.keys()) - - eq_( - sorted([_get_key(i) for i in table.indexes]), -diff -r 9d0639b9d3be test/sql/test_query.py ---- a/test/sql/test_query.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/sql/test_query.py Sat Apr 27 19:42:17 2013 -0400 -@@ -367,10 +367,10 @@ - ) - if use_labels: - eq_(result[0]['query_users_user_id'], 7) -- eq_(result[0].keys(), ["query_users_user_id", "query_users_user_name"]) -+ eq_(list(result[0].keys()), ["query_users_user_id", "query_users_user_name"]) - else: - eq_(result[0]['user_id'], 7) -- eq_(result[0].keys(), ["user_id", "user_name"]) -+ eq_(list(result[0].keys()), ["user_id", "user_name"]) - - eq_(result[0][0], 7) - eq_(result[0][users.c.user_id], 7) -@@ -523,13 +523,13 @@ - - def a_eq(got, wanted): - if got != wanted: -- print "Wanted %s" % wanted -- print "Received %s" % got -+ print("Wanted %s" % wanted) -+ print("Received %s" % got) - self.assert_(got == wanted, got) - - a_eq(prep('select foo'), 'select foo') - a_eq(prep("time='12:30:00'"), "time='12:30:00'") -- a_eq(prep(u"time='12:30:00'"), u"time='12:30:00'") -+ a_eq(prep("time='12:30:00'"), "time='12:30:00'") - a_eq(prep(":this:that"), ":this:that") - a_eq(prep(":this :that"), "? ?") - a_eq(prep("(:this),(:that :other)"), "(?),(? ?)") -@@ -769,7 +769,7 @@ - ).first() - eq_(r['user_id'], 1) - eq_(r['user_name'], "john") -- eq_(r.keys(), ["user_id", "user_name"]) -+ eq_(list(r.keys()), ["user_id", "user_name"]) - - @testing.only_on("sqlite", "sqlite specific feature") - def test_column_accessor_sqlite_raw(self): -@@ -784,7 +784,7 @@ - assert 'user_name' not in r - eq_(r['query_users.user_id'], 1) - eq_(r['query_users.user_name'], "john") -- eq_(r.keys(), ["query_users.user_id", "query_users.user_name"]) -+ eq_(list(r.keys()), ["query_users.user_id", "query_users.user_name"]) - - @testing.only_on("sqlite", "sqlite specific feature") - def test_column_accessor_sqlite_translated(self): -@@ -799,7 +799,7 @@ - eq_(r['user_name'], "john") - eq_(r['query_users.user_id'], 1) - eq_(r['query_users.user_name'], "john") -- eq_(r.keys(), ["user_id", "user_name"]) -+ eq_(list(r.keys()), ["user_id", "user_name"]) - - def test_column_accessor_labels_w_dots(self): - users.insert().execute( -@@ -812,7 +812,7 @@ - eq_(r['query_users.user_id'], 1) - eq_(r['query_users.user_name'], "john") - assert "user_name" not in r -- eq_(r.keys(), ["query_users.user_id", "query_users.user_name"]) -+ eq_(list(r.keys()), ["query_users.user_id", "query_users.user_name"]) - - def test_column_accessor_unary(self): - users.insert().execute( -@@ -889,7 +889,7 @@ - ]) - ).first() - -- eq_(row.keys(), ["case_insensitive", "CaseSensitive"]) -+ eq_(list(row.keys()), ["case_insensitive", "CaseSensitive"]) - eq_(row["case_insensitive"], 1) - eq_(row["CaseSensitive"], 2) - -@@ -911,7 +911,7 @@ - ]) - ).first() - -- eq_(row.keys(), ["case_insensitive", "CaseSensitive"]) -+ eq_(list(row.keys()), ["case_insensitive", "CaseSensitive"]) - eq_(row["case_insensitive"], 1) - eq_(row["CaseSensitive"], 2) - eq_(row["Case_insensitive"],1) -@@ -1072,14 +1072,14 @@ - def test_keys(self): - users.insert().execute(user_id=1, user_name='foo') - r = users.select().execute() -- eq_([x.lower() for x in r.keys()], ['user_id', 'user_name']) -+ eq_([x.lower() for x in list(r.keys())], ['user_id', 'user_name']) - r = r.first() -- eq_([x.lower() for x in r.keys()], ['user_id', 'user_name']) -+ eq_([x.lower() for x in list(r.keys())], ['user_id', 'user_name']) - - def test_items(self): - users.insert().execute(user_id=1, user_name='foo') - r = users.select().execute().first() -- eq_([(x[0].lower(), x[1]) for x in r.items()], [('user_id', 1), ('user_name', 'foo')]) -+ eq_([(x[0].lower(), x[1]) for x in list(r.items())], [('user_id', 1), ('user_name', 'foo')]) - - def test_len(self): - users.insert().execute(user_id=1, user_name='foo') -@@ -1098,8 +1098,8 @@ - r = users.select(users.c.user_id==1).execute().first() - eq_(r[0], 1) - eq_(r[1], 'foo') -- eq_([x.lower() for x in r.keys()], ['user_id', 'user_name']) -- eq_(r.values(), [1, 'foo']) -+ eq_([x.lower() for x in list(r.keys())], ['user_id', 'user_name']) -+ eq_(list(r.values()), [1, 'foo']) - - def test_column_order_with_text_query(self): - # should return values in query order -@@ -1107,8 +1107,8 @@ - r = testing.db.execute('select user_name, user_id from query_users').first() - eq_(r[0], 'foo') - eq_(r[1], 1) -- eq_([x.lower() for x in r.keys()], ['user_name', 'user_id']) -- eq_(r.values(), ['foo', 1]) -+ eq_([x.lower() for x in list(r.keys())], ['user_name', 'user_id']) -+ eq_(list(r.values()), ['foo', 1]) - - @testing.crashes('oracle', 'FIXME: unknown, varify not fails_on()') - @testing.crashes('firebird', 'An identifier must begin with a letter') -@@ -1137,7 +1137,7 @@ - self.assert_(r['_parent'] == 'Hidden parent') - self.assert_(r['_row'] == 'Hidden row') - try: -- print r._parent, r._row -+ print(r._parent, r._row) - self.fail('Should not allow access to private attributes') - except AttributeError: - pass # expected -@@ -2334,7 +2334,7 @@ - expr = select( - [t1.c.t1_id, t2.c.t2_id, t3.c.t3_id], - from_obj=[(t1.join(t2).outerjoin(t3, criteria))]) -- print expr -+ print(expr) - self.assertRows(expr, [(10, 20, 30), (11, 21, None)]) - - def test_mixed_where(self): -@@ -2416,7 +2416,7 @@ - select([ - flds.c.intcol, func.row_number().over(order_by=flds.c.strcol) - ]).execute().fetchall(), -- [(13, 1L), (5, 2L)] -+ [(13, 1), (5, 2)] - ) - - -diff -r 9d0639b9d3be test/sql/test_quote.py ---- a/test/sql/test_quote.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/sql/test_quote.py Sat Apr 27 19:42:17 2013 -0400 -@@ -552,8 +552,8 @@ - - def a_eq(have, want): - if have != want: -- print "Wanted %s" % want -- print "Received %s" % have -+ print("Wanted %s" % want) -+ print("Received %s" % have) - self.assert_(have == want) - - a_eq(unformat('foo'), ['foo']) -@@ -584,13 +584,13 @@ - - def a_eq(have, want): - if have != want: -- print "Wanted %s" % want -- print "Received %s" % have -+ print("Wanted %s" % want) -+ print("Received %s" % have) - self.assert_(have == want) - - a_eq(unformat('foo'), ['foo']) - a_eq(unformat('`foo`'), ['foo']) -- a_eq(unformat(`'foo'`), ["'foo'"]) -+ a_eq(unformat(repr('foo')), ["'foo'"]) - a_eq(unformat('foo.bar'), ['foo', 'bar']) - a_eq(unformat('`foo`.`bar`'), ['foo', 'bar']) - a_eq(unformat('foo.`bar`'), ['foo', 'bar']) -diff -r 9d0639b9d3be test/sql/test_rowcount.py ---- a/test/sql/test_rowcount.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/sql/test_rowcount.py Sat Apr 27 19:42:17 2013 -0400 -@@ -53,20 +53,20 @@ - # WHERE matches 3, 3 rows changed - department = employees_table.c.department - r = employees_table.update(department=='C').execute(department='Z') -- print "expecting 3, dialect reports %s" % r.rowcount -+ print("expecting 3, dialect reports %s" % r.rowcount) - assert r.rowcount == 3 - - def test_update_rowcount2(self): - # WHERE matches 3, 0 rows changed - department = employees_table.c.department - r = employees_table.update(department=='C').execute(department='C') -- print "expecting 3, dialect reports %s" % r.rowcount -+ print("expecting 3, dialect reports %s" % r.rowcount) - assert r.rowcount == 3 - - def test_delete_rowcount(self): - # WHERE matches 3, 3 rows deleted - department = employees_table.c.department - r = employees_table.delete(department=='C').execute() -- print "expecting 3, dialect reports %s" % r.rowcount -+ print("expecting 3, dialect reports %s" % r.rowcount) - assert r.rowcount == 3 - -diff -r 9d0639b9d3be test/sql/test_selectable.py ---- a/test/sql/test_selectable.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/sql/test_selectable.py Sat Apr 27 19:42:17 2013 -0400 -@@ -174,11 +174,11 @@ - - def test_clone_append_column(self): - sel = select([literal_column('1').label('a')]) -- eq_(sel.c.keys(), ['a']) -+ eq_(list(sel.c.keys()), ['a']) - cloned = visitors.ReplacingCloningVisitor().traverse(sel) - cloned.append_column(literal_column('2').label('b')) - cloned.append_column(func.foo()) -- eq_(cloned.c.keys(), ['a', 'b', 'foo()']) -+ eq_(list(cloned.c.keys()), ['a', 'b', 'foo()']) - - def test_append_column_after_replace_selectable(self): - basesel = select([literal_column('1').label('a')]) -@@ -362,10 +362,10 @@ - - def test_join(self): - a = join(table1, table2) -- print str(a.select(use_labels=True)) -+ print(str(a.select(use_labels=True))) - b = table2.alias('b') - j = join(a, b) -- print str(j) -+ print(str(j)) - criterion = a.c.table1_col1 == b.c.col2 - self.assert_(criterion.compare(j.onclause)) - -@@ -949,7 +949,7 @@ - primary_key=True), Column('x', Integer)) - d = Table('d', meta, Column('id', Integer, ForeignKey('c.id'), - primary_key=True), Column('x', Integer)) -- print list(a.join(b, a.c.x == b.c.id).primary_key) -+ print(list(a.join(b, a.c.x == b.c.id).primary_key)) - assert list(a.join(b, a.c.x == b.c.id).primary_key) == [a.c.id] - assert list(b.join(c, b.c.x == c.c.id).primary_key) == [b.c.id] - assert list(a.join(b).join(c, c.c.id == b.c.x).primary_key) \ -@@ -1618,7 +1618,7 @@ - def test_names_overlap_label(self): - sel = self._names_overlap().apply_labels() - eq_( -- sel.c.keys(), -+ list(sel.c.keys()), - ['t1_x', 't2_x'] - ) - self._assert_result_keys(sel, ['t1_x', 't2_x']) -@@ -1632,7 +1632,7 @@ - def test_names_overlap_keys_dont_nolabel(self): - sel = self._names_overlap_keys_dont() - eq_( -- sel.c.keys(), -+ list(sel.c.keys()), - ['a', 'b'] - ) - self._assert_result_keys(sel, ['x']) -@@ -1640,7 +1640,7 @@ - def test_names_overlap_keys_dont_label(self): - sel = self._names_overlap_keys_dont().apply_labels() - eq_( -- sel.c.keys(), -+ list(sel.c.keys()), - ['t1_a', 't2_b'] - ) - self._assert_result_keys(sel, ['t1_x', 't2_x']) -@@ -1654,7 +1654,7 @@ - def test_labels_overlap_nolabel(self): - sel = self._labels_overlap() - eq_( -- sel.c.keys(), -+ list(sel.c.keys()), - ['x_id', 'id'] - ) - self._assert_result_keys(sel, ['x_id', 'id']) -@@ -1663,7 +1663,7 @@ - sel = self._labels_overlap().apply_labels() - t2 = sel.froms[1] - eq_( -- sel.c.keys(), -+ list(sel.c.keys()), - ['t_x_id', t2.c.id.anon_label] - ) - self._assert_result_keys(sel, ['t_x_id', 'id_1']) -@@ -1677,12 +1677,12 @@ - - def test_labels_overlap_keylabels_dont_nolabel(self): - sel = self._labels_overlap_keylabels_dont() -- eq_(sel.c.keys(), ['a', 'b']) -+ eq_(list(sel.c.keys()), ['a', 'b']) - self._assert_result_keys(sel, ['x_id', 'id']) - - def test_labels_overlap_keylabels_dont_label(self): - sel = self._labels_overlap_keylabels_dont().apply_labels() -- eq_(sel.c.keys(), ['t_a', 't_x_b']) -+ eq_(list(sel.c.keys()), ['t_a', 't_x_b']) - self._assert_result_keys(sel, ['t_x_id', 'id_1']) - - def _keylabels_overlap_labels_dont(self): -@@ -1693,13 +1693,13 @@ - - def test_keylabels_overlap_labels_dont_nolabel(self): - sel = self._keylabels_overlap_labels_dont() -- eq_(sel.c.keys(), ['x_id', 'id']) -+ eq_(list(sel.c.keys()), ['x_id', 'id']) - self._assert_result_keys(sel, ['a', 'b']) - - def test_keylabels_overlap_labels_dont_label(self): - sel = self._keylabels_overlap_labels_dont().apply_labels() - t2 = sel.froms[1] -- eq_(sel.c.keys(), ['t_x_id', t2.c.id.anon_label]) -+ eq_(list(sel.c.keys()), ['t_x_id', t2.c.id.anon_label]) - self._assert_result_keys(sel, ['t_a', 't_x_b']) - self._assert_subq_result_keys(sel, ['t_a', 't_x_b']) - -@@ -1711,14 +1711,14 @@ - - def test_keylabels_overlap_labels_overlap_nolabel(self): - sel = self._keylabels_overlap_labels_overlap() -- eq_(sel.c.keys(), ['x_a', 'a']) -+ eq_(list(sel.c.keys()), ['x_a', 'a']) - self._assert_result_keys(sel, ['x_id', 'id']) - self._assert_subq_result_keys(sel, ['x_id', 'id']) - - def test_keylabels_overlap_labels_overlap_label(self): - sel = self._keylabels_overlap_labels_overlap().apply_labels() - t2 = sel.froms[1] -- eq_(sel.c.keys(), ['t_x_a', t2.c.a.anon_label]) -+ eq_(list(sel.c.keys()), ['t_x_a', t2.c.a.anon_label]) - self._assert_result_keys(sel, ['t_x_id', 'id_1']) - self._assert_subq_result_keys(sel, ['t_x_id', 'id_1']) - -@@ -1736,7 +1736,7 @@ - def test_keys_overlap_names_dont_label(self): - sel = self._keys_overlap_names_dont().apply_labels() - eq_( -- sel.c.keys(), -+ list(sel.c.keys()), - ['t1_x', 't2_x'] - ) - self._assert_result_keys(sel, ['t1_a', 't2_b']) -diff -r 9d0639b9d3be test/sql/test_types.py ---- a/test/sql/test_types.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/sql/test_types.py Sat Apr 27 19:42:17 2013 -0400 -@@ -141,22 +141,24 @@ - eq_(types.Integer().python_type, int) - eq_(types.Numeric().python_type, decimal.Decimal) - eq_(types.Numeric(asdecimal=False).python_type, float) -- # Py3K -- #eq_(types.LargeBinary().python_type, bytes) -- # Py2K -- eq_(types.LargeBinary().python_type, str) -- # end Py2K -+# start Py3K -+ eq_(types.LargeBinary().python_type, bytes) -+# end Py3K -+# start Py2K -+# eq_(types.LargeBinary().python_type, str) -+# end Py2K - eq_(types.Float().python_type, float) - eq_(types.Interval().python_type, datetime.timedelta) - eq_(types.Date().python_type, datetime.date) - eq_(types.DateTime().python_type, datetime.datetime) -- # Py3K -- #eq_(types.String().python_type, unicode) -- # Py2K -+# start Py3K - eq_(types.String().python_type, str) -- # end Py2K -- eq_(types.Unicode().python_type, unicode) -- eq_(types.String(convert_unicode=True).python_type, unicode) -+# end Py3K -+# start Py2K -+# eq_(types.String().python_type, str) -+# end Py2K -+ eq_(types.Unicode().python_type, str) -+ eq_(types.String(convert_unicode=True).python_type, str) - - assert_raises( - NotImplementedError, -@@ -257,14 +259,14 @@ - def test_processing(self): - users = self.tables.users - users.insert().execute( -- user_id=2, goofy='jack', goofy2='jack', goofy4=u'jack', -- goofy7=u'jack', goofy8=12, goofy9=12) -+ user_id=2, goofy='jack', goofy2='jack', goofy4='jack', -+ goofy7='jack', goofy8=12, goofy9=12) - users.insert().execute( -- user_id=3, goofy='lala', goofy2='lala', goofy4=u'lala', -- goofy7=u'lala', goofy8=15, goofy9=15) -+ user_id=3, goofy='lala', goofy2='lala', goofy4='lala', -+ goofy7='lala', goofy8=15, goofy9=15) - users.insert().execute( -- user_id=4, goofy='fred', goofy2='fred', goofy4=u'fred', -- goofy7=u'fred', goofy8=9, goofy9=9) -+ user_id=4, goofy='fred', goofy2='fred', goofy4='fred', -+ goofy7='fred', goofy8=9, goofy9=9) - - l = users.select().order_by(users.c.user_id).execute().fetchall() - for assertstr, assertint, assertint2, row in zip( -@@ -278,7 +280,7 @@ - eq_(row[5], assertint) - eq_(row[6], assertint2) - for col in row[3], row[4]: -- assert isinstance(col, unicode) -+ assert isinstance(col, str) - - def test_typedecorator_impl(self): - for impl_, exp, kw in [ -@@ -715,9 +717,9 @@ - expected - ) - -- data = u"Alors vous imaginez ma surprise, au lever du jour, quand "\ -- u"une drôle de petite voix m’a réveillé. "\ -- u"Elle disait: « S’il vous plaît… dessine-moi un mouton! »" -+ data = "Alors vous imaginez ma surprise, au lever du jour, quand "\ -+ "une drôle de petite voix m’a réveillé. "\ -+ "Elle disait: « S’il vous plaît… dessine-moi un mouton! »" - - def test_unicode_warnings_typelevel_native_unicode(self): - -@@ -726,13 +728,14 @@ - dialect = default.DefaultDialect() - dialect.supports_unicode_binds = True - uni = u.dialect_impl(dialect).bind_processor(dialect) -- # Py3K -- #assert_raises(exc.SAWarning, uni, b'x') -- #assert isinstance(uni(unicodedata), str) -- # Py2K -- assert_raises(exc.SAWarning, uni, 'x') -- assert isinstance(uni(unicodedata), unicode) -- # end Py2K -+# start Py3K -+ assert_raises(exc.SAWarning, uni, b'x') -+ assert isinstance(uni(unicodedata), str) -+# end Py3K -+# start Py2K -+# assert_raises(exc.SAWarning, uni, 'x') -+# assert isinstance(uni(unicodedata), unicode) -+# end Py2K - - def test_unicode_warnings_typelevel_sqla_unicode(self): - unicodedata = self.data -@@ -740,13 +743,14 @@ - dialect = default.DefaultDialect() - dialect.supports_unicode_binds = False - uni = u.dialect_impl(dialect).bind_processor(dialect) -- # Py3K -- #assert_raises(exc.SAWarning, uni, b'x') -- #assert isinstance(uni(unicodedata), bytes) -- # Py2K -- assert_raises(exc.SAWarning, uni, 'x') -- assert isinstance(uni(unicodedata), str) -- # end Py2K -+# start Py3K -+ assert_raises(exc.SAWarning, uni, b'x') -+ assert isinstance(uni(unicodedata), bytes) -+# end Py3K -+# start Py2K -+# assert_raises(exc.SAWarning, uni, 'x') -+# assert isinstance(uni(unicodedata), str) -+# end Py2K - - eq_(uni(unicodedata), unicodedata.encode('utf-8')) - -@@ -760,13 +764,14 @@ - s = String() - uni = s.dialect_impl(dialect).bind_processor(dialect) - # this is not the unicode type - no warning -- # Py3K -- #uni(b'x') -- #assert isinstance(uni(unicodedata), bytes) -- # Py2K -- uni('x') -- assert isinstance(uni(unicodedata), str) -- # end Py2K -+# start Py3K -+ uni(b'x') -+ assert isinstance(uni(unicodedata), bytes) -+# end Py3K -+# start Py2K -+# uni('x') -+# assert isinstance(uni(unicodedata), str) -+# end Py2K - - eq_(uni(unicodedata), unicodedata.encode('utf-8')) - -@@ -1366,7 +1371,7 @@ - metadata = self.metadata - t = self._fixture(metadata, Integer, 45) - val = testing.db.execute("select val from t").scalar() -- assert isinstance(val, (int, long)) -+ assert isinstance(val, int) - eq_(val, 45) - - @testing.provide_metadata -diff -r 9d0639b9d3be test/sql/test_unicode.py ---- a/test/sql/test_unicode.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/sql/test_unicode.py Sat Apr 27 19:42:17 2013 -0400 -@@ -19,13 +19,13 @@ - - metadata = MetaData(unicode_bind) - t1 = Table('unitable1', metadata, -- Column(u'méil', Integer, primary_key=True), -- Column(u'\u6e2c\u8a66', Integer), -+ Column('méil', Integer, primary_key=True), -+ Column('\u6e2c\u8a66', Integer), - test_needs_fk=True, - ) -- t2 = Table(u'Unitéble2', metadata, -- Column(u'méil', Integer, primary_key=True, key="a"), -- Column(u'\u6e2c\u8a66', Integer, ForeignKey(u'unitable1.méil'), -+ t2 = Table('Unitéble2', metadata, -+ Column('méil', Integer, primary_key=True, key="a"), -+ Column('\u6e2c\u8a66', Integer, ForeignKey('unitable1.méil'), - key="b" - ), - test_needs_fk=True, -@@ -33,27 +33,27 @@ - - # Few DBs support Unicode foreign keys - if testing.against('sqlite'): -- t3 = Table(u'\u6e2c\u8a66', metadata, -- Column(u'\u6e2c\u8a66_id', Integer, primary_key=True, -+ t3 = Table('\u6e2c\u8a66', metadata, -+ Column('\u6e2c\u8a66_id', Integer, primary_key=True, - autoincrement=False), -- Column(u'unitable1_\u6e2c\u8a66', Integer, -- ForeignKey(u'unitable1.\u6e2c\u8a66') -+ Column('unitable1_\u6e2c\u8a66', Integer, -+ ForeignKey('unitable1.\u6e2c\u8a66') - ), -- Column(u'Unitéble2_b', Integer, -- ForeignKey(u'Unitéble2.b') -+ Column('Unitéble2_b', Integer, -+ ForeignKey('Unitéble2.b') - ), -- Column(u'\u6e2c\u8a66_self', Integer, -- ForeignKey(u'\u6e2c\u8a66.\u6e2c\u8a66_id') -+ Column('\u6e2c\u8a66_self', Integer, -+ ForeignKey('\u6e2c\u8a66.\u6e2c\u8a66_id') - ), - test_needs_fk=True, - ) - else: -- t3 = Table(u'\u6e2c\u8a66', metadata, -- Column(u'\u6e2c\u8a66_id', Integer, primary_key=True, -+ t3 = Table('\u6e2c\u8a66', metadata, -+ Column('\u6e2c\u8a66_id', Integer, primary_key=True, - autoincrement=False), -- Column(u'unitable1_\u6e2c\u8a66', Integer), -- Column(u'Unitéble2_b', Integer), -- Column(u'\u6e2c\u8a66_self', Integer), -+ Column('unitable1_\u6e2c\u8a66', Integer), -+ Column('Unitéble2_b', Integer), -+ Column('\u6e2c\u8a66_self', Integer), - test_needs_fk=True, - ) - metadata.create_all() -@@ -72,42 +72,42 @@ - del unicode_bind - - def test_insert(self): -- t1.insert().execute({u'méil':1, u'\u6e2c\u8a66':5}) -+ t1.insert().execute({'méil':1, '\u6e2c\u8a66':5}) - t2.insert().execute({'a':1, 'b':1}) -- t3.insert().execute({u'\u6e2c\u8a66_id': 1, -- u'unitable1_\u6e2c\u8a66': 5, -- u'Unitéble2_b': 1, -- u'\u6e2c\u8a66_self': 1}) -+ t3.insert().execute({'\u6e2c\u8a66_id': 1, -+ 'unitable1_\u6e2c\u8a66': 5, -+ 'Unitéble2_b': 1, -+ '\u6e2c\u8a66_self': 1}) - - assert t1.select().execute().fetchall() == [(1, 5)] - assert t2.select().execute().fetchall() == [(1, 1)] - assert t3.select().execute().fetchall() == [(1, 5, 1, 1)] - - def test_reflect(self): -- t1.insert().execute({u'méil':2, u'\u6e2c\u8a66':7}) -+ t1.insert().execute({'méil':2, '\u6e2c\u8a66':7}) - t2.insert().execute({'a':2, 'b':2}) -- t3.insert().execute({u'\u6e2c\u8a66_id': 2, -- u'unitable1_\u6e2c\u8a66': 7, -- u'Unitéble2_b': 2, -- u'\u6e2c\u8a66_self': 2}) -+ t3.insert().execute({'\u6e2c\u8a66_id': 2, -+ 'unitable1_\u6e2c\u8a66': 7, -+ 'Unitéble2_b': 2, -+ '\u6e2c\u8a66_self': 2}) - - meta = MetaData(unicode_bind) - tt1 = Table(t1.name, meta, autoload=True) - tt2 = Table(t2.name, meta, autoload=True) - tt3 = Table(t3.name, meta, autoload=True) - -- tt1.insert().execute({u'méil':1, u'\u6e2c\u8a66':5}) -- tt2.insert().execute({u'méil':1, u'\u6e2c\u8a66':1}) -- tt3.insert().execute({u'\u6e2c\u8a66_id': 1, -- u'unitable1_\u6e2c\u8a66': 5, -- u'Unitéble2_b': 1, -- u'\u6e2c\u8a66_self': 1}) -+ tt1.insert().execute({'méil':1, '\u6e2c\u8a66':5}) -+ tt2.insert().execute({'méil':1, '\u6e2c\u8a66':1}) -+ tt3.insert().execute({'\u6e2c\u8a66_id': 1, -+ 'unitable1_\u6e2c\u8a66': 5, -+ 'Unitéble2_b': 1, -+ '\u6e2c\u8a66_self': 1}) - -- self.assert_(tt1.select(order_by=desc(u'méil')).execute().fetchall() == -+ self.assert_(tt1.select(order_by=desc('méil')).execute().fetchall() == - [(2, 7), (1, 5)]) -- self.assert_(tt2.select(order_by=desc(u'méil')).execute().fetchall() == -+ self.assert_(tt2.select(order_by=desc('méil')).execute().fetchall() == - [(2, 2), (1, 1)]) -- self.assert_(tt3.select(order_by=desc(u'\u6e2c\u8a66_id')). -+ self.assert_(tt3.select(order_by=desc('\u6e2c\u8a66_id')). - execute().fetchall() == - [(2, 7, 2, 2), (1, 5, 1, 1)]) - meta.drop_all() -@@ -117,7 +117,7 @@ - def test_default_exec(self): - metadata = MetaData(testing.db) - t1 = Table('t1', metadata, -- Column(u'special_col', Integer, Sequence('special_col'), primary_key=True), -+ Column('special_col', Integer, Sequence('special_col'), primary_key=True), - Column('data', String(50)) # to appease SQLite without DEFAULT VALUES - ) - metadata.create_all() -@@ -128,8 +128,8 @@ - # reset the identifier preparer, so that we can force it to cache - # a unicode identifier - engine.dialect.identifier_preparer = engine.dialect.preparer(engine.dialect) -- select([column(u'special_col')]).select_from(t1).execute().close() -- assert isinstance(engine.dialect.identifier_preparer.format_sequence(Sequence('special_col')), unicode) -+ select([column('special_col')]).select_from(t1).execute().close() -+ assert isinstance(engine.dialect.identifier_preparer.format_sequence(Sequence('special_col')), str) - - # now execute, run the sequence. it should run in u"Special_col.nextid" or similar as - # a unicode object; cx_oracle asserts that this is None or a String (postgresql lets it pass thru). -diff -r 9d0639b9d3be test/sql/test_update.py ---- a/test/sql/test_update.py Sat Apr 27 17:51:52 2013 -0400 -+++ b/test/sql/test_update.py Sat Apr 27 19:42:17 2013 -0400 -@@ -242,7 +242,7 @@ - 'WHERE ' - 'users.id = addresses.user_id AND ' - 'addresses.email_address = :email_address_1', -- checkparams={u'email_address_1': 'e1', 'name': 'newname'}) -+ checkparams={'email_address_1': 'e1', 'name': 'newname'}) - - def test_render_multi_table(self): - users = self.tables.users -@@ -250,8 +250,8 @@ - dingalings = self.tables.dingalings - - checkparams = { -- u'email_address_1': 'e1', -- u'id_1': 2, -+ 'email_address_1': 'e1', -+ 'id_1': 2, - 'name': 'newname' - } - -@@ -285,15 +285,15 @@ - 'WHERE ' - 'users.id = addresses.user_id AND ' - 'addresses.email_address = %s', -- checkparams={u'email_address_1': 'e1', 'name': 'newname'}, -+ checkparams={'email_address_1': 'e1', 'name': 'newname'}, - dialect=mysql.dialect()) - - def test_render_subquery(self): - users, addresses = self.tables.users, self.tables.addresses - - checkparams = { -- u'email_address_1': 'e1', -- u'id_1': 7, -+ 'email_address_1': 'e1', -+ 'id_1': 7, - 'name': 'newname' - } - -- cgit v1.2.1 From 61c796786cb222cfdca611395d8550973fc3f8d5 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 May 2013 18:23:26 -0400 Subject: do a sweep of some obvious 3kisms --- lib/sqlalchemy/engine/reflection.py | 11 ++++---- lib/sqlalchemy/engine/result.py | 2 -- lib/sqlalchemy/engine/url.py | 2 +- lib/sqlalchemy/ext/associationproxy.py | 43 +++++++++++++++++++------------ lib/sqlalchemy/orm/identity.py | 46 ++++++++++++++++------------------ lib/sqlalchemy/util/__init__.py | 2 +- lib/sqlalchemy/util/compat.py | 2 ++ 7 files changed, 57 insertions(+), 51 deletions(-) diff --git a/lib/sqlalchemy/engine/reflection.py b/lib/sqlalchemy/engine/reflection.py index 4b2987851..cf2caf679 100644 --- a/lib/sqlalchemy/engine/reflection.py +++ b/lib/sqlalchemy/engine/reflection.py @@ -389,12 +389,11 @@ class Inspector(object): del tblkw[k] tblkw[str(k)] = v -# start Py2K -# if isinstance(schema, str): -# schema = schema.decode(dialect.encoding) -# if isinstance(table_name, str): -# table_name = table_name.decode(dialect.encoding) -# end Py2K + if util.py2k: + if isinstance(schema, str): + schema = schema.decode(dialect.encoding) + if isinstance(table_name, str): + table_name = table_name.decode(dialect.encoding) # columns found_table = False diff --git a/lib/sqlalchemy/engine/result.py b/lib/sqlalchemy/engine/result.py index 4261a5877..65ce3b742 100644 --- a/lib/sqlalchemy/engine/result.py +++ b/lib/sqlalchemy/engine/result.py @@ -215,8 +215,6 @@ class ResultMetaData(object): processors.append(processor) rec = (processor, obj, i) -# name.encode('ascii') - # indexes as keys. This is only needed for the Python version of # RowProxy (the C version uses a faster path for integer indexes). primary_keymap[i] = rec diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py index b7d56374e..ed5729eea 100644 --- a/lib/sqlalchemy/engine/url.py +++ b/lib/sqlalchemy/engine/url.py @@ -149,7 +149,7 @@ def make_url(name_or_url): existing URL object is passed, just returns the object. """ - if isinstance(name_or_url, str): + if isinstance(name_or_url, util.string_types): return _parse_rfc1738_args(name_or_url) else: return name_or_url diff --git a/lib/sqlalchemy/ext/associationproxy.py b/lib/sqlalchemy/ext/associationproxy.py index e0a867e5a..39f8a7cf6 100644 --- a/lib/sqlalchemy/ext/associationproxy.py +++ b/lib/sqlalchemy/ext/associationproxy.py @@ -571,7 +571,7 @@ class _AssociationList(_AssociationCollection): def count(self, value): return sum([1 for _ in - filter(lambda v: v == value, iter(self))]) + util.itertools_filter(lambda v: v == value, iter(self))]) def extend(self, values): for v in values: @@ -740,7 +740,7 @@ class _AssociationDict(_AssociationCollection): return cmp(dict(self), other) def __repr__(self): - return repr(dict(list(self.items()))) + return repr(dict(self.items())) def get(self, key, default=None): try: @@ -756,26 +756,35 @@ class _AssociationDict(_AssociationCollection): return self[key] def keys(self): - return list(self.col.keys()) + return self.col.keys() - def iterkeys(self): - return iter(self.col.keys()) - - def values(self): - return [self._get(member) for member in list(self.col.values())] + def _iteritems(self): + for key in self.col: + yield (key, self._get(self.col[key])) + raise StopIteration - def itervalues(self): + def _itervalues(self): for key in self.col: yield self._get(self.col[key]) raise StopIteration - def items(self): - return [(k, self._get(self.col[k])) for k in self] + def _iterkeys(self): + return self.col.iterkeys() - def iteritems(self): - for key in self.col: - yield (key, self._get(self.col[key])) - raise StopIteration + + if util.py2k: + iterkeys = _iterkeys + itervalues = _itervalues + iteritems = _iteritems + + def values(self): + return [self._get(member) for member in list(self.col.values())] + + def items(self): + return [(k, self._get(self.col[k])) for k in self] + else: + values = _itervalues + items = _iteritems def pop(self, key, default=_NotProvided): if default is _NotProvided: @@ -813,7 +822,7 @@ class _AssociationDict(_AssociationCollection): self[key] = value def copy(self): - return dict(list(self.items())) + return dict(self.items()) def __hash__(self): raise TypeError("%s objects are unhashable" % type(self).__name__) @@ -846,6 +855,8 @@ class _AssociationSet(_AssociationCollection): else: return False + __nonzero__ = __bool__ + def __contains__(self, value): for member in self.col: # testlib.pragma exempt:__eq__ diff --git a/lib/sqlalchemy/orm/identity.py b/lib/sqlalchemy/orm/identity.py index f010a7699..55a78066a 100644 --- a/lib/sqlalchemy/orm/identity.py +++ b/lib/sqlalchemy/orm/identity.py @@ -6,7 +6,7 @@ import weakref from . import attributes - +from .. import util class IdentityMap(dict): def __init__(self): @@ -152,32 +152,28 @@ class WeakInstanceDict(IdentityMap): return result -# start Py3K - def items(self): - return iter(self._items()) - - def values(self): - return iter(self._values()) -# end Py3K -# start Py2K -# items = _items -# -# def iteritems(self): -# return iter(self.items()) -# -# values = _values -# -# def itervalues(self): -# return iter(self.values()) -# end Py2K + if util.py2k: + items = _items + + def iteritems(self): + return iter(self.items()) + + values = _values + + def itervalues(self): + return iter(self.values()) + else: + def items(self): + return iter(self._items()) + + def values(self): + return iter(self._values()) def all_states(self): -# start Py3K - return list(dict.values(self)) -# end Py3K -# start Py2K -# return dict.values(self) -# end Py2K + if util.py2k: + return dict.values(self) + else: + return list(dict.values(self)) def discard(self, state): st = dict.get(self, state.key, None) diff --git a/lib/sqlalchemy/util/__init__.py b/lib/sqlalchemy/util/__init__.py index d1fc8e8e5..9e099b072 100644 --- a/lib/sqlalchemy/util/__init__.py +++ b/lib/sqlalchemy/util/__init__.py @@ -9,7 +9,7 @@ from .compat import callable, cmp, reduce, \ pickle, dottedgetter, parse_qsl, namedtuple, next, WeakSet, reraise, \ raise_from_cause, text_type, string_types, int_types, binary_type, \ quote_plus, with_metaclass, print_, itertools_filterfalse, u, ue, b,\ - unquote_plus, b64decode, b64encode, byte_buffer + unquote_plus, b64decode, b64encode, byte_buffer, itertools_filter from ._collections import KeyedTuple, ImmutableContainer, immutabledict, \ Properties, OrderedProperties, ImmutableProperties, OrderedDict, \ diff --git a/lib/sqlalchemy/util/compat.py b/lib/sqlalchemy/util/compat.py index ea97999cf..182ab1c3d 100644 --- a/lib/sqlalchemy/util/compat.py +++ b/lib/sqlalchemy/util/compat.py @@ -75,6 +75,7 @@ if py3k: import itertools itertools_filterfalse = itertools.filterfalse + itertools_filter = filter itertools_imap = map import base64 @@ -135,6 +136,7 @@ else: import itertools itertools_filterfalse = itertools.ifilterfalse + itertools_filter = itertools.ifilter itertools_imap = itertools.imap -- cgit v1.2.1 From 29689fa566ba1bd3dc08727754632c9e8074137c Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 May 2013 18:25:43 -0400 Subject: fix the unicode test suite --- lib/sqlalchemy/testing/suite/test_types.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/sqlalchemy/testing/suite/test_types.py b/lib/sqlalchemy/testing/suite/test_types.py index 4dd3884ed..0d8bfdc0f 100644 --- a/lib/sqlalchemy/testing/suite/test_types.py +++ b/lib/sqlalchemy/testing/suite/test_types.py @@ -10,14 +10,15 @@ from ..schema import Table, Column from ... import testing import decimal import datetime - +from ...util import u +from ... import util class _UnicodeFixture(object): __requires__ = 'unicode_data', - data = "Alors vous imaginez ma surprise, au lever du jour, "\ + data = u("Alors vous imaginez ma surprise, au lever du jour, "\ "quand une drôle de petite voix m’a réveillé. Elle "\ - "disait: « S’il vous plaît… dessine-moi un mouton! »" + "disait: « S’il vous plaît… dessine-moi un mouton! »") @classmethod def define_tables(cls, metadata): @@ -47,7 +48,7 @@ class _UnicodeFixture(object): row, (self.data, ) ) - assert isinstance(row[0], str) + assert isinstance(row[0], util.text_type) def test_round_trip_executemany(self): unicode_table = self.tables.unicode_table @@ -72,19 +73,19 @@ class _UnicodeFixture(object): [(self.data, ) for i in range(3)] ) for row in rows: - assert isinstance(row[0], str) + assert isinstance(row[0], util.text_type) def _test_empty_strings(self): unicode_table = self.tables.unicode_table config.db.execute( unicode_table.insert(), - {"unicode_data": ''} + {"unicode_data": u('')} ) row = config.db.execute( select([unicode_table.c.unicode_data]) ).first() - eq_(row, ('',)) + eq_(row, (u(''),)) class UnicodeVarcharTest(_UnicodeFixture, fixtures.TablesTest): -- cgit v1.2.1 From 6cde27fe9161a21b075c7b8faa09d1e77169f1f2 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 May 2013 19:06:13 -0400 Subject: a pass where we try to squash down as many list()/keys() combinations as possible --- lib/sqlalchemy/__init__.py | 2 +- lib/sqlalchemy/engine/default.py | 2 +- lib/sqlalchemy/event.py | 2 +- lib/sqlalchemy/ext/associationproxy.py | 2 +- lib/sqlalchemy/ext/declarative/api.py | 2 +- lib/sqlalchemy/ext/declarative/base.py | 4 ++-- lib/sqlalchemy/ext/mutable.py | 4 ++-- lib/sqlalchemy/orm/attributes.py | 2 +- lib/sqlalchemy/orm/collections.py | 12 +++++----- lib/sqlalchemy/orm/persistence.py | 2 +- lib/sqlalchemy/orm/session.py | 8 +++---- lib/sqlalchemy/orm/state.py | 2 +- lib/sqlalchemy/orm/strategies.py | 2 +- lib/sqlalchemy/orm/unitofwork.py | 4 ++-- lib/sqlalchemy/pool.py | 2 +- lib/sqlalchemy/schema.py | 2 +- lib/sqlalchemy/sql/compiler.py | 4 ++-- lib/sqlalchemy/testing/engines.py | 42 ++++++++++++++++------------------ lib/sqlalchemy/testing/entities.py | 2 +- lib/sqlalchemy/testing/schema.py | 4 ++-- lib/sqlalchemy/util/_collections.py | 6 ++--- test/aaa_profiling/test_resultset.py | 5 ++-- 22 files changed, 58 insertions(+), 59 deletions(-) diff --git a/lib/sqlalchemy/__init__.py b/lib/sqlalchemy/__init__.py index 5b7123b6e..21e06f548 100644 --- a/lib/sqlalchemy/__init__.py +++ b/lib/sqlalchemy/__init__.py @@ -117,7 +117,7 @@ from .inspection import inspect from .engine import create_engine, engine_from_config -__all__ = sorted(name for name, obj in list(locals().items()) +__all__ = sorted(name for name, obj in locals().items() if not (name.startswith('_') or _inspect.ismodule(obj))) __version__ = '0.8.2' diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index e9645f363..85d11ff36 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -734,7 +734,7 @@ class DefaultExecutionContext(interfaces.ExecutionContext): e, None, None, None, self) else: inputsizes = {} - for key in list(self.compiled.bind_names.values()): + for key in self.compiled.bind_names.values(): typeengine = types[key] dbtype = typeengine.dialect_impl(self.dialect).\ get_dbapi_type(self.dialect.dbapi) diff --git a/lib/sqlalchemy/event.py b/lib/sqlalchemy/event.py index 33626cf2a..d8c44dd05 100644 --- a/lib/sqlalchemy/event.py +++ b/lib/sqlalchemy/event.py @@ -300,7 +300,7 @@ class _DispatchDescriptor(object): def clear(self): """Clear all class level listeners""" - for dispatcher in list(self._clslevel.values()): + for dispatcher in self._clslevel.values(): dispatcher[:] = [] def for_modify(self, obj): diff --git a/lib/sqlalchemy/ext/associationproxy.py b/lib/sqlalchemy/ext/associationproxy.py index 39f8a7cf6..08875c3a0 100644 --- a/lib/sqlalchemy/ext/associationproxy.py +++ b/lib/sqlalchemy/ext/associationproxy.py @@ -778,7 +778,7 @@ class _AssociationDict(_AssociationCollection): iteritems = _iteritems def values(self): - return [self._get(member) for member in list(self.col.values())] + return [self._get(member) for member in self.col.values()] def items(self): return [(k, self._get(self.col[k])) for k in self] diff --git a/lib/sqlalchemy/ext/declarative/api.py b/lib/sqlalchemy/ext/declarative/api.py index bc0c5a38c..2f222f682 100644 --- a/lib/sqlalchemy/ext/declarative/api.py +++ b/lib/sqlalchemy/ext/declarative/api.py @@ -424,7 +424,7 @@ class DeferredReflection(object): def prepare(cls, engine): """Reflect all :class:`.Table` objects for all current :class:`.DeferredReflection` subclasses""" - to_map = [m for m in list(_MapperConfig.configs.values()) + to_map = [m for m in _MapperConfig.configs.values() if issubclass(m.cls, cls)] for thingy in to_map: cls._sa_decl_prepare(thingy.local_table, engine) diff --git a/lib/sqlalchemy/ext/declarative/base.py b/lib/sqlalchemy/ext/declarative/base.py index 2099f9eb0..9187ed7f8 100644 --- a/lib/sqlalchemy/ext/declarative/base.py +++ b/lib/sqlalchemy/ext/declarative/base.py @@ -57,7 +57,7 @@ def _as_declarative(cls, classname, dict_): class_mapped = _declared_mapping_info(base) is not None - for name, obj in list(vars(base).items()): + for name, obj in vars(base).items(): if name == '__mapper_args__': if not mapper_args_fn and ( not class_mapped or @@ -129,7 +129,7 @@ def _as_declarative(cls, classname, dict_): ret.doc = obj.__doc__ # apply inherited columns as we should - for k, v in list(potential_columns.items()): + for k, v in potential_columns.items(): dict_[k] = v if inherited_table_args and not tablename: diff --git a/lib/sqlalchemy/ext/mutable.py b/lib/sqlalchemy/ext/mutable.py index 08c0bdf13..b1b851f72 100644 --- a/lib/sqlalchemy/ext/mutable.py +++ b/lib/sqlalchemy/ext/mutable.py @@ -485,7 +485,7 @@ class Mutable(MutableBase): def changed(self): """Subclasses should call this method whenever change events occur.""" - for parent, key in list(self._parents.items()): + for parent, key in self._parents.items(): flag_modified(parent, key) @classmethod @@ -579,7 +579,7 @@ class MutableComposite(MutableBase): def changed(self): """Subclasses should call this method whenever change events occur.""" - for parent, key in list(self._parents.items()): + for parent, key in self._parents.items(): prop = object_mapper(parent).get_property(key) for value, attr_name in zip( diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index 057247047..bfba695b8 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -866,7 +866,7 @@ class CollectionAttributeImpl(AttributeImpl): self.collection_factory = typecallable def __copy(self, item): - return [y for y in list(collections.collection_adapter(item))] + return [y for y in collections.collection_adapter(item)] def get_history(self, state, dict_, passive=PASSIVE_OFF): current = self.get(state, dict_, passive=passive) diff --git a/lib/sqlalchemy/orm/collections.py b/lib/sqlalchemy/orm/collections.py index bb7882ee9..03917d112 100644 --- a/lib/sqlalchemy/orm/collections.py +++ b/lib/sqlalchemy/orm/collections.py @@ -883,7 +883,7 @@ def _instrument_class(cls): # search for _sa_instrument_role-decorated methods in # method resolution order, assign to roles for supercls in cls.__mro__: - for name, method in list(vars(supercls).items()): + for name, method in vars(supercls).items(): if not util.callable(method): continue @@ -917,11 +917,11 @@ def _instrument_class(cls): collection_type = util.duck_type_collection(cls) if collection_type in __interfaces: canned_roles, decorators = __interfaces[collection_type] - for role, name in list(canned_roles.items()): + for role, name in canned_roles.items(): roles.setdefault(role, name) # apply ABC auto-decoration to methods that need it - for method, decorator in list(decorators.items()): + for method, decorator in decorators.items(): fn = getattr(cls, method, None) if (fn and method not in methods and not hasattr(fn, '_sa_instrumented')): @@ -952,12 +952,12 @@ def _instrument_class(cls): # apply ad-hoc instrumentation from decorators, class-level defaults # and implicit role declarations - for method_name, (before, argument, after) in list(methods.items()): + for method_name, (before, argument, after) in methods.items(): setattr(cls, method_name, _instrument_membership_mutator(getattr(cls, method_name), before, argument, after)) # intern the role map - for role, method_name in list(roles.items()): + for role, method_name in roles.items(): setattr(cls, '_sa_%s' % role, getattr(cls, method_name)) setattr(cls, '_sa_instrumented', id(cls)) @@ -1250,7 +1250,7 @@ def _dict_decorators(): def update(self, __other=Unspecified, **kw): if __other is not Unspecified: if hasattr(__other, 'keys'): - for key in list(__other.keys()): + for key in list(__other): if (key not in self or self[key] is not __other[key]): self[key] = __other[key] diff --git a/lib/sqlalchemy/orm/persistence.py b/lib/sqlalchemy/orm/persistence.py index 0eedea793..8ad1dbe9b 100644 --- a/lib/sqlalchemy/orm/persistence.py +++ b/lib/sqlalchemy/orm/persistence.py @@ -803,7 +803,7 @@ class BulkUD(object): raise sa_exc.ArgumentError( "Valid strategies for session synchronization " "are %s" % (", ".join(sorted(repr(x) - for x in list(lookup.keys()))))) + for x in lookup)))) else: return klass(*arg) diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index cbb508cf7..5a4486eef 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -35,7 +35,7 @@ class _SessionClassMethods(object): def close_all(cls): """Close *all* sessions in memory.""" - for sess in list(_sessions.values()): + for sess in _sessions.values(): sess.close() @classmethod @@ -250,7 +250,7 @@ class SessionTransaction(object): if s.key: del s.key - for s, (oldkey, newkey) in list(self._key_switches.items()): + for s, (oldkey, newkey) in self._key_switches.items(): self.session.identity_map.discard(s) s.key = oldkey self.session.identity_map.replace(s) @@ -2237,7 +2237,7 @@ class sessionmaker(_SessionClassMethods): session = Session() # invokes sessionmaker.__call__() """ - for k, v in list(self.kw.items()): + for k, v in self.kw.items(): local_kw.setdefault(k, v) return self.class_(**local_kw) @@ -2256,7 +2256,7 @@ class sessionmaker(_SessionClassMethods): return "%s(class_=%r%s)" % ( self.__class__.__name__, self.class_.__name__, - ", ".join("%s=%r" % (k, v) for k, v in list(self.kw.items())) + ", ".join("%s=%r" % (k, v) for k, v in self.kw.items()) ) _sessions = weakref.WeakValueDictionary() diff --git a/lib/sqlalchemy/orm/state.py b/lib/sqlalchemy/orm/state.py index 8fe37e41c..6ade91b3e 100644 --- a/lib/sqlalchemy/orm/state.py +++ b/lib/sqlalchemy/orm/state.py @@ -417,7 +417,7 @@ class InstanceState(interfaces._InspectionAttr): against this set when a refresh operation occurs. """ - return set([k for k, v in list(self.callables.items()) if v is self]) + return set([k for k, v in self.callables.items() if v is self]) def _instance_dict(self): return None diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py index e80745c79..4651c71b7 100644 --- a/lib/sqlalchemy/orm/strategies.py +++ b/lib/sqlalchemy/orm/strategies.py @@ -359,7 +359,7 @@ class LazyLoader(AbstractRelationshipLoader): ) if self.use_get: - for col in list(self._equated_columns.keys()): + for col in list(self._equated_columns): if col in self.mapper._equivalent_columns: for c in self.mapper._equivalent_columns[col]: self._equated_columns[c] = self._equated_columns[col] diff --git a/lib/sqlalchemy/orm/unitofwork.py b/lib/sqlalchemy/orm/unitofwork.py index 54b0ebf72..aa5f7836c 100644 --- a/lib/sqlalchemy/orm/unitofwork.py +++ b/lib/sqlalchemy/orm/unitofwork.py @@ -342,7 +342,7 @@ class UOWTransaction(object): for dep in convert[edge[1]]: self.dependencies.add((edge[0], dep)) - return set([a for a in list(self.postsort_actions.values()) + return set([a for a in self.postsort_actions.values() if not a.disabled ] ).difference(cycles) @@ -461,7 +461,7 @@ class PostSortRec(object): def __repr__(self): return "%s(%s)" % ( self.__class__.__name__, - ",".join(str(x) for x in list(self.__dict__.values())) + ",".join(str(x) for x in self.__dict__.values()) ) diff --git a/lib/sqlalchemy/pool.py b/lib/sqlalchemy/pool.py index 562a76163..0470e9e48 100644 --- a/lib/sqlalchemy/pool.py +++ b/lib/sqlalchemy/pool.py @@ -1004,7 +1004,7 @@ class _DBProxy(object): self._create_pool_mutex = threading.Lock() def close(self): - for key in list(self.pools.keys()): + for key in list(self.pools): del self.pools[key] def __del__(self): diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index 8e5c94aba..3a74cbd59 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -1044,7 +1044,7 @@ class Column(SchemaItem, expression.ColumnClause): if self.key in table._columns: col = table._columns.get(self.key) if col is not self: - for fk in list(col.foreign_keys): + for fk in col.foreign_keys: table.foreign_keys.remove(fk) if fk.constraint in table.constraints: # this might have been removed diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index c3aea159a..b2c4a94c0 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -2073,11 +2073,11 @@ class DDLCompiler(engine.Compiled): remote_table = list(constraint._elements.values())[0].column.table text += "FOREIGN KEY(%s) REFERENCES %s (%s)" % ( ', '.join(preparer.quote(f.parent.name, f.parent.quote) - for f in list(constraint._elements.values())), + for f in constraint._elements.values()), self.define_constraint_remote_table( constraint, remote_table, preparer), ', '.join(preparer.quote(f.column.name, f.column.quote) - for f in list(constraint._elements.values())) + for f in constraint._elements.values()) ) text += self.define_constraint_match(constraint) text += self.define_constraint_cascades(constraint) diff --git a/lib/sqlalchemy/testing/engines.py b/lib/sqlalchemy/testing/engines.py index cfaacc490..efc0103f2 100644 --- a/lib/sqlalchemy/testing/engines.py +++ b/lib/sqlalchemy/testing/engines.py @@ -8,7 +8,7 @@ from .util import decorator from .. import event, pool import re import warnings - +from .. import util class ConnectionKiller(object): @@ -37,12 +37,12 @@ class ConnectionKiller(object): "rollback/close connection: %s" % e) def rollback_all(self): - for rec in list(self.proxy_refs.keys()): + for rec in list(self.proxy_refs): if rec is not None and rec.is_valid: self._safe(rec.rollback) def close_all(self): - for rec in list(self.proxy_refs.keys()): + for rec in list(self.proxy_refs): if rec is not None: self._safe(rec._close) @@ -66,7 +66,7 @@ class ConnectionKiller(object): self.conns = set() - for rec in list(self.testing_engines.keys()): + for rec in list(self.testing_engines): if rec is not config.db: rec.dispose() @@ -75,7 +75,7 @@ class ConnectionKiller(object): for conn in self.conns: self._safe(conn.close) self.conns = set() - for rec in list(self.testing_engines.keys()): + for rec in list(self.testing_engines): rec.dispose() def assert_all_closed(self): @@ -353,24 +353,22 @@ class ReplayableSession(object): Callable = object() NoAttribute = object() -# start Py3K - Natives = set([getattr(types, t) - for t in dir(types) if not t.startswith('_')]). \ - union([type(t) if not isinstance(t, type) - else t for t in list(__builtins__.values())]).\ + if util.py2k: + Natives = set([getattr(types, t) + for t in dir(types) if not t.startswith('_')]).\ difference([getattr(types, t) - for t in ('FunctionType', 'BuiltinFunctionType', - 'MethodType', 'BuiltinMethodType', - 'LambdaType', )]) -# end Py3K -# start Py2K -# Natives = set([getattr(types, t) -# for t in dir(types) if not t.startswith('_')]). \ -# difference([getattr(types, t) -# for t in ('FunctionType', 'BuiltinFunctionType', -# 'MethodType', 'BuiltinMethodType', -# 'LambdaType', 'UnboundMethodType',)]) -# end Py2K + for t in ('FunctionType', 'BuiltinFunctionType', + 'MethodType', 'BuiltinMethodType', + 'LambdaType', 'UnboundMethodType',)]) + else: + Natives = set([getattr(types, t) + for t in dir(types) if not t.startswith('_')]).\ + union([type(t) if not isinstance(t, type) + else t for t in __builtins__.values()]).\ + difference([getattr(types, t) + for t in ('FunctionType', 'BuiltinFunctionType', + 'MethodType', 'BuiltinMethodType', + 'LambdaType', )]) def __init__(self): self.buffer = deque() diff --git a/lib/sqlalchemy/testing/entities.py b/lib/sqlalchemy/testing/entities.py index 221c23c56..c0dd58650 100644 --- a/lib/sqlalchemy/testing/entities.py +++ b/lib/sqlalchemy/testing/entities.py @@ -67,7 +67,7 @@ class ComparableEntity(BasicEntity): a = self b = other - for attr in list(a.__dict__.keys()): + for attr in list(a.__dict__): if attr.startswith('_'): continue value = getattr(a, attr) diff --git a/lib/sqlalchemy/testing/schema.py b/lib/sqlalchemy/testing/schema.py index 6f3e87cc9..025bbaabe 100644 --- a/lib/sqlalchemy/testing/schema.py +++ b/lib/sqlalchemy/testing/schema.py @@ -11,7 +11,7 @@ table_options = {} def Table(*args, **kw): """A schema.Table wrapper/hook for dialect-specific tweaks.""" - test_opts = dict([(k, kw.pop(k)) for k in list(kw.keys()) + test_opts = dict([(k, kw.pop(k)) for k in list(kw) if k.startswith('test_')]) kw.update(table_options) @@ -58,7 +58,7 @@ def Table(*args, **kw): def Column(*args, **kw): """A schema.Column wrapper/hook for dialect-specific tweaks.""" - test_opts = dict([(k, kw.pop(k)) for k in list(kw.keys()) + test_opts = dict([(k, kw.pop(k)) for k in list(kw) if k.startswith('test_')]) if not config.requirements.foreign_key_ddl.enabled: diff --git a/lib/sqlalchemy/util/_collections.py b/lib/sqlalchemy/util/_collections.py index fddedf4f7..c10d19ea1 100644 --- a/lib/sqlalchemy/util/_collections.py +++ b/lib/sqlalchemy/util/_collections.py @@ -94,7 +94,7 @@ class KeyedTuple(tuple): .. versionadded:: 0.8 """ - return dict((key, self.__dict__[key]) for key in list(self.keys())) + return dict((key, self.__dict__[key]) for key in self.keys()) class ImmutableContainer(object): @@ -242,7 +242,7 @@ class OrderedDict(dict): def update(self, ____sequence=None, **kwargs): if ____sequence is not None: if hasattr(____sequence, 'keys'): - for key in list(____sequence.keys()): + for key in ____sequence.keys(): self.__setitem__(key, ____sequence[key]) else: for key, value in ____sequence: @@ -273,7 +273,7 @@ class OrderedDict(dict): return iter(list(self.keys())) def items(self): - return [(key, self[key]) for key in list(self.keys())] + return [(key, self[key]) for key in self.keys()] def iteritems(self): return iter(list(self.items())) diff --git a/test/aaa_profiling/test_resultset.py b/test/aaa_profiling/test_resultset.py index 95a1fa3ae..27e60410d 100644 --- a/test/aaa_profiling/test_resultset.py +++ b/test/aaa_profiling/test_resultset.py @@ -2,6 +2,7 @@ from sqlalchemy import * from sqlalchemy.testing import fixtures, AssertsExecutionResults, profiling from sqlalchemy import testing from sqlalchemy.testing import eq_ +from sqlalchemy.util import u NUM_FIELDS = 10 NUM_RECORDS = 1000 @@ -19,10 +20,10 @@ class ResultSetTest(fixtures.TestBase, AssertsExecutionResults): def setup(self): metadata.create_all() - t.insert().execute([dict(('field%d' % fnum, 'value%d' % fnum) + t.insert().execute([dict(('field%d' % fnum, u('value%d' % fnum)) for fnum in range(NUM_FIELDS)) for r_num in range(NUM_RECORDS)]) - t2.insert().execute([dict(('field%d' % fnum, 'value%d' % fnum) + t2.insert().execute([dict(('field%d' % fnum, u('value%d' % fnum)) for fnum in range(NUM_FIELDS)) for r_num in range(NUM_RECORDS)]) -- cgit v1.2.1 From 3b4168875d464a141f56685f8b55dfbf70c11e5c Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 May 2013 19:47:13 -0400 Subject: - zoomark tests - rewrite all profiles, we'll review the diffs to see if anything is too far out --- lib/sqlalchemy/testing/exclusions.py | 2 +- test/aaa_profiling/test_zoomark.py | 2 + test/aaa_profiling/test_zoomark_orm.py | 2 + test/profiles.txt | 339 +++++++++++++++++++++------------ 4 files changed, 219 insertions(+), 126 deletions(-) diff --git a/lib/sqlalchemy/testing/exclusions.py b/lib/sqlalchemy/testing/exclusions.py index 93f444eb9..f580f3fde 100644 --- a/lib/sqlalchemy/testing/exclusions.py +++ b/lib/sqlalchemy/testing/exclusions.py @@ -92,7 +92,7 @@ class Predicate(object): return OrPredicate([cls.as_predicate(pred) for pred in predicate]) elif isinstance(predicate, tuple): return SpecPredicate(*predicate) - elif isinstance(predicate, str): + elif isinstance(predicate, util.string_types): return SpecPredicate(predicate, None, None) elif util.callable(predicate): return LambdaPredicate(predicate) diff --git a/test/aaa_profiling/test_zoomark.py b/test/aaa_profiling/test_zoomark.py index 79417e2dc..145f3c594 100644 --- a/test/aaa_profiling/test_zoomark.py +++ b/test/aaa_profiling/test_zoomark.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + """Benchmark for SQLAlchemy. An adaptation of Robert Brewers' ZooMark speed tests. """ diff --git a/test/aaa_profiling/test_zoomark_orm.py b/test/aaa_profiling/test_zoomark_orm.py index 40fb8b03b..ddcad681a 100644 --- a/test/aaa_profiling/test_zoomark_orm.py +++ b/test/aaa_profiling/test_zoomark_orm.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + """Benchmark for SQLAlchemy. An adaptation of Robert Brewers' ZooMark speed tests. """ diff --git a/test/profiles.txt b/test/profiles.txt index c9ba04c24..a41e153d9 100644 --- a/test/profiles.txt +++ b/test/profiles.txt @@ -1,67 +1,88 @@ # /Users/classic/dev/sqlalchemy/test/profiles.txt # This file is written out on a per-environment basis. -# For each test in aaa_profiling, the corresponding function and +# For each test in aaa_profiling, the corresponding function and # environment is located within this file. If it doesn't exist, # the test is skipped. -# If a callcount does exist, it is compared to what we received. +# If a callcount does exist, it is compared to what we received. # assertions are raised if the counts do not match. -# -# To add a new callcount test, apply the function_call_count -# decorator and re-run the tests using the --write-profiles +# +# To add a new callcount test, apply the function_call_count +# decorator and re-run the tests using the --write-profiles # option - this file will be rewritten including the new count. -# +# # TEST: test.aaa_profiling.test_compiler.CompileTest.test_insert -test.aaa_profiling.test_compiler.CompileTest.test_insert 2.5_sqlite_pysqlite_nocextensions 62 -test.aaa_profiling.test_compiler.CompileTest.test_insert 2.6_sqlite_pysqlite_nocextensions 62 -test.aaa_profiling.test_compiler.CompileTest.test_insert 2.7_mysql_mysqldb_cextensions 62 -test.aaa_profiling.test_compiler.CompileTest.test_insert 2.7_mysql_mysqldb_nocextensions 62 -test.aaa_profiling.test_compiler.CompileTest.test_insert 2.7_postgresql_psycopg2_cextensions 62 -test.aaa_profiling.test_compiler.CompileTest.test_insert 2.7_postgresql_psycopg2_nocextensions 62 -test.aaa_profiling.test_compiler.CompileTest.test_insert 2.7_sqlite_pysqlite_cextensions 62 -test.aaa_profiling.test_compiler.CompileTest.test_insert 2.7_sqlite_pysqlite_nocextensions 62 +test.aaa_profiling.test_compiler.CompileTest.test_insert 2.6_sqlite_pysqlite_nocextensions 67 +test.aaa_profiling.test_compiler.CompileTest.test_insert 2.7_mysql_mysqldb_cextensions 67 +test.aaa_profiling.test_compiler.CompileTest.test_insert 2.7_mysql_mysqldb_nocextensions 67 +test.aaa_profiling.test_compiler.CompileTest.test_insert 2.7_postgresql_psycopg2_cextensions 67 +test.aaa_profiling.test_compiler.CompileTest.test_insert 2.7_postgresql_psycopg2_nocextensions 67 +test.aaa_profiling.test_compiler.CompileTest.test_insert 2.7_sqlite_pysqlite_cextensions 67 +test.aaa_profiling.test_compiler.CompileTest.test_insert 2.7_sqlite_pysqlite_nocextensions 67 +test.aaa_profiling.test_compiler.CompileTest.test_insert 3.2_postgresql_psycopg2_nocextensions 69 +test.aaa_profiling.test_compiler.CompileTest.test_insert 3.2_sqlite_pysqlite_nocextensions 69 +test.aaa_profiling.test_compiler.CompileTest.test_insert 3.3_postgresql_psycopg2_nocextensions 69 +test.aaa_profiling.test_compiler.CompileTest.test_insert 3.3_sqlite_pysqlite_nocextensions 69 # TEST: test.aaa_profiling.test_compiler.CompileTest.test_select -test.aaa_profiling.test_compiler.CompileTest.test_select 2.5_sqlite_pysqlite_nocextensions 134 -test.aaa_profiling.test_compiler.CompileTest.test_select 2.6_sqlite_pysqlite_nocextensions 135 -test.aaa_profiling.test_compiler.CompileTest.test_select 2.7_mysql_mysqldb_cextensions 135 -test.aaa_profiling.test_compiler.CompileTest.test_select 2.7_mysql_mysqldb_nocextensions 135 -test.aaa_profiling.test_compiler.CompileTest.test_select 2.7_postgresql_psycopg2_cextensions 135 -test.aaa_profiling.test_compiler.CompileTest.test_select 2.7_postgresql_psycopg2_nocextensions 135 -test.aaa_profiling.test_compiler.CompileTest.test_select 2.7_sqlite_pysqlite_cextensions 135 -test.aaa_profiling.test_compiler.CompileTest.test_select 2.7_sqlite_pysqlite_nocextensions 135 +test.aaa_profiling.test_compiler.CompileTest.test_select 2.6_sqlite_pysqlite_nocextensions 141 +test.aaa_profiling.test_compiler.CompileTest.test_select 2.7_mysql_mysqldb_cextensions 141 +test.aaa_profiling.test_compiler.CompileTest.test_select 2.7_mysql_mysqldb_nocextensions 141 +test.aaa_profiling.test_compiler.CompileTest.test_select 2.7_postgresql_psycopg2_cextensions 141 +test.aaa_profiling.test_compiler.CompileTest.test_select 2.7_postgresql_psycopg2_nocextensions 141 +test.aaa_profiling.test_compiler.CompileTest.test_select 2.7_sqlite_pysqlite_cextensions 141 +test.aaa_profiling.test_compiler.CompileTest.test_select 2.7_sqlite_pysqlite_nocextensions 141 +test.aaa_profiling.test_compiler.CompileTest.test_select 3.2_postgresql_psycopg2_nocextensions 151 +test.aaa_profiling.test_compiler.CompileTest.test_select 3.2_sqlite_pysqlite_nocextensions 151 +test.aaa_profiling.test_compiler.CompileTest.test_select 3.3_postgresql_psycopg2_nocextensions 151 +test.aaa_profiling.test_compiler.CompileTest.test_select 3.3_sqlite_pysqlite_nocextensions 151 # TEST: test.aaa_profiling.test_compiler.CompileTest.test_select_labels -test.aaa_profiling.test_compiler.CompileTest.test_select_labels 2.7_sqlite_pysqlite_nocextensions 177 +test.aaa_profiling.test_compiler.CompileTest.test_select_labels 2.6_sqlite_pysqlite_nocextensions 175 +test.aaa_profiling.test_compiler.CompileTest.test_select_labels 2.7_mysql_mysqldb_cextensions 175 +test.aaa_profiling.test_compiler.CompileTest.test_select_labels 2.7_mysql_mysqldb_nocextensions 175 +test.aaa_profiling.test_compiler.CompileTest.test_select_labels 2.7_postgresql_psycopg2_cextensions 175 +test.aaa_profiling.test_compiler.CompileTest.test_select_labels 2.7_postgresql_psycopg2_nocextensions 175 +test.aaa_profiling.test_compiler.CompileTest.test_select_labels 2.7_sqlite_pysqlite_cextensions 175 +test.aaa_profiling.test_compiler.CompileTest.test_select_labels 2.7_sqlite_pysqlite_nocextensions 175 +test.aaa_profiling.test_compiler.CompileTest.test_select_labels 3.2_postgresql_psycopg2_nocextensions 185 +test.aaa_profiling.test_compiler.CompileTest.test_select_labels 3.2_sqlite_pysqlite_nocextensions 185 +test.aaa_profiling.test_compiler.CompileTest.test_select_labels 3.3_postgresql_psycopg2_nocextensions 185 +test.aaa_profiling.test_compiler.CompileTest.test_select_labels 3.3_sqlite_pysqlite_nocextensions 185 # TEST: test.aaa_profiling.test_compiler.CompileTest.test_update -test.aaa_profiling.test_compiler.CompileTest.test_update 2.5_sqlite_pysqlite_nocextensions 65 -test.aaa_profiling.test_compiler.CompileTest.test_update 2.6_sqlite_pysqlite_nocextensions 65 -test.aaa_profiling.test_compiler.CompileTest.test_update 2.7_mysql_mysqldb_cextensions 65 -test.aaa_profiling.test_compiler.CompileTest.test_update 2.7_mysql_mysqldb_nocextensions 65 -test.aaa_profiling.test_compiler.CompileTest.test_update 2.7_postgresql_psycopg2_cextensions 65 -test.aaa_profiling.test_compiler.CompileTest.test_update 2.7_postgresql_psycopg2_nocextensions 65 -test.aaa_profiling.test_compiler.CompileTest.test_update 2.7_sqlite_pysqlite_cextensions 65 -test.aaa_profiling.test_compiler.CompileTest.test_update 2.7_sqlite_pysqlite_nocextensions 65 +test.aaa_profiling.test_compiler.CompileTest.test_update 2.6_sqlite_pysqlite_nocextensions 70 +test.aaa_profiling.test_compiler.CompileTest.test_update 2.7_mysql_mysqldb_cextensions 70 +test.aaa_profiling.test_compiler.CompileTest.test_update 2.7_mysql_mysqldb_nocextensions 70 +test.aaa_profiling.test_compiler.CompileTest.test_update 2.7_postgresql_psycopg2_cextensions 70 +test.aaa_profiling.test_compiler.CompileTest.test_update 2.7_postgresql_psycopg2_nocextensions 70 +test.aaa_profiling.test_compiler.CompileTest.test_update 2.7_sqlite_pysqlite_cextensions 70 +test.aaa_profiling.test_compiler.CompileTest.test_update 2.7_sqlite_pysqlite_nocextensions 70 +test.aaa_profiling.test_compiler.CompileTest.test_update 3.2_postgresql_psycopg2_nocextensions 70 +test.aaa_profiling.test_compiler.CompileTest.test_update 3.2_sqlite_pysqlite_nocextensions 70 +test.aaa_profiling.test_compiler.CompileTest.test_update 3.3_postgresql_psycopg2_nocextensions 70 +test.aaa_profiling.test_compiler.CompileTest.test_update 3.3_sqlite_pysqlite_nocextensions 70 # TEST: test.aaa_profiling.test_compiler.CompileTest.test_update_whereclause -test.aaa_profiling.test_compiler.CompileTest.test_update_whereclause 2.5_sqlite_pysqlite_nocextensions 129 -test.aaa_profiling.test_compiler.CompileTest.test_update_whereclause 2.6_sqlite_pysqlite_nocextensions 130 -test.aaa_profiling.test_compiler.CompileTest.test_update_whereclause 2.7_mysql_mysqldb_cextensions 130 -test.aaa_profiling.test_compiler.CompileTest.test_update_whereclause 2.7_mysql_mysqldb_nocextensions 130 -test.aaa_profiling.test_compiler.CompileTest.test_update_whereclause 2.7_postgresql_psycopg2_cextensions 130 -test.aaa_profiling.test_compiler.CompileTest.test_update_whereclause 2.7_postgresql_psycopg2_nocextensions 130 -test.aaa_profiling.test_compiler.CompileTest.test_update_whereclause 2.7_sqlite_pysqlite_cextensions 130 -test.aaa_profiling.test_compiler.CompileTest.test_update_whereclause 2.7_sqlite_pysqlite_nocextensions 130 +test.aaa_profiling.test_compiler.CompileTest.test_update_whereclause 2.6_sqlite_pysqlite_nocextensions 137 +test.aaa_profiling.test_compiler.CompileTest.test_update_whereclause 2.7_mysql_mysqldb_cextensions 137 +test.aaa_profiling.test_compiler.CompileTest.test_update_whereclause 2.7_mysql_mysqldb_nocextensions 137 +test.aaa_profiling.test_compiler.CompileTest.test_update_whereclause 2.7_postgresql_psycopg2_cextensions 137 +test.aaa_profiling.test_compiler.CompileTest.test_update_whereclause 2.7_postgresql_psycopg2_nocextensions 137 +test.aaa_profiling.test_compiler.CompileTest.test_update_whereclause 2.7_sqlite_pysqlite_cextensions 137 +test.aaa_profiling.test_compiler.CompileTest.test_update_whereclause 2.7_sqlite_pysqlite_nocextensions 137 +test.aaa_profiling.test_compiler.CompileTest.test_update_whereclause 3.2_postgresql_psycopg2_nocextensions 136 +test.aaa_profiling.test_compiler.CompileTest.test_update_whereclause 3.2_sqlite_pysqlite_nocextensions 136 +test.aaa_profiling.test_compiler.CompileTest.test_update_whereclause 3.3_postgresql_psycopg2_nocextensions 136 +test.aaa_profiling.test_compiler.CompileTest.test_update_whereclause 3.3_sqlite_pysqlite_nocextensions 136 # TEST: test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_identity -test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_identity 2.5_sqlite_pysqlite_nocextensions 17987 test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_identity 2.6_sqlite_pysqlite_nocextensions 17987 test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_identity 2.7_mysql_mysqldb_cextensions 17987 test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_identity 2.7_mysql_mysqldb_nocextensions 17987 @@ -69,39 +90,52 @@ test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_ test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_identity 2.7_postgresql_psycopg2_nocextensions 17987 test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_identity 2.7_sqlite_pysqlite_cextensions 17987 test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_identity 2.7_sqlite_pysqlite_nocextensions 17987 +test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_identity 3.2_postgresql_psycopg2_nocextensions 18987 +test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_identity 3.2_sqlite_pysqlite_nocextensions 18987 +test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_identity 3.3_postgresql_psycopg2_nocextensions 18987 +test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_identity 3.3_sqlite_pysqlite_nocextensions 18987 # TEST: test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_no_identity -test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_no_identity 2.5_sqlite_pysqlite_nocextensions 116289 -test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_no_identity 2.6_sqlite_pysqlite_nocextensions 116790 -test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_no_identity 2.7_mysql_mysqldb_cextensions 122540 -test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_no_identity 2.7_mysql_mysqldb_nocextensions 125290 -test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_no_identity 2.7_postgresql_psycopg2_cextensions 115040 -test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_no_identity 2.7_postgresql_psycopg2_nocextensions 117790 -test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_no_identity 2.7_sqlite_pysqlite_cextensions 114040 -test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_no_identity 2.7_sqlite_pysqlite_nocextensions 116790 +test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_no_identity 2.6_sqlite_pysqlite_nocextensions 118319 +test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_no_identity 2.7_mysql_mysqldb_cextensions 124069 +test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_no_identity 2.7_mysql_mysqldb_nocextensions 126819 +test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_no_identity 2.7_postgresql_psycopg2_cextensions 116569 +test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_no_identity 2.7_postgresql_psycopg2_nocextensions 119319 +test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_no_identity 2.7_sqlite_pysqlite_cextensions 115569 +test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_no_identity 2.7_sqlite_pysqlite_nocextensions 118319 +test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_no_identity 3.2_postgresql_psycopg2_nocextensions 121790 +test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_no_identity 3.2_sqlite_pysqlite_nocextensions 121822 +test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_no_identity 3.3_postgresql_psycopg2_nocextensions 121822 +test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_no_identity 3.3_sqlite_pysqlite_nocextensions 121822 # TEST: test.aaa_profiling.test_orm.MergeBackrefsTest.test_merge_pending_with_all_pks -test.aaa_profiling.test_orm.MergeBackrefsTest.test_merge_pending_with_all_pks 2.5_sqlite_pysqlite_nocextensions 19852 -test.aaa_profiling.test_orm.MergeBackrefsTest.test_merge_pending_with_all_pks 2.6_sqlite_pysqlite_nocextensions 19217 -test.aaa_profiling.test_orm.MergeBackrefsTest.test_merge_pending_with_all_pks 2.7_mysql_mysqldb_cextensions 19491 -test.aaa_profiling.test_orm.MergeBackrefsTest.test_merge_pending_with_all_pks 2.7_mysql_mysqldb_nocextensions 19781 -test.aaa_profiling.test_orm.MergeBackrefsTest.test_merge_pending_with_all_pks 2.7_postgresql_psycopg2_cextensions 18878 -test.aaa_profiling.test_orm.MergeBackrefsTest.test_merge_pending_with_all_pks 2.7_postgresql_psycopg2_nocextensions 19168 -test.aaa_profiling.test_orm.MergeBackrefsTest.test_merge_pending_with_all_pks 2.7_sqlite_pysqlite_cextensions 18957 -test.aaa_profiling.test_orm.MergeBackrefsTest.test_merge_pending_with_all_pks 2.7_sqlite_pysqlite_nocextensions 19217 +test.aaa_profiling.test_orm.MergeBackrefsTest.test_merge_pending_with_all_pks 2.6_sqlite_pysqlite_nocextensions 19534 +test.aaa_profiling.test_orm.MergeBackrefsTest.test_merge_pending_with_all_pks 2.7_mysql_mysqldb_cextensions 19838 +test.aaa_profiling.test_orm.MergeBackrefsTest.test_merge_pending_with_all_pks 2.7_mysql_mysqldb_nocextensions 20098 +test.aaa_profiling.test_orm.MergeBackrefsTest.test_merge_pending_with_all_pks 2.7_postgresql_psycopg2_cextensions 19237 +test.aaa_profiling.test_orm.MergeBackrefsTest.test_merge_pending_with_all_pks 2.7_postgresql_psycopg2_nocextensions 19467 +test.aaa_profiling.test_orm.MergeBackrefsTest.test_merge_pending_with_all_pks 2.7_sqlite_pysqlite_cextensions 19274 +test.aaa_profiling.test_orm.MergeBackrefsTest.test_merge_pending_with_all_pks 2.7_sqlite_pysqlite_nocextensions 19534 +test.aaa_profiling.test_orm.MergeBackrefsTest.test_merge_pending_with_all_pks 3.2_postgresql_psycopg2_nocextensions 20424 +test.aaa_profiling.test_orm.MergeBackrefsTest.test_merge_pending_with_all_pks 3.2_sqlite_pysqlite_nocextensions 20447 +test.aaa_profiling.test_orm.MergeBackrefsTest.test_merge_pending_with_all_pks 3.3_postgresql_psycopg2_nocextensions 20344 +test.aaa_profiling.test_orm.MergeBackrefsTest.test_merge_pending_with_all_pks 3.3_sqlite_pysqlite_nocextensions 20433 # TEST: test.aaa_profiling.test_orm.MergeTest.test_merge_load -test.aaa_profiling.test_orm.MergeTest.test_merge_load 2.5_sqlite_pysqlite_nocextensions 1178 -test.aaa_profiling.test_orm.MergeTest.test_merge_load 2.6_sqlite_pysqlite_nocextensions 1174 -test.aaa_profiling.test_orm.MergeTest.test_merge_load 2.7_mysql_mysqldb_cextensions 1341 -test.aaa_profiling.test_orm.MergeTest.test_merge_load 2.7_mysql_mysqldb_nocextensions 1366 -test.aaa_profiling.test_orm.MergeTest.test_merge_load 2.7_postgresql_psycopg2_cextensions 1275 -test.aaa_profiling.test_orm.MergeTest.test_merge_load 2.7_postgresql_psycopg2_nocextensions 1307 -test.aaa_profiling.test_orm.MergeTest.test_merge_load 2.7_sqlite_pysqlite_cextensions 1149 -test.aaa_profiling.test_orm.MergeTest.test_merge_load 2.7_sqlite_pysqlite_nocextensions 1174 +test.aaa_profiling.test_orm.MergeTest.test_merge_load 2.6_sqlite_pysqlite_nocextensions 1221 +test.aaa_profiling.test_orm.MergeTest.test_merge_load 2.7_mysql_mysqldb_cextensions 1388 +test.aaa_profiling.test_orm.MergeTest.test_merge_load 2.7_mysql_mysqldb_nocextensions 1413 +test.aaa_profiling.test_orm.MergeTest.test_merge_load 2.7_postgresql_psycopg2_cextensions 1296 +test.aaa_profiling.test_orm.MergeTest.test_merge_load 2.7_postgresql_psycopg2_nocextensions 1321 +test.aaa_profiling.test_orm.MergeTest.test_merge_load 2.7_sqlite_pysqlite_cextensions 1196 +test.aaa_profiling.test_orm.MergeTest.test_merge_load 2.7_sqlite_pysqlite_nocextensions 1221 +test.aaa_profiling.test_orm.MergeTest.test_merge_load 3.2_postgresql_psycopg2_nocextensions 1332 +test.aaa_profiling.test_orm.MergeTest.test_merge_load 3.2_sqlite_pysqlite_nocextensions 1243 +test.aaa_profiling.test_orm.MergeTest.test_merge_load 3.3_postgresql_psycopg2_nocextensions 1357 +test.aaa_profiling.test_orm.MergeTest.test_merge_load 3.3_sqlite_pysqlite_nocextensions 1243 # TEST: test.aaa_profiling.test_orm.MergeTest.test_merge_no_load @@ -112,6 +146,10 @@ test.aaa_profiling.test_orm.MergeTest.test_merge_no_load 2.7_postgresql_psycopg2 test.aaa_profiling.test_orm.MergeTest.test_merge_no_load 2.7_postgresql_psycopg2_nocextensions 122,18 test.aaa_profiling.test_orm.MergeTest.test_merge_no_load 2.7_sqlite_pysqlite_cextensions 122,18 test.aaa_profiling.test_orm.MergeTest.test_merge_no_load 2.7_sqlite_pysqlite_nocextensions 122,18 +test.aaa_profiling.test_orm.MergeTest.test_merge_no_load 3.2_postgresql_psycopg2_nocextensions 127,19 +test.aaa_profiling.test_orm.MergeTest.test_merge_no_load 3.2_sqlite_pysqlite_nocextensions 127,19 +test.aaa_profiling.test_orm.MergeTest.test_merge_no_load 3.3_postgresql_psycopg2_nocextensions 127,19 +test.aaa_profiling.test_orm.MergeTest.test_merge_no_load 3.3_sqlite_pysqlite_nocextensions 127,19 # TEST: test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect @@ -122,10 +160,13 @@ test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 2.7_postgresql_psy test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 2.7_postgresql_psycopg2_nocextensions 82 test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 2.7_sqlite_pysqlite_cextensions 82 test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 2.7_sqlite_pysqlite_nocextensions 82 +test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 3.2_postgresql_psycopg2_nocextensions 70 +test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 3.2_sqlite_pysqlite_nocextensions 70 +test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 3.3_postgresql_psycopg2_nocextensions 69 +test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 3.3_sqlite_pysqlite_nocextensions 69 # TEST: test.aaa_profiling.test_pool.QueuePoolTest.test_second_connect -test.aaa_profiling.test_pool.QueuePoolTest.test_second_connect 2.5_sqlite_pysqlite_nocextensions 32 test.aaa_profiling.test_pool.QueuePoolTest.test_second_connect 2.6_sqlite_pysqlite_nocextensions 29 test.aaa_profiling.test_pool.QueuePoolTest.test_second_connect 2.7_mysql_mysqldb_cextensions 29 test.aaa_profiling.test_pool.QueuePoolTest.test_second_connect 2.7_mysql_mysqldb_nocextensions 29 @@ -133,10 +174,13 @@ test.aaa_profiling.test_pool.QueuePoolTest.test_second_connect 2.7_postgresql_ps test.aaa_profiling.test_pool.QueuePoolTest.test_second_connect 2.7_postgresql_psycopg2_nocextensions 29 test.aaa_profiling.test_pool.QueuePoolTest.test_second_connect 2.7_sqlite_pysqlite_cextensions 29 test.aaa_profiling.test_pool.QueuePoolTest.test_second_connect 2.7_sqlite_pysqlite_nocextensions 29 +test.aaa_profiling.test_pool.QueuePoolTest.test_second_connect 3.2_postgresql_psycopg2_nocextensions 23 +test.aaa_profiling.test_pool.QueuePoolTest.test_second_connect 3.2_sqlite_pysqlite_nocextensions 23 +test.aaa_profiling.test_pool.QueuePoolTest.test_second_connect 3.3_postgresql_psycopg2_nocextensions 22 +test.aaa_profiling.test_pool.QueuePoolTest.test_second_connect 3.3_sqlite_pysqlite_nocextensions 22 # TEST: test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect -test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 2.5_sqlite_pysqlite_nocextensions 6 test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 2.6_sqlite_pysqlite_nocextensions 6 test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 2.7_mysql_mysqldb_cextensions 6 test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 2.7_mysql_mysqldb_nocextensions 6 @@ -144,32 +188,41 @@ test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 2.7_po test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 2.7_postgresql_psycopg2_nocextensions 6 test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 2.7_sqlite_pysqlite_cextensions 6 test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 2.7_sqlite_pysqlite_nocextensions 6 +test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 3.2_postgresql_psycopg2_nocextensions 7 +test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 3.2_sqlite_pysqlite_nocextensions 7 +test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 3.3_postgresql_psycopg2_nocextensions 7 +test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 3.3_sqlite_pysqlite_nocextensions 7 # TEST: test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_connection_execute -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_connection_execute 2.5_sqlite_pysqlite_nocextensions 41 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_connection_execute 2.6_sqlite_pysqlite_nocextensions 42 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_connection_execute 2.7_mysql_mysqldb_cextensions 40 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_connection_execute 2.7_mysql_mysqldb_nocextensions 42 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_connection_execute 2.7_postgresql_psycopg2_cextensions 40 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_connection_execute 2.7_postgresql_psycopg2_nocextensions 42 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_connection_execute 2.7_sqlite_pysqlite_cextensions 40 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_connection_execute 2.7_sqlite_pysqlite_nocextensions 42 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_connection_execute 2.6_sqlite_pysqlite_nocextensions 43 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_connection_execute 2.7_mysql_mysqldb_cextensions 41 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_connection_execute 2.7_mysql_mysqldb_nocextensions 43 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_connection_execute 2.7_postgresql_psycopg2_cextensions 41 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_connection_execute 2.7_postgresql_psycopg2_nocextensions 43 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_connection_execute 2.7_sqlite_pysqlite_cextensions 41 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_connection_execute 2.7_sqlite_pysqlite_nocextensions 43 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_connection_execute 3.2_postgresql_psycopg2_nocextensions 41 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_connection_execute 3.2_sqlite_pysqlite_nocextensions 41 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_connection_execute 3.3_postgresql_psycopg2_nocextensions 41 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_connection_execute 3.3_sqlite_pysqlite_nocextensions 41 # TEST: test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.5_sqlite_pysqlite_nocextensions 64 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.6_sqlite_pysqlite_nocextensions 65 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_mysql_mysqldb_cextensions 63 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_mysql_mysqldb_nocextensions 65 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_postgresql_psycopg2_cextensions 63 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_postgresql_psycopg2_nocextensions 65 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_sqlite_pysqlite_cextensions 63 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_sqlite_pysqlite_nocextensions 65 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.6_sqlite_pysqlite_nocextensions 68 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_mysql_mysqldb_cextensions 66 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_mysql_mysqldb_nocextensions 68 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_postgresql_psycopg2_cextensions 66 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_postgresql_psycopg2_nocextensions 68 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_sqlite_pysqlite_cextensions 66 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_sqlite_pysqlite_nocextensions 68 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 3.2_postgresql_psycopg2_nocextensions 66 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 3.2_sqlite_pysqlite_nocextensions 66 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 3.3_postgresql_psycopg2_nocextensions 66 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 3.3_sqlite_pysqlite_nocextensions 66 # TEST: test.aaa_profiling.test_resultset.ResultSetTest.test_contains_doesnt_compile -test.aaa_profiling.test_resultset.ResultSetTest.test_contains_doesnt_compile 2.5_sqlite_pysqlite_nocextensions 14 test.aaa_profiling.test_resultset.ResultSetTest.test_contains_doesnt_compile 2.6_sqlite_pysqlite_nocextensions 14 test.aaa_profiling.test_resultset.ResultSetTest.test_contains_doesnt_compile 2.7_mysql_mysqldb_cextensions 14 test.aaa_profiling.test_resultset.ResultSetTest.test_contains_doesnt_compile 2.7_mysql_mysqldb_nocextensions 14 @@ -177,90 +230,126 @@ test.aaa_profiling.test_resultset.ResultSetTest.test_contains_doesnt_compile 2.7 test.aaa_profiling.test_resultset.ResultSetTest.test_contains_doesnt_compile 2.7_postgresql_psycopg2_nocextensions 14 test.aaa_profiling.test_resultset.ResultSetTest.test_contains_doesnt_compile 2.7_sqlite_pysqlite_cextensions 14 test.aaa_profiling.test_resultset.ResultSetTest.test_contains_doesnt_compile 2.7_sqlite_pysqlite_nocextensions 14 +test.aaa_profiling.test_resultset.ResultSetTest.test_contains_doesnt_compile 3.2_postgresql_psycopg2_nocextensions 15 +test.aaa_profiling.test_resultset.ResultSetTest.test_contains_doesnt_compile 3.2_sqlite_pysqlite_nocextensions 15 +test.aaa_profiling.test_resultset.ResultSetTest.test_contains_doesnt_compile 3.3_postgresql_psycopg2_nocextensions 15 +test.aaa_profiling.test_resultset.ResultSetTest.test_contains_doesnt_compile 3.3_sqlite_pysqlite_nocextensions 15 # TEST: test.aaa_profiling.test_resultset.ResultSetTest.test_string -test.aaa_profiling.test_resultset.ResultSetTest.test_string 2.5_sqlite_pysqlite_nocextensions 14413 -test.aaa_profiling.test_resultset.ResultSetTest.test_string 2.6_sqlite_pysqlite_nocextensions 14414 -test.aaa_profiling.test_resultset.ResultSetTest.test_string 2.7_mysql_mysqldb_cextensions 476 -test.aaa_profiling.test_resultset.ResultSetTest.test_string 2.7_mysql_mysqldb_nocextensions 14472 -test.aaa_profiling.test_resultset.ResultSetTest.test_string 2.7_postgresql_psycopg2_cextensions 20438 -test.aaa_profiling.test_resultset.ResultSetTest.test_string 2.7_postgresql_psycopg2_nocextensions 34458 -test.aaa_profiling.test_resultset.ResultSetTest.test_string 2.7_sqlite_pysqlite_cextensions 416 -test.aaa_profiling.test_resultset.ResultSetTest.test_string 2.7_sqlite_pysqlite_nocextensions 14414 +test.aaa_profiling.test_resultset.ResultSetTest.test_string 2.6_sqlite_pysqlite_nocextensions 15447 +test.aaa_profiling.test_resultset.ResultSetTest.test_string 2.7_mysql_mysqldb_cextensions 485 +test.aaa_profiling.test_resultset.ResultSetTest.test_string 2.7_mysql_mysqldb_nocextensions 15505 +test.aaa_profiling.test_resultset.ResultSetTest.test_string 2.7_postgresql_psycopg2_cextensions 20471 +test.aaa_profiling.test_resultset.ResultSetTest.test_string 2.7_postgresql_psycopg2_nocextensions 35491 +test.aaa_profiling.test_resultset.ResultSetTest.test_string 2.7_sqlite_pysqlite_cextensions 427 +test.aaa_profiling.test_resultset.ResultSetTest.test_string 2.7_sqlite_pysqlite_nocextensions 15447 +test.aaa_profiling.test_resultset.ResultSetTest.test_string 3.2_postgresql_psycopg2_nocextensions 14459 +test.aaa_profiling.test_resultset.ResultSetTest.test_string 3.2_sqlite_pysqlite_nocextensions 14430 +test.aaa_profiling.test_resultset.ResultSetTest.test_string 3.3_postgresql_psycopg2_nocextensions 14457 +test.aaa_profiling.test_resultset.ResultSetTest.test_string 3.3_sqlite_pysqlite_nocextensions 14430 # TEST: test.aaa_profiling.test_resultset.ResultSetTest.test_unicode -test.aaa_profiling.test_resultset.ResultSetTest.test_unicode 2.5_sqlite_pysqlite_nocextensions 14413 -test.aaa_profiling.test_resultset.ResultSetTest.test_unicode 2.6_sqlite_pysqlite_nocextensions 14414 -test.aaa_profiling.test_resultset.ResultSetTest.test_unicode 2.7_mysql_mysqldb_cextensions 476 -test.aaa_profiling.test_resultset.ResultSetTest.test_unicode 2.7_mysql_mysqldb_nocextensions 44472 -test.aaa_profiling.test_resultset.ResultSetTest.test_unicode 2.7_postgresql_psycopg2_cextensions 20438 -test.aaa_profiling.test_resultset.ResultSetTest.test_unicode 2.7_postgresql_psycopg2_nocextensions 34458 -test.aaa_profiling.test_resultset.ResultSetTest.test_unicode 2.7_sqlite_pysqlite_cextensions 416 -test.aaa_profiling.test_resultset.ResultSetTest.test_unicode 2.7_sqlite_pysqlite_nocextensions 14414 +test.aaa_profiling.test_resultset.ResultSetTest.test_unicode 2.6_sqlite_pysqlite_nocextensions 15447 +test.aaa_profiling.test_resultset.ResultSetTest.test_unicode 2.7_mysql_mysqldb_cextensions 485 +test.aaa_profiling.test_resultset.ResultSetTest.test_unicode 2.7_mysql_mysqldb_nocextensions 45505 +test.aaa_profiling.test_resultset.ResultSetTest.test_unicode 2.7_postgresql_psycopg2_cextensions 20471 +test.aaa_profiling.test_resultset.ResultSetTest.test_unicode 2.7_postgresql_psycopg2_nocextensions 35491 +test.aaa_profiling.test_resultset.ResultSetTest.test_unicode 2.7_sqlite_pysqlite_cextensions 427 +test.aaa_profiling.test_resultset.ResultSetTest.test_unicode 2.7_sqlite_pysqlite_nocextensions 15447 +test.aaa_profiling.test_resultset.ResultSetTest.test_unicode 3.2_postgresql_psycopg2_nocextensions 14459 +test.aaa_profiling.test_resultset.ResultSetTest.test_unicode 3.2_sqlite_pysqlite_nocextensions 14430 +test.aaa_profiling.test_resultset.ResultSetTest.test_unicode 3.3_postgresql_psycopg2_nocextensions 14457 +test.aaa_profiling.test_resultset.ResultSetTest.test_unicode 3.3_sqlite_pysqlite_nocextensions 14430 # TEST: test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_1a_populate -test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_1a_populate 2.7_postgresql_psycopg2_cextensions 5044 -test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_1a_populate 2.7_postgresql_psycopg2_nocextensions 5088 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_1a_populate 2.7_postgresql_psycopg2_cextensions 5131 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_1a_populate 2.7_postgresql_psycopg2_nocextensions 5693 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_1a_populate 3.2_postgresql_psycopg2_nocextensions 4828 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_1a_populate 3.3_postgresql_psycopg2_nocextensions 4792 # TEST: test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_2_insert -test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_2_insert 2.7_postgresql_psycopg2_cextensions 247 -test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_2_insert 2.7_postgresql_psycopg2_nocextensions 247 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_2_insert 2.7_postgresql_psycopg2_cextensions 256 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_2_insert 2.7_postgresql_psycopg2_nocextensions 256 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_2_insert 3.2_postgresql_psycopg2_nocextensions 239 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_2_insert 3.3_postgresql_psycopg2_nocextensions 237 # TEST: test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_3_properties -test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_3_properties 2.7_postgresql_psycopg2_cextensions 3366 -test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_3_properties 2.7_postgresql_psycopg2_nocextensions 3590 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_3_properties 2.7_postgresql_psycopg2_cextensions 3425 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_3_properties 2.7_postgresql_psycopg2_nocextensions 3749 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_3_properties 3.2_postgresql_psycopg2_nocextensions 3401 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_3_properties 3.3_postgresql_psycopg2_nocextensions 3385 # TEST: test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_4_expressions -test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_4_expressions 2.7_postgresql_psycopg2_cextensions 10915 -test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_4_expressions 2.7_postgresql_psycopg2_nocextensions 11982 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_4_expressions 2.7_postgresql_psycopg2_cextensions 11045 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_4_expressions 2.7_postgresql_psycopg2_nocextensions 12747 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_4_expressions 3.2_postgresql_psycopg2_nocextensions 11849 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_4_expressions 3.3_postgresql_psycopg2_nocextensions 11803 # TEST: test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_5_aggregates -test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_5_aggregates 2.7_postgresql_psycopg2_cextensions 1005 -test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_5_aggregates 2.7_postgresql_psycopg2_nocextensions 1109 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_5_aggregates 2.7_postgresql_psycopg2_cextensions 1050 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_5_aggregates 2.7_postgresql_psycopg2_nocextensions 1167 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_5_aggregates 3.2_postgresql_psycopg2_nocextensions 1114 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_5_aggregates 3.3_postgresql_psycopg2_nocextensions 1106 # TEST: test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_6_editing -test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_6_editing 2.7_postgresql_psycopg2_cextensions 1736 -test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_6_editing 2.7_postgresql_psycopg2_nocextensions 1779 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_6_editing 2.7_postgresql_psycopg2_cextensions 1811 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_6_editing 2.7_postgresql_psycopg2_nocextensions 1858 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_6_editing 3.2_postgresql_psycopg2_nocextensions 1731 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_6_editing 3.3_postgresql_psycopg2_nocextensions 1721 # TEST: test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_7_multiview -test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_7_multiview 2.7_postgresql_psycopg2_cextensions 2219 -test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_7_multiview 2.7_postgresql_psycopg2_nocextensions 2449 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_7_multiview 2.7_postgresql_psycopg2_cextensions 2300 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_7_multiview 2.7_postgresql_psycopg2_nocextensions 2559 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_7_multiview 3.2_postgresql_psycopg2_nocextensions 2483 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_7_multiview 3.3_postgresql_psycopg2_nocextensions 2473 # TEST: test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_1a_populate -test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_1a_populate 2.7_postgresql_psycopg2_cextensions 5977 -test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_1a_populate 2.7_postgresql_psycopg2_nocextensions 6096 +test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_1a_populate 2.7_postgresql_psycopg2_cextensions 6157 +test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_1a_populate 2.7_postgresql_psycopg2_nocextensions 6276 +test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_1a_populate 3.2_postgresql_psycopg2_nocextensions 6252 +test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_1a_populate 3.3_postgresql_psycopg2_nocextensions 6251 # TEST: test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_2_insert -test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_2_insert 2.7_postgresql_psycopg2_cextensions 392 -test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_2_insert 2.7_postgresql_psycopg2_nocextensions 399 +test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_2_insert 2.7_postgresql_psycopg2_cextensions 391 +test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_2_insert 2.7_postgresql_psycopg2_nocextensions 398 +test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_2_insert 3.2_postgresql_psycopg2_nocextensions 395 +test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_2_insert 3.3_postgresql_psycopg2_nocextensions 394 # TEST: test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_3_properties -test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_3_properties 2.7_postgresql_psycopg2_cextensions 6124 -test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_3_properties 2.7_postgresql_psycopg2_nocextensions 6356 +test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_3_properties 2.7_postgresql_psycopg2_cextensions 6422 +test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_3_properties 2.7_postgresql_psycopg2_nocextensions 6654 +test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_3_properties 3.2_postgresql_psycopg2_nocextensions 6560 +test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_3_properties 3.3_postgresql_psycopg2_nocextensions 6560 # TEST: test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_4_expressions -test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_4_expressions 2.7_postgresql_psycopg2_cextensions 18140 -test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_4_expressions 2.7_postgresql_psycopg2_nocextensions 19571 +test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_4_expressions 2.7_postgresql_psycopg2_cextensions 19145 +test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_4_expressions 2.7_postgresql_psycopg2_nocextensions 20576 +test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_4_expressions 3.2_postgresql_psycopg2_nocextensions 20279 +test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_4_expressions 3.3_postgresql_psycopg2_nocextensions 20279 # TEST: test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_5_aggregates -test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_5_aggregates 2.7_postgresql_psycopg2_cextensions 1018 -test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_5_aggregates 2.7_postgresql_psycopg2_nocextensions 1114 +test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_5_aggregates 2.7_postgresql_psycopg2_cextensions 1063 +test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_5_aggregates 2.7_postgresql_psycopg2_nocextensions 1171 +test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_5_aggregates 3.2_postgresql_psycopg2_nocextensions 1120 +test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_5_aggregates 3.3_postgresql_psycopg2_nocextensions 1113 # TEST: test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_6_editing -test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_6_editing 2.7_postgresql_psycopg2_cextensions 2614 -test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_6_editing 2.7_postgresql_psycopg2_nocextensions 2677 +test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_6_editing 2.7_postgresql_psycopg2_cextensions 2686 +test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_6_editing 2.7_postgresql_psycopg2_nocextensions 2749 +test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_6_editing 3.2_postgresql_psycopg2_nocextensions 2749 +test.aaa_profiling.test_zoomark_orm.ZooMarkTest.test_profile_6_editing 3.3_postgresql_psycopg2_nocextensions 2749 -- cgit v1.2.1 From 2e8816c88f4746dbf34f1815696d083ba2e2d738 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 May 2013 19:49:50 -0400 Subject: mssql test fixes --- test/dialect/test_mssql.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/dialect/test_mssql.py b/test/dialect/test_mssql.py index a986dac5a..4a99ef5f7 100644 --- a/test/dialect/test_mssql.py +++ b/test/dialect/test_mssql.py @@ -16,8 +16,8 @@ from sqlalchemy import testing from sqlalchemy.testing import emits_warning_on, assert_raises_message import decimal from sqlalchemy.engine.reflection import Inspector -from sqlalchemy.util.compat import b -from sqlalchemy import sql +from sqlalchemy.util import b, u, ue +from sqlalchemy import sql, util class CompileTest(fixtures.TestBase, AssertsCompiledSQL): @@ -862,11 +862,11 @@ class QueryUnicodeTest(fixtures.TestBase): # encode in UTF-8 (sting object) because this is the default # dialect encoding - con.execute("insert into unitest_table values ('bien u\ - umang\xc3\xa9')".encode('UTF-8')) + con.execute(ue("insert into unitest_table values ('bien u\ + umang\xc3\xa9')").encode('UTF-8')) try: r = t1.select().execute().first() - assert isinstance(r[1], str), \ + assert isinstance(r[1], util.text_type), \ '%s is %s instead of unicode, working on %s' % (r[1], type(r[1]), meta.bind) finally: @@ -2084,7 +2084,7 @@ class InfoCoerceUnicodeTest(fixtures.TestBase): dialect = mssql.dialect() value = CoerceUnicode().bind_processor(dialect)('a string') - assert isinstance(value, str) + assert isinstance(value, util.text_type) class ReflectHugeViewTest(fixtures.TestBase): __only_on__ = 'mssql' -- cgit v1.2.1 From 2be39d5342746ea08ec5f7dcb73b6177b004de54 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 May 2013 20:02:17 -0400 Subject: get profile 1a back down to 5100 calls, that one was 10% greater due to this --- lib/sqlalchemy/engine/base.py | 6 +++--- test/profiles.txt | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index c2ba0922b..2d9f3af94 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -734,9 +734,9 @@ class Connection(Connectable): distilled_params = _distill_params(multiparams, params) if distilled_params: - # need list() + keys() here to suit - # both dict and RowProxy - keys = list(distilled_params[0].keys()) + # note this is usually dict but we support RowProxy + # as well; but dict.keys() as an iterator is OK + keys = distilled_params[0].keys() else: keys = [] diff --git a/test/profiles.txt b/test/profiles.txt index a41e153d9..090cf5ea1 100644 --- a/test/profiles.txt +++ b/test/profiles.txt @@ -265,8 +265,7 @@ test.aaa_profiling.test_resultset.ResultSetTest.test_unicode 3.3_sqlite_pysqlite # TEST: test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_1a_populate -test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_1a_populate 2.7_postgresql_psycopg2_cextensions 5131 -test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_1a_populate 2.7_postgresql_psycopg2_nocextensions 5693 +test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_1a_populate 2.7_postgresql_psycopg2_nocextensions 5175 test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_1a_populate 3.2_postgresql_psycopg2_nocextensions 4828 test.aaa_profiling.test_zoomark.ZooMarkTest.test_profile_1a_populate 3.3_postgresql_psycopg2_nocextensions 4792 -- cgit v1.2.1 From a393ef6799b3ed619f91ab60bfa1299a5fe19e8f Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 May 2013 20:04:54 -0400 Subject: fix an errant str check --- lib/sqlalchemy/sql/compiler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index b2c4a94c0..41ef20a7a 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -2025,7 +2025,7 @@ class DDLCompiler(engine.Compiled): def get_column_default_string(self, column): if isinstance(column.server_default, schema.DefaultClause): - if isinstance(column.server_default.arg, str): + if isinstance(column.server_default.arg, util.string_types): return "'%s'" % column.server_default.arg else: return self.sql_compiler.process(column.server_default.arg) -- cgit v1.2.1 From 6abd0c4eac69ba9ca3530a9e5076d57a5b42b998 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 May 2013 20:17:22 -0400 Subject: clean up some of this collection stuff --- lib/sqlalchemy/ext/associationproxy.py | 30 ++++++++++-------------- lib/sqlalchemy/orm/identity.py | 3 +-- lib/sqlalchemy/util/_collections.py | 43 +++++++++++++++++++++------------- 3 files changed, 40 insertions(+), 36 deletions(-) diff --git a/lib/sqlalchemy/ext/associationproxy.py b/lib/sqlalchemy/ext/associationproxy.py index 08875c3a0..0482a9205 100644 --- a/lib/sqlalchemy/ext/associationproxy.py +++ b/lib/sqlalchemy/ext/associationproxy.py @@ -758,24 +758,15 @@ class _AssociationDict(_AssociationCollection): def keys(self): return self.col.keys() - def _iteritems(self): - for key in self.col: - yield (key, self._get(self.col[key])) - raise StopIteration - - def _itervalues(self): - for key in self.col: - yield self._get(self.col[key]) - raise StopIteration + if util.py2k: + def iteritems(self): + return ((key, self._get(self.col[key])) for key in self.col) - def _iterkeys(self): - return self.col.iterkeys() + def itervalues(self): + return (self._get(self.col[key]) for key in self.col) - - if util.py2k: - iterkeys = _iterkeys - itervalues = _itervalues - iteritems = _iteritems + def iterkeys(self): + return self.col.iterkeys() def values(self): return [self._get(member) for member in self.col.values()] @@ -783,8 +774,11 @@ class _AssociationDict(_AssociationCollection): def items(self): return [(k, self._get(self.col[k])) for k in self] else: - values = _itervalues - items = _iteritems + def items(self): + return ((key, self._get(self.col[key])) for key in self.col) + + def values(self): + return (self._get(self.col[key]) for key in self.col) def pop(self, key, default=_NotProvided): if default is _NotProvided: diff --git a/lib/sqlalchemy/orm/identity.py b/lib/sqlalchemy/orm/identity.py index 55a78066a..d0234a1d3 100644 --- a/lib/sqlalchemy/orm/identity.py +++ b/lib/sqlalchemy/orm/identity.py @@ -154,12 +154,11 @@ class WeakInstanceDict(IdentityMap): if util.py2k: items = _items + values = _values def iteritems(self): return iter(self.items()) - values = _values - def itervalues(self): return iter(self.values()) else: diff --git a/lib/sqlalchemy/util/_collections.py b/lib/sqlalchemy/util/_collections.py index c10d19ea1..ed9ecfedc 100644 --- a/lib/sqlalchemy/util/_collections.py +++ b/lib/sqlalchemy/util/_collections.py @@ -10,6 +10,7 @@ import itertools import weakref import operator from .compat import threading, itertools_filterfalse +from . import py2k EMPTY_SET = frozenset() @@ -55,7 +56,7 @@ class KeyedTuple(tuple): t = tuple.__new__(cls, vals) t._labels = [] if labels: - t.__dict__.update(list(zip(labels, vals))) + t.__dict__.update(zip(labels, vals)) t._labels = labels return t @@ -189,13 +190,13 @@ class Properties(object): return default def keys(self): - return list(self._data.keys()) + return self._data.keys() def values(self): - return list(self._data.values()) + return self._data.values() def items(self): - return list(self._data.items()) + return self._data.items() def has_key(self, key): return key in self._data @@ -260,23 +261,33 @@ class OrderedDict(dict): def __iter__(self): return iter(self._list) - def values(self): - return [self[key] for key in self._list] + if py2k: + def values(self): + return [self[key] for key in self._list] - def itervalues(self): - return iter([self[key] for key in self._list]) + def keys(self): + return self._list - def keys(self): - return list(self._list) + def itervalues(self): + return iter([self[key] for key in self._list]) - def iterkeys(self): - return iter(list(self.keys())) + def iterkeys(self): + return iter(self) - def items(self): - return [(key, self[key]) for key in self.keys()] + def iteritems(self): + return iter(self.items()) + + def items(self): + return [(key, self[key]) for key in self._list] + else: + def values(self): + return (self[key] for key in self._list) + + def keys(self): + return iter(self._list) - def iteritems(self): - return iter(list(self.items())) + def items(self): + return ((key, self[key]) for key in self._list) def __setitem__(self, key, object): if key not in self: -- cgit v1.2.1 From 5e6d7faea688946776e0faec9cb1b716b1ff9305 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 May 2013 20:24:39 -0400 Subject: clean up types.py --- lib/sqlalchemy/types.py | 99 ++++++++++++++++++++----------------------------- 1 file changed, 41 insertions(+), 58 deletions(-) diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index c601dc306..bfff05362 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -392,13 +392,11 @@ class TypeEngine(AbstractType): return default.DefaultDialect() def __str__(self): -# start Py3K - return str(self.compile()) -# end Py3K -# start Py2K -# return unicode(self.compile()).\ -# encode('ascii', 'backslashreplace') -# end Py2K + if util.py2k: + return unicode(self.compile()).\ + encode('ascii', 'backslashreplace') + else: + return str(self.compile()) def __init__(self, *args, **kwargs): """Support implementations that were passing arguments""" @@ -1315,12 +1313,10 @@ class Integer(_DateAffinity, TypeEngine): Integer: self.__class__, Numeric: Numeric, }, -# start Py2K -# operators.div: { -# Integer: self.__class__, -# Numeric: Numeric, -# }, -# end Py2K + operators.div: { + Integer: self.__class__, + Numeric: Numeric, + }, operators.truediv: { Integer: self.__class__, Numeric: Numeric, @@ -1485,12 +1481,10 @@ class Numeric(_DateAffinity, TypeEngine): Numeric: self.__class__, Integer: self.__class__, }, -# start Py2K -# operators.div: { -# Numeric: self.__class__, -# Integer: self.__class__, -# }, -# end Py2K + operators.div: { + Numeric: self.__class__, + Integer: self.__class__, + }, operators.truediv: { Numeric: self.__class__, Integer: self.__class__, @@ -1555,11 +1549,9 @@ class Float(Numeric): Interval: Interval, Numeric: self.__class__, }, -# start Py2K -# operators.div: { -# Numeric: self.__class__, -# }, -# end Py2K + operators.div: { + Numeric: self.__class__, + }, operators.truediv: { Numeric: self.__class__, }, @@ -1690,12 +1682,7 @@ class _Binary(TypeEngine): @property def python_type(self): -# start Py3K - return bytes -# end Py3K -# start Py2K -# return str -# end Py2K + return util.binary_type # Python 3 - sqlite3 doesn't need the `Binary` conversion # here, though pg8000 does to indicate "bytea" @@ -1713,28 +1700,26 @@ class _Binary(TypeEngine): # Python 3 has native bytes() type # both sqlite3 and pg8000 seem to return it, # psycopg2 as of 2.5 returns 'memoryview' -# start Py3K - def result_processor(self, dialect, coltype): - def process(value): - if value is not None: - value = bytes(value) - return value - return process -# end Py3K -# start Py2K -# def result_processor(self, dialect, coltype): -# if util.jython: -# def process(value): -# if value is not None: -# if isinstance(value, array.array): -# return value.tostring() -# return str(value) -# else: -# return None -# else: -# process = processors.to_str -# return process -# end Py2K + if util.py2k: + def result_processor(self, dialect, coltype): + if util.jython: + def process(value): + if value is not None: + if isinstance(value, array.array): + return value.tostring() + return str(value) + else: + return None + else: + process = processors.to_str + return process + else: + def result_processor(self, dialect, coltype): + def process(value): + if value is not None: + value = bytes(value) + return value + return process def coerce_compared_value(self, op, value): """See :meth:`.TypeEngine.coerce_compared_value` for a description.""" @@ -1996,7 +1981,7 @@ class Enum(String, SchemaType): convert_unicode = kw.pop('convert_unicode', None) if convert_unicode is None: for e in enums: - if isinstance(e, util.string_types): + if isinstance(e, util.text_type): convert_unicode = True break else: @@ -2295,11 +2280,9 @@ class Interval(_DateAffinity, TypeDecorator): operators.truediv: { Numeric: self.__class__ }, -# start Py2K -# operators.div: { -# Numeric: self.__class__ -# } -# end Py2K + operators.div: { + Numeric: self.__class__ + } } @property -- cgit v1.2.1 From 4276049e495b543db2e6b5a15a6ea62bbe27260a Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 May 2013 20:44:34 -0400 Subject: fix test_execute w c extensions --- lib/sqlalchemy/util/__init__.py | 3 ++- test/engine/test_execute.py | 6 ++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/sqlalchemy/util/__init__.py b/lib/sqlalchemy/util/__init__.py index 9e099b072..687abb39a 100644 --- a/lib/sqlalchemy/util/__init__.py +++ b/lib/sqlalchemy/util/__init__.py @@ -9,7 +9,8 @@ from .compat import callable, cmp, reduce, \ pickle, dottedgetter, parse_qsl, namedtuple, next, WeakSet, reraise, \ raise_from_cause, text_type, string_types, int_types, binary_type, \ quote_plus, with_metaclass, print_, itertools_filterfalse, u, ue, b,\ - unquote_plus, b64decode, b64encode, byte_buffer, itertools_filter + unquote_plus, b64decode, b64encode, byte_buffer, itertools_filter,\ + StringIO from ._collections import KeyedTuple, ImmutableContainer, immutabledict, \ Properties, OrderedProperties, ImmutableProperties, OrderedDict, \ diff --git a/test/engine/test_execute.py b/test/engine/test_execute.py index 8dca2d92a..1c577730b 100644 --- a/test/engine/test_execute.py +++ b/test/engine/test_execute.py @@ -19,7 +19,6 @@ from sqlalchemy.dialects.oracle.zxjdbc import ReturningParam from sqlalchemy.engine import result as _result, default from sqlalchemy.engine.base import Connection, Engine from sqlalchemy.testing import fixtures -import io users, metadata, users_autoinc = None, None, None class ExecuteTest(fixtures.TestBase): @@ -835,7 +834,7 @@ class EchoTest(fixtures.TestBase): class MockStrategyTest(fixtures.TestBase): def _engine_fixture(self): - buf = io.StringIO() + buf = util.StringIO() def dump(sql, *multiparams, **params): buf.write(util.text_type(sql.compile(dialect=engine.dialect))) engine = create_engine('postgresql://', strategy='mock', executor=dump) @@ -940,7 +939,6 @@ class ResultProxyTest(fixtures.TestBase): def test_row_c_sequence_check(self): import csv import collections - from io import StringIO metadata = MetaData() metadata.bind = 'sqlite://' @@ -953,7 +951,7 @@ class ResultProxyTest(fixtures.TestBase): users.insert().execute(name='Test') row = users.select().execute().fetchone() - s = StringIO() + s = util.StringIO() writer = csv.writer(s) # csv performs PySequenceCheck call writer.writerow(row) -- cgit v1.2.1 From 638803eef1e5dc6e985b176b43bb9cb2a3b5010b Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 27 May 2013 13:39:24 -0400 Subject: - fix a dict while iterate mutation - illustrate how OrderedDict can catch these, but commented out to save function overhead --- lib/sqlalchemy/ext/declarative/base.py | 2 +- lib/sqlalchemy/util/_collections.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/sqlalchemy/ext/declarative/base.py b/lib/sqlalchemy/ext/declarative/base.py index 9187ed7f8..5a2b88db4 100644 --- a/lib/sqlalchemy/ext/declarative/base.py +++ b/lib/sqlalchemy/ext/declarative/base.py @@ -173,7 +173,7 @@ def _as_declarative(cls, classname, dict_): # extract columns from the class dict declared_columns = set() - for key, c in our_stuff.items(): + for key, c in list(our_stuff.items()): if isinstance(c, (ColumnProperty, CompositeProperty)): for col in c.columns: if isinstance(col, Column) and \ diff --git a/lib/sqlalchemy/util/_collections.py b/lib/sqlalchemy/util/_collections.py index ed9ecfedc..5991fc8a4 100644 --- a/lib/sqlalchemy/util/_collections.py +++ b/lib/sqlalchemy/util/_collections.py @@ -261,6 +261,14 @@ class OrderedDict(dict): def __iter__(self): return iter(self._list) + + #def __iter__(self): + # len_ = len(self._list) + # for item in self._list: + # yield item + # assert len_ == len(self._list), \ + # "Dictionary changed size during iteration" + if py2k: def values(self): return [self[key] for key in self._list] @@ -281,12 +289,15 @@ class OrderedDict(dict): return [(key, self[key]) for key in self._list] else: def values(self): + #return (self[key] for key in self) return (self[key] for key in self._list) def keys(self): + #return iter(self) return iter(self._list) def items(self): + #return ((key, self[key]) for key in self) return ((key, self[key]) for key in self._list) def __setitem__(self, key, object): -- cgit v1.2.1 From 679b3036c2d6c3715ede329aeb82aad17f5cea24 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 27 May 2013 16:34:18 -0400 Subject: - oracle py3k fix --- lib/sqlalchemy/dialects/oracle/base.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/sqlalchemy/dialects/oracle/base.py b/lib/sqlalchemy/dialects/oracle/base.py index 4863b7ba1..6b6c32ae0 100644 --- a/lib/sqlalchemy/dialects/oracle/base.py +++ b/lib/sqlalchemy/dialects/oracle/base.py @@ -1185,7 +1185,9 @@ class OracleDialect(default.DefaultDialect): rp = connection.execute(sql.text(text), **params).scalar() if rp: - return rp.decode(self.encoding) + if util.py2k: + rp = rp.decode(self.encoding) + return rp else: return None -- cgit v1.2.1 From f9bb6c2a54ee10270a0661f938ac99b1dccfd8ef Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 27 May 2013 17:06:05 -0400 Subject: - additional oracle fixes. cx_oracle under py3k is complaining about tuples to executemany(), so just unconditionally turn this into a list - this one test segfaults only on py3k + cx_oracle --- lib/sqlalchemy/dialects/oracle/cx_oracle.py | 5 +++++ test/engine/test_reconnect.py | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/sqlalchemy/dialects/oracle/cx_oracle.py b/lib/sqlalchemy/dialects/oracle/cx_oracle.py index 5b0c3edd7..e013799db 100644 --- a/lib/sqlalchemy/dialects/oracle/cx_oracle.py +++ b/lib/sqlalchemy/dialects/oracle/cx_oracle.py @@ -819,6 +819,11 @@ class OracleDialect_cx_oracle(OracleDialect): id = random.randint(0, 2 ** 128) return (0x1234, "%032x" % id, "%032x" % 9) + def do_executemany(self, cursor, statement, parameters, context=None): + if isinstance(parameters, tuple): + parameters = list(parameters) + cursor.executemany(statement, parameters) + def do_begin_twophase(self, connection, xid): connection.connection.begin(*xid) diff --git a/test/engine/test_reconnect.py b/test/engine/test_reconnect.py index 3dec01c69..ee3ff1459 100644 --- a/test/engine/test_reconnect.py +++ b/test/engine/test_reconnect.py @@ -7,7 +7,7 @@ import sqlalchemy as tsa from sqlalchemy import testing from sqlalchemy.testing import engines from sqlalchemy.testing.util import gc_collect -from sqlalchemy import exc +from sqlalchemy import exc, util from sqlalchemy.testing import fixtures from sqlalchemy.testing.engines import testing_engine @@ -464,6 +464,9 @@ class RealReconnectTest(fixtures.TestBase): conn.invalidate() conn.invalidate() + @testing.skip_if( + [lambda: util.py3k, "oracle+cx_oracle"], + "Crashes on py3k+cx_oracle") def test_explode_in_initializer(self): engine = engines.testing_engine() def broken_initialize(connection): -- cgit v1.2.1 From 73404e36836a0f53be9ffe28006b8492be7b0190 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 27 May 2013 17:15:30 -0400 Subject: - run the whole test suite with the "debugging" ordered dict on, find some more failures --- lib/sqlalchemy/util/_collections.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/sqlalchemy/util/_collections.py b/lib/sqlalchemy/util/_collections.py index 5991fc8a4..689a6756b 100644 --- a/lib/sqlalchemy/util/_collections.py +++ b/lib/sqlalchemy/util/_collections.py @@ -143,7 +143,7 @@ class Properties(object): return len(self._data) def __iter__(self): - return iter(self._data.values()) + return iter(list(self._data.values())) def __add__(self, other): return list(self) + list(other) @@ -262,13 +262,6 @@ class OrderedDict(dict): return iter(self._list) - #def __iter__(self): - # len_ = len(self._list) - # for item in self._list: - # yield item - # assert len_ == len(self._list), \ - # "Dictionary changed size during iteration" - if py2k: def values(self): return [self[key] for key in self._list] @@ -300,6 +293,24 @@ class OrderedDict(dict): #return ((key, self[key]) for key in self) return ((key, self[key]) for key in self._list) + _debug_iter = False + if _debug_iter: + # normally disabled to reduce function call + # overhead + def __iter__(self): + len_ = len(self._list) + for item in self._list: + yield item + assert len_ == len(self._list), \ + "Dictionary changed size during iteration" + def values(self): + return (self[key] for key in self) + def keys(self): + return iter(self) + def items(self): + return ((key, self[key]) for key in self) + + def __setitem__(self, key, object): if key not in self: try: -- cgit v1.2.1 From 534e05888e1ec7018c03d979df4f34074a61f12b Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 29 May 2013 18:08:28 -0400 Subject: hstores are text, and in py3k they seem to be implcitly unicode. so add unicode encoding for py2k for the non-native hstore, pullreq for native psycopg2 support coming.... --- lib/sqlalchemy/dialects/postgresql/hstore.py | 36 ++++++++++++++++++++-------- test/dialect/test_postgresql.py | 25 +++++++++++++++++++ 2 files changed, 51 insertions(+), 10 deletions(-) diff --git a/lib/sqlalchemy/dialects/postgresql/hstore.py b/lib/sqlalchemy/dialects/postgresql/hstore.py index adfb82da7..b0b13eb0e 100644 --- a/lib/sqlalchemy/dialects/postgresql/hstore.py +++ b/lib/sqlalchemy/dialects/postgresql/hstore.py @@ -262,19 +262,35 @@ class HSTORE(sqltypes.Concatenable, sqltypes.TypeEngine): _adapt_expression(self, op, other_comparator) def bind_processor(self, dialect): - def process(value): - if isinstance(value, dict): - return _serialize_hstore(value) - else: - return value + if util.py2k: + encoding = dialect.encoding + def process(value): + if isinstance(value, dict): + return _serialize_hstore(value).encode(encoding) + else: + return value + else: + def process(value): + if isinstance(value, dict): + return _serialize_hstore(value) + else: + return value return process def result_processor(self, dialect, coltype): - def process(value): - if value is not None: - return _parse_hstore(value) - else: - return value + if util.py2k: + encoding = dialect.encoding + def process(value): + if value is not None: + return _parse_hstore(value.decode(encoding)) + else: + return value + else: + def process(value): + if value is not None: + return _parse_hstore(value) + else: + return value return process diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py index 286628d5e..3931a1968 100644 --- a/test/dialect/test_postgresql.py +++ b/test/dialect/test_postgresql.py @@ -3207,3 +3207,28 @@ class HStoreRoundTripTest(fixtures.TablesTest): def test_fixed_round_trip_native(self): engine = testing.db self._test_fixed_round_trip(engine) + + def _test_unicode_round_trip(self, engine): + s = select([ + hstore( + array([u'réveillé', u'drôle', u'S’il']), + array([u'réveillé', u'drôle', u'S’il']) + ) + ]) + eq_( + engine.scalar(s), + { + u'réveillé': u'réveillé', + u'drôle': u'drôle', + u'S’il': u'S’il' + } + ) + + def test_unicode_round_trip_python(self): + engine = self._non_native_engine() + self._test_unicode_round_trip(engine) + + @testing.only_on("postgresql+psycopg2") + def test_unicode_round_trip_native(self): + engine = testing.db + self._test_unicode_round_trip(engine) -- cgit v1.2.1 From d02d86a11452b67981e2c9637cedbfc902b237c5 Mon Sep 17 00:00:00 2001 From: Dmitry Mugtasimov Date: Tue, 28 May 2013 16:50:12 +0400 Subject: Unicode support for psycopg2 native hstore implementation --- lib/sqlalchemy/dialects/postgresql/psycopg2.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index ce06aab05..da333e8eb 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -392,7 +392,8 @@ class PGDialect_psycopg2(PGDialect): hstore_oids = self._hstore_oids(conn) if hstore_oids is not None: oid, array_oid = hstore_oids - extras.register_hstore(conn, oid=oid, array_oid=array_oid) + extras.register_hstore(conn, oid=oid, array_oid=array_oid, + unicode=True) fns.append(on_connect) if fns: -- cgit v1.2.1 From 6c4a61b07a7aec8f6043c3e82eded27dda631cf4 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 29 May 2013 18:29:12 -0400 Subject: - repair for py3k - fix test --- lib/sqlalchemy/dialects/postgresql/psycopg2.py | 7 ++++++- test/dialect/test_postgresql.py | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index da333e8eb..fcc1946ff 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -392,8 +392,13 @@ class PGDialect_psycopg2(PGDialect): hstore_oids = self._hstore_oids(conn) if hstore_oids is not None: oid, array_oid = hstore_oids - extras.register_hstore(conn, oid=oid, array_oid=array_oid, + if util.py2k: + extras.register_hstore(conn, oid=oid, + array_oid=array_oid, unicode=True) + else: + extras.register_hstore(conn, oid=oid, + array_oid=array_oid) fns.append(on_connect) if fns: diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py index 3931a1968..00e5c07ab 100644 --- a/test/dialect/test_postgresql.py +++ b/test/dialect/test_postgresql.py @@ -2901,8 +2901,8 @@ class HStoreTest(fixtures.TestBase): dialect, None) assert_raises_message( ValueError, - r'''After '\[\.\.\.\], "key1"=>"value1", ', could not parse ''' - '''residual at position 36: 'crapcrapcrap, "key3"\[\.\.\.\]''', + r'''After u?'\[\.\.\.\], "key1"=>"value1", ', could not parse ''' + '''residual at position 36: u?'crapcrapcrap, "key3"\[\.\.\.\]''', proc, '"key2"=>"value2", "key1"=>"value1", ' 'crapcrapcrap, "key3"=>"value3"' -- cgit v1.2.1 From da07a712f395a74b3b25987c6628f03a0b6a3812 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 29 May 2013 18:30:56 -0400 Subject: changelog --- doc/build/changelog/changelog_08.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index bec8a3f05..acf4ea670 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -6,6 +6,15 @@ .. changelog:: :version: 0.8.2 + .. change:: + :tags: bug, postgresql + :tickets: 2735 + + Fixed the HSTORE type to correctly encode/decode for unicode. + This is always on, as the hstore is a textual type, and + matches the behavior of psycopg2 when using Python 3. + Courtesy Dmitry Mugtasimov. + .. change:: :tags: bug, examples -- cgit v1.2.1 From be2c145a84df5db0233f84995765d3f614776f75 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 29 May 2013 18:46:10 -0400 Subject: keep the contract for Properties as returning lists for keys, values, items. It's not the same as a dictionary as __iter__ does the values --- lib/sqlalchemy/util/_collections.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/sqlalchemy/util/_collections.py b/lib/sqlalchemy/util/_collections.py index 689a6756b..86a90828a 100644 --- a/lib/sqlalchemy/util/_collections.py +++ b/lib/sqlalchemy/util/_collections.py @@ -190,13 +190,13 @@ class Properties(object): return default def keys(self): - return self._data.keys() + return list(self._data) def values(self): - return self._data.values() + return list(self._data.values()) def items(self): - return self._data.items() + return list(self._data.items()) def has_key(self, key): return key in self._data -- cgit v1.2.1