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 --- lib/sqlalchemy/sql/compiler.py | 63 +++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 31 deletions(-) (limited to 'lib/sqlalchemy/sql/compiler.py') 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'(? Date: Sat, 27 Apr 2013 20:58:13 -0400 Subject: import of "sqlalchemy" and "sqlalchemy.orm" works. --- lib/sqlalchemy/sql/compiler.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'lib/sqlalchemy/sql/compiler.py') 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: -- 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/sql/compiler.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'lib/sqlalchemy/sql/compiler.py') 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: -- 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/sql/compiler.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/sqlalchemy/sql/compiler.py') 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): -- 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/sql/compiler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/sql/compiler.py') 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) -- 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(-) (limited to 'lib/sqlalchemy/sql/compiler.py') 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