"""Provide the 'autogenerate' feature which can produce migration operations
automatically."""
+try:
+ import builtins
+except ImportError:
+ import __builtin__ as builtins
import logging
import re
}
def _render_server_default(default, autogen_context):
+ string_type = getattr(builtins, 'basestring', str)
rendered = _user_defined_render("server_default", default, autogen_context)
if rendered is not False:
return rendered
if isinstance(default, sa_schema.DefaultClause):
- if isinstance(default.arg, basestring):
+ if isinstance(default.arg, string_type):
default = default.arg
else:
default = str(default.arg.compile(
dialect=autogen_context['dialect']))
- if isinstance(default, basestring):
+ if isinstance(default, string_type):
# TODO: this is just a hack to get
# tests to pass until we figure out
# WTF sqlite is doing
+try:
+ import builtins
+except ImportError:
+ import __builtin__ as builtins
+
from sqlalchemy.sql.expression import _BindParamClause
from sqlalchemy.ext.compiler import compiles
from sqlalchemy import schema, text
def _exec(self, construct, execution_options=None,
multiparams=(),
params=util.immutabledict()):
- if isinstance(construct, basestring):
+ if isinstance(construct, getattr(builtins, 'basestring', str)):
construct = text(construct)
if self.as_sql:
if multiparams or params:
# TODO: coverage
raise Exception("Execution arguments not allowed with as_sql")
+ unicode = getattr(builtins, 'unicode', str)
self.static_output(unicode(
construct.compile(dialect=self.dialect)
).replace("\t", " ").strip() + self.command_terminator)
+try:
+ import builtins
+except ImportError:
+ import __builtin__ as builtins
+
from sqlalchemy.ext.compiler import compiles
from sqlalchemy import types as sqltypes
from sqlalchemy import schema
)
def _render_value(compiler, expr):
- if isinstance(expr, basestring):
+ if isinstance(expr, getattr(builtins, 'basestring', str)):
return "'%s'" % expr
else:
return compiler.sql_compiler.process(expr)
+try:
+ import builtins
+except ImportError:
+ import __builtin__ as builtins
from contextlib import contextmanager
from sqlalchemy.types import NULLTYPE, Integer
ForeignKey.
"""
- if isinstance(fk._colspec, basestring):
+ if isinstance(fk._colspec, getattr(builtins, 'basestring', str)):
table_key, cname = fk._colspec.rsplit('.', 1)
sname, tname = self._parse_table_key(table_key)
if table_key not in metadata.tables:
def assert_compiled(element, assert_string, dialect=None):
dialect = _get_dialect(dialect)
+ unicode = getattr(builtins, 'unicode', str)
eq_(
unicode(element.compile(dialect=dialect)).\
replace("\n", "").replace("\t", ""),
# as tests get more involved
self.connection = None
def _exec(self, construct, *args, **kw):
+ basestring = getattr(builtins, 'basestring', str)
+ unicode = getattr(builtins, 'unicode', str)
if isinstance(construct, basestring):
construct = text(construct)
sql = unicode(construct.compile(dialect=self.dialect))
def write_script(scriptdir, rev_id, content):
old = scriptdir._revision_map[rev_id]
path = old.path
+ if not hasattr(builtins, 'unicode') and isinstance(content, bytes):
+ content = content.decode()
with open(path, 'w') as fp:
fp.write(textwrap.dedent(content))
pyc_path = util.pyc_file_from_path(path)
)
eq_(
[(rec[0], rec[1].name) for rec in diffs],
- [('remove_table', 'extra'), ('remove_table', u'user')]
+ [('remove_table', 'extra'), ('remove_table', 'user')]
)
class AutogenKeyTest(AutogenTest, TestCase):