diff options
| author | Markus Heiser <markus.heiser@darmarit.de> | 2024-06-12 18:01:18 +0200 |
|---|---|---|
| committer | Markus Heiser <markus.heiser@darmarIT.de> | 2024-07-14 18:10:06 +0200 |
| commit | 2039060b640189e250020e6e17db10b0a0730e7e (patch) | |
| tree | de3d278a4cce77d40e893206e4b0f756b3411e03 /searx/plugins | |
| parent | e4da22ee51d86252144885ec5ba11e8c13ed2010 (diff) | |
[mod] revision of the settings_loader
The intention of this PR is to modernize the settings_loader implementations.
The concept is old (remember, this is partly from 2014), back then we only had
one config file, meanwhile we have had a folder with config files for a very
long time. Callers can now load a YAML configuration from this folder as
follows ::
settings_loader.get_yaml_cfg('my-config.yml')
- BTW this is a fix of #3557.
- Further the `existing_filename_or_none` construct dates back to times when
there was not yet a `pathlib.Path` in all Python versions we supported in the
past.
- Typehints have been added wherever appropriate
At the same time, this patch should also be downward compatible and not
introduce a new environment variable. The localization of the folder with the
configurations is further based on:
SEARXNG_SETTINGS_PATH (wich defaults to /etc/searxng/settings.yml)
Which means, the default config folder is `/etc/searxng/`.
ATTENTION: intended functional changes!
If SEARXNG_SETTINGS_PATH was set and pointed to a not existing file, the
previous implementation silently loaded the default configuration. This
behavior has been changed: if the file or folder does not exist, an
EnvironmentError exception will be thrown in future.
Closes: https://github.com/searxng/searxng/issues/3557
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/plugins')
| -rw-r--r-- | searx/plugins/hostnames.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/searx/plugins/hostnames.py b/searx/plugins/hostnames.py index 2fdf1669d..2783f23eb 100644 --- a/searx/plugins/hostnames.py +++ b/searx/plugins/hostnames.py @@ -96,7 +96,7 @@ from flask_babel import gettext from searx import settings from searx.plugins import logger -from searx.settings_loader import get_yaml_file +from searx.settings_loader import get_yaml_cfg name = gettext('Hostnames plugin') description = gettext('Rewrite hostnames, remove results or prioritize them based on the hostname') @@ -118,7 +118,7 @@ def _load_regular_expressions(settings_key): # load external file with configuration if isinstance(setting_value, str): - setting_value = get_yaml_file(setting_value) + setting_value = get_yaml_cfg(setting_value) if isinstance(setting_value, list): return {re.compile(r) for r in setting_value} @@ -163,10 +163,10 @@ def _matches_parsed_url(result, pattern): def on_result(_request, _search, result): for pattern, replacement in replacements.items(): if _matches_parsed_url(result, pattern): - logger.debug(result['url']) + # logger.debug(result['url']) result[parsed] = result[parsed]._replace(netloc=pattern.sub(replacement, result[parsed].netloc)) result['url'] = urlunparse(result[parsed]) - logger.debug(result['url']) + # logger.debug(result['url']) for url_field in _url_fields: if not result.get(url_field): |