def fetch_blocks_from_about(domain: str) -> dict:
# DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
- if type(domain) != str:
+ if not isinstance(domain, str):
raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
elif domain == "":
- raise ValueError(f"Parameter 'domain' is empty")
+ raise ValueError("Parameter 'domain' is empty")
# DEBUG: print("DEBUG: Fetching mastodon blocks from domain:", domain)
blocklist = {
network.fetch_response(domain, "/about/more", fba.headers, (config.get("connection_timeout"), config.get("read_timeout"))).text,
"html.parser",
)
- except BaseException as e:
- print("ERROR: Cannot fetch from domain:", domain, e)
- instances.update_last_error(domain, e)
+ 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"):
def fetch_blocks(domain: str, origin: str, nodeinfo_url: str):
# DEBUG: print(f"DEBUG: domain='{domain}',origin='{origin}',nodeinfo_url='{nodeinfo_url}' - CALLED!")
- if type(domain) != str:
+ if not isinstance(domain, str):
raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
elif domain == "":
- raise ValueError(f"Parameter 'domain' is empty")
- elif type(origin) != str and origin != None:
+ raise ValueError("Parameter 'domain' is empty")
+ elif not isinstance(origin, str) and origin is not None:
raise ValueError(f"Parameter origin[]={type(origin)} is not 'str'")
elif origin == "":
- raise ValueError(f"Parameter 'origin' is empty")
- elif type(nodeinfo_url) != str:
+ raise ValueError("Parameter 'origin' is empty")
+ elif not isinstance(nodeinfo_url, str):
raise ValueError(f"Parameter nodeinfo_url[]={type(nodeinfo_url)} is not 'str'")
elif nodeinfo_url == "":
- raise ValueError(f"Parameter 'nodeinfo_url' is empty")
+ raise ValueError("Parameter 'nodeinfo_url' is empty")
try:
# json endpoint for newer mastodongs
csrf = meta.find("meta", attrs={"name": "csrf-token"})["content"]
# DEBUG: print("DEBUG: Adding CSRF token:", domain, csrf)
reqheaders = {**fba.api_headers, **{"X-CSRF-Token": csrf}}
- except BaseException as e:
- # DEBUG: print("DEBUG: No CSRF token found, using normal headers:", domain, e)
+ except BaseException as exception:
+ # DEBUG: print("DEBUG: No CSRF token found, using normal headers:", domain, exception)
reqheaders = fba.api_headers
# DEBUG: print("DEBUG: Querying API domain_blocks:", domain)
else:
print("WARNING: Unknown severity:", block['severity'], block['domain'])
- except BaseException as e:
- # DEBUG: print(f"DEBUG: Failed, trying mastodon-specific fetches: domain='{domain}',exception[{type(e)}]={str(e)}")
+ except BaseException as exception:
+ # DEBUG: print(f"DEBUG: Failed, trying mastodon-specific fetches: domain='{domain}',exception[{type(exception)}]={str(exception)}")
json = fetch_blocks_from_about(domain)
print(f"INFO: Checking {len(json.items())} entries from domain='{domain}',software='mastodon' ...")
blocked, blocked_hash, reason = block.values()
# DEBUG: print(f"DEBUG: blocked='{blocked}',blocked_hash='{blocked_hash}',reason='{reason}':")
blocked = fba.tidyup_domain(blocked)
- reason = fba.tidyup_reason(reason) if reason != None and reason != "" else None
+ reason = fba.tidyup_reason(reason) if reason is not None and reason != "" else None
# DEBUG: print(f"DEBUG: blocked='{blocked}',reason='{reason}' - AFTER!")
if blocked == "":
)
searchres = fba.cursor.fetchone()
- if searchres == None:
+ if searchres is None:
print(f"WARNING: Cannot deobsfucate blocked='{blocked}',blocked_hash='{blocked_hash}' - SKIPPED!")
continue
# DEBUG: print("DEBUG: Committing changes ...")
fba.connection.commit()
- except Exception as e:
- print(f"ERROR: domain='{domain}',software='mastodon',exception[{type(e)}]:'{str(e)}'")
+ except Exception as exception:
+ print(f"ERROR: domain='{domain}',software='mastodon',exception[{type(exception)}]:'{str(exception)}'")
# DEBUG: print("DEBUG: EXIT!")