From: Roland Häder Date: Wed, 21 Jun 2023 02:05:52 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ad9c9f89ed82f8aee59678f941173d61e3f9e665;p=fba.git Continued: - also moved fba.config to package fba.helpers --- diff --git a/api.py b/api.py index eb7a8f8..41580f3 100644 --- a/api.py +++ b/api.py @@ -29,10 +29,10 @@ import uvicorn import requests import validators -from fba import config from fba import fba from fba import network +from fba.helpers import config from fba.helpers import tidyup router = fastapi.FastAPI(docs_url=config.get("base_url") + "/docs", redoc_url=config.get("base_url") + "/redoc") diff --git a/fba/__init__.py b/fba/__init__.py index 8012885..e5e1748 100644 --- a/fba/__init__.py +++ b/fba/__init__.py @@ -17,7 +17,6 @@ __all__ = [ # Main packages: 'boot', 'commands', - 'config', 'csrf', 'federation', 'fba', diff --git a/fba/commands.py b/fba/commands.py index 4dca5fd..24d4840 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -26,12 +26,12 @@ import markdown import reqto import validators -from fba import config from fba import federation from fba import fba from fba import network from fba.helpers import blacklist +from fba.helpers import config from fba.helpers import cookies from fba.helpers import locking from fba.helpers import tidyup diff --git a/fba/config.py b/fba/config.py deleted file mode 100644 index 1ae1a25..0000000 --- a/fba/config.py +++ /dev/null @@ -1,33 +0,0 @@ -# Fedi API Block - An aggregator for fetching blocking data from fediverse nodes -# Copyright (C) 2023 Free Software Foundation -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -import json - -with open("config.json") as f: - # DEBUG: print("DEBUG: Loading configuration file ...") - _config = json.loads(f.read()) - -def get(key: str) -> any: - # DEBUG: print(f"DEBUG: key[{type(key)}]={key} - CALLED!") - if not isinstance(key, str): - raise ValueError(f"Parameter key[]='{type(key)}' is not 'str'") - elif key == "": - raise ValueError("Parameter 'key' is empty") - elif not key in _config: - raise KeyError(f"key='{key}' does not exist in _config array") - - # DEBUG: print(f"DEBUG: _config[{key}]={_config[key]} - EXIT!") - return _config[key] diff --git a/fba/csrf.py b/fba/csrf.py index 859d5cb..8cd8c5e 100644 --- a/fba/csrf.py +++ b/fba/csrf.py @@ -18,9 +18,9 @@ import bs4 import reqto import validators -from fba import config from fba import network +from fba.helpers import config from fba.helpers import cookies def determine(domain: str, headers: dict) -> dict: diff --git a/fba/federation.py b/fba/federation.py index 397e63b..b41e651 100644 --- a/fba/federation.py +++ b/fba/federation.py @@ -18,11 +18,11 @@ from urllib.parse import urlparse import bs4 import validators -from fba import config from fba import csrf from fba import network from fba.helpers import blacklist +from fba.helpers import config from fba.helpers import tidyup from fba.helpers import version diff --git a/fba/helpers/__init__.py b/fba/helpers/__init__.py index 473eed0..b332bae 100644 --- a/fba/helpers/__init__.py +++ b/fba/helpers/__init__.py @@ -16,6 +16,7 @@ __all__ = [ 'blacklist', 'cache', + 'config', 'cookies', 'dicts', 'locking', diff --git a/fba/helpers/config.py b/fba/helpers/config.py new file mode 100644 index 0000000..1ae1a25 --- /dev/null +++ b/fba/helpers/config.py @@ -0,0 +1,33 @@ +# Fedi API Block - An aggregator for fetching blocking data from fediverse nodes +# Copyright (C) 2023 Free Software Foundation +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import json + +with open("config.json") as f: + # DEBUG: print("DEBUG: Loading configuration file ...") + _config = json.loads(f.read()) + +def get(key: str) -> any: + # DEBUG: print(f"DEBUG: key[{type(key)}]={key} - CALLED!") + if not isinstance(key, str): + raise ValueError(f"Parameter key[]='{type(key)}' is not 'str'") + elif key == "": + raise ValueError("Parameter 'key' is empty") + elif not key in _config: + raise KeyError(f"key='{key}' does not exist in _config array") + + # DEBUG: print(f"DEBUG: _config[{key}]={_config[key]} - EXIT!") + return _config[key] diff --git a/fba/models/error_log.py b/fba/models/error_log.py index 6602406..68c5407 100644 --- a/fba/models/error_log.py +++ b/fba/models/error_log.py @@ -16,9 +16,10 @@ import json import time -from fba import config from fba import fba +from fba.helpers import config + def add(domain: str, error: dict): # DEBUG: print("DEBUG: domain,error[]:", domain, type(error)) if not isinstance(domain, str): diff --git a/fba/models/instances.py b/fba/models/instances.py index 83402e7..ecb5454 100644 --- a/fba/models/instances.py +++ b/fba/models/instances.py @@ -20,13 +20,13 @@ import time import requests import validators -from fba import config from fba import fba from fba import federation from fba import network from fba.helpers import blacklist from fba.helpers import cache +from fba.helpers import config from fba.models import error_log diff --git a/fba/network.py b/fba/network.py index 79ac8f7..33ae3c6 100644 --- a/fba/network.py +++ b/fba/network.py @@ -20,9 +20,9 @@ import requests import urllib3 import validators -from fba import config from fba import fba +from fba.helpers import config from fba.helpers import cookies from fba.models import instances diff --git a/fba/networks/friendica.py b/fba/networks/friendica.py index e6138c7..1ebd0a0 100644 --- a/fba/networks/friendica.py +++ b/fba/networks/friendica.py @@ -17,10 +17,10 @@ import bs4 import validators -from fba import config from fba import network from fba.helpers import blacklist +from fba.helpers import config from fba.helpers import tidyup from fba.models import instances diff --git a/fba/networks/lemmy.py b/fba/networks/lemmy.py index e8ca1e1..cf44f42 100644 --- a/fba/networks/lemmy.py +++ b/fba/networks/lemmy.py @@ -19,13 +19,13 @@ import inspect import bs4 import validators -from fba import config from fba import csrf from fba import fba from fba import federation from fba import network from fba.helpers import blacklist +from fba.helpers import config from fba.helpers import tidyup from fba.models import blocks diff --git a/fba/networks/mastodon.py b/fba/networks/mastodon.py index 9aeec1b..29718a0 100644 --- a/fba/networks/mastodon.py +++ b/fba/networks/mastodon.py @@ -19,12 +19,12 @@ import inspect import bs4 import validators -from fba import config from fba import csrf from fba import fba from fba import network from fba.helpers import blacklist +from fba.helpers import config from fba.helpers import tidyup from fba.models import blocks diff --git a/fba/networks/misskey.py b/fba/networks/misskey.py index 3b93b54..ff5da39 100644 --- a/fba/networks/misskey.py +++ b/fba/networks/misskey.py @@ -16,11 +16,11 @@ import json -from fba import config from fba import csrf from fba import network from fba.helpers import blacklist +from fba.helpers import config from fba.helpers import dicts from fba.helpers import tidyup diff --git a/fba/networks/peertube.py b/fba/networks/peertube.py index f630642..13672ea 100644 --- a/fba/networks/peertube.py +++ b/fba/networks/peertube.py @@ -14,10 +14,11 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from fba import config from fba import csrf from fba import network +from fba.helpers import config + from fba.models import instances def fetch_peers(domain: str) -> list: diff --git a/fba/networks/pleroma.py b/fba/networks/pleroma.py index 75dfd2b..f82575e 100644 --- a/fba/networks/pleroma.py +++ b/fba/networks/pleroma.py @@ -19,12 +19,12 @@ import inspect import bs4 import validators -from fba import config from fba import fba from fba import federation from fba import network from fba.helpers import blacklist +from fba.helpers import config from fba.helpers import tidyup from fba.models import blocks