From 8ee8a4c066529c4b8b2fea60b853060d53c83e48 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 9 Jun 2023 11:57:40 +0200 Subject: [PATCH] Continued: - renaming 'exception' to 'exc' didn't fix the problem, I thought here about overlapping/overwriting definitions - but pylint3 would have it shown anyway --- fba/blocks.py | 12 ++++++------ fba/commands.py | 20 ++++++++++---------- fba/csrf.py | 4 ++-- fba/fba.py | 28 ++++++++++++++-------------- fba/federation/lemmy.py | 4 ++-- fba/federation/mastodon.py | 14 +++++++------- fba/federation/misskey.py | 12 ++++++------ fba/federation/peertube.py | 4 ++-- fba/federation/pleroma.py | 4 ++-- fba/instances.py | 12 ++++++------ fba/network.py | 18 +++++++++--------- 11 files changed, 66 insertions(+), 66 deletions(-) diff --git a/fba/blocks.py b/fba/blocks.py index 42cc83c..50ceec8 100644 --- a/fba/blocks.py +++ b/fba/blocks.py @@ -56,8 +56,8 @@ def update_reason(reason: str, blocker: str, blocked: str, block_level: str): # DEBUG: print(f"DEBUG: Did not update any rows: blocker='{blocker}',blocked='{blocked}',block_level='{block_level}',reason='{reason}' - EXIT!") return - except BaseException as exc: - print(f"ERROR: failed SQL query: reason='{reason}',blocker='{blocker}',blocked='{blocked}',block_level='{block_level}',exc[{type(exc)}]:'{str(exc)}'") + except BaseException as exception: + print(f"ERROR: failed SQL query: reason='{reason}',blocker='{blocker}',blocked='{blocked}',block_level='{block_level}',exception[{type(exception)}]:'{str(exception)}'") sys.exit(255) # DEBUG: print("DEBUG: EXIT!") @@ -93,8 +93,8 @@ def update_last_seen(blocker: str, blocked: str, block_level: str): # DEBUG: print(f"DEBUG: Did not update any rows: blocker='{blocker}',blocked='{blocked}',block_level='{block_level}' - EXIT!") return - except BaseException as exc: - print(f"ERROR: failed SQL query: blocker='{blocker}',blocked='{blocked}',block_level='{block_level}',exc[{type(exc)}]:'{str(exc)}'") + except BaseException as exception: + print(f"ERROR: failed SQL query: blocker='{blocker}',blocked='{blocked}',block_level='{block_level}',exception[{type(exception)}]:'{str(exception)}'") sys.exit(255) # DEBUG: print("DEBUG: EXIT!") @@ -164,8 +164,8 @@ def add_instance(blocker: str, blocked: str, reason: str, block_level: str): time.time() ), ) - except BaseException as exc: - print(f"ERROR: failed SQL query: blocker='{blocker}',blocked='{blocked}',reason='{reason}',block_level='{block_level}',exc[{type(exc)}]:'{str(exc)}'") + except BaseException as exception: + print(f"ERROR: failed SQL query: blocker='{blocker}',blocked='{blocked}',reason='{reason}',block_level='{block_level}',exception[{type(exception)}]:'{str(exception)}'") sys.exit(255) # DEBUG: print("DEBUG: EXIT!") diff --git a/fba/commands.py b/fba/commands.py index 03fe16d..b1e60d8 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -88,8 +88,8 @@ def fetch_bkali(args: argparse.Namespace): # DEBUG: print(f"DEBUG: Adding domain='{entry['domain']}' ...") domains.append(entry["domain"]) - except BaseException as exc: - print(f"ERROR: Cannot fetch graphql,exc[{type(exc)}]:'{str(exc)}'") + except BaseException as exception: + print(f"ERROR: Cannot fetch graphql,exception[{type(exception)}]:'{str(exception)}'") sys.exit(255) # DEBUG: print(f"DEBUG: domains()={len(domains)}") @@ -242,8 +242,8 @@ def fetch_blocks(args: argparse.Namespace): # DEBUG: print("DEBUG: Committing changes ...") fba.connection.commit() - except BaseException as exc: - print(f"ERROR: blocker='{blocker}',software='{software}',exc[{type(exc)}]:'{str(exc)}'") + except BaseException as exception: + print(f"ERROR: blocker='{blocker}',software='{software}',exception[{type(exception)}]:'{str(exception)}'") else: print("WARNING: Unknown software:", blocker, software) @@ -296,8 +296,8 @@ def fetch_cs(args: argparse.Namespace): # DEBUG: print(f"DEBUG: blocked[]={type(blocked)}") domains["reject"] = domains["reject"] + fba.find_domains(blocked) - except BaseException as exc: - print(f"ERROR: Cannot fetch from meta.chaos.social,exc[{type(exc)}]:'{str(exc)}'") + except BaseException as exception: + print(f"ERROR: Cannot fetch from meta.chaos.social,exception[{type(exception)}]:'{str(exception)}'") sys.exit(255) # DEBUG: print(f"DEBUG: domains()={len(domains)}") @@ -354,8 +354,8 @@ def fetch_fba_rss(args: argparse.Namespace): # DEBUG: print(f"DEBUG: Adding domain='{domain}'") domains.append(domain) - except BaseException as exc: - print(f"ERROR: Cannot fetch args.feed='{args.feed}',exc[{type(exc)}]:'{str(exc)}'") + except BaseException as exception: + print(f"ERROR: Cannot fetch args.feed='{args.feed}',exception[{type(exception)}]:'{str(exception)}'") sys.exit(255) # DEBUG: print(f"DEBUG: domains()={len(domains)}") @@ -407,8 +407,8 @@ def fetch_fbabot_atom(args: argparse.Namespace): # DEBUG: print(f"DEBUG: Adding domain='{domain}',domains()={len(domains)}") domains.append(domain) - except BaseException as exc: - print(f"ERROR: Cannot fetch feed='{feed}',exc[{type(exc)}]:'{str(exc)}'") + except BaseException as exception: + print(f"ERROR: Cannot fetch feed='{feed}',exception[{type(exception)}]:'{str(exception)}'") sys.exit(255) # DEBUG: print(f"DEBUG: domains({len(domains)})={domains}") diff --git a/fba/csrf.py b/fba/csrf.py index 1bfd1d5..caaed38 100644 --- a/fba/csrf.py +++ b/fba/csrf.py @@ -58,8 +58,8 @@ def determine(domain: str, headers: dict) -> dict: reqheaders = {**headers, **{"X-CSRF-Token": csrf}} - except BaseException as exc: - # DEBUG: print(f"DEBUG: No CSRF token found, using normal headers: domain='{domain}',exc[{type(exc)}]={exc}") + except BaseException as exception: + # DEBUG: print(f"DEBUG: No CSRF token found, using normal headers: domain='{domain}',exception[{type(exception)}]={exception}") pass # DEBUG: print(f"DEBUG: reqheaders()={len(reqheaders)} - EXIT!") diff --git a/fba/fba.py b/fba/fba.py index a34690f..42889b4 100644 --- a/fba/fba.py +++ b/fba/fba.py @@ -131,8 +131,8 @@ def fetch_instances(domain: str, origin: str, software: str, script: str, path: if not instances.is_registered(instance): # DEBUG: print("DEBUG: Adding new instance:", instance, domain) instances.add(instance, domain, script) - except BaseException as exc: - print(f"ERROR: instance='{instance}',exc[{type(exc)}]:'{str(exc)}'") + except BaseException as exception: + print(f"ERROR: instance='{instance}',exception[{type(exception)}]:'{str(exception)}'") continue # DEBUG: print("DEBUG: EXIT!") @@ -335,8 +335,8 @@ def log_error(domain: str, response: requests.models.Response): # Cleanup old entries # DEBUG: print(f"DEBUG: Purging old records (distance: {config.get('error_log_cleanup')})") cursor.execute("DELETE FROM error_log WHERE created < ?", [time.time() - config.get("error_log_cleanup")]) - except BaseException as exc: - print(f"ERROR: failed SQL query: domain='{domain}',exc[{type(exc)}]:'{str(exc)}'") + except BaseException as exception: + print(f"ERROR: failed SQL query: domain='{domain}',exception[{type(exception)}]:'{str(exception)}'") sys.exit(255) # DEBUG: print("DEBUG: EXIT!") @@ -392,9 +392,9 @@ def fetch_peers(domain: str, software: str) -> list: # DEBUG: print("DEBUG: Querying API was successful:", domain, len(data)) peers = data - except BaseException as exc: - print("WARNING: Some error during fetch_peers():", domain, exc) - instances.update_last_error(domain, exc) + except BaseException as exception: + print("WARNING: Some error during fetch_peers():", domain, exception) + instances.update_last_error(domain, exception) # DEBUG: print(f"DEBUG: Adding '{len(peers)}' for domain='{domain}'") instances.set_data("total_peers", domain, len(peers)) @@ -456,9 +456,9 @@ def fetch_nodeinfo(domain: str, path: str = None) -> list: instances.update_last_error(domain, response) continue - except BaseException as exc: + except BaseException as exception: # DEBUG: print("DEBUG: Cannot fetch API request:", request) - instances.update_last_error(domain, exc) + instances.update_last_error(domain, exception) pass # DEBUG: print(f"DEBUG: data()={len(data)} - EXIT!") @@ -502,9 +502,9 @@ def fetch_wellknown_nodeinfo(domain: str) -> list: else: print("WARNING: nodeinfo does not contain 'links':", domain) - except BaseException as exc: + except BaseException as exception: print("WARNING: Failed fetching .well-known info:", domain) - instances.update_last_error(domain, exc) + instances.update_last_error(domain, exception) pass # DEBUG: print("DEBUG: Returning data[]:", type(data)) @@ -551,9 +551,9 @@ def fetch_generator_from_path(domain: str, path: str = "/") -> str: instances.set_data("detection_mode", domain, "SITE_NAME") remove_pending_error(domain) - except BaseException as exc: - # DEBUG: print(f"DEBUG: Cannot fetch / from '{domain}':", exc) - instances.update_last_error(domain, exc) + except BaseException as exception: + # DEBUG: print(f"DEBUG: Cannot fetch / from '{domain}':", exception) + instances.update_last_error(domain, exception) pass # DEBUG: print(f"DEBUG: software[]={type(software)}") diff --git a/fba/federation/lemmy.py b/fba/federation/lemmy.py index f92f592..d186b0d 100644 --- a/fba/federation/lemmy.py +++ b/fba/federation/lemmy.py @@ -47,8 +47,8 @@ def fetch_peers(domain: str) -> list: print("WARNING: JSON response does not contain 'federated_instances':", domain) instances.update_last_error(domain, response) - except BaseException as exc: - print(f"WARNING: Exception during fetching JSON: domain='{domain}',exc[{type(exc)}]:'{str(exc)}'") + except BaseException as exception: + print(f"WARNING: Exception during fetching JSON: domain='{domain}',exception[{type(exception)}]:'{str(exception)}'") # DEBUG: print(f"DEBUG: Adding '{len(peers)}' for domain='{domain}'") instances.set_data("total_peers", domain, len(peers)) diff --git a/fba/federation/mastodon.py b/fba/federation/mastodon.py index 4a6ecff..54a376e 100644 --- a/fba/federation/mastodon.py +++ b/fba/federation/mastodon.py @@ -72,9 +72,9 @@ def fetch_blocks_from_about(domain: str) -> dict: network.fetch_response(domain, "/about/more", network.web_headers, (config.get("connection_timeout"), config.get("read_timeout"))).text, "html.parser", ) - except BaseException as exc: - print("ERROR: Cannot fetch from domain:", domain, exc) - instances.update_last_error(domain, exc) + except BaseException as exception: + print("ERROR: Cannot fetch from domain:", domain, exception) + instances.update_last_error(domain, exception) return {} for header in doc.find_all("h3"): @@ -163,8 +163,8 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str): else: print("WARNING: Unknown severity:", block['severity'], block['domain']) - except BaseException as exc: - # DEBUG: print(f"DEBUG: Failed, trying mastodon-specific fetches: domain='{domain}',exc[{type(exc)}]={str(exc)}") + except BaseException as exception: + # DEBUG: print(f"DEBUG: Failed, trying mastodon-specific fetches: domain='{domain}',exception[{type(exception)}]={str(exception)}") rows = fetch_blocks_from_about(domain) print(f"INFO: Checking {len(rows.items())} entries from domain='{domain}',software='mastodon' ...") @@ -246,7 +246,7 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str): # DEBUG: print("DEBUG: Committing changes ...") fba.connection.commit() - except BaseException as exc: - print(f"ERROR: domain='{domain}',software='mastodon',exc[{type(exc)}]:'{str(exc)}'") + except BaseException as exception: + print(f"ERROR: domain='{domain}',software='mastodon',exception[{type(exception)}]:'{str(exception)}'") # DEBUG: print("DEBUG: EXIT!") diff --git a/fba/federation/misskey.py b/fba/federation/misskey.py index 549ff17..9e5c9af 100644 --- a/fba/federation/misskey.py +++ b/fba/federation/misskey.py @@ -180,9 +180,9 @@ def fetch_blocks(domain: str) -> dict: # DEBUG: print("DEBUG: API is no more returning new instances, aborting loop!") break - except BaseException as exc: - print("WARNING: Caught error, exiting loop:", domain, exc) - instances.update_last_error(domain, exc) + except BaseException as exception: + print("WARNING: Caught error, exiting loop:", domain, exception) + instances.update_last_error(domain, exception) offset = 0 break @@ -237,9 +237,9 @@ def fetch_blocks(domain: str) -> dict: # DEBUG: print("DEBUG: API is no more returning new instances, aborting loop!") break - except BaseException as exc: - print("ERROR: Exception during POST:", domain, exc) - instances.update_last_error(domain, exc) + except BaseException as exception: + print("ERROR: Exception during POST:", domain, exception) + instances.update_last_error(domain, exception) offset = 0 break diff --git a/fba/federation/peertube.py b/fba/federation/peertube.py index 06ffd04..f4997ad 100644 --- a/fba/federation/peertube.py +++ b/fba/federation/peertube.py @@ -56,8 +56,8 @@ def fetch_peers(domain: str) -> list: # Continue with next row start = start + 100 - except BaseException as exc: - print(f"WARNING: Exception during fetching JSON: domain='{domain}',exc[{type(exc)}]:'{str(exc)}'") + except BaseException as exception: + print(f"WARNING: Exception during fetching JSON: domain='{domain}',exception[{type(exception)}]:'{str(exception)}'") # DEBUG: print(f"DEBUG: Adding '{len(peers)}' for domain='{domain}'") instances.set_data("total_peers", domain, len(peers)) diff --git a/fba/federation/pleroma.py b/fba/federation/pleroma.py index b063d48..5e3bbf1 100644 --- a/fba/federation/pleroma.py +++ b/fba/federation/pleroma.py @@ -194,7 +194,7 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str): entry["reason"] = reason["reason"] fba.connection.commit() - except BaseException as exc: - print(f"ERROR: domain='{domain}',software='pleroma',exc[{type(exc)}]:'{str(exc)}'") + except BaseException as exception: + print(f"ERROR: domain='{domain}',software='pleroma',exception[{type(exception)}]:'{str(exception)}'") # DEBUG: print("DEBUG: EXIT!") diff --git a/fba/instances.py b/fba/instances.py index c55cb60..903fc3c 100644 --- a/fba/instances.py +++ b/fba/instances.py @@ -136,8 +136,8 @@ def update_data(domain: str): except: pass - except BaseException as exc: - print(f"ERROR: failed SQL query: domain='{domain}',sql_string='{sql_string}',exc[{type(exc)}]:'{str(exc)}'") + except BaseException as exception: + print(f"ERROR: failed SQL query: domain='{domain}',sql_string='{sql_string}',exception[{type(exception)}]:'{str(exception)}'") sys.exit(255) # DEBUG: print("DEBUG: EXIT!") @@ -233,8 +233,8 @@ def add(domain: str, origin: str, command: str, path: str = None): update_last_error(domain, fba.pending_errors[domain]) fba.remove_pending_error(domain) - except BaseException as exc: - print(f"ERROR: failed SQL query: domain='{domain}',exc[{type(exc)}]:'{str(exc)}'") + except BaseException as exception: + print(f"ERROR: failed SQL query: domain='{domain}',exception[{type(exception)}]:'{str(exception)}'") sys.exit(255) else: # DEBUG: print("DEBUG: Updating nodeinfo for domain:", domain) @@ -303,8 +303,8 @@ def is_registered(domain: str) -> bool: # Check Set all cache.set_all("is_registered", fba.cursor.fetchall(), True) - except BaseException as exc: - print(f"ERROR: failed SQL query: domain='{domain}',exc[{type(exc)}]:'{str(exc)}'") + except BaseException as exception: + print(f"ERROR: failed SQL query: domain='{domain}',exception[{type(exception)}]:'{str(exception)}'") sys.exit(255) # Is cache found? diff --git a/fba/network.py b/fba/network.py index 7138e8c..5fd6eb1 100644 --- a/fba/network.py +++ b/fba/network.py @@ -67,8 +67,8 @@ def post_json_api(domain: str, path: str, parameter: str, extra_headers: dict = print(f"WARNING: Cannot query JSON API: domain='{domain}',path='{path}',parameter()={len(parameter)},response.status_code='{response.status_code}',data[]='{type(data)}'") instances.update_last_error(domain, response) - except BaseException as exc: - print(f"WARNING: Some error during post(): domain='{domain}',path='{path}',parameter()={len(parameter)},exc[{type(exc)}]:'{str(exc)}'") + except BaseException as exception: + print(f"WARNING: Some error during post(): domain='{domain}',path='{path}',parameter()={len(parameter)},exception[{type(exception)}]:'{str(exception)}'") # DEBUG: print(f"DEBUG: Returning data({len(data)})=[]:{type(data)}") return data @@ -133,9 +133,9 @@ def fetch_friendica_blocks(domain: str) -> dict: fetch_response(domain, "/friendica", web_headers, (config.get("connection_timeout"), config.get("read_timeout"))).text, "html.parser", ) - except BaseException as exc: - print("WARNING: Failed to fetch /friendica from domain:", domain, exc) - instances.update_last_error(domain, exc) + except BaseException as exception: + print("WARNING: Failed to fetch /friendica from domain:", domain, exception) + instances.update_last_error(domain, exception) return {} blocklist = doc.find(id="about_blocklist") @@ -189,10 +189,10 @@ def fetch_response(domain: str, path: str, headers: dict, timeout: list) -> requ timeout=timeout ) - except requests.exceptions.ConnectionError as exc: - # DEBUG: print(f"DEBUG: Fetching '{path}' from '{domain}' failed. exc[{type(exc)}]='{str(exc)}'") - instances.update_last_error(domain, exc) - raise exc + except requests.exceptions.ConnectionError as exception: + # DEBUG: print(f"DEBUG: Fetching '{path}' from '{domain}' failed. exception[{type(exception)}]='{str(exception)}'") + instances.update_last_error(domain, exception) + raise exception # DEBUG: print(f"DEBUG: response[]='{type(response)}' - EXXIT!") return response -- 2.39.5