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
@@ -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:
|
||||
|
Reference in New Issue
Block a user