.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
16from .tracker_patterns import TrackerPatternsDB
17
18CURRENCIES: CurrenciesDB
19USER_AGENTS: dict[str, typing.Any]
20EXTERNAL_URLS: dict[str, typing.Any]
21WIKIDATA_UNITS: dict[str, typing.Any]
22EXTERNAL_BANGS: dict[str, typing.Any]
23OSM_KEYS_TAGS: dict[str, typing.Any]
24ENGINE_DESCRIPTIONS: dict[str, typing.Any]
25ENGINE_TRAITS: dict[str, typing.Any]
26LOCALES: dict[str, typing.Any]
27TRACKER_PATTERNS: TrackerPatternsDB
28
29lazy_globals = {
30 "CURRENCIES": CurrenciesDB(),
31 "USER_AGENTS": None,
32 "EXTERNAL_URLS": None,
33 "WIKIDATA_UNITS": None,
34 "EXTERNAL_BANGS": None,
35 "OSM_KEYS_TAGS": None,
36 "ENGINE_DESCRIPTIONS": None,
37 "ENGINE_TRAITS": None,
38 "LOCALES": None,
39 "TRACKER_PATTERNS": TrackerPatternsDB(),
40}
41
42data_json_files = {
43 "USER_AGENTS": "useragents.json",
44 "EXTERNAL_URLS": "external_urls.json",
45 "WIKIDATA_UNITS": "wikidata_units.json",
46 "EXTERNAL_BANGS": "external_bangs.json",
47 "OSM_KEYS_TAGS": "osm_keys_tags.json",
48 "ENGINE_DESCRIPTIONS": "engine_descriptions.json",
49 "ENGINE_TRAITS": "engine_traits.json",
50 "LOCALES": "locales.json",
51}
52
53
54def __getattr__(name):
55 # lazy init of the global objects
56 if name not in lazy_globals:
57 raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
58
59 data = lazy_globals[name]
60 if data is not None:
61 return data
62
63 log.debug("init searx.data.%s", name)
64
65 with open(data_dir / data_json_files[name], encoding='utf-8') as f:
66 lazy_globals[name] = json.load(f)
67
68 return lazy_globals[name]
69
70
72 """Load data from `ahmia_blacklist.txt` and return a list of MD5 values of onion
73 names. The MD5 values are fetched by::
74
75 searxng_extra/update/update_ahmia_blacklist.py
76
77 This function is used by :py:mod:`searx.plugins.ahmia_filter`.
78
79 """
80 with open(data_dir / 'ahmia_blacklist.txt', encoding='utf-8') as f:
81 return f.read().split()
__getattr__(name)
Definition __init__.py:54
ahmia_blacklist_loader()
Definition __init__.py:71