Fixed following SonarQube issues:

- Remove this assignment to the local variable, the value is never used.
  - Rename local variables to match the regular expression
  - Add logic to this except clause or eliminate it and rethrow the exception automatically.
  - Rename fields to match the regular expression
  - Extract this nested conditional expression into an independent statement.
  - Change this default value to "None" and initialize this parameter inside the function/method.
  - Update this function so that its implementation is not identical to __repr__
  - Refactor this method to not always return the same value
  - Reraise this exception to stop the application as the user expects
  - Add missing parameters _w _PY3. This method overrides simplejson.decoder.JSONDecoder.decode.
  - Remove this redundant continue.
  - Remove this unused function declaration
  - Remove this identity check; it will always be False.
This commit is contained in:
Aditya Toshniwal
2020-08-03 12:59:51 +05:30
committed by Akshay Joshi
parent eb2c554601
commit 536593bf8a
19 changed files with 74 additions and 113 deletions

View File

@@ -31,7 +31,7 @@ class DataTypeJSONEncoder(json.JSONEncoder):
class ColParamsJSONDecoder(json.JSONDecoder):
def decode(self, obj):
def decode(self, obj, **kwargs):
retval = obj
try:
retval = json.JSONDecoder.decode(self, obj)

View File

@@ -721,7 +721,7 @@ class DictWriter(object):
raise ValueError("extrasaction (%s) must be 'raise' or 'ignore'"
% self.extrasaction)
dialect = kwds.get('dialect', "excel")
self.Writer = Writer(f, dialect, *args, **kwds)
self.writer = Writer(f, dialect, *args, **kwds)
def writeheader(self):
header = dict(zip(self.fieldnames, self.fieldnames))
@@ -736,7 +736,7 @@ class DictWriter(object):
return (rowdict.get(key, self.restval) for key in self.fieldnames)
def writerow(self, rowdict):
return self.Writer.writerow(self._dict_to_list(rowdict))
return self.writer.writerow(self._dict_to_list(rowdict))
def writerows(self, rowdicts):
return self.Writer.writerows(map(self._dict_to_list, rowdicts))
return self.writer.writerows(map(self._dict_to_list, rowdicts))

View File

@@ -198,12 +198,7 @@ class Connection(BaseConnection):
)
def __str__(self):
return "PG Connection: {0} ({1}) -> {2} (ajax:{3})".format(
self.conn_id, self.db,
'Connected' if self.conn and not self.conn.closed else
"Disconnected",
self.async_
)
return self.__repr__()
def connect(self, **kwargs):
if self.conn:
@@ -714,27 +709,6 @@ WHERE
return False, \
gettext('The query executed did not return any data.')
def convert_keys_to_unicode(results, conn_encoding):
"""
[ This is only for Python2.x]
We need to convert all keys to unicode as psycopg2
sends them as string
Args:
res: Query result set from psycopg2
conn_encoding: Connection encoding
Returns:
Result set (With all the keys converted to unicode)
"""
new_results = []
for row in results:
new_results.append(
dict([(k.decode(conn_encoding), v)
for k, v in row.items()])
)
return new_results
def handle_null_values(results, replace_nulls_with):
"""
This function is used to replace null values with the given string
@@ -1279,9 +1253,14 @@ WHERE
)
except psycopg2.Error as e:
msg = e.pgerror if e.pgerror else e.message \
if e.message else e.diag.message_detail \
if e.diag.message_detail else str(e)
if e.pgerror:
msg = e.pgerror
elif e.message:
msg = e.message
elif e.diag.message_detail:
msg = e.diag.message_detail
else:
msg = str(e)
current_app.logger.error(
gettext(

View File

@@ -372,8 +372,11 @@ WHERE db.oid = {0}""".format(did))
else:
return False
my_id = (u'CONN:{0}'.format(conn_id)) if conn_id is not None else \
(u'DB:{0}'.format(database)) if database is not None else None
my_id = None
if conn_id is not None:
my_id = u'CONN:{0}'.format(conn_id)
elif database is not None:
my_id = u'DB:{0}'.format(database)
if my_id is not None:
if my_id in self.connections:

View File

@@ -103,11 +103,11 @@ class SessionManager(object):
class CachingSessionManager(SessionManager):
def __init__(self, parent, num_to_store, skip_paths=[]):
def __init__(self, parent, num_to_store, skip_paths=None):
self.parent = parent
self.num_to_store = num_to_store
self._cache = OrderedDict()
self.skip_paths = skip_paths
self.skip_paths = [] if skip_paths is None else skip_paths
def _normalize(self):
if len(self._cache) > self.num_to_store:
@@ -187,13 +187,13 @@ class CachingSessionManager(SessionManager):
class FileBackedSessionManager(SessionManager):
def __init__(self, path, secret, disk_write_delay, skip_paths=[]):
def __init__(self, path, secret, disk_write_delay, skip_paths=None):
self.path = path
self.secret = secret
self.disk_write_delay = disk_write_delay
if not os.path.exists(self.path):
os.makedirs(self.path)
self.skip_paths = skip_paths
self.skip_paths = [] if skip_paths is None else skip_paths
def exists(self, sid):
fname = os.path.join(self.path, sid)