summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-04-27 19:53:57 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-04-27 19:53:57 -0400
commit4b614b9b35cd2baddb7ca67c04bee5d70ec6a172 (patch)
tree7483cd269f5823f903f96709eb864fff9b6d9383 /lib/sqlalchemy/sql/compiler.py
parent9716a5c45e6185c5871555722d8495880f0e8c7a (diff)
downloadsqlalchemy-4b614b9b35cd2baddb7ca67c04bee5d70ec6a172.tar.gz
- the raw 2to3 run
- went through examples/ and cleaned out excess list() calls
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r--lib/sqlalchemy/sql/compiler.py63
1 files changed, 32 insertions, 31 deletions
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'(?<![:\w\$\x5c]):([\w\$]+)(?![:\w\$])', re.UNICODE)
BIND_PARAMS_ESC = re.compile(r'\x5c(:[\w\$]+)(?![:\w\$])', re.UNICODE)
@@ -83,9 +83,9 @@ OPERATORS = {
operators.add: ' + ',
operators.mul: ' * ',
operators.sub: ' - ',
- # Py2K
- operators.div: ' / ',
- # end Py2K
+# start Py2K
+# operators.div: ' / ',
+# end Py2K
operators.mod: ' % ',
operators.truediv: ' / ',
operators.neg: '-',
@@ -334,7 +334,7 @@ class SQLCompiler(engine.Compiled):
if params:
pd = {}
- for bindparam, name in self.bind_names.iteritems():
+ for bindparam, name in self.bind_names.items():
if bindparam.key in params:
pd[name] = params[bindparam.key]
elif name in params:
@@ -480,7 +480,7 @@ class SQLCompiler(engine.Compiled):
def visit_textclause(self, textclause, **kwargs):
if textclause.typemap is not None:
- for colname, type_ in textclause.typemap.iteritems():
+ for colname, type_ in textclause.typemap.items():
self.result_map[colname
if self.dialect.case_sensitive
else colname.lower()] = \
@@ -826,12 +826,12 @@ class SQLCompiler(engine.Compiled):
of the DBAPI.
"""
- if isinstance(value, basestring):
+ if isinstance(value, str):
value = value.replace("'", "''")
return "'%s'" % value
elif value is None:
return "NULL"
- elif isinstance(value, (float, int, long)):
+ elif isinstance(value, (float, int)):
return repr(value)
elif isinstance(value, decimal.Decimal):
return str(value)
@@ -1136,7 +1136,7 @@ class SQLCompiler(engine.Compiled):
self, ashint=True)
})
for (from_, dialect), hinttext in
- select._hints.iteritems()
+ select._hints.items()
if dialect in ('*', self.dialect.name)
])
hint_text = self.get_select_hint_text(byfrom)
@@ -1214,7 +1214,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 self.ctes.values()]
+ [txt for txt in list(self.ctes.values())]
)
cte_text += "\n "
return cte_text
@@ -1325,7 +1325,7 @@ class SQLCompiler(engine.Compiled):
dialect_hints = dict([
(table, hint_text)
for (table, dialect), hint_text in
- insert_stmt._hints.items()
+ list(insert_stmt._hints.items())
if dialect in ('*', self.dialect.name)
])
if insert_stmt.table in dialect_hints:
@@ -1422,7 +1422,7 @@ class SQLCompiler(engine.Compiled):
dialect_hints = dict([
(table, hint_text)
for (table, dialect), hint_text in
- update_stmt._hints.items()
+ list(update_stmt._hints.items())
if dialect in ('*', self.dialect.name)
])
if update_stmt.table in dialect_hints:
@@ -1528,7 +1528,7 @@ class SQLCompiler(engine.Compiled):
values = []
if stmt_parameters is not None:
- for k, v in stmt_parameters.iteritems():
+ for k, v in stmt_parameters.items():
colkey = sql._column_as_key(k)
if colkey is not None:
parameters.setdefault(colkey, v)
@@ -1559,7 +1559,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 stmt_parameters.items()
+ for c, param in list(stmt_parameters.items())
)
assert self.isupdate
affected_tables = set()
@@ -1752,7 +1752,7 @@ class SQLCompiler(engine.Compiled):
dialect_hints = dict([
(table, hint_text)
for (table, dialect), hint_text in
- delete_stmt._hints.items()
+ list(delete_stmt._hints.items())
if dialect in ('*', self.dialect.name)
])
if delete_stmt.table in dialect_hints:
@@ -1868,22 +1868,23 @@ class DDLCompiler(engine.Compiled):
and not first_pk)
if column.primary_key:
first_pk = True
- except exc.CompileError, ce:
- # Py3K
- #raise exc.CompileError("(in table '%s', column '%s'): %s"
- # % (
- # table.description,
- # column.name,
- # ce.args[0]
- # )) from ce
- # Py2K
+ except exc.CompileError as ce:
+# start Py3K
raise exc.CompileError("(in table '%s', column '%s'): %s"
- % (
+ % (
table.description,
column.name,
ce.args[0]
- )), None, sys.exc_info()[2]
- # end Py2K
+ )) 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:
@@ -2036,7 +2037,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, basestring):
+ if isinstance(column.server_default.arg, str):
return "'%s'" % column.server_default.arg
else:
return self.sql_compiler.process(column.server_default.arg)
@@ -2084,11 +2085,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 constraint._elements.values()),
+ for f in list(constraint._elements.values())),
self.define_constraint_remote_table(
constraint, remote_table, preparer),
', '.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_match(constraint)
text += self.define_constraint_cascades(constraint)
@@ -2355,7 +2356,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(unicode(value))
+ or not self.legal_characters.match(str(value))
or (lc_value != value))
def quote_schema(self, schema, force):