Fixed code smell 'variable shadows a builtin' reported by SonarQube.

This commit is contained in:
Aditya Toshniwal
2020-07-28 16:20:26 +05:30
committed by Akshay Joshi
parent 46ba0310fa
commit a0893fe43b
5 changed files with 74 additions and 74 deletions

View File

@@ -45,7 +45,7 @@ def mktemp(dir=None, suffix=''):
def main(options, args): def main(options, args):
dmg_file, license = args dmg_file, license_file = args
with mktemp('.') as tmp_file: with mktemp('.') as tmp_file:
with open(tmp_file, 'w') as f: with open(tmp_file, 'w') as f:
f.write("""data 'TMPL' (128, "LPic") { f.write("""data 'TMPL' (128, "LPic") {
@@ -90,8 +90,9 @@ data 'STR#' (5002, "English") {
$"2C20 7072 6573 7320 2244 6973 6167 7265" $"2C20 7072 6573 7320 2244 6973 6167 7265"
$"6522 2E" $"6522 2E"
};\n\n""") };\n\n""")
with open(license, 'r') as lines: with open(license_file, 'r') as lines:
kind = 'RTF ' if license.lower().endswith('.rtf') else 'TEXT' kind = 'RTF ' if license_file.lower().endswith('.rtf') \
else 'TEXT'
f.write('data \'%s\' (5000, "English") {\n' % kind) f.write('data \'%s\' (5000, "English") {\n' % kind)
def escape(s): def escape(s):

View File

@@ -374,7 +374,7 @@ class TypeView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare):
status=200 status=200
) )
def _cltype_formatter(self, type): def _cltype_formatter(self, in_type):
""" """
Args: Args:
@@ -385,13 +385,13 @@ class TypeView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare):
after length/precision so we will set flag for after length/precision so we will set flag for
sql template sql template
""" """
if '[]' in type: if '[]' in in_type:
type = type.replace('[]', '') in_type = in_type.replace('[]', '')
self.hasSqrBracket = True self.hasSqrBracket = True
else: else:
self.hasSqrBracket = False self.hasSqrBracket = False
return type return in_type
@staticmethod @staticmethod
def convert_length_precision_to_string(data): def convert_length_precision_to_string(data):

View File

