logger.debug("software='%s' - EXIT!", software)
return software
-def determine_software(domain: str, path: str = None) -> str:
- logger.debug("domain='%s',path='%s' - CALLED!", domain, path)
+def determine_software(domain: str, path: str = None, nodeinfo_url: str = None) -> str:
+ logger.debug("domain='%s',path='%s',nodeinfo_url='%s' - CALLED!", domain, path, nodeinfo_url)
domain_helper.raise_on(domain)
if not isinstance(path, str) and path is not None:
raise ValueError(f"Parameter path[]='{type(path)}' is not of type 'str'")
+ elif not isinstance(nodeinfo_url, str) and nodeinfo_url is not None:
+ raise ValueError(f"Parameter nodeinfo_url[]='{type(nodeinfo_url)}' is not of type 'str'")
- logger.debug("Determining software for domain='%s',path='%s'", domain, path)
+ logger.debug("Fetching nodeinfo from domain='%s',path='%s',nodeinfo_url='%s' ...", domain, path, nodeinfo_url)
+ data = nodeinfo.fetch(domain, path, nodeinfo_url)
software = None
- logger.debug("Fetching nodeinfo from domain='%s' ...", domain)
- data = nodeinfo.fetch_nodeinfo(domain, path)
-
logger.debug("data[%s]='%s'", type(data), data)
if "exception" in data:
# Continue raising it
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import logging
+import validators
from urllib.parse import urlparse
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
-def fetch_nodeinfo(domain: str, path: str = None) -> dict:
- logger.debug("domain='%s',path='%s' - CALLED!", domain, path)
+def fetch(domain: str, path: str = None, nodeinfo_url: str = None) -> dict:
+ logger.debug("domain='%s',path='%s',nodeinfo_url='%s' - CALLED!", domain, path, nodeinfo_url)
domain_helper.raise_on(domain)
if not isinstance(path, str) and path is not None:
raise ValueError(f"Parameter path[]='{type(path)}' is not of type 'str'")
+ elif not isinstance(nodeinfo_url, str) and nodeinfo_url is not None:
+ raise ValueError(f"Parameter nodeinfo_url[]='{type(nodeinfo_url)}' is not of type 'str'")
- logger.debug("Fetching nodeinfo from domain='%s' ...", domain)
- data = fetch_wellknown_nodeinfo(domain)
+ logger.debug("nodeinfo_url='%s'", nodeinfo_url)
+ is_url = nodeinfo_url is not None and validators.url(nodeinfo_url)
- logger.debug("data[%s](%d)='%s'", type(data), len(data), data)
- if "exception" in data:
- logger.warning("Exception returned: '%s', raising again ...", type(data["exception"]))
- raise data["exception"]
- elif "error_message" not in data and "json" in data and len(data["json"]) > 0:
- logger.debug("Invoking instances.set_last_nodeinfo(%s) ...", domain)
- instances.set_last_nodeinfo(domain)
+ logger.debug("is_url='%s'", is_url)
+ if not is_url:
+ logger.debug("Fetching well-known nodeinfo from domain='%s' ...", domain)
+ data = fetch_wellknown_nodeinfo(domain)
- logger.debug("Found data[json]()=%d - EXIT!", len(data['json']))
- return data
+ logger.debug("data[%s](%d)='%s'", type(data), len(data), data)
+ if "exception" in data:
+ logger.warning("Exception returned: '%s', raising again ...", type(data["exception"]))
+ raise data["exception"]
+ elif "error_message" not in data and "json" in data and len(data["json"]) > 0:
+ logger.debug("Invoking instances.set_last_nodeinfo(%s) ...", domain)
+ instances.set_last_nodeinfo(domain)
+
+ logger.debug("Found data[json]()=%d - EXIT!", len(data['json']))
+ return data
# No CSRF by default, you don't have to add network.api_headers by yourself here
headers = tuple()
for request in request_paths:
logger.debug("request='%s'", request)
- http_url = f"http://{domain}{str(path)}"
- https_url = f"https://{domain}{str(path)}"
+ 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("path[%s]='%s',request='%s',http_url='%s',https_url='%s'", type(path), path, request, http_url, https_url)
- if path is None or path in [request, http_url, https_url]:
- logger.debug("path='%s',http_url='%s',https_url='%s'", path, http_url, https_url)
- if path in [http_url, https_url]:
- logger.debug("domain='%s',path='%s' has protocol in path, splitting ...", domain, path)
- components = urlparse(path)
- path = components.path
-
+ if (path is None and nodeinfo_url is None) or path in [request, http_url, https_url] or (is_url and nodeinfo_url.endswith(request)):
logger.debug("Fetching request='%s' from domain='%s' ...", request, domain)
data = network.get_json_api(
domain,