2"""Implementation of the default settings.
11from base64
import b64decode
12from os.path
import dirname, abspath
14from .sxng_locales
import sxng_locales
16searx_dir = abspath(dirname(__file__))
18logger = logging.getLogger(
'searx')
19OUTPUT_FORMATS = [
'html',
'csv',
'json',
'rss']
20SXNG_LOCALE_TAGS = [
'all',
'auto'] + list(l[0]
for l
in sxng_locales)
21SIMPLE_STYLE = (
'auto',
'light',
'dark',
'black')
46 """Check and update a setting value"""
50 type_definition: typing.Union[
None, typing.Any, typing.Tuple[typing.Any]] =
None,
51 default: typing.Any =
None,
52 environ_name: str =
None,
55 type_definition
if type_definition
is None or isinstance(type_definition, tuple)
else (type_definition,)
62 types_str = [t.__name__
if isinstance(t, type)
else repr(t)
for t
in self.
type_definition]
63 return ', '.join(types_str)
68 type_list = tuple(t
for t
in self.
type_definition if isinstance(t, type))
69 if not isinstance(value, type_list):
72 def __call__(self, value: typing.Any) -> typing.Any:
73 if value == _UNDEFINED:
79 value = STR_TO_BOOL[value.lower()]
86 """Check the value is a sublist of type definition."""
89 if not isinstance(value, list):
90 raise ValueError(
'The value has to a list')
97 """Check and update a setting value that is a directory path"""
101 if not os.path.isdir(value):
102 raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), value)
104 def __call__(self, value: typing.Any) -> typing.Any:
111 """str are base64 decoded"""
113 def __call__(self, value: typing.Any) -> typing.Any:
114 if isinstance(value, str):
115 value = b64decode(value)
121 for key, value
in schema.items():
122 if isinstance(value, SettingsValue):
124 settings[key] = value(settings.get(key, _UNDEFINED))
125 except Exception
as e:
127 logger.error(
'%s: %s',
'.'.join([*path_list, key]), e)
129 elif isinstance(value, dict):
130 error = error
or apply_schema(settings.setdefault(key, {}), schema[key], [*path_list, key])
132 settings.setdefault(key, value)
133 if len(path_list) == 0
and error:
134 raise ValueError(
'Invalid settings.yml')
142 'privacypolicy_url':
SettingsValue((
None,
False, str),
None),
144 'donation_url':
SettingsValue((bool, str),
"https://docs.searxng.org/donate.html"),
148 'issue_url':
SettingsValue(str,
'https://github.com/searxng/searxng/issues'),
149 'new_issue_url':
SettingsValue(str,
'https://github.com/searxng/searxng/issues/new'),
151 'public_instances':
SettingsValue((
False, str),
'https://searx.space'),
152 'wiki_url':
SettingsValue(str,
'https://github.com/searxng/searxng/wiki'),
160 'default_lang':
SettingsValue(tuple(SXNG_LOCALE_TAGS + [
'']),
''),
165 'SearxEngineAccessDenied':
SettingsValue(numbers.Real, 86400),
167 'SearxEngineTooManyRequests':
SettingsValue(numbers.Real, 3600),
168 'cf_SearxEngineCaptcha':
SettingsValue(numbers.Real, 1296000),
169 'cf_SearxEngineAccessDenied':
SettingsValue(numbers.Real, 86400),
170 'recaptcha_SearxEngineCaptcha':
SettingsValue(numbers.Real, 604800),
177 'bind_address':
SettingsValue(str,
'127.0.0.1',
'SEARXNG_BIND_ADDRESS'),
179 'public_instance':
SettingsValue(bool,
False,
'SEARXNG_PUBLIC_INSTANCE'),
180 'secret_key':
SettingsValue(str, environ_name=
'SEARXNG_SECRET'),
181 'base_url':
SettingsValue((
False, str),
False,
'SEARXNG_BASE_URL'),
182 'image_proxy':
SettingsValue(bool,
False,
'SEARXNG_IMAGE_PROXY'),
183 'http_protocol_version':
SettingsValue((
'1.0',
'1.1'),
'1.0'),
188 'url':
SettingsValue((
None,
False, str),
False,
'SEARXNG_REDIS_URL'),
192 'static_use_hash':
SettingsValue(bool,
False,
'SEARXNG_STATIC_USE_HASH'),
204 'cache_url':
SettingsValue(str,
'https://web.archive.org/web/'),
216 'max_request_timeout':
SettingsValue((
None, numbers.Real),
None),
242 'categories_as_tabs':
SettingsValue(dict, CATEGORIES_AS_TABS),
typing.Any check_type_definition(self, typing.Any value)
typing.Any __call__(self, typing.Any value)
typing.Any __call__(self, typing.Any value)
typing.Any check_type_definition(self, typing.Any value)
__init__(self, typing.Union[None, typing.Any, typing.Tuple[typing.Any]] type_definition=None, typing.Any default=None, str environ_name=None)
None check_type_definition(self, typing.Any value)
typing.Any __call__(self, typing.Any value)
type_definition_repr(self)
settings_set_defaults(settings)
apply_schema(settings, schema, path_list)