.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, locked=False)
 
- Public Member Functions inherited from searx.preferences.Setting
 get_value (self)
 
 save (self, str name, flask.Response resp)
 

Public Attributes

 choices = lang
 
 value = data
 
- Public Attributes inherited from searx.preferences.EnumStringSetting
 choices = choices
 
 value
 
- Public Attributes inherited from searx.preferences.Setting
 value = default_value
 
 locked = locked
 

Protected Member Functions

 _validate_selection (self, selection)
 
- Protected Member Functions inherited from searx.preferences.EnumStringSetting

Detailed Description

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

Definition at line 165 of file preferences.py.

Member Function Documentation

◆ _validate_selection()

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

Reimplemented from searx.preferences.EnumStringSetting.

Definition at line 168 of file preferences.py.

168 def _validate_selection(self, selection):
169 if selection != '' and selection != 'auto' and not VALID_LANGUAGE_CODE.match(selection):
170 raise ValidationException('Invalid language code: "{0}"'.format(selection))
171

References searx.format.

Referenced by searx.preferences.EnumStringSetting.parse().

+ Here is the caller graph for this function:

◆ 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 172 of file preferences.py.

172 def parse(self, data: str):
173 """Parse and validate ``data`` and store the result at ``self.value``"""
174 if data not in self.choices and data != self.value:
175 # hack to give some backwards compatibility with old language cookies
176 data = str(data).replace('_', '-')
177 lang = data.split('-', maxsplit=1)[0]
178
179 if data in self.choices:
180 pass
181 elif lang in self.choices:
182 data = lang
183 else:
184 data = self.value
185 self._validate_selection(data)
186 self.value = data
187
188

References searx.preferences.BooleanChoices.choices, searx.preferences.EnumStringSetting.choices, searx.preferences.MultipleChoiceSetting.choices, searx.preferences.SearchLanguageSetting.choices, searx.preferences.BooleanSetting.value, searx.preferences.EnumStringSetting.value, searx.preferences.MapSetting.value, searx.preferences.MultipleChoiceSetting.value, searx.preferences.SearchLanguageSetting.value, and searx.preferences.Setting.value.

Member Data Documentation

◆ choices

◆ value


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