.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
compat.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Compatibility with older versions"""
3
4# pylint: disable=unused-import
5
6__all__ = [
7 "tomllib",
8]
9
10import sys
11import warnings
12
13
14# TOML (lib) compatibility
15# ------------------------
16
17if sys.version_info >= (3, 11):
18 import tomllib
19else:
20 import tomli as tomllib
21
22
23# limiter backward compatibility
24# ------------------------------
25
26LIMITER_CFG_DEPRECATED = {
27 "real_ip": "limiter: config section 'real_ip' is deprecated",
28 "real_ip.x_for": "real_ip.x_for has been replaced by botdetection.trusted_proxies",
29 "real_ip.ipv4_prefix": "real_ip.ipv4_prefix has been replaced by botdetection.ipv4_prefix",
30 "real_ip.ipv6_prefix": "real_ip.ipv6_prefix has been replaced by botdetection.ipv6_prefix'",
31}
32
33
34def limiter_fix_cfg(cfg, cfg_file):
35
36 kwargs = {
37 "category": DeprecationWarning,
38 "filename": str(cfg_file),
39 "lineno": 0,
40 "module": "searx.limiter",
41 }
42
43 for opt, msg in LIMITER_CFG_DEPRECATED.items():
44 try:
45 val = cfg.get(opt)
46 except KeyError:
47 continue
48
49 warnings.warn_explicit(msg, **kwargs)
50 if opt == "real_ip.ipv4_prefix":
51 cfg.set("botdetection.ipv4_prefix", val)
52 if opt == "real_ip.ipv6_prefix":
53 cfg.set("botdetection.ipv6_prefix", val)
limiter_fix_cfg(cfg, cfg_file)
Definition compat.py:34