From 739097a5009e76bacb50188ecfaa793d29c1ff05 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 3 Jun 2023 16:53:14 +0200 Subject: [PATCH] Continued: - invoking update_instance_data() but having no pending instance data doesn't make any sense --- fba/fba.py | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/fba/fba.py b/fba/fba.py index fae4847..19e59ed 100644 --- a/fba/fba.py +++ b/fba/fba.py @@ -66,6 +66,7 @@ nodeinfo_identifier = [ headers = { "User-Agent": config["useragent"], } + # HTTP headers for API requests api_headers = { "User-Agent": config["useragent"], @@ -432,10 +433,13 @@ def has_pending_instance_data(domain: str) -> bool: return has_pending def update_instance_data(domain: str): + # DEBUG: print(f"DEBUG: domain={domain} - CALLED!") if type(domain) != str: raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'") elif domain == "": raise ValueError(f"Parameter 'domain' cannot be empty") + elif not has_pending_instance_data(domain): + raise Exception(f"Domain '{domain}' has no pending instance data, but function invoked") # DEBUG: print(f"DEBUG: Updating nodeinfo for domain='{domain}' ...") sql_string = '' @@ -547,6 +551,7 @@ def update_last_error(domain: str, res: any): # DEBUG: print("DEBUG: EXIT!") def update_last_instance_fetch(domain: str): + # DEBUG: print(f"DEBUG: domain={domain} - CALLED!") if type(domain) != str: raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'") elif domain == "": @@ -562,6 +567,7 @@ def update_last_instance_fetch(domain: str): # DEBUG: print("DEBUG: EXIT!") def update_last_nodeinfo(domain: str): + # DEBUG: print(f"DEBUG: domain={domain} - CALLED!") if type(domain) != str: raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'") elif domain == "": @@ -578,6 +584,7 @@ def update_last_nodeinfo(domain: str): # DEBUG: print("DEBUG: EXIT!") def get_peers(domain: str, software: str) -> list: + # DEBUG: print(f"DEBUG: domain({len(domain)})={domain},software={software} - CALLED!") if type(domain) != str: raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'") elif domain == "": @@ -800,18 +807,20 @@ def post_json_api(domain: str, path: str, parameter: str, extra_headers: dict = return data def fetch_nodeinfo(domain: str, path: str = None) -> list: + # DEBUG: print(f"DEBUG: domain='{domain}',path={path} - CALLED!") if type(domain) != str: raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'") elif domain == "": raise ValueError(f"Parameter 'domain' cannot be empty") + elif type(path) != str and path != None: + raise ValueError(f"Parameter path[]={type(path)} is not 'str'") # DEBUG: print("DEBUG: Fetching nodeinfo from domain,path:", domain, path) - nodeinfo = fetch_wellknown_nodeinfo(domain) - # DEBUG: print("DEBUG: nodeinfo:", nodeinfo) + # DEBUG: print(f"DEBUG: nodeinfo({len(nodeinfo)})={nodeinfo}") if len(nodeinfo) > 0: - # DEBUG: print("DEBUG: Returning auto-discovered nodeinfo:", len(nodeinfo)) + # DEBUG: print("DEBUG: nodeinfo()={len(nodeinfo))} - EXIT!") return nodeinfo requests = [ @@ -853,10 +862,11 @@ def fetch_nodeinfo(domain: str, path: str = None) -> list: update_last_error(domain, e) pass - # DEBUG: print("DEBUG: Returning data[]:", type(data)) + # DEBUG: print(f"DEBUG: data()={len(data)} - EXIT!") return data def fetch_wellknown_nodeinfo(domain: str) -> list: + # DEBUG: print(f"DEBUG: domain={domain} - CALLED!") if type(domain) != str: raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'") elif domain == "": @@ -902,6 +912,7 @@ def fetch_wellknown_nodeinfo(domain: str) -> list: return data def fetch_generator_from_path(domain: str, path: str = "/") -> str: + # DEBUG: print(f"DEBUG: domain({len(domain)})={domain},path={path} - CALLED!") if type(domain) != str: raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'") elif domain == "": @@ -972,10 +983,13 @@ def fetch_generator_from_path(domain: str, path: str = "/") -> str: return software def determine_software(domain: str, path: str = None) -> str: + # DEBUG: print(f"DEBUG: domain({len(domain)})={domain},path={path} - CALLED!") if type(domain) != str: raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'") elif domain == "": raise ValueError(f"Parameter 'domain' cannot be empty") + elif type(path) != str and path != None: + raise ValueError(f"Parameter path[]={type(path)} is not 'str'") # DEBUG: print("DEBUG: Determining software for domain,path:", domain, path) software = None @@ -1054,6 +1068,7 @@ def determine_software(domain: str, path: str = None) -> str: return software def update_block_reason(reason: str, blocker: str, blocked: str, block_level: str): + # DEBUG: print(f"DEBUG: reason='{reason}',blocker={blocker},blocked={blocked},block_level={block_level} - CALLED!") if type(reason) != str and reason != None: raise ValueError(f"Parameter reason[]='{type(reason)}' is not 'str'") elif type(blocker) != str: @@ -1150,6 +1165,7 @@ def block_instance(blocker: str, blocked: str, reason: str, block_level: str): # DEBUG: print("DEBUG: EXIT!") def is_instance_registered(domain: str) -> bool: + # DEBUG: print(f"DEBUG: domain={domain} - CALLED!") if type(domain) != str: raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'") elif domain == "": @@ -1174,6 +1190,7 @@ def is_instance_registered(domain: str) -> bool: return registered def add_instance(domain: str, origin: str, originator: str, path: str = None): + # DEBUG: print(f"DEBUG: domain={domain},origin={origin},originator={originator},path={path} - CALLED!") if type(domain) != str: raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'") elif domain == "": @@ -1233,6 +1250,7 @@ def add_instance(domain: str, origin: str, originator: str, path: str = None): # DEBUG: print("DEBUG: EXIT!") def send_bot_post(instance: str, blocks: dict): + # DEBUG: print(f"DEBUG: instance={instance},blocks()={len(blocks)} - CALLED!") message = instance + " has blocked the following instances:\n\n" truncated = False @@ -1268,6 +1286,7 @@ def send_bot_post(instance: str, blocks: dict): return True def get_mastodon_blocks(domain: str) -> dict: + # DEBUG: print(f"DEBUG: domain={domain} - CALLED!") if type(domain) != str: raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'") elif domain == "": @@ -1317,6 +1336,7 @@ def get_mastodon_blocks(domain: str) -> dict: } def get_friendica_blocks(domain: str) -> dict: + # DEBUG: print(f"DEBUG: domain={domain} - CALLED!") if type(domain) != str: raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'") elif domain == "": @@ -1355,6 +1375,7 @@ def get_friendica_blocks(domain: str) -> dict: } def get_misskey_blocks(domain: str) -> dict: + # DEBUG: print(f"DEBUG: domain={domain} - CALLED!") if type(domain) != str: raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'") elif domain == "": @@ -1475,25 +1496,27 @@ def get_misskey_blocks(domain: str) -> dict: } def tidyup(string: str) -> str: + # DEBUG: print(f"DEBUG: string='{string}' - CALLED!") if type(string) != str: raise ValueError(f"Parameter string[]={type(string)} is not expected") - # some retards put their blocks in variable case + # All lower-case and strip spaces out string = string.lower().strip() - # other retards put the port + # No port number string = re.sub("\:\d+$", "", string) - # bigger retards put the schema in their blocklist, sometimes even without slashes + # No protocol, sometimes with the slashes string = re.sub("^https?\:(\/*)", "", string) - # and trailing slash + # No trailing slash string = re.sub("\/$", "", string) - # and the @ + # No @ sign string = re.sub("^\@", "", string) - # the biggest retards of them all try to block individual users + # No individual users in block lists string = re.sub("(.+)\@", "", string) + # DEBUG: print(f"DEBUG: string='{string}' - EXIT!") return string -- 2.39.5