def is_blacklisted(domain: str) -> bool:
# DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
def is_instance_blocked(blocker: str, blocked: str, block_level: str) -> bool:
# DEBUG: print(f"DEBUG: blocker={blocker},blocked={blocked},block_level={block_level} - CALLED!")
if not isinstance(blocker, str):
- raise ValueError(f"Parameter blocker[]={type(blocker)} is not of type 'str'")
+ raise ValueError(f"Parameter blocker[]='{type(blocker)}' is not of type 'str'")
elif blocker == "":
raise ValueError("Parameter 'blocker' is empty")
elif not isinstance(blocked, str):
- raise ValueError(f"Parameter blocked[]={type(blocked)} is not of type 'str'")
+ raise ValueError(f"Parameter blocked[]='{type(blocked)}' is not of type 'str'")
elif blocked == "":
raise ValueError("Parameter 'blocked' is empty")
elif not isinstance(block_level, str):
- raise ValueError(f"Parameter block_level[]={type(block_level)} is not of type 'str'")
+ raise ValueError(f"Parameter block_level[]='{type(block_level)}' is not of type 'str'")
elif block_level == "":
raise ValueError("Parameter 'block_level' is empty")
def add_instance(blocker: str, blocked: str, reason: str, block_level: str):
# DEBUG: print("DEBUG: blocker,blocked,reason,block_level:", blocker, blocked, reason, block_level)
if not isinstance(blocker, str):
- raise ValueError(f"Parameter blocker[]={type(blocker)} is not 'str'")
+ raise ValueError(f"Parameter blocker[]='{type(blocker)}' is not 'str'")
elif blocker == "":
raise ValueError("Parameter 'blocker' is empty")
elif not validators.domain(blocker.split("/")[0]):
raise ValueError(f"Bad blocker='{blocker}'")
elif not isinstance(blocked, str):
- raise ValueError(f"Parameter blocked[]={type(blocked)} is not 'str'")
+ raise ValueError(f"Parameter blocked[]='{type(blocked)}' is not 'str'")
elif blocked == "":
raise ValueError("Parameter 'blocked' is empty")
+ elif not isinstance(block_level, str):
+ raise ValueError(f"Parameter block_level[]='{type(block_level)}' is not of type 'str'")
+ elif block_level == "":
+ raise ValueError("Parameter 'block_level' is empty")
elif not validators.domain(blocked.split("/")[0]):
raise ValueError(f"Bad blocked='{blocked}'")
elif blacklist.is_blacklisted(blocker):
return key in _cache
def set_all(key: str, rows: list, value: any):
- # DEBUG: print(f"DEBUG: key='{key}',rows()={len(rows)},value[]={type(value)} - CALLED!")
+ # DEBUG: print(f"DEBUG: key='{key}',rows()={len(rows)},value[]='{type(value)}' - CALLED!")
if not isinstance(key, str):
raise ValueError("Parameter key[]='{type(key)}' is not 'str'")
elif not key_exists(key):
return status
def fetch_bkali(args: argparse.Namespace):
- # DEBUG: print(f"DEBUG: args[]={type(args)} - CALLED!")
+ # DEBUG: print(f"DEBUG: args[]='{type(args)}' - CALLED!")
domains = list()
try:
fetched = network.post_json_api("gql.api.bka.li", "/v1/graphql", json.dumps({
# DEBUG: print("DEBUG: EXIT!")
def fetch_blocks(args: argparse.Namespace):
- # DEBUG: print(f"DEBUG: args[]={type(args)} - CALLED!")
+ # DEBUG: print(f"DEBUG: args[]='{type(args)}' - CALLED!")
if args.domain is not None and args.domain != "":
# DEBUG: print(f"DEBUG: args.domain='{args.domain}' - checking ...")
if not validators.domain(args.domain):
# DEBUG: print("DEBUG: EXIT!")
def fetch_cs(args: argparse.Namespace):
- # DEBUG: print(f"DEBUG: args[]={type(args)} - CALLED!")
+ # DEBUG: print(f"DEBUG: args[]='{type(args)}' - CALLED!")
extensions = [
'extra',
'abbr',
}
raw = fba.fetch_url("https://raw.githubusercontent.com/chaossocial/meta/master/federation.md", network.web_headers, (config.get("connection_timeout"), config.get("read_timeout"))).text
- # DEBUG: print(f"DEBUG: raw()={len(raw)}[]={type(raw)}")
+ # DEBUG: print(f"DEBUG: raw()={len(raw)}[]='{type(raw)}'")
doc = bs4.BeautifulSoup(markdown.markdown(raw, extensions=extensions), features='html.parser')
- # DEBUG: print(f"DEBUG: doc()={len(doc)}[]={type(doc)}")
+ # DEBUG: print(f"DEBUG: doc()={len(doc)}[]='{type(doc)}'")
silenced = doc.find("h2", {"id": "silenced-instances"}).findNext("table").find("tbody")
- # DEBUG: print(f"DEBUG: silenced[]={type(silenced)}")
+ # DEBUG: print(f"DEBUG: silenced[]='{type(silenced)}'")
domains["silenced"] = domains["silenced"] + federation.find_domains(silenced)
blocked = doc.find("h2", {"id": "blocked-instances"}).findNext("table").find("tbody")
- # DEBUG: print(f"DEBUG: blocked[]={type(blocked)}")
+ # DEBUG: print(f"DEBUG: blocked[]='{type(blocked)}'")
domains["reject"] = domains["reject"] + federation.find_domains(blocked)
# DEBUG: print(f"DEBUG: domains()={len(domains)}")
# DEBUG: print("DEBUG: EXIT!")
def fetch_fba_rss(args: argparse.Namespace):
- # DEBUG: print(f"DEBUG: args[]={type(args)} - CALLED!")
+ # DEBUG: print(f"DEBUG: args[]='{type(args)}' - CALLED!")
domains = list()
print(f"INFO: Fetch FBA-specific RSS args.feed='{args.feed}' ...")
# DEBUG: print(f"DEBUG: Parsing RSS feed ({len(response.text)} Bytes) ...")
rss = atoma.parse_rss_bytes(response.content)
- # DEBUG: print(f"DEBUG: rss[]={type(rss)}")
+ # DEBUG: print(f"DEBUG: rss[]='{type(rss)}'")
for item in rss.items:
# DEBUG: print(f"DEBUG: item={item}")
domain = item.link.split("=")[1]
# DEBUG: print("DEBUG: EXIT!")
def fetch_fbabot_atom(args: argparse.Namespace):
- # DEBUG: print(f"DEBUG: args[]={type(args)} - CALLED!")
+ # DEBUG: print(f"DEBUG: args[]='{type(args)}' - CALLED!")
feed = "https://ryona.agency/users/fba/feed.atom"
domains = list()
# DEBUG: print(f"DEBUG: Parsing ATOM feed ({len(response.text)} Bytes) ...")
atom = atoma.parse_atom_bytes(response.content)
- # DEBUG: print(f"DEBUG: atom[]={type(atom)}")
+ # DEBUG: print(f"DEBUG: atom[]='{type(atom)}'")
for entry in atom.entries:
- # DEBUG: print(f"DEBUG: entry[]={type(entry)}")
+ # DEBUG: print(f"DEBUG: entry[]='{type(entry)}'")
doc = bs4.BeautifulSoup(entry.content.value, "html.parser")
- # DEBUG: print(f"DEBUG: doc[]={type(doc)}")
+ # DEBUG: print(f"DEBUG: doc[]='{type(doc)}'")
for element in doc.findAll("a"):
for href in element["href"].split(","):
# DEBUG: print(f"DEBUG: href[{type(href)}]={href}")
# DEBUG: print("DEBUG: EXIT!")
def fetch_instances(args: argparse.Namespace):
- # DEBUG: print(f"DEBUG: args[]={type(args)} - CALLED!")
+ # DEBUG: print(f"DEBUG: args[]='{type(args)}' - CALLED!")
locking.acquire()
# Initial fetch
# DEBUG: print("DEBUG: EXIT!")
def fetch_federater(args: argparse.Namespace):
- # DEBUG: print(f"DEBUG: args[]={type(args)} - CALLED!")
+ # DEBUG: print(f"DEBUG: args[]='{type(args)}' - CALLED!")
locking.acquire()
# Fetch this URL
## DEBUG: print(f"DEBUG: response.content={response.content}")
reader = csv.DictReader(response.content.decode('utf-8').splitlines(), dialect='unix')
#, fieldnames='domain,severity,reject_media,reject_reports,public_comment,obfuscate'
- # DEBUG: print(f"DEBUG: reader[]={type(reader)}")
+ # DEBUG: print(f"DEBUG: reader[]='{type(reader)}'")
for row in reader:
if not validators.domain(row["#domain"]):
print(f"WARNING: domain='{row['#domain']}' is not a valid domain - skipped!")
# Run match()
match = pattern.match(version)
- # DEBUG: print(f"DEBUG: match[]={type(match)}")
+ # DEBUG: print(f"DEBUG: match[]='{type(match)}'")
if isinstance(match, re.Match):
# DEBUG: print(f"DEBUG: version='{version}' is matching pattern='{pattern}'")
break
def get_hash(domain: str) -> str:
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
def log_error(domain: str, error: dict):
# DEBUG: print("DEBUG: domain,error[]:", domain, type(error))
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
elif config.get("write_error_log").lower() != "true":
def fetch_instances(domain: str, origin: str, software: str, script: str, path: str = None):
# DEBUG: print(f"DEBUG: domain='{domain}',origin='{origin}',software='{software}',path='{path}' - CALLED!")
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
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'")
+ raise ValueError(f"Parameter origin[]='{type(origin)}' is not 'str'")
elif software is None:
# DEBUG: print(f"DEBUG: software for domain='{domain}' is not set, determining ...")
software = determine_software(domain, path)
# DEBUG: print(f"DEBUG: Determined software='{software}' for domain='{domain}'")
elif not isinstance(software, str):
- raise ValueError(f"Parameter software[]={type(software)} is not 'str'")
+ raise ValueError(f"Parameter software[]='{type(software)}' is not 'str'")
elif not isinstance(script, str):
- raise ValueError(f"Parameter script[]={type(script)} is not 'str'")
+ raise ValueError(f"Parameter script[]='{type(script)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
def fetch_peers(domain: str, software: str) -> list:
# DEBUG: print(f"DEBUG: domain({len(domain)})={domain},software={software} - CALLED!")
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
elif not isinstance(software, str) and software is not None:
- raise ValueError(f"software[]={type(software)} is not 'str'")
+ raise ValueError(f"software[]='{type(software)}' is not 'str'")
if software == "misskey":
# DEBUG: print(f"DEBUG: Invoking misskey.fetch_peers({domain}) ...")
def fetch_nodeinfo(domain: str, path: str = None) -> list:
# DEBUG: print(f"DEBUG: domain='{domain}',path={path} - CALLED!")
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
elif not isinstance(path, str) and path is not None:
- raise ValueError(f"Parameter path[]={type(path)} is not 'str'")
+ raise ValueError(f"Parameter path[]='{type(path)}' is not 'str'")
# DEBUG: print(f"DEBUG: Fetching nodeinfo from domain='{domain}' ...")
nodeinfo = fetch_wellknown_nodeinfo(domain)
def fetch_wellknown_nodeinfo(domain: str) -> list:
# DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
def fetch_generator_from_path(domain: str, path: str = "/") -> str:
# DEBUG: print(f"DEBUG: domain({len(domain)})={domain},path={path} - CALLED!")
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
elif not isinstance(path, str):
- raise ValueError(f"path[]={type(path)} is not 'str'")
+ raise ValueError(f"path[]='{type(path)}' is not 'str'")
elif path == "":
raise ValueError("Parameter 'path' is empty")
print(f"INFO: domain='{domain}' has og:site_name='{software}'")
instances.set_data("detection_mode", domain, "SITE_NAME")
- # DEBUG: print(f"DEBUG: software[]={type(software)}")
+ # DEBUG: print(f"DEBUG: software[]='{type(software)}'")
if isinstance(software, str) and software == "":
# DEBUG: print(f"DEBUG: Corrected empty string to None for software of domain='{domain}'")
software = None
# DEBUG: print(f"DEBUG: software='{software}' may contain a version number, domain='{domain}', removing it ...")
software = fba.remove_version(software)
- # DEBUG: print(f"DEBUG: software[]={type(software)}")
+ # DEBUG: print(f"DEBUG: software[]='{type(software)}'")
if isinstance(software, str) and " powered by " in software:
# DEBUG: print(f"DEBUG: software='{software}' has 'powered by' in it")
software = fba.remove_version(fba.strip_powered_by(software))
def determine_software(domain: str, path: str = None) -> str:
# DEBUG: print(f"DEBUG: domain({len(domain)})={domain},path={path} - CALLED!")
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
elif not isinstance(path, str) and path is not None:
- raise ValueError(f"Parameter path[]={type(path)} is not 'str'")
+ raise ValueError(f"Parameter path[]='{type(path)}' is not 'str'")
# DEBUG: print("DEBUG: Determining software for domain,path:", domain, path)
software = None
# DEBUG: print(f"DEBUG: software='{software}' has ' see ' in it")
software = fba.strip_until(software, " see ")
- # DEBUG: print(f"DEBUG: software[]={type(software)}")
+ # DEBUG: print(f"DEBUG: software[]='{type(software)}'")
if software == "":
print("WARNING: tidyup.domain() left no software name behind:", domain)
software = None
- # DEBUG: print(f"DEBUG: software[]={type(software)}")
+ # DEBUG: print(f"DEBUG: software[]='{type(software)}'")
if str(software) == "":
# DEBUG: print(f"DEBUG: software for '{domain}' was not detected, trying generator ...")
software = fetch_generator_from_path(domain)
# DEBUG: print(f"DEBUG: software='{software}' may contain a version number, domain='{domain}', removing it ...")
software = fba.remove_version(software)
- # DEBUG: print(f"DEBUG: software[]={type(software)}")
+ # DEBUG: print(f"DEBUG: software[]='{type(software)}'")
if isinstance(software, str) and "powered by" in software:
# DEBUG: print(f"DEBUG: software='{software}' has 'powered by' in it")
software = fba.remove_version(fba.strip_powered_by(software))
return software
def find_domains(tag: bs4.element.Tag) -> list:
- # DEBUG: print(f"DEBUG: tag[]={type(tag)} - CALLED!")
+ # DEBUG: print(f"DEBUG: tag[]='{type(tag)}' - CALLED!")
if not isinstance(tag, bs4.element.Tag):
- raise ValueError(f"Parameter tag[]={type(tag)} is not type of bs4.element.Tag")
+ raise ValueError(f"Parameter tag[]='{type(tag)}' is not type of bs4.element.Tag")
elif len(tag.select("tr")) == 0:
raise KeyError("No table rows found in table!")
domains = list()
for element in tag.select("tr"):
- # DEBUG: print(f"DEBUG: element[]={type(element)}")
+ # DEBUG: print(f"DEBUG: element[]='{type(element)}'")
if not element.find("td"):
# DEBUG: print("DEBUG: Skipping element, no <td> found")
continue
def reason(string: str) -> str:
# DEBUG: print(f"DEBUG: string='{string}' - CALLED!")
if not isinstance(string, str):
- raise ValueError(f"Parameter string[]={type(string)} is not 'str'")
+ raise ValueError(f"Parameter string[]='{type(string)}' is not 'str'")
# Strip string
string = string.strip()
def domain(string: str) -> str:
# DEBUG: print(f"DEBUG: string='{string}' - CALLED!")
if not isinstance(string, str):
- raise ValueError(f"Parameter string[]={type(string)} is not 'str'")
+ raise ValueError(f"Parameter string[]='{type(string)}' is not 'str'")
# All lower-case and strip spaces out + last dot
string = string.lower().strip().rstrip(".")
def has_pending_instance_data(domain: str) -> bool:
# DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
def update_data(domain: str):
# DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
elif not has_pending_instance_data(domain):
def update_last_instance_fetch(domain: str):
# DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
def update_last_blocked(domain: str):
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
def add(domain: str, origin: str, command: str, path: str = None):
# DEBUG: print(f"DEBUG: domain='{domain}',origin='{origin}',command='{command}',path='{path}' - CALLED!")
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
elif not isinstance(origin, str) and origin is not None:
- raise ValueError(f"origin[]={type(origin)} is not 'str'")
+ raise ValueError(f"origin[]='{type(origin)}' is not 'str'")
elif origin == "":
raise ValueError("Parameter 'origin' is empty")
elif not isinstance(command, str):
- raise ValueError(f"command[]={type(command)} is not 'str'")
+ raise ValueError(f"command[]='{type(command)}' is not 'str'")
elif command == "":
raise ValueError("Parameter 'command' is empty")
elif not validators.domain(domain.split("/")[0]):
def update_last_nodeinfo(domain: str):
# DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
def update_last_error(domain: str, error: dict):
# DEBUG: print("DEBUG: domain,error[]:", domain, type(error))
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
# 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)
- else:
+ 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"])
set_data("last_error_details", domain, error["error_message"])
+ 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}) ...")
def is_registered(domain: str) -> bool:
# DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
def post_json_api(domain: str, path: str, data: str, headers: dict = {}) -> dict:
# DEBUG: print(f"DEBUG: domain='{domain}',path='{path}',data='{data}',headers()={len(headers)} - CALLED!")
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
elif not isinstance(path, str):
- raise ValueError(f"path[]={type(path)} is not 'str'")
+ raise ValueError(f"path[]='{type(path)}' is not 'str'")
elif path == "":
raise ValueError("Parameter 'path' cannot be empty")
elif not isinstance(data, str):
- raise ValueError(f"data[]={type(data)} is not 'str'")
+ raise ValueError(f"data[]='{type(data)}' is not 'str'")
elif not isinstance(headers, dict):
- raise ValueError(f"headers[]={type(headers)} is not 'list'")
+ raise ValueError(f"headers[]='{type(headers)}' is not 'list'")
json_reply = {
"status_code": 200,
if not isinstance(url, str):
raise ValueError(f"Parameter url[]='{type(url)}' is not 'str'")
elif not isinstance(timeout, tuple):
- raise ValueError(f"timeout[]={type(timeout)} is not 'tuple'")
+ raise ValueError(f"timeout[]='{type(timeout)}' is not 'tuple'")
json_reply = {
"status_code": 200,
def get_json_api(domain: str, path: str, headers: dict, timeout: tuple) -> dict:
# DEBUG: print(f"DEBUG: domain='{domain}',path='{path}',timeout()={len(timeout)} - CALLED!")
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
elif not isinstance(path, str):
- raise ValueError(f"path[]={type(path)} is not 'str'")
+ raise ValueError(f"path[]='{type(path)}' is not 'str'")
elif path == "":
raise ValueError("Parameter 'path' cannot be empty")
elif not isinstance(headers, dict):
- raise ValueError(f"headers[]={type(headers)} is not 'list'")
+ raise ValueError(f"headers[]='{type(headers)}' is not 'list'")
elif not isinstance(timeout, tuple):
- raise ValueError(f"timeout[]={type(timeout)} is not 'tuple'")
+ raise ValueError(f"timeout[]='{type(timeout)}' is not 'tuple'")
json_reply = {
"status_code": 200,
elif path == "":
raise ValueError("Parameter 'path' is empty")
elif not isinstance(headers, dict):
- raise ValueError(f"headers[]={type(headers)} is not 'dict'")
+ raise ValueError(f"headers[]='{type(headers)}' is not 'dict'")
elif not isinstance(timeout, tuple):
- raise ValueError(f"timeout[]={type(timeout)} is not 'tuple'")
+ raise ValueError(f"timeout[]='{type(timeout)}' is not 'tuple'")
try:
# DEBUG: print(f"DEBUG: Sending GET request to '{domain}{path}' ...")
return response
def json_from_response(response: requests.models.Response) -> list:
- # DEBUG: print(f"DEBUG: response[]={type(response)} - CALLED!")
+ # DEBUG: print(f"DEBUG: response[]='{type(response)}' - CALLED!")
if not isinstance(response, requests.models.Response):
raise ValueError(f"Parameter response[]='{type(response)}' is not type of 'Response'")
except json.decoder.JSONDecodeError:
pass
- # DEBUG: print(f"DEBUG: data[]={type(data)} - EXIT!")
+ # DEBUG: print(f"DEBUG: data[]='{type(data)}' - EXIT!")
return data
def fetch_blocks(domain: str) -> dict:
# DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
def fetch_peers(domain: str) -> list:
# DEBUG: print(f"DEBUG: domain({len(domain)})={domain},software='lemmy' - CALLED!")
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
def fetch_blocks_from_about(domain: str) -> dict:
# DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
def fetch_blocks(domain: str, origin: str, nodeinfo_url: str):
# DEBUG: print(f"DEBUG: domain='{domain}',origin='{origin}',nodeinfo_url='{nodeinfo_url}' - CALLED!")
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
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'")
+ raise ValueError(f"Parameter origin[]='{type(origin)}' is not 'str'")
elif origin == "":
raise ValueError("Parameter 'origin' is empty")
elif not isinstance(nodeinfo_url, str):
- raise ValueError(f"Parameter nodeinfo_url[]={type(nodeinfo_url)} is not 'str'")
+ raise ValueError(f"Parameter nodeinfo_url[]='{type(nodeinfo_url)}' is not 'str'")
elif nodeinfo_url == "":
raise ValueError("Parameter 'nodeinfo_url' is empty")
if "error_message" in data:
print(f"WARNING: Was not able to fetch domain_blocks from domain='{domain}': status_code='{data['status_code']}',error_message='{data['error_message']}'")
instances.update_last_error(domain, data)
+ return
+ elif "json" in data and "error" in data["json"]:
+ print(f"WARNING: JSON API returned error message: '{data['json']['error']}'")
+ instances.update_last_error(domain, data)
+ return
else:
# Getting blocklist
blocklist = data["json"]
print(f"INFO: Checking {len(blocklist)} entries from domain='{domain}',software='mastodon' ...")
for block in blocklist:
# Map block -> entry
+ # DEBUG: print(f"DEBUG: block[{type(block)}]='{block}'")
entry = {
"domain": block["domain"],
"hash" : block["digest"],
def fetch_peers(domain: str) -> list:
# DEBUG: print(f"DEBUG: domain({len(domain)})={domain} - CALLED!")
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
}), headers)
# Check records
- # DEBUG: print(f"DEBUG: fetched[]={type(fetched)}")
+ # DEBUG: print(f"DEBUG: fetched[]='{type(fetched)}'")
if "error_message" in fetched:
print(f"WARNING: post_json_api() for domain='{domain}' returned error message: {fetched['error_message']}")
instances.update_last_error(domain, fetched)
offset = offset + step
already = 0
- # DEBUG: print(f"DEBUG: rows({len(rows)})[]={type(rows)}")
+ # DEBUG: print(f"DEBUG: rows({len(rows)})[]='{type(rows)}'")
for row in rows:
# DEBUG: print(f"DEBUG: row()={len(row)}")
if not "host" in row:
print(f"WARNING: row()={len(row)} does not contain key 'host': {row},domain='{domain}'")
continue
elif not isinstance(row["host"], str):
- print(f"WARNING: row[host][]={type(row['host'])} is not 'str'")
+ print(f"WARNING: row[host][]='{type(row['host'])}' is not 'str'")
continue
elif blacklist.is_blacklisted(row["host"]):
# DEBUG: print(f"DEBUG: row[host]='{row['host']}' is blacklisted. domain='{domain}'")
def fetch_blocks(domain: str) -> dict:
# DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
"offset" : offset - 1
}), headers)
- # DEBUG: print(f"DEBUG: fetched[]={type(fetched)}")
+ # DEBUG: print(f"DEBUG: fetched[]='{type(fetched)}'")
if "error_message" in fetched:
print(f"WARNING: post_json_api() for domain='{domain}' returned error message: {fetched['error_message']}")
instances.update_last_error(domain, fetched)
"offset" : offset - 1
}), headers)
- # DEBUG: print(f"DEBUG: fetched[]={type(fetched)}")
+ # DEBUG: print(f"DEBUG: fetched[]='{type(fetched)}'")
if "error_message" in fetched:
print(f"WARNING: post_json_api() for domain='{domain}' returned error message: {fetched['error_message']}")
instances.update_last_error(domain, fetched)
def fetch_peers(domain: str) -> list:
print(f"DEBUG: domain({len(domain)})={domain},software='peertube' - CALLED!")
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError("Parameter 'domain' is empty")
def fetch_blocks(domain: str, origin: str, nodeinfo_url: str):
# DEBUG: print(f"DEBUG: domain='{domain}',origin='{origin}',nodeinfo_url='{nodeinfo_url}' - CALLED!")
if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
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'")
+ raise ValueError(f"Parameter origin[]='{type(origin)}' is not 'str'")
elif origin == "":
raise ValueError("Parameter 'origin' is empty")
elif not isinstance(nodeinfo_url, str):
- raise ValueError(f"Parameter nodeinfo_url[]={type(nodeinfo_url)} is not 'str'")
+ raise ValueError(f"Parameter nodeinfo_url[]='{type(nodeinfo_url)}' is not 'str'")
elif nodeinfo_url == "":
raise ValueError("Parameter 'nodeinfo_url' is empty")