.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
__init__.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""This module holds the *data* created by::
3
4 make data.all
5
6"""
7from __future__ import annotations
8
9__all__ = ["ahmia_blacklist_loader"]
10
11import json
12import typing
13
14from .core import log, data_dir
15from .currencies import CurrenciesDB
16
17CURRENCIES: CurrenciesDB
18USER_AGENTS: dict[str, typing.Any]
19EXTERNAL_URLS: dict[str, typing.Any]
20WIKIDATA_UNITS: dict[str, typing.Any]
21EXTERNAL_BANGS: dict[str, typing.Any]
22OSM_KEYS_TAGS: dict[str, typing.Any]
23ENGINE_DESCRIPTIONS: dict[str, typing.Any]
24ENGINE_TRAITS: dict[str, typing.Any]
25LOCALES: dict[str, typing.Any]
26
27lazy_globals = {
28 "CURRENCIES": CurrenciesDB(),
29 "USER_AGENTS": None,
30 "EXTERNAL_URLS": None,
31 "WIKIDATA_UNITS": None,
32 "EXTERNAL_BANGS": None,
33 "OSM_KEYS_TAGS": None,
34 "ENGINE_DESCRIPTIONS": None,
35 "ENGINE_TRAITS": None,
36 "LOCALES": None,
37}
38
39data_json_files = {
40 "USER_AGENTS": "useragents.json",
41 "EXTERNAL_URLS": "external_urls.json",
42 "WIKIDATA_UNITS": "wikidata_units.json",
43 "EXTERNAL_BANGS": "external_bangs.json",
44 "OSM_KEYS_TAGS": "osm_keys_tags.json",
45 "ENGINE_DESCRIPTIONS": "engine_descriptions.json",
46 "ENGINE_TRAITS": "engine_traits.json",
47 "LOCALES": "locales.json",
48}
49
50
51def __getattr__(name):
52 # lazy init of the global objects
53 if name not in lazy_globals:
54 raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
55
56 data = lazy_globals[name]
57 if data is not None:
58 return data
59
60 log.debug("init searx.data.%s", name)
61
62 with open(data_dir / data_json_files[name], encoding='utf-8') as f:
63 lazy_globals[name] = json.load(f)
64
65 return lazy_globals[name]
66
67
69 """Load data from `ahmia_blacklist.txt` and return a list of MD5 values of onion
70 names. The MD5 values are fetched by::
71
72 searxng_extra/update/update_ahmia_blacklist.py
73
74 This function is used by :py:mod:`searx.plugins.ahmia_filter`.
75
76 """
77 with open(data_dir / 'ahmia_blacklist.txt', encoding='utf-8') as f:
78 return f.read().split()
__getattr__(name)
Definition __init__.py:51
ahmia_blacklist_loader()
Definition __init__.py:68