]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
python3k fixes
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 9 Aug 2009 20:50:46 +0000 (20:50 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 9 Aug 2009 20:50:46 +0000 (20:50 +0000)
lib/sqlalchemy/dialects/mssql/base.py
lib/sqlalchemy/schema.py
lib/sqlalchemy/test/testing.py
lib/sqlalchemy/util.py
test/aaa_profiling/test_compiler.py
test/aaa_profiling/test_pool.py
test/base/test_utils.py
test/engine/test_transaction.py
test/ex/test_examples.py

index 07ed37c356bbfbd2af921e23d101558e3cb6b017..b36cebd37eb0e14570ca29b5966c39a294498789 100644 (file)
@@ -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)
index ec7a9f394d74ec8a5a65a9cbe36cafeace23ba0d..7af4d39d47e8daace37634016b1ad7771856b352 100644 (file)
@@ -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)
index 16a13d9d3b8f6bbd1b52a255593490b30227db97..91e9c68ae1ac728153b4946962298112fc700840 100644 (file)
@@ -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:
index f970f3737d9df43e2fd187db9722beed74076950..67990a2028d04b16ecf2fc724a3bcb9ee3e6b984 100644 (file)
@@ -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
index 1c06d828602806492c42fad896cf09abcbdc8e0f..d3cb65db96bd9e2c0dc8e5dca678c39cc4104065 100644 (file)
@@ -15,7 +15,7 @@ class CompileTest(TestBase, AssertsExecutionResults):
             Column('c1', Integer, primary_key=True),
             Column('c2', String(30)))
 
-    @profiling.function_call_count(72, {'2.4': 45, '3.0':77})
+    @profiling.function_call_count(72, {'2.4': 45, '3.0':77, '3.1':77})
     def test_insert(self):
         t1.insert().compile()
 
@@ -23,7 +23,7 @@ class CompileTest(TestBase, AssertsExecutionResults):
     def test_update(self):
         t1.update().compile()
 
-    @profiling.function_call_count(195, versions={'2.4':118, '3.0':208})
+    @profiling.function_call_count(195, versions={'2.4':118, '3.0':208, '3.1':208})
     def test_select(self):
         s = select([t1], t1.c.c2==t2.c.c1)
         s.compile()
index 0cd60b049ff9e5e4323523ba2a01aaac30897e69..18ae0c1b38fbeeeaf2a1cecc31877fd7505e57a0 100644 (file)
@@ -18,7 +18,7 @@ class QueuePoolTest(TestBase, AssertsExecutionResults):
                          use_threadlocal=True)
 
 
-    @profiling.function_call_count(54, {'2.4': 36, '3.0':57})
+    @profiling.function_call_count(54, {'2.4': 36, '3.0':57, '3.1':57})
     def test_first_connect(self):
         conn = pool.connect()
 
@@ -35,7 +35,7 @@ class QueuePoolTest(TestBase, AssertsExecutionResults):
     def test_second_samethread_connect(self):
         conn = pool.connect()
 
-        @profiling.function_call_count(5, {'2.4': 3, '3.0':6})
+        @profiling.function_call_count(5, {'2.4': 3, '3.0':6, '3.1':6})
         def go():
             return pool.connect()
         c2 = go()
index e4c2eaba059309c5752067e1fda39b567ed9d2ac..5377daedd1504983c2afcab78fbccb8d4313bd0e 100644 (file)
@@ -336,19 +336,19 @@ class DictlikeIteritemsTest(TestBase):
     def test_object(self):
         self._notok(object())
 
+    # Py2K
     def test_duck_1(self):
         class duck1(object):
             def iteritems(duck):
                 return iter(self.baseline)
         self._ok(duck1())
+    # end Py2K
 
-    # Py2K
     def test_duck_2(self):
         class duck2(object):
             def items(duck):
                 return list(self.baseline)
         self._ok(duck2())
-    # end Py2K
 
     # Py2K
     def test_duck_3(self):
index 8e3f3412d653b28c7049a6008f0a1a339cd41992..16f746ea6b007bd52253c9d1ec73ff4bf8ff0000 100644 (file)
@@ -818,12 +818,12 @@ class ForUpdateTest(TestBase):
 
         errors, threads = [], []
         for i in xrange(thread_count):
-            thread = threading.Thread(target=self.overlap,
+            thrd = threading.Thread(target=self.overlap,
                                       args=(groups.pop(0), errors, update_style))
-            thread.start()
-            threads.append(thread)
-        for thread in threads:
-            thread.join()
+            thrd.start()
+            threads.append(thrd)
+        for thrd in threads:
+            thrd.join()
 
         return errors
 
index 7724f90a47df406c00ad34eb802cb6f72c0da62c..e7ae33cc876038c800059abcfae21d5f587a4989 100644 (file)
@@ -45,7 +45,7 @@ class ExamplesTest(TestBase):
     # ensure that examples with external dependencies are not run if those dependencies are 
     # not present (i.e. elementtree, postgis)
     def test_examples(self):
-       pass
+        pass
         #for module in find_modules():
         #    check_import.description = module
         #    yield check_import, module