summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/schema.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/schema.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/schema.py')
-rw-r--r--lib/sqlalchemy/schema.py97
1 files changed, 50 insertions, 47 deletions
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