diff options
Diffstat (limited to 'lib/sqlalchemy/sql')
| -rw-r--r-- | lib/sqlalchemy/sql/__init__.py | 2 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 63 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/expression.py | 84 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/functions.py | 3 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/operators.py | 10 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/util.py | 16 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/visitors.py | 4 |
7 files changed, 92 insertions, 90 deletions
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'(?<![:\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): diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 7846ac3b2..1ad6364d2 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -1375,7 +1375,7 @@ func = _FunctionGenerator() modifier = _FunctionGenerator(group=False) -class _truncated_label(unicode): +class _truncated_label(str): """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( - unicode(self) + - unicode(other)) + str(self) + + str(other)) def __radd__(self, other): return _anonymous_label( - unicode(other) + - unicode(self)) + str(other) + + str(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, basestring): + if isinstance(element, str): return element else: try: @@ -1486,7 +1486,7 @@ def _labeled(element): def _column_as_key(element): - if isinstance(element, basestring): + if isinstance(element, str): 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, basestring): - return TextClause(unicode(element)) + elif isinstance(element, str): + return TextClause(str(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, basestring): - return TextClause(unicode(element)) + if isinstance(element, str): + return TextClause(str(element)) elif hasattr(insp, "selectable"): return insp.selectable raise exc.ArgumentError("FROM expression expected") @@ -1914,11 +1914,12 @@ class ClauseElement(Visitable): return dialect.statement_compiler(dialect, self, **kw) 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 __and__(self, other): return and_(self, other) @@ -1929,7 +1930,7 @@ class ClauseElement(Visitable): def __invert__(self): return self._negate() - def __nonzero__(self): + def __bool__(self): raise TypeError("Boolean value of this clause is not defined") def _negate(self): @@ -2507,7 +2508,7 @@ class ColumnCollection(util.OrderedProperties): def update(self, value): self._data.update(value) self._all_cols.clear() - self._all_cols.update(self._data.values()) + self._all_cols.update(list(self._data.values())) def extend(self, iter): self.update((c.key, c) for c in iter) @@ -2523,13 +2524,13 @@ class ColumnCollection(util.OrderedProperties): return and_(*l) def __contains__(self, other): - if not isinstance(other, basestring): + if not isinstance(other, str): 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(self._data.values()) + self.__dict__['_all_cols'] = util.column_set(list(self._data.values())) def contains_column(self, col): # this has to be done via set() membership @@ -3202,7 +3203,7 @@ class TextClause(Executable, ClauseElement): self._execution_options.union( {'autocommit': autocommit}) if typemap is not None: - for key in typemap.keys(): + for key in list(typemap.keys()): typemap[key] = sqltypes.to_instance(typemap[key]) def repl(m): @@ -3236,10 +3237,10 @@ class TextClause(Executable, ClauseElement): def _copy_internals(self, clone=_clone, **kw): self.bindparams = dict((b.key, clone(b, **kw)) - for b in self.bindparams.values()) + for b in list(self.bindparams.values())) def get_children(self, **kwargs): - return self.bindparams.values() + return list(self.bindparams.values()) class Null(ColumnElement): @@ -3750,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, basestring): + if isinstance(operator, str): operator = operators.custom_op(operator) self._orig = (left, right) self.left = _literal_as_text(left).self_group(against=operator) @@ -3764,7 +3765,7 @@ class BinaryExpression(ColumnElement): else: self.modifiers = modifiers - def __nonzero__(self): + def __bool__(self): if self.operator in (operator.eq, operator.ne): return self.operator(hash(self._orig[0]), hash(self._orig[1])) else: @@ -4057,11 +4058,12 @@ class Alias(FromClause): @property def description(self): - # Py3K - #return self.name - # Py2K - return self.name.encode('ascii', 'backslashreplace') - # end Py2K +# start Py3K + return self.name +# end Py3K +# start Py2K +# return self.name.encode('ascii', 'backslashreplace') +# end Py2K def as_scalar(self): try: @@ -4471,11 +4473,12 @@ class ColumnClause(Immutable, ColumnElement): @util.memoized_property def description(self): - # Py3K - #return self.name - # Py2K - return self.name.encode('ascii', 'backslashreplace') - # end Py2K +# start Py3K + return self.name +# end Py3K +# start Py2K +# return self.name.encode('ascii', 'backslashreplace') +# end Py2K @_memoized_property def _key_label(self): @@ -4602,11 +4605,12 @@ class TableClause(Immutable, FromClause): @util.memoized_property def description(self): - # Py3K - #return self.name - # Py2K - return self.name.encode('ascii', 'backslashreplace') - # end Py2K +# start Py3K + return self.name +# end Py3K +# start Py2K +# return self.name.encode('ascii', 'backslashreplace') +# end Py2K def append_column(self, c): self._columns[c.key] = c diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py index c1c07dfb6..a2b7ac628 100644 --- a/lib/sqlalchemy/sql/functions.py +++ b/lib/sqlalchemy/sql/functions.py @@ -41,7 +41,7 @@ class _GenericMeta(VisitableType): super(_GenericMeta, cls).__init__(clsname, bases, clsdict) -class GenericFunction(Function): +class GenericFunction(Function, metaclass=_GenericMeta): """Define a 'generic' function. A generic function is a pre-established :class:`.Function` @@ -112,7 +112,6 @@ class GenericFunction(Function): name is still recognized for backwards-compatibility. """ - __metaclass__ = _GenericMeta coerce_arguments = True diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py index a7e6af116..cf1c484d0 100644 --- a/lib/sqlalchemy/sql/operators.py +++ b/lib/sqlalchemy/sql/operators.py @@ -14,8 +14,8 @@ from operator import ( getitem, lshift, rshift ) -# Py2K -from operator import (div,) +# start Py2K +#from operator import (div,) # end Py2K from ..util import symbol @@ -789,9 +789,9 @@ _PRECEDENCE = { getitem: 15, mul: 8, truediv: 8, - # Py2K - div: 8, - # end Py2K +# start Py2K +# div: 8, +# end Py2K mod: 8, neg: 8, add: 7, diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index 4aa2d7496..12edab3e1 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, basestring): + if isinstance(element, str): element = element.replace("'", "''") return "'%s'" % element else: @@ -349,7 +349,7 @@ def join_condition(a, b, ignore_nonexistent_tables=False, continue try: col = fk.get_referent(left) - except exc.NoReferenceError, nrte: + except exc.NoReferenceError as nrte: if nrte.table_name == left.name: raise else: @@ -367,7 +367,7 @@ def join_condition(a, b, ignore_nonexistent_tables=False, continue try: col = fk.get_referent(b) - except exc.NoReferenceError, nrte: + except exc.NoReferenceError as nrte: if nrte.table_name == b.name: raise else: @@ -518,15 +518,15 @@ class AnnotatedColumnElement(Annotated): # so that the resulting objects are pickleable. annotated_classes = {} -for cls in expression.__dict__.values() + [schema.Column, schema.Table]: +for cls in list(expression.__dict__.values()) + [schema.Column, schema.Table]: if isinstance(cls, type) and issubclass(cls, expression.ClauseElement): if issubclass(cls, expression.ColumnElement): annotation_cls = "AnnotatedColumnElement" else: annotation_cls = "Annotated" - exec "class Annotated%s(%s, cls):\n" \ - " pass" % (cls.__name__, annotation_cls) in locals() - exec "annotated_classes[cls] = Annotated%s" % (cls.__name__,) + exec("class Annotated%s(%s, cls):\n" \ + " pass" % (cls.__name__, annotation_cls), locals()) + exec("annotated_classes[cls] = Annotated%s" % (cls.__name__,)) def _deep_annotate(element, annotations, exclude=None): @@ -765,7 +765,7 @@ class AliasedRow(object): return self.row[self.map[key]] def keys(self): - return self.row.keys() + return list(self.row.keys()) class ClauseAdapter(visitors.ReplacingCloningVisitor): diff --git a/lib/sqlalchemy/sql/visitors.py b/lib/sqlalchemy/sql/visitors.py index f1dbb9e32..2ff7750ca 100644 --- a/lib/sqlalchemy/sql/visitors.py +++ b/lib/sqlalchemy/sql/visitors.py @@ -87,14 +87,12 @@ def _generate_dispatch(cls): cls._compiler_dispatch = _compiler_dispatch -class Visitable(object): +class Visitable(object, metaclass=VisitableType): """Base class for visitable objects, applies the ``VisitableType`` metaclass. """ - __metaclass__ = VisitableType - class ClauseVisitor(object): """Base class for visitor objects which can traverse using |
