mirror of https://github.com/searxng/searxng.git
[pylint] searx/__init__.py & searx/settings_defaults.py
BTW: normalize some indentations in searx/settings_defaults.py Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
parent
6fa114c9ba
commit
495d86b520
|
@ -1,25 +1,12 @@
|
||||||
'''
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
searx is free software: you can redistribute it and/or modify
|
# lint: pylint
|
||||||
it under the terms of the GNU Affero General Public License as published by
|
# pylint: disable=missing-function-docstring, missing-module-docstring
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
searx is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Affero General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with searx. If not, see < http://www.gnu.org/licenses/ >.
|
|
||||||
|
|
||||||
(C) 2013- by Adam Tauber, <asciimoo@gmail.com>
|
|
||||||
'''
|
|
||||||
|
|
||||||
|
from os.path import dirname, abspath
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import searx.settings_loader
|
import searx.settings_loader
|
||||||
from searx.settings_defaults import settings_set_defaults
|
from searx.settings_defaults import settings_set_defaults
|
||||||
from os.path import dirname, abspath
|
|
||||||
|
|
||||||
|
|
||||||
searx_dir = abspath(dirname(__file__))
|
searx_dir = abspath(dirname(__file__))
|
||||||
searx_parent_dir = abspath(dirname(dirname(__file__)))
|
searx_parent_dir = abspath(dirname(dirname(__file__)))
|
||||||
|
@ -45,7 +32,7 @@ else:
|
||||||
logger.info('max_request_timeout=%i second(s)', max_request_timeout)
|
logger.info('max_request_timeout=%i second(s)', max_request_timeout)
|
||||||
|
|
||||||
|
|
||||||
class _brand_namespace:
|
class _brand_namespace: # pylint: disable=invalid-name
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_val(cls, group, name, default=''):
|
def get_val(cls, group, name, default=''):
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
# lint: pylint
|
# lint: pylint
|
||||||
# pylint: disable=missing-function-docstring, missing-module-docstring
|
# pylint: disable=missing-function-docstring
|
||||||
|
"""Implementation of the default settings.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
import typing
|
import typing
|
||||||
import numbers
|
import numbers
|
||||||
|
@ -48,16 +51,20 @@ class SettingsValue:
|
||||||
type_definition: typing.Union[None, typing.Any, typing.Tuple[typing.Any]]=None,
|
type_definition: typing.Union[None, typing.Any, typing.Tuple[typing.Any]]=None,
|
||||||
default: typing.Any=None,
|
default: typing.Any=None,
|
||||||
environ_name: str=None):
|
environ_name: str=None):
|
||||||
self.type_definition = type_definition \
|
self.type_definition = (
|
||||||
if type_definition is None or isinstance(type_definition, tuple) \
|
type_definition
|
||||||
|
if type_definition is None or isinstance(type_definition, tuple)
|
||||||
else (type_definition,)
|
else (type_definition,)
|
||||||
|
)
|
||||||
self.default = default
|
self.default = default
|
||||||
self.environ_name = environ_name
|
self.environ_name = environ_name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def type_definition_repr(self):
|
def type_definition_repr(self):
|
||||||
types_str = [t.__name__ if isinstance(t, type) else repr(t)
|
types_str = [
|
||||||
for t in self.type_definition]
|
t.__name__ if isinstance(t, type) else repr(t)
|
||||||
|
for t in self.type_definition
|
||||||
|
]
|
||||||
return ', '.join(types_str)
|
return ', '.join(types_str)
|
||||||
|
|
||||||
def check_type_definition(self, value: typing.Any) -> None:
|
def check_type_definition(self, value: typing.Any) -> None:
|
||||||
|
@ -65,8 +72,9 @@ class SettingsValue:
|
||||||
return
|
return
|
||||||
type_list = tuple(t for t in self.type_definition if isinstance(t, type))
|
type_list = tuple(t for t in self.type_definition if isinstance(t, type))
|
||||||
if not isinstance(value, type_list):
|
if not isinstance(value, type_list):
|
||||||
raise ValueError('The value has to be one of these types/values: {}'\
|
raise ValueError(
|
||||||
.format(self.type_definition_repr))
|
'The value has to be one of these types/values: {}'.format(
|
||||||
|
self.type_definition_repr))
|
||||||
|
|
||||||
def __call__(self, value: typing.Any) -> typing.Any:
|
def __call__(self, value: typing.Any) -> typing.Any:
|
||||||
if value == _UNDEFINED:
|
if value == _UNDEFINED:
|
||||||
|
@ -76,7 +84,7 @@ class SettingsValue:
|
||||||
value = os.environ[self.environ_name]
|
value = os.environ[self.environ_name]
|
||||||
if self.type_definition == (bool,):
|
if self.type_definition == (bool,):
|
||||||
value = STR_TO_BOOL[value.lower()]
|
value = STR_TO_BOOL[value.lower()]
|
||||||
#
|
|
||||||
self.check_type_definition(value)
|
self.check_type_definition(value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue