From: Roland Häder Date: Mon, 12 Jun 2023 10:25:17 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ae3bdfbcbc08bf7c87ecc483fb45038181b2071c;p=fba.git Continued: - renamed hash -> blocked_hash to avoid redefining builtin references - also combined 2 isinstance() into one --- diff --git a/fba/commands.py b/fba/commands.py index 534c861..96018e9 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -568,7 +568,7 @@ def fetch_oliphant(args: argparse.Namespace): print(f"WARNING: domain='{domain}' is not a valid domain - skipped!") continue elif blacklist.is_blacklisted(domain): - print(f"WARNING: domain='{domain}' is blacklisted - skipped!") + # DEBUG: print(f"DEBUG: domain='{domain}' is blacklisted - skipped!") continue elif instances.is_recent(domain): # DEBUG: print(f"DEBUG: domain='{domain}' has been recently checked - skipped!") diff --git a/fba/fba.py b/fba/fba.py index 9cd6b9c..d935bcb 100644 --- a/fba/fba.py +++ b/fba/fba.py @@ -54,7 +54,7 @@ def log_error(domain: str, error: dict): return # DEBUG: print("DEBUG: BEFORE error[]:", type(error)) - if isinstance(error, BaseException) or isinstance(error, json.decoder.JSONDecodeError): + if isinstance(error, BaseException, error, json.decoder.JSONDecodeError): error = f"error[{type(error)}]='{str(error)}'" # DEBUG: print("DEBUG: AFTER error[]:", type(error)) diff --git a/fba/instances.py b/fba/instances.py index ec1dfb7..4cccb37 100644 --- a/fba/instances.py +++ b/fba/instances.py @@ -264,7 +264,7 @@ def update_last_error(domain: str, error: dict): raise ValueError("Parameter 'domain' is empty") # DEBUG: print("DEBUG: BEFORE error[]:", type(error)) - if isinstance(error, BaseException) or isinstance(error, json.decoder.JSONDecodeError): + if isinstance(error, (BaseException, json.decoder.JSONDecodeError)): error = f"error[{type(error)}]='{str(error)}'" # DEBUG: print("DEBUG: AFTER error[]:", type(error)) @@ -276,6 +276,8 @@ def update_last_error(domain: str, error: dict): # DEBUG: print(f"DEBUG: Setting last_error_details='{error.reason}'") set_data("last_status_code" , domain, error.status_code) set_data("last_error_details", domain, error.reason) + elif not isinstance(error, dict): + raise KeyError(f"Cannot handle keys in error[{type(error)}]='{error}'") elif "status_code" in error and "error_message" in error: # DEBUG: print(f"DEBUG: Setting last_error_details='{error['error_message']}'") set_data("last_status_code" , domain, error["status_code"]) @@ -283,8 +285,6 @@ def update_last_error(domain: str, error: dict): elif "json" in error and "error" in error["json"]: set_data("last_status_code" , domain, error["status_code"]) set_data("last_error_details", domain, error["json"]["error"]) - else: - raise KeyError(f"Cannot handle keys in error[{type(error)}]='{error}'") # Running pending updated # DEBUG: print(f"DEBUG: Invoking update_data({domain}) ...") @@ -337,8 +337,8 @@ def is_recent(domain: str) -> bool: # DEBUG: print(f"DEBUG: recently='{recently}' - EXIT!") return recently -def deobsure(char: str, domain: str, hash: str = None) -> tuple: - #print(f"DEBUG: char='{char}',domain='{domain}',hash='{hash}' - CALLED!") +def deobsure(char: str, domain: str, blocked_hash: str = None) -> tuple: + #print(f"DEBUG: char='{char}',domain='{domain}',blocked_hash='{blocked_hash}' - CALLED!") if not isinstance(char, str): raise ValueError(f"Parameter char[]='{type(char)}' is not 'str'") elif char == "": @@ -347,12 +347,12 @@ def deobsure(char: str, domain: str, hash: str = None) -> tuple: raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'") elif domain == "": raise ValueError("Parameter 'domain' is empty") - elif not isinstance(hash, str) and hash is not None: - raise ValueError(f"Parameter hash[]='{type(hash)}' is not 'str'") + elif not isinstance(blocked_hash, str) and blocked_hash is not None: + raise ValueError(f"Parameter blocked_hash[]='{type(blocked_hash)}' is not 'str'") - if isinstance(hash, str): + if isinstance(blocked_hash, str): fba.cursor.execute( - "SELECT domain, origin, nodeinfo_url FROM instances WHERE hash = ? LIMIT 1", [hash] + "SELECT domain, origin, nodeinfo_url FROM instances WHERE hash = ? LIMIT 1", [blocked_hash] ) else: fba.cursor.execute(