diff options
Diffstat (limited to 'searx/compat.py')
| -rw-r--r-- | searx/compat.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/searx/compat.py b/searx/compat.py index 035726469..2f45eb0e4 100644 --- a/searx/compat.py +++ b/searx/compat.py @@ -8,6 +8,8 @@ __all__ = [ ] import sys +import warnings + # TOML (lib) compatibility # ------------------------ @@ -16,3 +18,36 @@ if sys.version_info >= (3, 11): import tomllib else: import tomli as tomllib + + +# limiter backward compatibility +# ------------------------------ + +LIMITER_CFG_DEPRECATED = { + "real_ip": "limiter: config section 'real_ip' is deprecated", + "real_ip.x_for": "real_ip.x_for has been replaced by botdetection.trusted_proxies", + "real_ip.ipv4_prefix": "real_ip.ipv4_prefix has been replaced by botdetection.ipv4_prefix", + "real_ip.ipv6_prefix": "real_ip.ipv6_prefix has been replaced by botdetection.ipv6_prefix'", +} + + +def limiter_fix_cfg(cfg, cfg_file): + + kwargs = { + "category": DeprecationWarning, + "filename": str(cfg_file), + "lineno": 0, + "module": "searx.limiter", + } + + for opt, msg in LIMITER_CFG_DEPRECATED.items(): + try: + val = cfg.get(opt) + except KeyError: + continue + + warnings.warn_explicit(msg, **kwargs) + if opt == "real_ip.ipv4_prefix": + cfg.set("botdetection.ipv4_prefix", val) + if opt == "real_ip.ipv6_prefix": + cfg.set("botdetection.ipv6_prefix", val) |