diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-08-09 20:50:46 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-08-09 20:50:46 +0000 |
| commit | e7241263aa9db24885b41984b85300178428a60c (patch) | |
| tree | 7c2e9a8bbab97e390d02b13865db5a68d166995a /lib/sqlalchemy | |
| parent | 7974625e8b86a28f3ac81c3c620df9b2801b133d (diff) | |
| download | sqlalchemy-e7241263aa9db24885b41984b85300178428a60c.tar.gz | |
python3k fixes
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/dialects/mssql/base.py | 4 | ||||
| -rw-r--r-- | lib/sqlalchemy/schema.py | 11 | ||||
| -rw-r--r-- | lib/sqlalchemy/test/testing.py | 21 | ||||
| -rw-r--r-- | lib/sqlalchemy/util.py | 7 |
4 files changed, 36 insertions, 7 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index 07ed37c35..b36cebd37 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -1029,8 +1029,8 @@ class MSSQLCompiler(compiler.SQLCompiler): adapter = sql_util.ClauseAdapter(target) def col_label(col): - adapted = adapter.traverse(c) - if isinstance(c, expression._Label): + adapted = adapter.traverse(col) + if isinstance(col, expression._Label): return adapted.label(c.key) else: return self.label_select_column(None, adapted, asfrom=False) diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index ec7a9f394..7af4d39d4 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -170,7 +170,16 @@ class Table(SchemaItem, expression.TableClause): ddl_events = ('before-create', 'after-create', 'before-drop', 'after-drop') - def __new__(cls, name, metadata, *args, **kw): + def __new__(cls, *args, **kw): + if not args: + # python3k pickle seems to call this + return object.__new__(cls) + + try: + name, metadata, args = args[0], args[1], args[2:] + except IndexError: + raise TypeError("Table() takes at least two arguments") + schema = kw.get('schema', None) useexisting = kw.pop('useexisting', False) mustexist = kw.pop('mustexist', False) diff --git a/lib/sqlalchemy/test/testing.py b/lib/sqlalchemy/test/testing.py index 16a13d9d3..91e9c68ae 100644 --- a/lib/sqlalchemy/test/testing.py +++ b/lib/sqlalchemy/test/testing.py @@ -9,12 +9,13 @@ import warnings from cStringIO import StringIO from sqlalchemy.test import config, assertsql, util as testutil -from sqlalchemy.util import function_named +from sqlalchemy.util import function_named, py3k from engines import drop_all_tables from sqlalchemy import exc as sa_exc, util, types as sqltypes, schema, pool from nose import SkipTest + _ops = { '<': operator.lt, '>': operator.gt, '==': operator.eq, @@ -593,10 +594,24 @@ class AssertsCompiledSQL(object): c = clause.compile(dialect=dialect, **kw) + # Py3K + ## I kid you not. + ## + ## 1. Doesn't work: + ## http://mail.python.org/pipermail/python-3000/2008-February/012144.html + ## + ## 2. no more setdefaultencoding(). (although this is undocumented) + ## + ## 3. Therefore: + ## http://docs.python.org/3.1/library/sys.html#sys.stdin + ## + #sys.stdout.buffer.write(("\nSQL String:\n" + str(c) + repr(getattr(c, 'params', {}))).encode('utf-8')) + # Py2K print "\nSQL String:\n" + str(c) + repr(getattr(c, 'params', {})) - + # end Py2K + cc = re.sub(r'[\n\t]', '', str(c)) - + eq_(cc, result, "%r != %r on dialect %r" % (cc, result, dialect)) if checkparams is not None: diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py index f970f3737..67990a202 100644 --- a/lib/sqlalchemy/util.py +++ b/lib/sqlalchemy/util.py @@ -540,10 +540,15 @@ def duck_type_collection(specimen, default=None): def dictlike_iteritems(dictlike): """Return a (key, value) iterator for almost any dict-like object.""" + # Py3K + #if hasattr(dictlike, 'items'): + # return dictlike.items() + # Py2K if hasattr(dictlike, 'iteritems'): return dictlike.iteritems() elif hasattr(dictlike, 'items'): return iter(dictlike.items()) + # end Py2K getter = getattr(dictlike, '__getitem__', getattr(dictlike, 'get', None)) if getter is None: @@ -970,7 +975,7 @@ class IdentitySet(object): if len(self) < len(other): return False - for m in itertools.ifilterfalse(self._members.has_key, + for m in itertools.ifilterfalse(self._members.__contains__, other._members.iterkeys()): return False return True |
