diff options
author | Alexandre Flament <alex@al-f.net> | 2021-10-26 10:31:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-26 10:31:11 +0200 |
commit | 9fe1ee4ed964810c7de9a39ec7f865d0df96e5eb (patch) | |
tree | ed933547df3bc250d1cac558cb37be0f6b9ba93a /searx/settings_defaults.py | |
parent | dfdf71bf08d48332a30ff982dcc8b4ac499d9c8d (diff) | |
parent | 60db344cc0715eab4d03dad5629f4c47954c466c (diff) | |
download | searxng-9fe1ee4ed964810c7de9a39ec7f865d0df96e5eb.tar.gz searxng-9fe1ee4ed964810c7de9a39ec7f865d0df96e5eb.zip |
Merge pull request #423 from dalf/available-languages
[enh] reduce the available language list
Diffstat (limited to 'searx/settings_defaults.py')
-rw-r--r-- | searx/settings_defaults.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/searx/settings_defaults.py b/searx/settings_defaults.py index 49462ccb4..331cd643d 100644 --- a/searx/settings_defaults.py +++ b/searx/settings_defaults.py @@ -17,7 +17,7 @@ searx_dir = abspath(dirname(__file__)) logger = logging.getLogger('searx') OUTPUT_FORMATS = ['html', 'csv', 'json', 'rss'] -LANGUAGE_CODES = ('', 'all') + tuple(l[0] for l in languages) +LANGUAGE_CODES = ['all'] + list(l[0] for l in languages) OSCAR_STYLE = ('logicodev', 'logicodev-dark', 'pointhi') CATEGORY_ORDER = [ 'general', @@ -98,6 +98,18 @@ class SettingsValue: self.check_type_definition(value) return value + +class SettingSublistValue(SettingsValue): + """Check the value is a sublist of type definition. + """ + + def check_type_definition(self, value: typing.Any) -> typing.Any: + if not isinstance(value, list): + raise ValueError('The value has to a list') + for item in value: + 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 """ @@ -148,7 +160,8 @@ SCHEMA = { 'search': { 'safe_search': SettingsValue((0,1,2), 0), 'autocomplete': SettingsValue(str, ''), - 'default_lang': SettingsValue(LANGUAGE_CODES, ''), + 'default_lang': SettingsValue(tuple(LANGUAGE_CODES + ['']), ''), + 'languages': SettingSublistValue(LANGUAGE_CODES, LANGUAGE_CODES), 'ban_time_on_fail': SettingsValue(numbers.Real, 5), 'max_ban_time_on_fail': SettingsValue(numbers.Real, 120), 'formats': SettingsValue(list, OUTPUT_FORMATS), |