@@ -129,11 +129,11 @@ class BatchProcess(object):
created = False created = False
size = 0 size = 0
id = ctime uid = ctime
while not created: while not created:
try: try:
id += random_number(size) uid += random_number(size)
log_dir = os.path.join(log_dir, id) log_dir = os.path.join(log_dir, uid)
size += 1 size += 1
if not os.path.exists(log_dir): if not os.path.exists(log_dir):
os.makedirs(log_dir, int('700', 8)) os.makedirs(log_dir, int('700', 8))
@@ -178,7 +178,7 @@ class BatchProcess(object):
tmp_desc = dumps(self.desc) tmp_desc = dumps(self.desc)
j = Process( j = Process(
pid=int(id), pid=int(uid),
command=_cmd, command=_cmd,
arguments=args_val, arguments=args_val,
logdir=log_dir, logdir=log_dir,

View File

@@ -539,7 +539,7 @@ class Filemanager(object):
kernel32.SetThreadErrorMode(oldmode, ctypes.byref(oldmode)) kernel32.SetThreadErrorMode(oldmode, ctypes.byref(oldmode))
@staticmethod @staticmethod
def list_filesystem(dir, path, trans_data, file_type, show_hidden): def list_filesystem(in_dir, path, trans_data, file_type, show_hidden):
""" """
It lists all file and folders within the given It lists all file and folders within the given
directory. directory.
@@ -552,7 +552,7 @@ class Filemanager(object):
path = unquote(path).encode('utf-8').decode('utf-8') path = unquote(path).encode('utf-8').decode('utf-8')
try: try:
Filemanager.check_access_permission(dir, path) Filemanager.check_access_permission(in_dir, path)
except Exception as e: except Exception as e:
Filemanager.resume_windows_warning() Filemanager.resume_windows_warning()
err_msg = gettext(u"Error: {0}").format(e) err_msg = gettext(u"Error: {0}").format(e)
@@ -564,7 +564,7 @@ class Filemanager(object):
files = {} files = {}
if (_platform == "win32" and (path == '/' or path == '\\'))\ if (_platform == "win32" and (path == '/' or path == '\\'))\
and dir is None: and in_dir is None:
drives = Filemanager._get_drives() drives = Filemanager._get_drives()
for drive in drives: for drive in drives:
protected = 0 protected = 0
@@ -589,7 +589,7 @@ class Filemanager(object):
Filemanager.resume_windows_warning() Filemanager.resume_windows_warning()
return files return files
orig_path = Filemanager.get_abs_path(dir, path) orig_path = Filemanager.get_abs_path(in_dir, path)
if not path_exists(orig_path): if not path_exists(orig_path):
Filemanager.resume_windows_warning() Filemanager.resume_windows_warning()
@@ -669,62 +669,62 @@ class Filemanager(object):
return files return files
@staticmethod @staticmethod
def check_access_permission(dir, path): def check_access_permission(in_dir, path):
if not config.SERVER_MODE: if not config.SERVER_MODE:
return True return True
if dir is None: if in_dir is None:
dir = "" in_dir = ""
orig_path = Filemanager.get_abs_path(dir, path) orig_path = Filemanager.get_abs_path(in_dir, path)
# This translates path with relative path notations like ./ and ../ to # This translates path with relative path notations like ./ and ../ to
# absolute path. # absolute path.
orig_path = os.path.abspath(orig_path) orig_path = os.path.abspath(orig_path)
if dir: if in_dir:
if _platform == 'win32': if _platform == 'win32':
if dir[-1] == '\\' or dir[-1] == '/': if in_dir[-1] == '\\' or in_dir[-1] == '/':
dir = dir[:-1] in_dir = in_dir[:-1]
else: else:
if dir[-1] == '/': if in_dir[-1] == '/':
dir = dir[:-1] in_dir = in_dir[:-1]
# Do not allow user to access outside his storage dir in server mode. # Do not allow user to access outside his storage dir in server mode.
if not orig_path.startswith(dir): if not orig_path.startswith(in_dir):
raise Exception( raise Exception(
gettext(u"Access denied ({0})").format(path)) gettext(u"Access denied ({0})").format(path))
return True return True
@staticmethod @staticmethod
def get_abs_path(dir, path): def get_abs_path(in_dir, path):
if (path.startswith('\\\\') and _platform == 'win32')\ if (path.startswith('\\\\') and _platform == 'win32')\
or config.SERVER_MODE is False or dir is None: or config.SERVER_MODE is False or in_dir is None:
return u"{}".format(path) return u"{}".format(path)
if path == '/' or path == '\\': if path == '/' or path == '\\':
if _platform == 'win32': if _platform == 'win32':
if dir.endswith('\\') or dir.endswith('/'): if in_dir.endswith('\\') or in_dir.endswith('/'):
return u"{}".format(dir) return u"{}".format(in_dir)
else: else:
return u"{}{}".format(dir, '\\') return u"{}{}".format(in_dir, '\\')
else: else:
if dir.endswith('/'): if in_dir.endswith('/'):
return u"{}".format(dir) return u"{}".format(in_dir)
else: else:
return u"{}{}".format(dir, '/') return u"{}{}".format(in_dir, '/')
if dir.endswith('/') or dir.endswith('\\'): if in_dir.endswith('/') or in_dir.endswith('\\'):
if path.startswith('/') or path.startswith('\\'): if path.startswith('/') or path.startswith('\\'):
return u"{}{}".format(dir[:-1], path) return u"{}{}".format(in_dir[:-1], path)
else: else:
return u"{}/{}".format(dir, path) return u"{}/{}".format(in_dir, path)
else: else:
if path.startswith('/') or path.startswith('\\'): if path.startswith('/') or path.startswith('\\'):
return u"{}{}".format(dir, path) return u"{}{}".format(in_dir, path)
else: else:
return u"{}/{}".format(dir, path) return u"{}/{}".format(in_dir, path)
def validate_request(self, capability): def validate_request(self, capability):
""" """
@@ -810,14 +810,14 @@ class Filemanager(object):
Returns files and folders in give path Returns files and folders in give path
""" """
trans_data = Filemanager.get_trasaction_selection(self.trans_id) trans_data = Filemanager.get_trasaction_selection(self.trans_id)
dir = None the_dir = None
if config.SERVER_MODE: if config.SERVER_MODE:
dir = self.dir the_dir = self.dir
if dir is not None and not dir.endswith('/'): if the_dir is not None and not the_dir.endswith('/'):
dir += u'/' the_dir += u'/'
filelist = self.list_filesystem( filelist = self.list_filesystem(
dir, path, trans_data, file_type, show_hidden) the_dir, path, trans_data, file_type, show_hidden)
return filelist return filelist
def rename(self, old=None, new=None, req=None): def rename(self, old=None, new=None, req=None):
@@ -830,11 +830,11 @@ class Filemanager(object):
'Code': 0 'Code': 0
} }
dir = self.dir if self.dir is not None else '' the_dir = self.dir if self.dir is not None else ''
try: try:
Filemanager.check_access_permission(dir, old) Filemanager.check_access_permission(the_dir, old)
Filemanager.check_access_permission(dir, new) Filemanager.check_access_permission(the_dir, new)
except Exception as e: except Exception as e:
res = { res = {
'Error': gettext(u"Error: {0}").format(e), 'Error': gettext(u"Error: {0}").format(e),
@@ -862,8 +862,8 @@ class Filemanager(object):
newpath = path + newname newpath = path + newname
# make system old path # make system old path
oldpath_sys = u"{0}{1}".format(dir, old) oldpath_sys = u"{0}{1}".format(the_dir, old)
newpath_sys = u"{0}{1}".format(dir, newpath) newpath_sys = u"{0}{1}".format(the_dir, newpath)
error_msg = gettext(u'Renamed successfully.') error_msg = gettext(u'Renamed successfully.')
code = 1 code = 1
@@ -895,13 +895,13 @@ class Filemanager(object):
'Code': 0 'Code': 0
} }
dir = self.dir if self.dir is not None else '' the_dir = self.dir if self.dir is not None else ''
path = path.encode( path = path.encode(
'utf-8').decode('utf-8') if hasattr(str, 'decode') else path 'utf-8').decode('utf-8') if hasattr(str, 'decode') else path
orig_path = u"{0}{1}".format(dir, path) orig_path = u"{0}{1}".format(the_dir, path)
try: try:
Filemanager.check_access_permission(dir, path) Filemanager.check_access_permission(the_dir, path)
except Exception as e: except Exception as e:
res = { res = {
'Error': gettext(u"Error: {0}").format(e), 'Error': gettext(u"Error: {0}").format(e),
@@ -938,7 +938,7 @@ class Filemanager(object):
'Code': 0 'Code': 0
} }
dir = self.dir if self.dir is not None else '' the_dir = self.dir if self.dir is not None else ''
err_msg = '' err_msg = ''
code = 1 code = 1
try: try:
@@ -950,7 +950,7 @@ class Filemanager(object):
path = req.form.get('currentpath').encode( path = req.form.get('currentpath').encode(
'utf-8').decode('utf-8') 'utf-8').decode('utf-8')
file_name = file_obj.filename.encode('utf-8').decode('utf-8') file_name = file_obj.filename.encode('utf-8').decode('utf-8')
orig_path = u"{0}{1}".format(dir, path) orig_path = u"{0}{1}".format(the_dir, path)
new_name = u"{0}{1}".format(orig_path, file_name) new_name = u"{0}{1}".format(orig_path, file_name)
with open(new_name, 'wb') as f: with open(new_name, 'wb') as f:
@@ -966,7 +966,7 @@ class Filemanager(object):
e.strerror if hasattr(e, 'strerror') else gettext(u'Unknown')) e.strerror if hasattr(e, 'strerror') else gettext(u'Unknown'))
try: try:
Filemanager.check_access_permission(dir, path) Filemanager.check_access_permission(the_dir, path)
except Exception as e: except Exception as e:
res = { res = {
'Error': gettext(u"Error: {0}").format(e), 'Error': gettext(u"Error: {0}").format(e),
@@ -986,7 +986,7 @@ class Filemanager(object):
""" """
Checks whether given file exists or not Checks whether given file exists or not
""" """
dir = self.dir if self.dir is not None else '' the_dir = self.dir if self.dir is not None else ''
err_msg = '' err_msg = ''
code = 1 code = 1
@@ -996,9 +996,9 @@ class Filemanager(object):
name = name.encode('utf-8').decode('utf-8') name = name.encode('utf-8').decode('utf-8')
path = path.encode('utf-8').decode('utf-8') path = path.encode('utf-8').decode('utf-8')
try: try:
orig_path = u"{0}{1}".format(dir, path) orig_path = u"{0}{1}".format(the_dir, path)
Filemanager.check_access_permission( Filemanager.check_access_permission(
dir, u"{}{}".format(path, name)) the_dir, u"{}{}".format(path, name))
new_name = u"{0}{1}".format(orig_path, name) new_name = u"{0}{1}".format(orig_path, name)
if not os.path.exists(new_name): if not os.path.exists(new_name):
@@ -1020,21 +1020,21 @@ class Filemanager(object):
return result return result
@staticmethod @staticmethod
def get_new_name(dir, path, new_name, count=1): def get_new_name(in_dir, path, new_name, count=1):
""" """
Utility to provide new name for folder if file Utility to provide new name for folder if file
with same name already exists with same name already exists
""" """
last_char = new_name[-1] last_char = new_name[-1]
t_new_path = u"{}/{}{}_{}".format(dir, path, new_name, count) t_new_path = u"{}/{}{}_{}".format(in_dir, path, new_name, count)
if last_char == 'r' and not path_exists(t_new_path): if last_char == 'r' and not path_exists(t_new_path):
return t_new_path, new_name return t_new_path, new_name
else: else:
last_char = int(t_new_path[-1]) + 1 last_char = int(t_new_path[-1]) + 1
new_path = u"{}/{}{}_{}".format(dir, path, new_name, last_char) new_path = u"{}/{}{}_{}".format(in_dir, path, new_name, last_char)
if path_exists(new_path): if path_exists(new_path):
count += 1 count += 1
return Filemanager.get_new_name(dir, path, new_name, count) return Filemanager.get_new_name(in_dir, path, new_name, count)
else: else:
return new_path, new_name return new_path, new_name
@@ -1121,10 +1121,10 @@ class Filemanager(object):
'Code': 0 'Code': 0
} }
dir = self.dir if self.dir is not None else '' the_dir = self.dir if self.dir is not None else ''
try: try:
Filemanager.check_access_permission(dir, u"{}{}".format( Filemanager.check_access_permission(the_dir, u"{}{}".format(
path, name)) path, name))
except Exception as e: except Exception as e:
res = { res = {
@@ -1133,8 +1133,8 @@ class Filemanager(object):
} }
return res return res
if dir != "": if the_dir != "":
new_path = u"{}/{}{}/".format(dir, path, name) new_path = u"{}/{}{}/".format(the_dir, path, name)
else: else:
new_path = u"{}{}/".format(path, name) new_path = u"{}{}/".format(path, name)
@@ -1148,7 +1148,7 @@ class Filemanager(object):
code = 0 code = 0
err_msg = gettext(u"Error: {0}").format(e.strerror) err_msg = gettext(u"Error: {0}").format(e.strerror)
else: else:
new_path, new_name = self.get_new_name(dir, path, name) new_path, new_name = self.get_new_name(the_dir, path, name)
try: try:
os.mkdir(new_path) os.mkdir(new_path)
except Exception as e: except Exception as e:
@@ -1174,17 +1174,17 @@ class Filemanager(object):
'Code': 0 'Code': 0
} }
dir = self.dir if self.dir is not None else '' the_dir = self.dir if self.dir is not None else ''
if hasattr(str, 'decode'): if hasattr(str, 'decode'):
path = path.encode('utf-8') path = path.encode('utf-8')
orig_path = u"{0}{1}".format(dir, path.decode('utf-8')) orig_path = u"{0}{1}".format(the_dir, path.decode('utf-8'))
else: else:
orig_path = u"{0}{1}".format(dir, path) orig_path = u"{0}{1}".format(the_dir, path)
try: try:
Filemanager.check_access_permission( Filemanager.check_access_permission(
dir, u"{}{}".format(path, path) the_dir, u"{}{}".format(path, path)
) )
except Exception as e: except Exception as e:
resp = Response(gettext(u"Error: {0}").format(e)) resp = Response(gettext(u"Error: {0}").format(e))
@@ -1199,10 +1199,10 @@ class Filemanager(object):
return resp return resp
def permission(self, path=None, req=None): def permission(self, path=None, req=None):
dir = self.dir if self.dir is not None else '' the_dir = self.dir if self.dir is not None else ''
res = {'Code': 1} res = {'Code': 1}
try: try:
Filemanager.check_access_permission(dir, path) Filemanager.check_access_permission(the_dir, path)
except Exception as e: except Exception as e:
err_msg = gettext(u"Error: {0}").format(e) err_msg = gettext(u"Error: {0}").format(e)
res['Code'] = 0 res['Code'] = 0

View File

@@ -565,8 +565,7 @@ def create_server(server):
conn.commit() conn.commit()
conn.close() conn.close()
type = get_server_type(server) server['type'] = get_server_type(server)
server['type'] = type
# Add server info to parent_node_dict # Add server info to parent_node_dict
regression.parent_node_dict["server"].append( regression.parent_node_dict["server"].append(
{ {