Pārlūkot izejas kodu

HUE-8737 [core] Futurize apps/rdbms for Python 3.5

Ying Chen 6 gadi atpakaļ
vecāks
revīzija
69b904f28c
2 mainītis faili ar 16 papildinājumiem un 13 dzēšanām
  1. 11 10
      apps/rdbms/src/rdbms/api.py
  2. 5 3
      apps/rdbms/src/rdbms/tests.py

+ 11 - 10
apps/rdbms/src/rdbms/api.py

@@ -15,6 +15,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from builtins import zip
 import datetime
 import decimal
 import json
@@ -57,9 +58,9 @@ def error_handler(view_fn):
   def decorator(*args, **kwargs):
     try:
       return view_fn(*args, **kwargs)
-    except Http404, e:
+    except Http404 as e:
       raise e
-    except Exception, e:
+    except Exception as e:
       LOG.exception('error in %s' % view_fn)
 
       response = {
@@ -163,14 +164,14 @@ def execute_query(request, design_id=None):
         response['status'] = 0
         response['results'] = results_to_dict(results)
         response['design'] = design.id
-      except Exception, e:
+      except Exception as e:
         response['status'] = -1
         response['message'] = str(e)
 
     else:
       response['message'] = _('There was an error with your query.')
       response['errors'] = form.errors
-  except RuntimeError, e:
+  except RuntimeError as e:
     response['message']= str(e)
 
   return JsonResponse(response, encoder=ResultEncoder)
@@ -201,14 +202,14 @@ def explain_query(request):
 
         response['status'] = 0
         response['results'] = results_to_dict(results)
-      except Exception, e:
+      except Exception as e:
         response['status'] = -1
         response['message'] = str(e)
 
     else:
       response['message'] = _('There was an error with your query.')
       response['errors'] = form.errors
-  except RuntimeError, e:
+  except RuntimeError as e:
     response['message']= str(e)
 
   return JsonResponse(response)
@@ -225,7 +226,7 @@ def fetch_results(request, id, first_row=0):
   spits out a warning if first_row doesn't match the servers conception.
   Multiple readers will produce a confusing interaction here, and that's known.
   """
-  first_row = long(first_row)
+  first_row = int(first_row)
   results = type('Result', (object,), {
                 'rows': 0,
                 'columns': [],
@@ -246,7 +247,7 @@ def fetch_results(request, id, first_row=0):
     datatable = db.execute_and_wait(design)
     results = db.client.create_result(datatable)
     status = 0
-  except Exception, e:
+  except Exception as e:
     fetch_error = True
     error_message = str(e)
     status = -1
@@ -280,7 +281,7 @@ def save_query(request, design_id=None):
       response['status'] = 0
     else:
       response['errors'] = query_form.errors
-  except RuntimeError, e:
+  except RuntimeError as e:
     response['message'] = str(e)
 
   return JsonResponse(response)
@@ -305,7 +306,7 @@ def results_to_dict(results):
   data = {}
   rows = []
   for row in results.rows():
-    rows.append(dict(zip(results.columns, [escape(r) if isinstance(r, (str, unicode)) else r for r in row])))
+    rows.append(dict(list(zip(results.columns, [escape(r) if isinstance(r, str) else r for r in row]))))
   data['rows'] = rows
   data['start_row'] = results.start_row
   data['has_more'] = results.has_more

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

@@ -15,6 +15,8 @@
 # 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
 import uuid
@@ -28,7 +30,7 @@ from librdbms import conf as rdbms_conf
 from librdbms.server import dbms
 
 
-class MockRdbms:
+class MockRdbms(object):
   def get_databases(self):
     return ['db1', 'db2']
 
@@ -36,7 +38,7 @@ class MockRdbms:
     return ['table1', 'table2']
 
 
-class TestMockedRdbms:
+class TestMockedRdbms(object):
   def setUp(self):
     self.client = make_logged_in_client()
 
@@ -145,6 +147,6 @@ class TestAPI(TestSQLiteRdbmsBase):
     finish = rdbms_conf.DATABASES['sqlitee'].OPTIONS.set_for_testing({'nonsensical': None})
     try:
       self.client.get(reverse('rdbms:api_tables', args=['sqlitee', self.database]))
-    except TypeError, e:
+    except TypeError as e:
       assert_true('nonsensical' in str(e), e)
     finish()