def check_instance(args: argparse.Namespace) -> int:
logger.debug("args.domain='%s' - CALLED!", args.domain)
+
status = 0
if not validators.domain(args.domain):
logger.warning("args.domain='%s' is not valid", args.domain)
def set_all(key: str, rows: list, value: any):
logger.debug("key='%s',rows()=%d,value[]='%s' - CALLED!", key, len(rows), type(value))
+
if not isinstance(key, str):
raise ValueError(f"Parameter key[]='{type(key)}' is not of type 'str'")
elif not key_exists(key):
def set_sub_key(key: str, sub: str, value: any):
logger.debug("key='%s',sub='%s',value[]='%s' - CALLED!", key, sub, type(value))
+
if not isinstance(key, str):
raise ValueError(f"Parameter key[]='{type(key)}' is not of type 'str'")
elif not isinstance(sub, str):
def sub_key_exists(key: str, sub: str) -> bool:
logger.debug("key='%s',sub='%s' - CALLED!", key, sub)
+
if not isinstance(key, str):
raise ValueError(f"Parameter key[]='{type(key)}' is not of type 'str'")
elif not isinstance(sub, str):
def get(key: str) -> any:
logger.debug("key[%s]='%s' - CALLED!", type(key), key)
+
if not isinstance(key, str):
raise ValueError(f"Parameter key[]='{type(key)}' is not of type 'str'")
elif key == "":
def has_key(lists: list, key: str, value: any) -> bool:
logger.debug("lists()=%d,key='%s',value[]='%s' - CALLED!", len(lists), key, type(value))
+
if not isinstance(lists, list):
raise ValueError(f"Parameter lists[]='{type(lists)}' is not of type 'list'")
elif not isinstance(key, str):
def raise_on(domain: str):
logger.debug("domain='%s' - CALLED!", domain)
+
if not isinstance(domain, str):
raise ValueError(f"Parameter domain[]='{type(domain)}' is not of type 'str'")
elif domain == "":
def is_wanted(domain: str) -> bool:
logger.debug("domain='%s' - CALLED!", domain)
+
if not isinstance(domain, str):
raise ValueError(f"Parameter domain[]='{type(domain)}' is not of type 'str'")
elif domain == "":
def from_response(response: requests.models.Response) -> any:
logger.debug("response[]='%s' - CALLED!", type(response))
+
if not isinstance(response, requests.models.Response):
raise ValueError(f"Parameter response[]='{type(response)}' is not type of 'Response'")
elif not response.ok or response.status_code > 200:
def alias(software: str) -> str:
logger.debug("software='%s'- CALLED!", software)
+
if not isinstance(software, str) and software is not None:
raise ValueError(f"software[]='{type(software)}' is not type 'str'")
def strip_hosted_on(software: str) -> str:
logger.debug("software='%s' - CALLED!", software)
+
if not isinstance(software, str):
raise ValueError(f"Parameter software[]='{type(software)}' is not of type 'str'")
elif software == "":
def strip_until(software: str, until: str) -> str:
logger.debug("software='%s',until='%s' - CALLED!", software, until)
+
if not isinstance(software, str):
raise ValueError(f"Parameter software[]='{type(software)}' is not of type 'str'")
elif software == "":
def reason(string: str) -> str:
logger.debug("string='%s' - CALLED!", string)
+
if not isinstance(string, str):
raise ValueError(f"Parameter string[]='{type(string)}' is not of type 'str'")
def domain(string: str) -> str:
logger.debug("string='%s' - CALLED!", string)
+
if not isinstance(string, str):
raise ValueError(f"Parameter string[]='{type(string)}' is not of type 'str'")
def remove(software: str) -> str:
logger.debug("software='%s' - CALLED!", software)
+
if "." not in software and " " not in software:
logger.warning("software='%s' does not contain a version number.", software)
return software
logger.debug("domain='%s' - CALLED!", domain)
domain_helper.raise_on(domain)
+ if not instances.is_registered(domain):
+ raise Exception(f"domain='{domain}' is not registered but function is invoked.")
+
# Init block list
blocklist = list()
def fetch_api_url(url: str, timeout: tuple) -> dict:
logger.debug("url='%s',timeout()=%d - CALLED!", url, len(timeout))
+
if not isinstance(url, str):
raise ValueError(f"Parameter url[]='{type(url)}' is not of type 'str'")
elif url == "":
def update_reason(reason: str, blocker: str, blocked: str, block_level: str):
logger.debug("reason='%s',blocker='%s',blocked='%s',block_level='%s' - CALLED!", reason, blocker, blocked, block_level)
+ domain_helper.raise_on(blocker)
+ domain_helper.raise_on(blocked)
+
if not isinstance(reason, str) and reason is not None:
raise ValueError(f"Parameter reason[]='{type(reason)}' is not of type 'str'")
- elif not isinstance(blocker, str):
- raise ValueError(f"Parameter blocker[]='{type(blocker)}' is not of type 'str'")
- elif blocker == "":
- raise ValueError("Parameter 'blocker' is empty")
- elif blocker.lower() != blocker:
- raise ValueError(f"Parameter blocker='{blocker}' must be all lower-case")
- elif not isinstance(blocked, str):
- raise ValueError(f"Parameter blocked[]='{type(blocked)}' is not of type 'str'")
- elif blocked == "":
- raise ValueError("Parameter 'blocked' is empty")
- elif blocked.lower() != blocked:
- raise ValueError(f"Parameter blocked='{blocked}' must be all lower-case")
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 block_level in ["accept", "suspend", "silence", "nsfw", "quarantined_instances"]:
raise ValueError(f"block_level='{block_level}' is not wanted.")
+ elif not is_instance_blocked(blocker, blocked, block_level):
+ raise Exception(f"blocker='{blocker}',blocked='{blocked}',block_level='{block_level}' is not registered but function is invoked")
logger.debug("Updating block reason='%s',blocker='%s',blocked='%s',block_level='%s'", reason, blocker, blocked, block_level)
database.cursor.execute(
def update_last_seen(blocker: str, blocked: str, block_level: str):
logger.debug("blocker='%s',blocked='%s',block_level='%s' - CALLED!", blocker, blocked, block_level)
- if not isinstance(blocker, str):
- raise ValueError(f"Parameter blocker[]='{type(blocker)}' is not of type 'str'")
- elif blocker == "":
- raise ValueError("Parameter 'blocker' is empty")
- elif blocker.lower() != blocker:
- raise ValueError(f"Parameter blocker='{blocker}' must be all lower-case")
- elif not isinstance(blocked, str):
- raise ValueError(f"Parameter blocked[]='{type(blocked)}' is not of type 'str'")
- elif blocked == "":
- raise ValueError("Parameter 'blocked' is empty")
- elif blocked.lower() != blocked:
- raise ValueError(f"Parameter blocked='{blocked}' must be all lower-case")
- elif not isinstance(block_level, str):
+ domain_helper.raise_on(blocker)
+ domain_helper.raise_on(blocked)
+
+ if 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 block_level in ["accept", "suspend", "silence", "nsfw", "quarantined_instances"]:
raise ValueError(f"blocked='{blocked}' has unwanted block_level='{block_level}'")
+ elif blacklist.is_blacklisted(blocker):
+ raise Exception(f"blocker='{blocker}' is blacklisted but function invoked")
+ elif blacklist.is_blacklisted(blocked):
+ raise Exception(f"blocked='{blocked}' is blacklisted but function invoked")
+ elif not is_instance_blocked(blocker, blocked, block_level):
+ raise Exception(f"blocker='{blocker}',blocked='{blocked}',block_level='{block_level}' is not registered but function is invoked")
database.cursor.execute(
"UPDATE blocks SET last_seen = ? WHERE blocker = ? AND blocked = ? AND block_level = ? LIMIT 1",
def is_instance_blocked(blocker: str, blocked: str, block_level: str = None) -> bool:
logger.debug("blocker='%s',blocked='%s',block_level='%s' - CALLED!", blocker, blocked, block_level)
- if not isinstance(blocker, str):
- raise ValueError(f"Parameter blocker[]='{type(blocker)}' is not of type 'str'")
- elif blocker == "":
- raise ValueError("Parameter 'blocker' is empty")
- elif blocker.lower() != blocker:
- raise ValueError(f"Parameter blocker='{blocker}' must be all lower-case")
- elif not isinstance(blocked, str):
- raise ValueError(f"Parameter blocked[]='{type(blocked)}' is not of type 'str'")
- elif blocked == "":
- raise ValueError("Parameter 'blocked' is empty")
- elif blocked.lower() != blocked:
- raise ValueError(f"Parameter blocked='{blocked}' must be all lower-case")
- elif not isinstance(block_level, str) and block_level is not None:
+ domain_helper.raise_on(blocker)
+ domain_helper.raise_on(blocked)
+
+ if not isinstance(block_level, str) and block_level is not None:
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 block_level in ["accept", "suspend", "silence", "nsfw", "quarantined_instances"]:
raise ValueError(f"blocked='{blocked}' has unwanted block_level='{block_level}'")
+ elif blacklist.is_blacklisted(blocker):
+ raise Exception(f"blocker='{blocker}' is blacklisted but function invoked")
+ elif blacklist.is_blacklisted(blocked):
+ raise Exception(f"blocked='{blocked}' is blacklisted but function invoked")
if block_level is None:
database.cursor.execute(
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 block_level in ["accept", "suspend", "silence", "nsfw", "quarantined_instances"]:
+ raise ValueError(f"blocked='{blocked}' has unwanted block_level='{block_level}'")
elif blacklist.is_blacklisted(blocker):
raise Exception(f"blocker='{blocker}' is blacklisted but function invoked")
elif blacklist.is_blacklisted(blocked):
raise Exception(f"blocked='{blocked}' is blacklisted but function invoked")
- elif block_level in ["accept", "suspend", "silence", "nsfw", "quarantined_instances"]:
- raise ValueError(f"blocked='{blocked}' has unwanted block_level='{block_level}'")
if reason is not None:
# Maybe needs cleaning
def valid(value: str, column: str) -> bool:
logger.debug("value='%s' - CALLED!", value)
+
if not isinstance(value, str):
raise ValueError(f"Parameter value[]='{type(value)}' is not of type 'str'")
elif value == "":
def translate_idnas(rows: list, column: str):
logger.debug("rows[]='%s' - CALLED!", type(rows))
+
if not isinstance(rows, list):
raise ValueError(f"rows[]='{type(rows)}' is not of type 'list'")
elif len(rows) == 0:
def alias_block_level(block_level: str) -> str:
logger.debug("block_level='%s' - CALLED!", block_level)
+
if not isinstance(block_level, str):
raise ValueError(f"Parameter block_level[]='{type(block_level)}' is not of type 'str'")
elif block_level == "":
def _set_data(key: str, domain: str, value: any):
logger.debug("key='%s',domain='%s',value[]='%s' - CALLED!", key, domain, type(value))
domain_helper.raise_on(domain)
+
if not isinstance(key, str):
raise ValueError(f"Parameter key[]='{type(key)}' is not of type 'str'")
elif key == "":
def translate_idnas(rows: list, column: str):
logger.debug("rows[]='%s' - CALLED!", type(rows))
+
if not isinstance(rows, list):
raise ValueError("rows[]='{type(rows)}' is not of type 'list'")
elif len(rows) == 0:
logger.debug("domain='%s' - CALLED!", domain)
domain_helper.raise_on(domain)
+ if not instances.is_registered(domain):
+ raise Exception(f"domain='{domain}' is not registered but function is invoked.")
+
blocklist = list()
block_tag = None
logger.debug("domain='%s - CALLED!", domain)
domain_helper.raise_on(domain)
+ if not instances.is_registered(domain):
+ raise Exception(f"domain='{domain}' is not registered but function is invoked.")
+
translations = [
"Blocked Instances".lower(),
"Instàncies bloquejades".lower(),
def parse_script(doc: bs4.BeautifulSoup, only: str = None) -> list:
logger.debug("doc[]='%s',only='%s' - CALLED!")
+
if not isinstance(doc, bs4.BeautifulSoup):
raise ValueError(f"Parameter doc[]='{type(only)}' is not of type 'bs4.BeautifulSoup'")
elif not isinstance(only, str) and only is not None:
logger.debug("domain='%s' - CALLED!", domain)
domain_helper.raise_on(domain)
+ if not instances.is_registered(domain):
+ raise Exception(f"domain='{domain}' is not registered but function is invoked.")
+
logger.debug("Fetching mastodon blocks from domain='%s'", domain)
doc = None
for path in ["/about/more", "/about"]:
logger.debug("domain='%s' - CALLED!", domain)
domain_helper.raise_on(domain)
+ if not instances.is_registered(domain):
+ raise Exception(f"domain='{domain}' is not registered but function is invoked.")
+
blocklist = list()
logger.debug("Invoking federation.fetch_blocks(%s) ...", domain)
logger.debug("domain='%s' - CALLED!", domain)
domain_helper.raise_on(domain)
+ if not instances.is_registered(domain):
+ raise Exception(f"domain='{domain}' is not registered but function is invoked.")
+
# No CSRF by default, you don't have to add network.api_headers by yourself here
headers = tuple()
logger.debug("domain='%s' - CALLED!", domain)
domain_helper.raise_on(domain)
+ if not instances.is_registered(domain):
+ raise Exception(f"domain='{domain}' is not registered but function is invoked.")
+
blockdict = list()
rows = None
+
try:
logger.debug("Fetching nodeinfo: domain='%s'", domain)
rows = nodeinfo.fetch(domain, update_mode=False)
logger.debug("domain='%s' - CALLED!", domain)
domain_helper.raise_on(domain)
+ if not instances.is_registered(domain):
+ raise Exception(f"domain='{domain}' is not registered but function is invoked.")
+
logger.debug("Fetching mastodon blocks from domain='%s'", domain)
doc = None
for path in ["/instance/about/index.html"]:
def fetch_url(url: str, headers: dict, timeout: tuple) -> requests.models.Response:
logger.debug("url='%s',headers()=%d,timeout(%d)='%s' - CALLED!", url, len(headers), len(timeout), timeout)
+
if not isinstance(url, str):
raise ValueError(f"Parameter url[]='{type(url)}' is not of type 'str'")
elif url == "":
def find_domains(tags: bs4.element.ResultSet, search: str) -> list:
logger.debug("tags[%s]()=%d,search='%s' - CALLED!", type(tags), len(tags), search)
+
if not isinstance(tags, bs4.element.ResultSet):
raise ValueError(f"Parameter tags[]='{type(tags)}' is not of type 'ResultSet'")
elif not isinstance(search, str):