.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.settings_defaults.SettingsValue Class Reference
+ Inheritance diagram for searx.settings_defaults.SettingsValue:

Public Member Functions

 __init__ (self, typing.Union[None, typing.Any, typing.Tuple[typing.Any]] type_definition=None, typing.Any default=None, str environ_name=None)
 
 type_definition_repr (self)
 
None check_type_definition (self, typing.Any value)
 
typing.Any __call__ (self, typing.Any value)
 

Public Attributes

tuple type_definition
 
 default = default
 
 environ_name = environ_name
 
 type_definition_repr
 

Detailed Description

Check and update a setting value

Definition at line 45 of file settings_defaults.py.

Constructor & Destructor Documentation

◆ __init__()

searx.settings_defaults.SettingsValue.__init__ ( self,
typing.Union[None, typing.Any, typing.Tuple[typing.Any]] type_definition = None,
typing.Any default = None,
str environ_name = None )

Definition at line 48 of file settings_defaults.py.

53 ):
54 self.type_definition = (
55 type_definition if type_definition is None or isinstance(type_definition, tuple) else (type_definition,)
56 )
57 self.default = default
58 self.environ_name = environ_name
59

Member Function Documentation

◆ __call__()

typing.Any searx.settings_defaults.SettingsValue.__call__ ( self,
typing.Any value )

Reimplemented in searx.settings_defaults.SettingsBytesValue, and searx.settings_defaults.SettingsDirectoryValue.

Definition at line 72 of file settings_defaults.py.

72 def __call__(self, value: typing.Any) -> typing.Any:
73 if value == _UNDEFINED:
74 value = self.default
75 # override existing value with environ
76 if self.environ_name and self.environ_name in os.environ:
77 value = os.environ[self.environ_name]
78 if self.type_definition == (bool,):
79 value = STR_TO_BOOL[value.lower()]
80
81 self.check_type_definition(value)
82 return value
83
84

References searx.settings_defaults.SettingsDirectoryValue.check_type_definition(), searx.settings_defaults.SettingSublistValue.check_type_definition(), searx.settings_defaults.SettingsValue.check_type_definition(), searx.botdetection.config.Config.default(), searx.enginelib.traits.EngineTraitsEncoder.default(), searx.settings_defaults.SettingsValue.default, searx.webutils.JSONEncoder.default(), searx.settings_defaults.SettingsValue.environ_name, searx.settings_defaults.SettingSublistValue.type_definition, and searx.settings_defaults.SettingsValue.type_definition.

+ Here is the call graph for this function:

◆ check_type_definition()

None searx.settings_defaults.SettingsValue.check_type_definition ( self,
typing.Any value )

Reimplemented in searx.settings_defaults.SettingsDirectoryValue, and searx.settings_defaults.SettingSublistValue.

Definition at line 65 of file settings_defaults.py.

65 def check_type_definition(self, value: typing.Any) -> None:
66 if value in self.type_definition:
67 return
68 type_list = tuple(t for t in self.type_definition if isinstance(t, type))
69 if not isinstance(value, type_list):
70 raise ValueError('The value has to be one of these types/values: {}'.format(self.type_definition_repr))
71

References searx.settings_defaults.SettingSublistValue.type_definition, and searx.settings_defaults.SettingsValue.type_definition.

Referenced by searx.settings_defaults.SettingsValue.__call__().

+ Here is the caller graph for this function:

◆ type_definition_repr()

searx.settings_defaults.SettingsValue.type_definition_repr ( self)

Definition at line 61 of file settings_defaults.py.

61 def type_definition_repr(self):
62 types_str = [t.__name__ if isinstance(t, type) else repr(t) for t in self.type_definition]
63 return ', '.join(types_str)
64

References searx.settings_defaults.SettingSublistValue.type_definition, and searx.settings_defaults.SettingsValue.type_definition.

Member Data Documentation

◆ default

searx.settings_defaults.SettingsValue.default = default

◆ environ_name

searx.settings_defaults.SettingsValue.environ_name = environ_name

Definition at line 58 of file settings_defaults.py.

Referenced by searx.settings_defaults.SettingsValue.__call__().

◆ type_definition

tuple searx.settings_defaults.SettingsValue.type_definition
Initial value:
= (
type_definition if type_definition is None or isinstance(type_definition, tuple) else (type_definition,)
)

Definition at line 54 of file settings_defaults.py.

Referenced by searx.settings_defaults.SettingsValue.__call__(), searx.settings_defaults.SettingSublistValue.check_type_definition(), searx.settings_defaults.SettingsValue.check_type_definition(), and searx.settings_defaults.SettingsValue.type_definition_repr().

◆ type_definition_repr

searx.settings_defaults.SettingsValue.type_definition_repr

Definition at line 70 of file settings_defaults.py.


The documentation for this class was generated from the following file: