Fixed the errors, and warnings reported by pylama.

TODO::
- Don't use unicode in Python 3 for removing the support of Python 2 (
  psycopg2 driver - __init__.py, server_manager.py).
- Merge the lastest pgcli (version: 3.0.0) for SQL autocompletion.
pull/33/head
Ashesh Vashi 2020-05-08 14:13:32 +05:30
parent 9338bdcb3a
commit e73e2d2502
10 changed files with 43 additions and 49 deletions

View File

@ -13,7 +13,7 @@ import simplejson as json
from functools import wraps
import pgadmin.browser.server_groups.servers.databases as database
from flask import render_template, make_response, request, jsonify
from flask import render_template, request, jsonify
from flask_babelex import gettext
from pgadmin.browser.server_groups.servers.databases.schemas.tables.\
constraints.type import ConstraintRegistry, ConstraintTypeModule
@ -517,7 +517,7 @@ class ForeignKeyConstraintView(PGChildNodeView):
return make_json_response(
status=400,
success=0,
errormsg=_(
errormsg=gettext(
"Could not find required parameter ({})."
).format(arg)
)
@ -525,7 +525,7 @@ class ForeignKeyConstraintView(PGChildNodeView):
return make_json_response(
status=400,
success=0,
errormsg=_(
errormsg=gettext(
"Could not find required parameter ({})."
).format(arg)
)

View File

@ -11,10 +11,11 @@ import os
from pgadmin.utils.driver import DriverRegistry
from regression.python_test_utils.template_helper import file_as_template
DriverRegistry.load_drivers()
from pgadmin.utils.route import BaseTestGenerator
from regression.python_test_utils import test_utils
DriverRegistry.load_drivers()
class TestColumnForeignKeyGetConstraintCols(BaseTestGenerator):
scenarios = [

View File

@ -72,7 +72,7 @@ def unescape_dquotes_process_arg(arg):
def _log_exception():
type_, value_, traceback_ = info = sys.exc_info()
type_, value_, traceback_ = sys.exc_info()
with open(_log_file, 'a') as fp:
from traceback import format_exception
@ -352,7 +352,7 @@ def execute(argv):
args.update({'exit_code': e.errno})
# Unknown errors
except Exception:
except Exception as e:
info = _log_exception()
args.update({'exit_code': 501})
if process_stderr:

View File

@ -15,11 +15,6 @@ import re
import getpass
if 'raw_input' in __builtins__:
input = raw_input
range = xrange
def user_info():
if config.SERVER_MODE is False:
print(u"NOTE: Configuring authentication for DESKTOP mode.")
@ -48,9 +43,10 @@ def user_info():
)
email_filter = re.compile(
"^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9]"
"(?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9]"
"(?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
"^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9]"
"(?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9]"
"(?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
)
email = input("Email address: ")
while email == '' or not email_filter.match(email):

View File

@ -31,7 +31,7 @@ def run_backup_job(tester, job_id, expected_params, assert_in, assert_not_in,
if cnt >= 5:
break
# Check the process list
response1 = tester.get('/misc/bgprocess/?_='.format(
response1 = tester.get('/misc/bgprocess/?_={0}'.format(
random.randint(1, 9999999)))
assert_equal(response1.status_code, 200)
process_list = json.loads(response1.data.decode('utf-8'))
@ -39,7 +39,7 @@ def run_backup_job(tester, job_id, expected_params, assert_in, assert_not_in,
try:
the_process = next(
p for p in process_list if p['id'] == job_id)
except Exception as _:
except Exception:
the_process = None
if the_process and 'execution_time' in the_process:
@ -68,12 +68,12 @@ def run_backup_job(tester, job_id, expected_params, assert_in, assert_not_in,
assert_not_in(opt, the_process['details'])
# Check the process details
p_details = tester.get('/misc/bgprocess/{0}?_='.format(
p_details = tester.get('/misc/bgprocess/{0}?_={1}'.format(
job_id, random.randint(1, 9999999))
)
assert_equal(p_details.status_code, 200)
p_details = tester.get('/misc/bgprocess/{0}/{1}/{2}/?_='.format(
p_details = tester.get('/misc/bgprocess/{0}/{1}/{2}/?_={3}'.format(
job_id, 0, 0, random.randint(1, 9999999))
)
assert_equal(p_details.status_code, 200)

View File

@ -8,7 +8,6 @@
##########################################################################
"""A blueprint module implementing the datagrid frame."""
MODULE_NAME = 'datagrid'
import simplejson as json
import pickle
@ -17,9 +16,10 @@ import random
from threading import Lock
from flask import Response, url_for, session, request, make_response
from werkzeug.useragents import UserAgent
from flask import current_app as app
from flask import current_app as app, render_template
from flask_babelex import gettext
from flask_security import login_required
from pgadmin.tools.sqleditor.command import *
from pgadmin.tools.sqleditor.command import ObjectRegistry, SQLFilter
from pgadmin.utils import PgAdminModule
from pgadmin.utils.ajax import make_json_response, bad_request, \
internal_server_error
@ -32,6 +32,7 @@ from pgadmin.utils.preferences import Preferences
from pgadmin.settings import get_setting
from pgadmin.browser.utils import underscore_unescape
MODULE_NAME = 'datagrid'
query_tool_close_session_lock = Lock()
@ -153,7 +154,7 @@ def initialize_datagrid(trans_id, cmd_type, obj_type, sgid, sid, did, obj_id):
auto_reconnect=False,
use_binary_placeholder=True,
array_to_string=True)
except (ConnectionLost, SSHTunnelConnectionLost) as e:
except (ConnectionLost, SSHTunnelConnectionLost):
raise
except Exception as e:
app.logger.error(e)

View File

@ -9,13 +9,11 @@
"""A blueprint module implementing the debugger"""
MODULE_NAME = 'debugger'
import simplejson as json
import random
import re
from flask import url_for, Response, render_template, request, session, \
from flask import url_for, Response, render_template, request, \
current_app
from flask_babelex import gettext
from flask_security import login_required
@ -34,6 +32,8 @@ from config import PG_DEFAULT_DRIVER
from pgadmin.model import db, DebuggerFunctionArguments
from pgadmin.tools.debugger.utils.debugger_instance import DebuggerInstance
MODULE_NAME = 'debugger'
# Constants
ASYNC_OK = 1
@ -344,7 +344,6 @@ def init_function(node_type, sid, did, scid, fid, trid=None):
# Get the server version, server type and user information
server_type = manager.server_type
user = manager.user_info
# Check server type is ppas or not
ppas_server = False
@ -2122,7 +2121,7 @@ def close_debugger_session(_trans_id, close_all=False):
dbg_obj['exe_conn_id'],
dbg_obj['database_id'])
manager.release(conn_id=dbg_obj['exe_conn_id'])
except Exception as _:
except Exception:
raise
finally:
de_inst.clear()

View File

@ -79,7 +79,7 @@ class MaintenanceJobTest(BaseTestGenerator):
if cnt >= 10:
break
# Check the process list
response1 = self.tester.get('/misc/bgprocess/?_='.format(
response1 = self.tester.get('/misc/bgprocess/?_={0}'.format(
random.randint(1, 9999999)))
self.assertEqual(response1.status_code, 200)
process_list = json.loads(response1.data.decode('utf-8'))
@ -87,7 +87,7 @@ class MaintenanceJobTest(BaseTestGenerator):
try:
the_process = next(
p for p in process_list if p['id'] == job_id)
except Exception as _:
except Exception:
the_process = None
if the_process and 'execution_time' in the_process:
@ -104,13 +104,15 @@ class MaintenanceJobTest(BaseTestGenerator):
self.assertIn(self.expected_cmd, the_process['details'])
# Check the process details
p_details = self.tester.get('/misc/bgprocess/{0}?_='.format(
p_details = self.tester.get('/misc/bgprocess/{0}?_={1}'.format(
job_id, random.randint(1, 9999999))
)
self.assertEqual(p_details.status_code, 200)
p_details = self.tester.get('/misc/bgprocess/{0}/{1}/{2}/?_='.format(
job_id, 0, 0, random.randint(1, 9999999))
p_details = self.tester.get(
'/misc/bgprocess/{0}/{1}/{2}/?_={3}'.format(
job_id, 0, 0, random.randint(1, 9999999)
)
)
self.assertEqual(p_details.status_code, 200)
p_details_data = json.loads(p_details.data.decode('utf-8'))

View File

@ -7,7 +7,6 @@
#
##########################################################################
import sys
import time
import random
import os
@ -120,7 +119,7 @@ class RestoreJobTest(BaseTestGenerator):
if cnt >= 5:
break
# Check the process list
response1 = self.tester.get('/misc/bgprocess/?_='.format(
response1 = self.tester.get('/misc/bgprocess/?_={0}'.format(
random.randint(1, 9999999)))
self.assertEqual(response1.status_code, 200)
process_list = json.loads(response1.data.decode('utf-8'))
@ -128,7 +127,7 @@ class RestoreJobTest(BaseTestGenerator):
try:
the_process = next(
p for p in process_list if p['id'] == job_id)
except Exception as _:
except Exception:
the_process = None
if the_process and 'execution_time' in the_process:
@ -150,14 +149,16 @@ class RestoreJobTest(BaseTestGenerator):
self.assertNotIn(opt, the_process['details'])
# Check the process details
p_details = self.tester.get('/misc/bgprocess/{0}?_='.format(
p_details = self.tester.get('/misc/bgprocess/{0}?_={1}'.format(
job_id, random.randint(1, 9999999))
)
self.assertEqual(p_details.status_code, 200)
json.loads(p_details.data.decode('utf-8'))
p_details = self.tester.get('/misc/bgprocess/{0}/{1}/{2}/?_='.format(
job_id, 0, 0, random.randint(1, 9999999))
p_details = self.tester.get(
'/misc/bgprocess/{0}/{1}/{2}/?_={3}'.format(
job_id, 0, 0, random.randint(1, 9999999)
)
)
self.assertEqual(p_details.status_code, 200)
p_details_data = json.loads(p_details.data.decode('utf-8'))

View File

@ -18,13 +18,12 @@ import select
import six
import datetime
from collections import deque
import simplejson as json
import psycopg2
from flask import g, current_app
from flask_babelex import gettext
from flask_security import current_user
from pgadmin.utils.crypto import decrypt
from psycopg2.extensions import adapt, encodings
from psycopg2.extensions import encodings
import config
from pgadmin.model import User
@ -697,10 +696,10 @@ WHERE
current_app.logger.error(
u"failed to execute query ((with server cursor) "
u"for the server #{server_id} - {conn_id} "
u"(query-id: {query_id}):\nerror message:{errmsg}".format(
u"(query-id: {query_id}):\n"
u"error message:{errmsg}".format(
server_id=self.manager.sid,
conn_id=self.conn_id,
query=query,
errmsg=errmsg,
query_id=query_id
)
@ -769,7 +768,6 @@ WHERE
header = []
json_columns = []
conn_encoding = encodings[cur.connection.encoding]
for c in cur.ordered_description():
# This is to handle the case in which column name is non-ascii
@ -880,7 +878,6 @@ WHERE
u"Error Message:{errmsg}".format(
server_id=self.manager.sid,
conn_id=self.conn_id,
query=query,
errmsg=errmsg,
query_id=query_id
)
@ -946,7 +943,6 @@ WHERE
u"Error Message:{errmsg}".format(
server_id=self.manager.sid,
conn_id=self.conn_id,
query=query.decode(encoding),
errmsg=errmsg,
query_id=query_id
)
@ -1018,7 +1014,6 @@ WHERE
u"Error Message:{errmsg}".format(
server_id=self.manager.sid,
conn_id=self.conn_id,
query=query,
errmsg=errmsg,
query_id=query_id
)
@ -1048,7 +1043,7 @@ WHERE
current_app.logger.warning(
"Failed to reconnect the database server "
"(#{server_id})".format(
"(Server #{server_id}, Connection #{conn_id})".format(
server_id=self.manager.sid,
conn_id=self.conn_id
)
@ -1097,7 +1092,6 @@ WHERE
u"Error Message:{errmsg}".format(
server_id=self.manager.sid,
conn_id=self.conn_id,
query=query,
errmsg=errmsg,
query_id=query_id
)
@ -1215,7 +1209,7 @@ WHERE
for col in self.column_info:
new_row.append(row[col['name']])
result.append(new_row)
except psycopg2.ProgrammingError as e:
except psycopg2.ProgrammingError:
result = None
else:
# User performed operation which dose not produce record/s as