diff --git a/tools/dependency_inventory.py b/tools/dependency_inventory.py index 36479a024..ff82fbb27 100644 --- a/tools/dependency_inventory.py +++ b/tools/dependency_inventory.py @@ -165,7 +165,6 @@ def get_js_deps(): if module[2] != "": licence = module[2] - url = "Unknown" if module[3] != "": url = module[3] diff --git a/web/pgadmin/browser/server_groups/servers/__init__.py b/web/pgadmin/browser/server_groups/servers/__init__.py index 870da543b..78200b69e 100644 --- a/web/pgadmin/browser/server_groups/servers/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/__init__.py @@ -1016,9 +1016,11 @@ class ServerNode(PGChildNodeView): else: return unauthorized(gettext("Unauthorized request.")) - data = request.form if request.form else json.loads( - request.data, encoding='utf-8' - ) if request.data else {} + data = {} + if request.form: + data = request.form + elif request.data: + data = json.loads(request.data, encoding='utf-8') password = None passfile = None diff --git a/web/pgadmin/browser/server_groups/servers/databases/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/__init__.py index 6c6472583..52fb050d8 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/__init__.py @@ -862,8 +862,6 @@ class DatabaseView(PGChildNodeView): ) else: - status = self.manager.release(did=did) - SQL = render_template( "/".join([self.template_path, self._DELETE_SQL]), datname=res, conn=self.conn diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/__init__.py index 3d8697a9d..60bfc9af8 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/__init__.py @@ -305,9 +305,12 @@ class ForeignTableView(PGChildNodeView, DataTypeReader, data[key] = [] elif key == 'typnotnull': - data[key] = True if (req[key] == 'true' or req[key] - is True) else False if \ - (req[key] == 'false' or req[key]) is False else '' + if req[key] == 'true' or req[key] is True: + data[key] = True + elif req[key] == 'false' or req[key] is False: + data[key] = False + else: + data[key] = '' else: data[key] = req[key] diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/__init__.py index eeed70eb5..0fbdbca1a 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/__init__.py @@ -450,7 +450,7 @@ class PartitionsView(BaseTableView, DataTypeReader, VacuumSettings, ) res[row['name']] = data - return res + return res @BaseTableView.check_precondition def sql(self, gid, sid, did, scid, tid, ptid): diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/__init__.py index fea69fb0d..5fb2b8cfe 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/__init__.py @@ -473,15 +473,15 @@ class TypeView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare): # If we have length & precision both if is_tlength and is_precision: - matchObj = re.search(r'(\d+),(\d+)', row['fulltype']) - if matchObj: - t_len = matchObj.group(1) - t_prec = matchObj.group(2) + match_obj = re.search(r'(\d+),(\d+)', row['fulltype']) + if match_obj: + t_len = match_obj.group(1) + t_prec = match_obj.group(2) elif is_tlength: # If we have length only - matchObj = re.search(r'(\d+)', row['fulltype']) - if matchObj: - t_len = matchObj.group(1) + match_obj = re.search(r'(\d+)', row['fulltype']) + if match_obj: + t_len = match_obj.group(1) t_prec = None type_name = DataTypeReader.parse_type_name(row['typname']) diff --git a/web/pgadmin/misc/bgprocess/processes.py b/web/pgadmin/misc/bgprocess/processes.py index d73e6d783..efaaf2075 100644 --- a/web/pgadmin/misc/bgprocess/processes.py +++ b/web/pgadmin/misc/bgprocess/processes.py @@ -202,25 +202,6 @@ class BatchProcess(object): return file_quote(exe_file) return None - def convert_environment_variables(env): - """ - This function is use to convert environment variable to string - because environment variable must be string in popen - :param env: Dict of environment variable - :return: Encoded environment variable as string - """ - encoding = sys.getdefaultencoding() - if encoding is None or encoding == 'ascii': - encoding = 'utf-8' - temp_env = dict() - for key, value in env.items(): - if not isinstance(key, str): - key = key.encode(encoding) - if not isinstance(value, str): - value = value.encode(encoding) - temp_env[key] = value - return temp_env - if self.stime is not None: if self.etime is None: raise Exception(_('The process has already been started.')) @@ -409,7 +390,7 @@ class BatchProcess(object): out_completed = err_completed = False process_output = (out != -1 and err != -1) enc = sys.getdefaultencoding() - if enc is None or enc == 'ascii': + if enc == 'ascii': enc = 'utf-8' def read_log(logfile, log, pos, ctime, ecode=None): diff --git a/web/pgadmin/misc/file_manager/__init__.py b/web/pgadmin/misc/file_manager/__init__.py index 78a24c24a..b6dab51bd 100644 --- a/web/pgadmin/misc/file_manager/__init__.py +++ b/web/pgadmin/misc/file_manager/__init__.py @@ -671,29 +671,28 @@ class Filemanager(object): @staticmethod def check_access_permission(in_dir, path): - if not config.SERVER_MODE: - return True + if config.SERVER_MODE: + if in_dir is None: + in_dir = "" + orig_path = Filemanager.get_abs_path(in_dir, path) - if in_dir is None: - in_dir = "" - orig_path = Filemanager.get_abs_path(in_dir, path) + # This translates path with relative path notations + # like ./ and ../ to absolute path. + orig_path = os.path.abspath(orig_path) - # This translates path with relative path notations like ./ and ../ to - # absolute path. - orig_path = os.path.abspath(orig_path) + if in_dir: + if _platform == 'win32': + if in_dir[-1] == '\\' or in_dir[-1] == '/': + in_dir = in_dir[:-1] + else: + if in_dir[-1] == '/': + in_dir = in_dir[:-1] - if in_dir: - if _platform == 'win32': - if in_dir[-1] == '\\' or in_dir[-1] == '/': - in_dir = in_dir[:-1] - else: - if in_dir[-1] == '/': - in_dir = in_dir[:-1] - - # Do not allow user to access outside his storage dir in server mode. - if not orig_path.startswith(in_dir): - raise Exception( - gettext(u"Access denied ({0})").format(path)) + # Do not allow user to access outside his storage dir + # in server mode. + if not orig_path.startswith(in_dir): + raise Exception( + gettext(u"Access denied ({0})").format(path)) return True @staticmethod diff --git a/web/pgadmin/tools/debugger/__init__.py b/web/pgadmin/tools/debugger/__init__.py index 9b5bf5ddd..3209e4f0a 100644 --- a/web/pgadmin/tools/debugger/__init__.py +++ b/web/pgadmin/tools/debugger/__init__.py @@ -492,7 +492,6 @@ def init_function(node_type, sid, did, scid, fid, trid=None): for pr_arg_mode in pro_arg_modes: if pr_arg_mode == 'o' or pr_arg_mode == 't': data['require_input'] = False - continue else: data['require_input'] = True break @@ -2124,7 +2123,8 @@ 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: - raise - finally: + de_inst.clear() + except Exception: + de_inst.clear() + raise diff --git a/web/pgadmin/tools/schema_diff/directory_compare.py b/web/pgadmin/tools/schema_diff/directory_compare.py index 4841322b1..0fe730623 100644 --- a/web/pgadmin/tools/schema_diff/directory_compare.py +++ b/web/pgadmin/tools/schema_diff/directory_compare.py @@ -319,7 +319,7 @@ def are_dictionaries_identical(source_dict, target_dict, ignore_whitespaces, return True -def directory_diff(source_dict, target_dict, ignore_keys=[], difference={}): +def directory_diff(source_dict, target_dict, ignore_keys=[], difference=None): """ This function is used to recursively compare two dictionaries and return the difference. @@ -330,6 +330,7 @@ def directory_diff(source_dict, target_dict, ignore_keys=[], difference={}): :param difference: """ + difference = {} if difference is None else difference src_keys = set(source_dict.keys()) tar_keys = set(target_dict.keys()) diff --git a/web/pgadmin/tools/sqleditor/__init__.py b/web/pgadmin/tools/sqleditor/__init__.py index 0ec573b0e..58bb6cde8 100644 --- a/web/pgadmin/tools/sqleditor/__init__.py +++ b/web/pgadmin/tools/sqleditor/__init__.py @@ -259,10 +259,7 @@ def start_view_data(trans_id): update_session_grid_transaction(trans_id, session_obj) # Execute sql asynchronously - try: - status, result = conn.execute_async(sql) - except (ConnectionLost, SSHTunnelConnectionLost) as e: - raise + status, result = conn.execute_async(sql) else: status = False result = error_msg diff --git a/web/pgadmin/tools/sqleditor/utils/start_running_query.py b/web/pgadmin/tools/sqleditor/utils/start_running_query.py index b4d213992..cddd64ecd 100644 --- a/web/pgadmin/tools/sqleditor/utils/start_running_query.py +++ b/web/pgadmin/tools/sqleditor/utils/start_running_query.py @@ -137,10 +137,7 @@ class StartRunningQuery: # Execute sql asynchronously with params is None # and formatted_error is True. - try: - status, result = conn.execute_async(sql) - except (ConnectionLost, SSHTunnelConnectionLost, CryptKeyMissing): - raise + status, result = conn.execute_async(sql) # If the transaction aborted for some reason and # Auto RollBack is True then issue a rollback to cleanup. diff --git a/web/pgadmin/utils/ajax.py b/web/pgadmin/utils/ajax.py index acde2793b..7c37d20ed 100644 --- a/web/pgadmin/utils/ajax.py +++ b/web/pgadmin/utils/ajax.py @@ -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) diff --git a/web/pgadmin/utils/csv.py b/web/pgadmin/utils/csv.py index ee586991c..fd67df230 100644 --- a/web/pgadmin/utils/csv.py +++ b/web/pgadmin/utils/csv.py @@ -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)) diff --git a/web/pgadmin/utils/driver/psycopg2/connection.py b/web/pgadmin/utils/driver/psycopg2/connection.py index 9c78b502e..33af4f57c 100644 --- a/web/pgadmin/utils/driver/psycopg2/connection.py +++ b/web/pgadmin/utils/driver/psycopg2/connection.py @@ -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( diff --git a/web/pgadmin/utils/driver/psycopg2/server_manager.py b/web/pgadmin/utils/driver/psycopg2/server_manager.py index 923046e70..ce11a31f1 100644 --- a/web/pgadmin/utils/driver/psycopg2/server_manager.py +++ b/web/pgadmin/utils/driver/psycopg2/server_manager.py @@ -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: diff --git a/web/pgadmin/utils/session.py b/web/pgadmin/utils/session.py index a8b94142f..177a996b8 100644 --- a/web/pgadmin/utils/session.py +++ b/web/pgadmin/utils/session.py @@ -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) diff --git a/web/regression/python_test_utils/test_utils.py b/web/regression/python_test_utils/test_utils.py index 2f36b5e81..b93d8ad19 100644 --- a/web/regression/python_test_utils/test_utils.py +++ b/web/regression/python_test_utils/test_utils.py @@ -1129,9 +1129,9 @@ def check_binary_path_or_skip_test(cls, utility_name): cls.server['default_binary_paths'][cls.server['type']], utility_name ) - ret_val = does_utility_exist(binary_path) - if ret_val is not None: - cls.skipTest(ret_val) + retVal = does_utility_exist(binary_path) + if retVal is not None: + cls.skipTest(retVal) def get_watcher_dialogue_status(self): diff --git a/web/regression/runtests.py b/web/regression/runtests.py index 73d3eb7ba..86c5a0a8e 100644 --- a/web/regression/runtests.py +++ b/web/regression/runtests.py @@ -819,6 +819,7 @@ if __name__ == '__main__': app_starter_local.stop_app() if handle_cleanup: handle_cleanup() + raise else: print( "\n============= Either Selenium Grid is NOT up OR" @@ -840,6 +841,7 @@ if __name__ == '__main__': except SystemExit: if handle_cleanup: handle_cleanup() + raise print_test_results() # Stop code coverage