mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Fixed convention related issues reported by SonarQube.
This commit is contained in:
committed by
Akshay Joshi
parent
2cefa9afca
commit
357a9179b1
@@ -33,7 +33,7 @@ else:
|
||||
|
||||
import config
|
||||
from pgadmin import create_app
|
||||
from pgadmin.utils import u, fs_encoding, file_quote
|
||||
from pgadmin.utils import u_encode, fs_encoding, file_quote
|
||||
# Get the config database schema version. We store this in pgadmin.model
|
||||
# as it turns out that putting it in the config files isn't a great idea
|
||||
from pgadmin.model import SCHEMA_VERSION
|
||||
@@ -79,7 +79,7 @@ config.SETTINGS_SCHEMA_VERSION = SCHEMA_VERSION
|
||||
# Check if the database exists. If it does not, create it.
|
||||
if not os.path.isfile(config.SQLITE_PATH):
|
||||
setup_py = os.path.join(
|
||||
os.path.dirname(os.path.realpath(u(__file__, fs_encoding))),
|
||||
os.path.dirname(os.path.realpath(u_encode(__file__, fs_encoding))),
|
||||
u'setup.py'
|
||||
)
|
||||
exec(open(file_quote(setup_py), 'r').read())
|
||||
|
@@ -56,11 +56,11 @@ class DashboardModule(PgAdminModule):
|
||||
title=gettext('Dashboard'),
|
||||
icon='',
|
||||
content='',
|
||||
isCloseable=True,
|
||||
isPrivate=False,
|
||||
is_closeable=True,
|
||||
is_private=False,
|
||||
limit=1,
|
||||
isIframe=False,
|
||||
canHide=True
|
||||
is_iframe=False,
|
||||
can_hide=True
|
||||
).__dict__
|
||||
]
|
||||
|
||||
|
@@ -21,7 +21,7 @@ from pickle import dumps, loads
|
||||
from subprocess import Popen, PIPE
|
||||
import logging
|
||||
|
||||
from pgadmin.utils import u, file_quote, fs_encoding, \
|
||||
from pgadmin.utils import u_encode, file_quote, fs_encoding, \
|
||||
get_complete_file_path
|
||||
|
||||
import pytz
|
||||
@@ -197,7 +197,7 @@ class BatchProcess(object):
|
||||
for path in paths:
|
||||
if not os.path.isdir(path):
|
||||
continue
|
||||
exe_file = os.path.join(u(path, fs_encoding), program)
|
||||
exe_file = os.path.join(u_encode(path, fs_encoding), program)
|
||||
if is_exe(exe_file):
|
||||
return file_quote(exe_file)
|
||||
return None
|
||||
@@ -229,7 +229,7 @@ class BatchProcess(object):
|
||||
)
|
||||
|
||||
executor = file_quote(os.path.join(
|
||||
os.path.dirname(u(__file__)), u'process_executor.py'
|
||||
os.path.dirname(u_encode(__file__)), u'process_executor.py'
|
||||
))
|
||||
paths = os.environ['PATH'].split(os.pathsep)
|
||||
interpreter = None
|
||||
@@ -240,8 +240,8 @@ class BatchProcess(object):
|
||||
)
|
||||
|
||||
if os.name == 'nt':
|
||||
paths.insert(0, os.path.join(u(sys.prefix), u'Scripts'))
|
||||
paths.insert(0, u(sys.prefix))
|
||||
paths.insert(0, os.path.join(u_encode(sys.prefix), u'Scripts'))
|
||||
paths.insert(0, u_encode(sys.prefix))
|
||||
|
||||
interpreter = which(u'pythonw.exe', paths)
|
||||
if interpreter is None:
|
||||
@@ -293,10 +293,10 @@ class BatchProcess(object):
|
||||
# directory in the PATH environment variable. Hence - it will
|
||||
# anyway be the redundant value in paths.
|
||||
if not current_app.PGADMIN_RUNTIME:
|
||||
paths.insert(0, os.path.join(u(sys.prefix), u'bin'))
|
||||
paths.insert(0, os.path.join(u_encode(sys.prefix), u'bin'))
|
||||
python_binary_name = 'python{0}'.format(sys.version_info[0]) \
|
||||
if sys.version_info[0] >= 3 else 'python'
|
||||
interpreter = which(u(python_binary_name), paths)
|
||||
interpreter = which(u_encode(python_binary_name), paths)
|
||||
|
||||
p = None
|
||||
cmd = [
|
||||
|
@@ -745,7 +745,7 @@ class Filemanager(object):
|
||||
trans_data = Filemanager.get_trasaction_selection(self.trans_id)
|
||||
return False if capability not in trans_data['capabilities'] else True
|
||||
|
||||
def getinfo(self, path=None, getsize=True, name=None, req=None):
|
||||
def getinfo(self, path=None, get_size=True, name=None, req=None):
|
||||
"""
|
||||
Returns a JSON object containing information
|
||||
about the given file.
|
||||
|
@@ -14,11 +14,11 @@ from pgadmin import db
|
||||
|
||||
|
||||
def db_upgrade(app):
|
||||
from pgadmin.utils import u, fs_encoding
|
||||
from pgadmin.utils import u_encode, fs_encoding
|
||||
with app.app_context():
|
||||
flask_migrate.Migrate(app, db)
|
||||
migration_folder = os.path.join(
|
||||
os.path.dirname(os.path.realpath(u(__file__, fs_encoding))),
|
||||
os.path.dirname(os.path.realpath(u_encode(__file__, fs_encoding))),
|
||||
os.pardir, os.pardir,
|
||||
u'migrations'
|
||||
)
|
||||
|
@@ -117,8 +117,8 @@ def panel(trans_id, editor_title):
|
||||
# If title has slash(es) in it then replace it
|
||||
if request.args and request.args['fslashes'] != '':
|
||||
try:
|
||||
fslashesList = request.args['fslashes'].split(',')
|
||||
for idx in fslashesList:
|
||||
fslashes_list = request.args['fslashes'].split(',')
|
||||
for idx in fslashes_list:
|
||||
idx = int(idx)
|
||||
editor_title = editor_title[:idx] + '/' + editor_title[idx:]
|
||||
except IndexError as e:
|
||||
|
@@ -39,7 +39,7 @@ from pgadmin.utils.exception import ConnectionLost, SSHTunnelConnectionLost,\
|
||||
CryptKeyMissing
|
||||
from pgadmin.utils.sqlautocomplete.autocomplete import SQLAutoComplete
|
||||
from pgadmin.tools.sqleditor.utils.query_tool_preferences import \
|
||||
RegisterQueryToolPreferences
|
||||
register_query_tool_preferences
|
||||
from pgadmin.tools.sqleditor.utils.query_tool_fs_utils import \
|
||||
read_file_generator
|
||||
from pgadmin.tools.sqleditor.utils.filter_dialog import FilterDialog
|
||||
@@ -110,7 +110,7 @@ class SqlEditorModule(PgAdminModule):
|
||||
]
|
||||
|
||||
def register_preferences(self):
|
||||
RegisterQueryToolPreferences(self)
|
||||
register_query_tool_preferences(self)
|
||||
|
||||
|
||||
blueprint = SqlEditorModule(MODULE_NAME, __name__, static_url_path='/static')
|
||||
|
@@ -919,7 +919,7 @@ class QueryToolCommand(BaseCommand, FetchedRowTracker):
|
||||
conn = manager.connection(did=self.did, conn_id=self.conn_id)
|
||||
|
||||
# Get the driver version as a float
|
||||
driver_version = float('.'.join(driver.Version().split('.')[:2]))
|
||||
driver_version = float('.'.join(driver.version().split('.')[:2]))
|
||||
|
||||
# Checking for updatable resultsets uses features in psycopg 2.8
|
||||
if driver_version < 2.8:
|
||||
|
@@ -14,7 +14,7 @@ from pgadmin.utils import SHORTCUT_FIELDS as shortcut_fields, \
|
||||
from pgadmin.utils.preferences import Preferences
|
||||
|
||||
|
||||
def RegisterQueryToolPreferences(self):
|
||||
def register_query_tool_preferences(self):
|
||||
self.info_notifier_timeout = self.preference.register(
|
||||
'display', 'info_notifier_timeout',
|
||||
gettext("Query info notifier timeout"), 'integer', 5,
|
||||
|
@@ -173,7 +173,7 @@ if not fs_encoding or fs_encoding == 'ascii':
|
||||
fs_encoding = 'utf-8'
|
||||
|
||||
|
||||
def u(_s, _encoding=sys_encoding):
|
||||
def u_encode(_s, _encoding=sys_encoding):
|
||||
return _s
|
||||
|
||||
|
||||
|
@@ -51,7 +51,7 @@ class BaseDriver(object):
|
||||
"""
|
||||
|
||||
@abstractproperty
|
||||
def Version(cls):
|
||||
def version(cls):
|
||||
pass
|
||||
|
||||
@abstractproperty
|
||||
|
@@ -22,7 +22,7 @@ from threading import Lock
|
||||
|
||||
import config
|
||||
from pgadmin.model import Server
|
||||
from .keywords import ScanKeyword
|
||||
from .keywords import scan_keyword
|
||||
from ..abstract import BaseDriver
|
||||
from .connection import Connection
|
||||
from .server_manager import ServerManager
|
||||
@@ -120,16 +120,16 @@ class Driver(BaseDriver):
|
||||
|
||||
return managers[str(sid)]
|
||||
|
||||
def Version(cls):
|
||||
def version(cls):
|
||||
"""
|
||||
Version(...)
|
||||
version(...)
|
||||
|
||||
Returns the current version of psycopg2 driver
|
||||
"""
|
||||
version = getattr(psycopg2, '__version__', None)
|
||||
_version = getattr(psycopg2, '__version__', None)
|
||||
|
||||
if version:
|
||||
return version
|
||||
if _version:
|
||||
return _version
|
||||
|
||||
raise Exception(
|
||||
"Driver Version information for psycopg2 is not available!"
|
||||
@@ -239,7 +239,7 @@ class Driver(BaseDriver):
|
||||
mgr.release()
|
||||
|
||||
@staticmethod
|
||||
def qtLiteral(value, forceQuote=False):
|
||||
def qtLiteral(value, force_quote=False):
|
||||
adapted = adapt(value)
|
||||
|
||||
# Not all adapted objects have encoding
|
||||
@@ -255,7 +255,7 @@ class Driver(BaseDriver):
|
||||
if isinstance(res, bytes):
|
||||
res = res.decode('utf-8')
|
||||
|
||||
if forceQuote is True:
|
||||
if force_quote is True:
|
||||
# Convert the input to the string to use the startsWith(...)
|
||||
res = str(res)
|
||||
if not res.startswith("'"):
|
||||
@@ -269,7 +269,7 @@ class Driver(BaseDriver):
|
||||
# COL_NAME_KEYWORD 1
|
||||
# TYPE_FUNC_NAME_KEYWORD 2
|
||||
# RESERVED_KEYWORD 3
|
||||
extraKeywords = {
|
||||
extra_keywords = {
|
||||
'connect': 3,
|
||||
'convert': 3,
|
||||
'distributed': 0,
|
||||
@@ -293,22 +293,22 @@ class Driver(BaseDriver):
|
||||
'varchar2': 3
|
||||
}
|
||||
|
||||
return extraKeywords.get(key, None) or ScanKeyword(key)
|
||||
return extra_keywords.get(key, None) or scan_keyword(key)
|
||||
|
||||
@staticmethod
|
||||
def needsQuoting(key, forTypes):
|
||||
def needsQuoting(key, for_types):
|
||||
value = key
|
||||
valNoArray = value
|
||||
val_noarray = value
|
||||
|
||||
# check if the string is number or not
|
||||
if isinstance(value, int):
|
||||
return True
|
||||
# certain types should not be quoted even though it contains a space.
|
||||
# Evilness.
|
||||
elif forTypes and value[-2:] == u"[]":
|
||||
valNoArray = value[:-2]
|
||||
elif for_types and value[-2:] == u"[]":
|
||||
val_noarray = value[:-2]
|
||||
|
||||
if forTypes and valNoArray.lower() in [
|
||||
if for_types and val_noarray.lower() in [
|
||||
u'bit varying',
|
||||
u'"char"',
|
||||
u'character varying',
|
||||
@@ -323,14 +323,14 @@ class Driver(BaseDriver):
|
||||
return False
|
||||
|
||||
# If already quoted?, If yes then do not quote again
|
||||
if forTypes and valNoArray and \
|
||||
(valNoArray.startswith('"') or valNoArray.endswith('"')):
|
||||
if for_types and val_noarray and \
|
||||
(val_noarray.startswith('"') or val_noarray.endswith('"')):
|
||||
return False
|
||||
|
||||
if u'0' <= valNoArray[0] <= u'9':
|
||||
if u'0' <= val_noarray[0] <= u'9':
|
||||
return True
|
||||
|
||||
for c in valNoArray:
|
||||
for c in val_noarray:
|
||||
if (not (u'a' <= c <= u'z') and c != u'_' and
|
||||
not (u'0' <= c <= u'9')):
|
||||
return True
|
||||
@@ -346,7 +346,7 @@ class Driver(BaseDriver):
|
||||
return False
|
||||
|
||||
# COL_NAME_KEYWORD
|
||||
if forTypes and category == 1:
|
||||
if for_types and category == 1:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
@@ -35,7 +35,7 @@ from .typecast import register_global_typecasters, \
|
||||
register_string_typecasters, register_binary_typecasters, \
|
||||
unregister_numeric_typecasters, \
|
||||
register_array_to_string_typecasters, ALL_JSON_TYPES
|
||||
from .encoding import getEncoding, configureDriverEncodings
|
||||
from .encoding import get_encoding, configure_driver_encodings
|
||||
from pgadmin.utils import csv
|
||||
from pgadmin.utils.master_password import get_crypt_key
|
||||
from io import StringIO
|
||||
@@ -44,7 +44,7 @@ _ = gettext
|
||||
|
||||
# Register global type caster which will be applicable to all connections.
|
||||
register_global_typecasters()
|
||||
configureDriverEncodings(encodings)
|
||||
configure_driver_encodings(encodings)
|
||||
|
||||
|
||||
class Connection(BaseConnection):
|
||||
@@ -400,7 +400,7 @@ class Connection(BaseConnection):
|
||||
register_binary_typecasters(self.conn)
|
||||
|
||||
postgres_encoding, self.python_encoding, typecast_encoding = \
|
||||
getEncoding(self.conn.encoding)
|
||||
get_encoding(self.conn.encoding)
|
||||
|
||||
# Note that we use 'UPDATE pg_settings' for setting bytea_output as a
|
||||
# convenience hack for those running on old, unsupported versions of
|
||||
|
@@ -17,9 +17,9 @@ result.
|
||||
from collections import OrderedDict
|
||||
import psycopg2
|
||||
from psycopg2.extensions import cursor as _cursor, encodings
|
||||
from .encoding import configureDriverEncodings
|
||||
from .encoding import configure_driver_encodings
|
||||
|
||||
configureDriverEncodings(encodings)
|
||||
configure_driver_encodings(encodings)
|
||||
|
||||
|
||||
class _WrapperColumn(object):
|
||||
|
@@ -59,7 +59,7 @@ encode_dict = {
|
||||
}
|
||||
|
||||
|
||||
def getEncoding(key):
|
||||
def get_encoding(key):
|
||||
"""
|
||||
:param key: Database Encoding
|
||||
:return:
|
||||
@@ -72,7 +72,7 @@ def getEncoding(key):
|
||||
return encode_dict.get(key, ['UNICODE', 'utf-8', 'utf-8'])
|
||||
|
||||
|
||||
def configureDriverEncodings(encodings):
|
||||
def configure_driver_encodings(encodings):
|
||||
# Replace the python encoding for original name and renamed encodings
|
||||
# psycopg2 removes the underscore in conn.encoding
|
||||
# Setting the encodings dict value will only help for select statements
|
||||
|
@@ -10,8 +10,8 @@
|
||||
# ScanKeyword function for PostgreSQL 9.5rc1
|
||||
|
||||
|
||||
def ScanKeyword(key):
|
||||
keywordDict = {
|
||||
def scan_keyword(key):
|
||||
keywords = {
|
||||
'abort': 0,
|
||||
'absolute': 0,
|
||||
'access': 0,
|
||||
@@ -429,4 +429,4 @@ def ScanKeyword(key):
|
||||
'zone': 0,
|
||||
}
|
||||
|
||||
return keywordDict.get(key, None)
|
||||
return keywords.get(key, None)
|
||||
|
@@ -17,9 +17,9 @@ from psycopg2.extensions import DECIMAL as _DECIMAL, encodings
|
||||
import psycopg2
|
||||
from psycopg2.extras import Json as psycopg2_json
|
||||
|
||||
from .encoding import configureDriverEncodings, getEncoding
|
||||
from .encoding import configure_driver_encodings, get_encoding
|
||||
|
||||
configureDriverEncodings(encodings)
|
||||
configure_driver_encodings(encodings)
|
||||
|
||||
|
||||
# OIDs of data types which need to typecast as string to avoid JavaScript
|
||||
@@ -180,7 +180,7 @@ def register_string_typecasters(connection):
|
||||
# are escaped again and sent to the DB.
|
||||
|
||||
postgres_encoding, python_encoding, typecast_encoding = \
|
||||
getEncoding(connection.encoding)
|
||||
get_encoding(connection.encoding)
|
||||
if postgres_encoding != 'UNICODE':
|
||||
def non_ascii_escape(value, cursor):
|
||||
if value is None:
|
||||
|
@@ -10,7 +10,7 @@
|
||||
import os
|
||||
from contextlib import contextmanager
|
||||
from subprocess import call
|
||||
from pgadmin.utils import u, fs_encoding, file_quote
|
||||
from pgadmin.utils import u_encode, fs_encoding, file_quote
|
||||
|
||||
|
||||
# enum-like for tracking whether we have
|
||||
@@ -32,10 +32,10 @@ class JavascriptBundler:
|
||||
self.js_state = JsState.NEW
|
||||
except OSError:
|
||||
webdir_path()
|
||||
generatedJavascriptDir = os.path.join(
|
||||
generated_js_dir = os.path.join(
|
||||
webdir_path(), 'pgadmin', 'static', 'js', 'generated')
|
||||
if os.path.exists(generatedJavascriptDir) and \
|
||||
os.listdir(generatedJavascriptDir):
|
||||
if os.path.exists(generated_js_dir) and \
|
||||
os.listdir(generated_js_dir):
|
||||
self.js_state = JsState.OLD
|
||||
else:
|
||||
self.js_state = JsState.NONE
|
||||
@@ -54,8 +54,8 @@ def pushd(new_dir):
|
||||
|
||||
def webdir_path():
|
||||
dirname = os.path.dirname
|
||||
thisPath = os.path.realpath(u(__file__, fs_encoding))
|
||||
return dirname(dirname(dirname(dirname(thisPath))))
|
||||
this_path = os.path.realpath(u_encode(__file__, fs_encoding))
|
||||
return dirname(dirname(dirname(dirname(this_path))))
|
||||
|
||||
|
||||
def try_building_js():
|
||||
|
@@ -17,24 +17,24 @@ class MenuItem(object):
|
||||
|
||||
class Panel(object):
|
||||
def __init__(
|
||||
self, name, title, content='', width=500, height=600, isIframe=True,
|
||||
showTitle=True, isCloseable=True, isPrivate=False, priority=None,
|
||||
icon=None, data=None, events=None, limit=None, canHide=False
|
||||
self, name, title, content='', width=500, height=600, is_iframe=True,
|
||||
show_title=True, is_closeable=True, is_private=False, priority=None,
|
||||
icon=None, data=None, events=None, limit=None, can_hide=False
|
||||
):
|
||||
self.name = name
|
||||
self.title = title
|
||||
self.content = content
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.isIframe = isIframe
|
||||
self.showTitle = showTitle
|
||||
self.isCloseable = isCloseable
|
||||
self.isPrivate = isPrivate
|
||||
self.isIframe = is_iframe
|
||||
self.showTitle = show_title
|
||||
self.isCloseable = is_closeable
|
||||
self.isPrivate = is_private
|
||||
self.icon = icon
|
||||
self.data = data
|
||||
self.events = events
|
||||
self.limit = limit
|
||||
self.canHide = canHide
|
||||
self.canHide = can_hide
|
||||
if priority is None:
|
||||
global PRIORITY
|
||||
PRIORITY += 100
|
||||
|
@@ -6,7 +6,7 @@
|
||||
# This software is released under the PostgreSQL Licence
|
||||
#
|
||||
##########################################################################
|
||||
from pgadmin.utils.driver.psycopg2.encoding import getEncoding
|
||||
from pgadmin.utils.driver.psycopg2.encoding import get_encoding
|
||||
from pgadmin.utils.route import BaseTestGenerator
|
||||
|
||||
|
||||
@@ -223,5 +223,5 @@ class TestEncoding(BaseTestGenerator):
|
||||
]
|
||||
|
||||
def runTest(self):
|
||||
result = getEncoding(self.db_encoding)
|
||||
result = get_encoding(self.db_encoding)
|
||||
self.assertEquals(result, self.expected_return_value)
|
||||
|
Reference in New Issue
Block a user