.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.preferences.SearchLanguageSetting Class Reference
Inheritance diagram for searx.preferences.SearchLanguageSetting:
Collaboration diagram for searx.preferences.SearchLanguageSetting:

Public Member Functions

 parse (self, str data)
Public Member Functions inherited from searx.preferences.EnumStringSetting
 __init__ (self, str default_value, Iterable[str] choices, bool locked=False)
Public Member Functions inherited from searx.preferences.Setting
 __init__ (self, t.Any default_value, bool locked=False)
 get_value (self)
 save (self, str name, flask.Response resp)

Protected Member Functions

 _validate_selection (self, str selection)

Additional Inherited Members

Public Attributes inherited from searx.preferences.EnumStringSetting
Iterable[str] choices = choices
Public Attributes inherited from searx.preferences.Setting
t.Any value = default_value
bool locked = locked

Detailed Description

Available choices may change, so user's value may not be in choices anymore

Definition at line 172 of file preferences.py.

Member Function Documentation

◆ _validate_selection()

searx.preferences.SearchLanguageSetting._validate_selection ( self,
str selection )
protected

Reimplemented from searx.preferences.EnumStringSetting.

Definition at line 177 of file preferences.py.

177 def _validate_selection(self, selection: str):
178 if selection != '' and selection != 'auto' and not VALID_LANGUAGE_CODE.match(selection):
179 raise ValidationException('Invalid language code: "{0}"'.format(selection))
180

◆ parse()

searx.preferences.SearchLanguageSetting.parse ( self,
str data )
Parse and validate ``data`` and store the result at ``self.value``

Reimplemented from searx.preferences.EnumStringSetting.

Definition at line 181 of file preferences.py.

181 def parse(self, data: str):
182 """Parse and validate ``data`` and store the result at ``self.value``"""
183 if data not in self.choices and data != self.value:
184 # hack to give some backwards compatibility with old language cookies
185 data = str(data).replace('_', '-')
186 lang = data.split('-', maxsplit=1)[0]
187
188 if data in self.choices:
189 pass
190 elif lang in self.choices:
191 data = lang
192 else:
193 data = self.value
194 self._validate_selection(data)
195 self.value = data
196
197

References searx.preferences.EnumStringSetting.choices, and searx.preferences.Setting.value.


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