From e52294dbb3603ea0af168142ee80fb556bb0ffcc Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 15 Feb 2023 18:40:20 -0500 Subject: [PATCH] Appease the linter --- app/classes/controllers/servers_controller.py | 2 +- app/classes/minecraft/mc_ping.py | 2 +- app/classes/shared/helpers.py | 8 ++++---- app/classes/shared/main_controller.py | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/classes/controllers/servers_controller.py b/app/classes/controllers/servers_controller.py index 1503b78f..8a74d3b8 100644 --- a/app/classes/controllers/servers_controller.py +++ b/app/classes/controllers/servers_controller.py @@ -163,7 +163,7 @@ class ServersController(metaclass=Singleton): return server["server_obj"] logger.warning(f"Unable to find server object for server id {server_id}") - raise Exception(f"Unable to find server object for server id {server_id}") + raise ValueError(f"Unable to find server object for server id {server_id}") def init_all_servers(self): servers = self.get_all_defined_servers() diff --git a/app/classes/minecraft/mc_ping.py b/app/classes/minecraft/mc_ping.py index 79610d8d..f760a8f9 100644 --- a/app/classes/minecraft/mc_ping.py +++ b/app/classes/minecraft/mc_ping.py @@ -123,7 +123,7 @@ def ping(ip, port): try: k = sock.recv(1) if not k: - raise Exception() + raise ValueError() except: return 0 k = k[0] diff --git a/app/classes/shared/helpers.py b/app/classes/shared/helpers.py index ba333e92..6f814a95 100644 --- a/app/classes/shared/helpers.py +++ b/app/classes/shared/helpers.py @@ -94,7 +94,7 @@ class Helpers: try: # Get tags from Gitlab, select the latest and parse the semver response = get( - "https://gitlab.com/api/v4/projects/20430749/repository/tags" + "https://gitlab.com/api/v4/projects/20430749/repository/tags", timeout=1 ) if response.status_code == 200: remote_version = pkg_version.parse(json.loads(response.text)[0]["name"]) @@ -131,7 +131,7 @@ class Helpers: try: # Get minecraft server download page # (hopefully the don't change the structure) - download_page = get(url, headers=headers) + download_page = get(url, headers=headers, timeout=1) # Search for our string targets win_download_url = re.search(target_win, download_page.text).group(0) @@ -281,7 +281,7 @@ class Helpers: @staticmethod def check_port(server_port): try: - ip = get("https://api.ipify.org").content.decode("utf8") + ip = get("https://api.ipify.org", timeout=1).content.decode("utf8") except: ip = "google.com" a_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -751,7 +751,7 @@ class Helpers: use_ssl=True, ) # + "?d=404" try: - if requests.head(url).status_code != 404: + if requests.head(url, timeout=1).status_code != 404: profile_url = url except Exception as e: logger.debug(f"Could not pull resource from Gravatar with error {e}") diff --git a/app/classes/shared/main_controller.py b/app/classes/shared/main_controller.py index 52bb6a72..3207be9d 100644 --- a/app/classes/shared/main_controller.py +++ b/app/classes/shared/main_controller.py @@ -347,7 +347,7 @@ class Controller: elif root_create_data["create_type"] == "import_zip": # TODO: Copy files from the zip file to the new server directory server_file = create_data["jarfile"] - raise Exception("Not yet implemented") + raise NotImplementedError("Not yet implemented") _create_server_properties_if_needed( create_data["server_properties_port"], ) @@ -379,7 +379,7 @@ class Controller: logger.error(f"Server import failed with error: {ex}") elif root_create_data["create_type"] == "import_zip": # TODO: Copy files from the zip file to the new server directory - raise Exception("Not yet implemented") + raise NotImplementedError("Not yet implemented") _create_server_properties_if_needed(0, True) @@ -401,7 +401,7 @@ class Controller: logger.error(f"Server import failed with error: {ex}") elif root_create_data["create_type"] == "import_zip": # TODO: Copy files from the zip file to the new server directory - raise Exception("Not yet implemented") + raise NotImplementedError("Not yet implemented") _create_server_properties_if_needed(0, True)