##### Cache #####
def key_exists(key: str) -> bool:
- return key in _cache
+ logger.debug("key='%s' - CALLED!", key)
+ exists = key in _cache
+
+ logger.debug("exists='%s' - EXIT!", exists)
+ return exists
def set_all(key: str, rows: list, value: any):
logger.debug("key='%s',rows()=%d,value[]='%s' - CALLED!", key, len(rows), type(value))
logger.debug("Cache for key='%s' not initialized.", key)
_cache[key] = dict()
+ logger.debug("Setting %d row(s) for key='%s',value[%s]='%s' ...", len(rows), key, type(value), value)
for sub in rows:
logger.debug("Setting key='%s',sub[%s]='%s'", key, type(sub), sub)
if isinstance(sub, sqlite3.Row):
elif not key_exists(key):
raise Exception(f"Cache for key='{key}' is not initialized, but function invoked")
- logger.debug("Setting key='%s',sub='%s',value[]='%s' ...", key, sub, type(value))
+ logger.debug("Setting key='%s',sub='%s',value[%s]='%s' ...", key, sub, type(value), value)
_cache[key][sub] = value
logger.debug("EXIT!")
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
+# Request paths
+_request_paths = [
+ "/nodeinfo/2.1.json",
+ "/nodeinfo/2.1",
+ "/nodeinfo/2.0.json",
+ "/nodeinfo/2.0",
+ "/nodeinfo/1.0.json",
+ "/nodeinfo/1.0",
+ "/api/v1/instance",
+]
+
+# "rel" identifiers (no real URLs)
+_nodeinfo_identifier = [
+ "https://nodeinfo.diaspora.software/ns/schema/2.1",
+ "http://nodeinfo.diaspora.software/ns/schema/2.1",
+ "https://nodeinfo.diaspora.software/ns/schema/2.0",
+ "http://nodeinfo.diaspora.software/ns/schema/2.0",
+ "https://nodeinfo.diaspora.software/ns/schema/1.1",
+ "http://nodeinfo.diaspora.software/ns/schema/1.1",
+ "https://nodeinfo.diaspora.software/ns/schema/1.0",
+ "http://nodeinfo.diaspora.software/ns/schema/1.0",
+]
+
def fetch(domain: str, path: str = None, update_mode: bool = True) -> dict:
logger.debug("domain='%s',path='%s',update_mode='%s' - CALLED!", domain, path, update_mode)
domain_helper.raise_on(domain)
try:
logger.debug("Checking CSRF for domain='%s'", domain)
headers = csrf.determine(domain, dict())
+ logger.debug("headers()=%d", len(headers))
except network.exceptions as exception:
logger.warning("Exception '%s' during checking CSRF (nodeinfo,%s) - EXIT!", type(exception), __name__)
instances.set_last_error(domain, exception)
"exception" : exception,
}
- request_paths = [
- "/nodeinfo/2.1.json",
- "/nodeinfo/2.1",
- "/nodeinfo/2.0.json",
- "/nodeinfo/2.0",
- "/nodeinfo/1.0.json",
- "/nodeinfo/1.0",
- "/api/v1/instance",
- ]
-
- for request in request_paths:
+ logger.debug("Checking %d request paths ...", len(_request_paths))
+ for request in _request_paths:
logger.debug("request='%s'", request)
http_url = f"http://{domain}{str(path) if path is not None else '/'}"
https_url = f"https://{domain}{str(path) if path is not None else '/'}"
logger.debug("domain='%s',request='%s'", domain, request)
instances.set_nodeinfo_url(domain, "https://{domain}{request}")
+
+ logger.debug("BREAK!")
break
logger.warning("Failed fetching nodeinfo from domain='%s',status_code='%s',error_message='%s'", domain, data['status_code'], data['error_message'])
logger.debug("domain='%s' - CALLED!", domain)
domain_helper.raise_on(domain)
- # "rel" identifiers (no real URLs)
- nodeinfo_identifier = [
- "https://nodeinfo.diaspora.software/ns/schema/2.1",
- "http://nodeinfo.diaspora.software/ns/schema/2.1",
- "https://nodeinfo.diaspora.software/ns/schema/2.0",
- "http://nodeinfo.diaspora.software/ns/schema/2.0",
- "https://nodeinfo.diaspora.software/ns/schema/1.1",
- "http://nodeinfo.diaspora.software/ns/schema/1.1",
- "https://nodeinfo.diaspora.software/ns/schema/1.0",
- "http://nodeinfo.diaspora.software/ns/schema/1.0",
- ]
-
# No CSRF by default, you don't have to add network.api_headers by yourself here
headers = tuple()
logger.debug("data[]='%s'", type(data))
if "error_message" not in data and "json" in data and len(data["json"]) > 0:
- logger.debug("path='%s' returned valid json()=%d", path, len(data["json"]))
+ logger.debug("path='%s' returned valid json()=%d - BREAK!", path, len(data["json"]))
break
logger.debug("data[]='%s'", type(data))
if "exception" in data:
- logger.warning("domain='%s' returned exception '%s'", domain, str(data["exception"]))
+ logger.warning("domain='%s' returned exception '%s' - RAISE!", domain, str(data["exception"]))
raise data["exception"]
elif "error_message" in data:
- logger.warning("domain='%s' returned error message: '%s'", domain, data["error_message"])
+ logger.warning("domain='%s' returned error message: '%s' - EXIT!", domain, data["error_message"])
return data
elif "json" not in data:
- logger.warning("domain='%s' returned no 'json' key", domain)
+ logger.warning("domain='%s' returned no 'json' key - EXIT!", domain)
return dict()
infos = data["json"]
- logger.debug("infos()=%d has been returned", len(infos))
+ logger.debug("infos(%d)[]='%s' has been returned", len(infos), type(infos))
if "links" in infos:
logger.debug("Marking domain='%s' as successfully handled ...", domain)
instances.set_success(domain)
logger.debug("Found infos[links]()=%d record(s),", len(infos["links"]))
- for niid in nodeinfo_identifier:
+ for niid in _nodeinfo_identifier:
data = dict()
logger.debug("Checking niid='%s' ...", niid)
instances.set_detection_mode(domain, "AUTO_DISCOVERY")
instances.set_nodeinfo_url(domain, link["href"])
- logger.debug("Marking domain='%s' as successfully handled ...", domain)
+ logger.debug("Marking domain='%s' as successfully handled - BREAK!", domain)
instances.set_success(domain)
break
else:
logger.debug("data()=%d", len(data))
if "error_message" not in data and "json" in data:
- logger.debug("Auto-discovery successful: domain='%s'", domain)
+ logger.debug("Auto-discovery successful: domain='%s' - BREAK!", domain)
break
elif "server" in infos:
logger.debug("Found infos[server][software]='%s'", infos["server"]["software"])