Explorar el Código

HUE-8737 [core] Futurize desktop/libs/librdbms for Python 3.5

Ying Chen hace 6 años
padre
commit
9301554843

+ 3 - 1
apps/rdbms/src/rdbms/tests.py

@@ -15,7 +15,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from builtins import str
 from builtins import object
 import json
 import os
@@ -130,6 +129,9 @@ class TestAPI(TestSQLiteRdbmsBase):
       'query': 'SELECT * FROM test1'
     }
     response = self.client.post(reverse('rdbms:api_execute_query'), data, follow=True)
+    import traceback
+    for tb in traceback.extract_stack():
+      print(tb)
     response_dict = json.loads(response.content)
     assert_equal(1, len(response_dict['results']['rows']), response_dict)
 

+ 6 - 4
desktop/libs/librdbms/java/query.py

@@ -15,6 +15,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from __future__ import print_function
+from builtins import range
 from py4j.java_gateway import JavaGateway
 
 gateway = JavaGateway()
@@ -35,13 +37,13 @@ try:
 
       md = rs.getMetaData()
 
-      for i in xrange(md.getColumnCount()):
-        print md.getColumnTypeName(i + 1)
+      for i in range(md.getColumnCount()):
+        print(md.getColumnTypeName(i + 1))
 
-      while rs.next():
+      while next(rs):
         username = rs.getString("username")
         email = rs.getString("email")
-        print username, email
+        print(username, email)
     finally:
       rs.close()
   finally:

+ 3 - 1
desktop/libs/librdbms/src/librdbms/design.py

@@ -18,6 +18,8 @@
 """
 The HQLdesign class can (de)serialize a design to/from a QueryDict.
 """
+
+from builtins import object
 import json
 import logging
 
@@ -97,7 +99,7 @@ class SQLdesign(object):
   def loads(data):
     """Returns SQLdesign from the serialized form"""
     dic = json.loads(data)
-    dic = dict(map(lambda k: (str(k), dic.get(k)), dic.keys()))
+    dic = dict([(str(k), dic.get(k)) for k in list(dic.keys())])
     if dic['VERSION'] != SERIALIZATION_VERSION:
       LOG.error('Design version mismatch. Found %s; expect %s' % (dic['VERSION'], SERIALIZATION_VERSION))
 

+ 10 - 8
desktop/libs/librdbms/src/librdbms/jdbc.py

@@ -15,6 +15,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from builtins import range
+from builtins import object
 import logging
 import os
 import sys
@@ -28,7 +30,7 @@ LOG = logging.getLogger(__name__)
 
 try:
   from py4j.java_gateway import JavaGateway, JavaObject
-except ImportError, e:
+except ImportError as e:
   LOG.exception('Failed to import py4j')
 
 
@@ -45,7 +47,7 @@ def query_and_fetch(db, statement, n=None):
       return data, meta
     finally:
       curs.close()
-  except Exception, e:
+  except Exception as e:
     message = force_unicode(smart_str(e))
     if 'Access denied' in message:
       raise AuthenticationRequired()
@@ -54,7 +56,7 @@ def query_and_fetch(db, statement, n=None):
     db.close()
 
 
-class Jdbc():
+class Jdbc(object):
 
   def __init__(self, driver_name, url, username, password, impersonation_property=None, impersonation_user=None):
     if 'py4j' not in sys.modules:
@@ -81,7 +83,7 @@ class Jdbc():
     try:
       self.connect()
       return True
-    except Exception, e:
+    except Exception as e:
       message = force_unicode(smart_str(e))
       if throw_exception:
         if 'Access denied' in message:
@@ -106,7 +108,7 @@ class Jdbc():
       self.conn = None
 
 
-class Cursor():
+class Cursor(object):
   """Similar to DB-API 2.0 Cursor interface"""
 
   def __init__(self, conn):
@@ -130,9 +132,9 @@ class Cursor():
   def fetchmany(self, n=None):
     res = []
 
-    while self.rs.next() and (n is None or n > 0):
+    while next(self.rs) and (n is None or n > 0):
       row = []
-      for c in xrange(self._meta.getColumnCount()):
+      for c in range(self._meta.getColumnCount()):
         cell = self.rs.getObject(c + 1)
 
         if isinstance(cell, JavaObject):
@@ -161,7 +163,7 @@ class Cursor():
         self._meta.getPrecision(i),
         self._meta.getScale(i),
         self._meta.isNullable(i),
-      ] for i in xrange(1, self._meta.getColumnCount() + 1)]
+      ] for i in range(1, self._meta.getColumnCount() + 1)]
 
   def close(self):
     self._meta = None

+ 2 - 1
desktop/libs/librdbms/src/librdbms/server/dbms.py

@@ -15,6 +15,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from builtins import object
 import logging
 
 from desktop.lib.python_util import force_dict_to_strings
@@ -54,7 +55,7 @@ def get(user, query_server=None):
 
 def get_query_server_config(server=None):
   if not server or server not in DATABASES:
-    keys = DATABASES.keys()
+    keys = list(DATABASES.keys())
     name = keys and keys[0] or None
   else:
     name = server

+ 1 - 1
desktop/libs/librdbms/src/librdbms/server/mysql_lib.py

@@ -19,7 +19,7 @@ import logging
 
 try:
     import MySQLdb as Database
-except ImportError, e:
+except ImportError as e:
     from django.core.exceptions import ImproperlyConfigured
     raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
 

+ 1 - 1
desktop/libs/librdbms/src/librdbms/server/oracle_lib.py

@@ -19,7 +19,7 @@ import logging
 
 try:
   import cx_Oracle as Database
-except ImportError, e:
+except ImportError as e:
   from django.core.exceptions import ImproperlyConfigured
   raise ImproperlyConfigured("Error loading cx_Oracle module: %s" % e)
 

+ 1 - 1
desktop/libs/librdbms/src/librdbms/server/postgresql_lib.py

@@ -19,7 +19,7 @@ import logging
 
 try:
     import psycopg2 as Database
-except ImportError, e:
+except ImportError as e:
     from django.core.exceptions import ImproperlyConfigured
     raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
 

+ 1 - 0
desktop/libs/librdbms/src/librdbms/server/rdbms_base_lib.py

@@ -15,6 +15,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from builtins import object
 import logging
 
 from librdbms.design import SQLdesign

+ 2 - 2
desktop/libs/librdbms/src/librdbms/server/sqlite_lib.py

@@ -20,9 +20,9 @@ import logging
 try:
   try:
     from pysqlite2 import dbapi2 as Database
-  except ImportError, e1:
+  except ImportError as e1:
     from sqlite3 import dbapi2 as Database
-except ImportError, exc:
+except ImportError as exc:
   from django.core.exceptions import ImproperlyConfigured
   raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)