|
@@ -4,9 +4,8 @@
|
|
from __future__ import annotations
|
|
from __future__ import annotations
|
|
|
|
|
|
import pathlib
|
|
import pathlib
|
|
-from pydantic import BaseModel
|
|
|
|
|
|
+import msgspec
|
|
|
|
|
|
-from searx.compat import tomllib
|
|
|
|
from .cache import FaviconCacheConfig
|
|
from .cache import FaviconCacheConfig
|
|
from .proxy import FaviconProxyConfig
|
|
from .proxy import FaviconProxyConfig
|
|
|
|
|
|
@@ -19,7 +18,7 @@ TOML_CACHE_CFG: dict[str, "FaviconConfig"] = {}
|
|
DEFAULT_CFG_TOML_PATH = pathlib.Path(__file__).parent / "favicons.toml"
|
|
DEFAULT_CFG_TOML_PATH = pathlib.Path(__file__).parent / "favicons.toml"
|
|
|
|
|
|
|
|
|
|
-class FaviconConfig(BaseModel):
|
|
|
|
|
|
+class FaviconConfig(msgspec.Struct): # pylint: disable=too-few-public-methods
|
|
"""The class aggregates configurations of the favicon tools"""
|
|
"""The class aggregates configurations of the favicon tools"""
|
|
|
|
|
|
cfg_schema: int
|
|
cfg_schema: int
|
|
@@ -28,10 +27,10 @@ class FaviconConfig(BaseModel):
|
|
By specifying a version, it is possible to ensure downward compatibility in
|
|
By specifying a version, it is possible to ensure downward compatibility in
|
|
the event of future changes to the configuration schema"""
|
|
the event of future changes to the configuration schema"""
|
|
|
|
|
|
- cache: FaviconCacheConfig = FaviconCacheConfig()
|
|
|
|
|
|
+ cache: FaviconCacheConfig = FaviconCacheConfig
|
|
"""Setup of the :py:obj:`.cache.FaviconCacheConfig`."""
|
|
"""Setup of the :py:obj:`.cache.FaviconCacheConfig`."""
|
|
|
|
|
|
- proxy: FaviconProxyConfig = FaviconProxyConfig()
|
|
|
|
|
|
+ proxy: FaviconProxyConfig = FaviconCacheConfig
|
|
"""Setup of the :py:obj:`.proxy.FaviconProxyConfig`."""
|
|
"""Setup of the :py:obj:`.proxy.FaviconProxyConfig`."""
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
@@ -45,18 +44,22 @@ class FaviconConfig(BaseModel):
|
|
return cached
|
|
return cached
|
|
|
|
|
|
with cfg_file.open("rb") as f:
|
|
with cfg_file.open("rb") as f:
|
|
|
|
+ data = f.read()
|
|
|
|
|
|
- cfg = tomllib.load(f)
|
|
|
|
- cfg = cfg.get("favicons", cfg)
|
|
|
|
|
|
+ cfg = msgspec.toml.decode(data, type=_FaviconConfig)
|
|
|
|
+ schema = cfg.favicons.cfg_schema
|
|
|
|
+ if schema != CONFIG_SCHEMA:
|
|
|
|
+ raise ValueError(
|
|
|
|
+ f"config schema version {CONFIG_SCHEMA} is needed, version {schema} is given in {cfg_file}"
|
|
|
|
+ )
|
|
|
|
|
|
- schema = cfg.get("cfg_schema")
|
|
|
|
- if schema != CONFIG_SCHEMA:
|
|
|
|
- raise ValueError(
|
|
|
|
- f"config schema version {CONFIG_SCHEMA} is needed, version {schema} is given in {cfg_file}"
|
|
|
|
- )
|
|
|
|
|
|
+ cfg = cfg.favicons
|
|
|
|
+ if use_cache and cached:
|
|
|
|
+ TOML_CACHE_CFG[str(cfg_file.resolve())] = cfg
|
|
|
|
+
|
|
|
|
+ return cfg
|
|
|
|
|
|
- cfg = cls(**cfg)
|
|
|
|
- if use_cache and cached:
|
|
|
|
- TOML_CACHE_CFG[str(cfg_file.resolve())] = cfg
|
|
|
|
|
|
|
|
- return cfg
|
|
|
|
|
|
+class _FaviconConfig(msgspec.Struct): # pylint: disable=too-few-public-methods
|
|
|
|
+ # wrapper struct for root object "favicons."
|
|
|
|
+ favicons: FaviconConfig
|