[format.python] initial formatting of the python code

This patch was generated by black [1]::

    make format.python

[1] https://github.com/psf/black

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
Markus Heiser 2021-12-27 09:26:22 +01:00
parent fcdc2c2cd2
commit 3d96a9839a
184 changed files with 2800 additions and 2836 deletions

View file

@ -53,29 +53,24 @@ SEARX_ENVIRON_VARIABLES = {
}
class SettingsValue:
"""Check and update a setting value
"""
"""Check and update a setting value"""
def __init__(self,
type_definition: typing.Union[None, typing.Any, typing.Tuple[typing.Any]]=None,
default: typing.Any=None,
environ_name: str=None):
def __init__(
self,
type_definition: typing.Union[None, typing.Any, typing.Tuple[typing.Any]] = None,
default: typing.Any = None,
environ_name: str = None,
):
self.type_definition = (
type_definition
if type_definition is None or isinstance(type_definition, tuple)
else (type_definition,)
type_definition if type_definition is None or isinstance(type_definition, tuple) else (type_definition,)
)
self.default = default
self.environ_name = environ_name
@property
def type_definition_repr(self):
types_str = [
t.__name__ if isinstance(t, type) else repr(t)
for t in self.type_definition
]
types_str = [t.__name__ if isinstance(t, type) else repr(t) for t in self.type_definition]
return ', '.join(types_str)
def check_type_definition(self, value: typing.Any) -> None:
@ -83,9 +78,7 @@ class SettingsValue:
return
type_list = tuple(t for t in self.type_definition if isinstance(t, type))
if not isinstance(value, type_list):
raise ValueError(
'The value has to be one of these types/values: {}'.format(
self.type_definition_repr))
raise ValueError('The value has to be one of these types/values: {}'.format(self.type_definition_repr))
def __call__(self, value: typing.Any) -> typing.Any:
if value == _UNDEFINED:
@ -101,8 +94,7 @@ class SettingsValue:
class SettingSublistValue(SettingsValue):
"""Check the value is a sublist of type definition.
"""
"""Check the value is a sublist of type definition."""
def check_type_definition(self, value: typing.Any) -> typing.Any:
if not isinstance(value, list):
@ -111,9 +103,9 @@ class SettingSublistValue(SettingsValue):
if not item in self.type_definition[0]:
raise ValueError('{} not in {}'.format(item, self.type_definition))
class SettingsDirectoryValue(SettingsValue):
"""Check and update a setting value that is a directory path
"""
"""Check and update a setting value that is a directory path"""
def check_type_definition(self, value: typing.Any) -> typing.Any:
super().check_type_definition(value)
@ -159,7 +151,7 @@ SCHEMA = {
'wiki_url': SettingsValue(str, 'https://github.com/searxng/searxng/wiki'),
},
'search': {
'safe_search': SettingsValue((0,1,2), 0),
'safe_search': SettingsValue((0, 1, 2), 0),
'autocomplete': SettingsValue(str, ''),
'default_lang': SettingsValue(tuple(LANGUAGE_CODES + ['']), ''),
'languages': SettingSublistValue(LANGUAGE_CODES, LANGUAGE_CODES),
@ -168,7 +160,7 @@ SCHEMA = {
'formats': SettingsValue(list, OUTPUT_FORMATS),
},
'server': {
'port': SettingsValue((int,str), 8888, 'SEARXNG_PORT'),
'port': SettingsValue((int, str), 8888, 'SEARXNG_PORT'),
'bind_address': SettingsValue(str, '127.0.0.1', 'SEARXNG_BIND_ADDRESS'),
'secret_key': SettingsValue(str, environ_name='SEARXNG_SECRET'),
'base_url': SettingsValue((False, str), False),
@ -213,8 +205,7 @@ SCHEMA = {
# Tor configuration
'using_tor_proxy': SettingsValue(bool, False),
'extra_proxy_timeout': SettingsValue(int, 0),
'networks': {
},
'networks': {},
},
'plugins': SettingsValue(list, []),
'enabled_plugins': SettingsValue((None, list), None),
@ -222,10 +213,10 @@ SCHEMA = {
'off_when_debug': SettingsValue(bool, True),
},
'engines': SettingsValue(list, []),
'doi_resolvers': {
},
'doi_resolvers': {},
}
def settings_set_defaults(settings):
# compatibility with searx variables
for searx, searxng in SEARX_ENVIRON_VARIABLES.items():