From 5206099ea449fe000e4d45efb5af4323257d924a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 20 Nov 2023 00:28:01 +0100 Subject: [PATCH] Continued: - named parameters - skip None type --- fba/commands.py | 10 ++++++++-- fba/helpers/processing.py | 3 ++- fba/http/federation.py | 12 ++++++------ fba/utils.py | 14 ++++++++++++-- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/fba/commands.py b/fba/commands.py index b000e3d..04a959d 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -148,6 +148,9 @@ def fetch_pixelfed_api(args: argparse.Namespace) -> int: if "domain" not in row: logger.warning("row='%s' does not contain element 'domain' - SKIPPED!", row) continue + elif row["domain"] is None: + logger.debug("row[domain] is None - SKIPPED!") + continue elif row["domain"] == "": logger.debug("row[domain] is empty - SKIPPED!") continue @@ -1639,8 +1642,8 @@ def fetch_relaylist(args: argparse.Namespace) -> int: for row in fetched["json"]: logger.debug("row[]='%s'", type(row)) domain = urlparse(row["url"]).netloc.lower().split(":")[0] - logger.debug("domain='%s' - AFTER!", domain) + if domain is None and domain == "": logger.debug("domain='%s' is empty after tidyup.domain() - SKIPPED!", domain) continue @@ -1776,6 +1779,7 @@ def fetch_relays(args: argparse.Namespace) -> int: logger.debug("Appending domain='%s' to peers list for relay='%s' ...", domain, row["domain"]) peers.append(domain) + logger.debug("domains()=%d,domain='%s'", len(domains), domain) if dict_helper.has_key(domains, "domain", domain): logger.debug("domain='%s' already added", domain) continue @@ -1817,6 +1821,7 @@ def fetch_relays(args: argparse.Namespace) -> int: logger.debug("Appending domain='%s' to peers list for relay='%s' ...", domain, row["domain"]) peers.append(domain) + logger.debug("domains()=%d,domain='%s'", len(domains), domain) if dict_helper.has_key(domains, "domain", domain): logger.debug("domain='%s' already added", domain) continue @@ -1840,11 +1845,12 @@ def fetch_relays(args: argparse.Namespace) -> int: logger.debug("Appending domain='%s' to peers list for relay='%s' ...", domain, row["domain"]) peers.append(domain) + logger.debug("domains()=%d,domain='%s'", len(domains), domain) if dict_helper.has_key(domains, "domain", domain): logger.debug("domain='%s' already added", domain) continue - logger.debug("Appending domain='%s',origin='%s',software='%s'", domain, row["domain"], row["software"]) + logger.debug("Appending domain='%s',origin='%s',software='%s' ...", domain, row["domain"], row["software"]) domains.append({ "domain": domain, "origin": row["domain"], diff --git a/fba/helpers/processing.py b/fba/helpers/processing.py index d702807..c79815c 100644 --- a/fba/helpers/processing.py +++ b/fba/helpers/processing.py @@ -48,8 +48,8 @@ def instance(blocked: str, blocker: str, command: str) -> bool: logger.debug("blocked='%s' - BEFORE!", blocked) blocked = utils.deobfuscate(blocked, blocker) + logger.debug("blocked='%s' - AFTER!", blocked) - logger.debug("blocked='%s' - DEOBFUSCATED!", blocked) if instances.has_pending(blocker): logger.debug("Flushing updates for blocker='%s' ...", blocker) instances.update(blocker) @@ -226,6 +226,7 @@ def csv_block(blocker: str, url: str, command: str): "reason" : reason, }) + logger.debug("reject_media='%s',reject_reports='%s'", reject_media, reject_reports) if reject_media: block(blocker, domain, None, "reject_media") if reject_reports: diff --git a/fba/http/federation.py b/fba/http/federation.py index 6f7f033..27fcad3 100644 --- a/fba/http/federation.py +++ b/fba/http/federation.py @@ -227,8 +227,8 @@ def fetch_peers(domain: str, software: str, origin: str) -> list: data = network.get_json_api( domain, path, - headers, - (config.get("connection_timeout"), config.get("read_timeout")) + headers=headers, + timeout=(config.get("connection_timeout"), config.get("read_timeout")) ) logger.debug("data[]='%s'", type(data)) @@ -268,8 +268,8 @@ def fetch_generator_from_path(domain: str, path: str = "/") -> str: response = network.fetch_response( domain, path, - network.web_headers, - (config.get("connection_timeout"), config.get("read_timeout")), + headers=network.web_headers, + timeout=(config.get("connection_timeout"), config.get("read_timeout")), allow_redirects=True ) @@ -568,8 +568,8 @@ def fetch_blocks(domain: str) -> list: data = network.get_json_api( domain, "/api/v1/instance/domain_blocks", - headers, - (config.get("connection_timeout"), config.get("read_timeout")) + headers=headers, + timeout=(config.get("connection_timeout"), config.get("read_timeout")) ) rows = list() diff --git a/fba/utils.py b/fba/utils.py index 6652c19..8244a78 100644 --- a/fba/utils.py +++ b/fba/utils.py @@ -62,9 +62,19 @@ def fetch_url(url: str, headers: dict, timeout: tuple) -> requests.models.Respon # Invoke other function, avoid trailing ? logger.debug("components[%s]='%s'", type(components), components) if components.query != "": - response = network.fetch_response(components.netloc.split(":")[0], f"{components.path}?{components.query}", headers, timeout) + response = network.fetch_response( + components.netloc.split(":")[0], + f"{components.path}?{components.query}", + headers, + timeout + ) else: - response = network.fetch_response(components.netloc.split(":")[0], components.path if isinstance(components.path, str) and components.path != '' else '/', headers, timeout) + response = network.fetch_response( + components.netloc.split(":")[0], + components.path if isinstance(components.path, str) and components.path != '' else '/', + headers, + timeout + ) logger.debug("response[]='%s' - EXIT!", type(response)) return response -- 2.39.5