diff options
author | Alexandre Flament <alex@al-f.net> | 2020-10-01 11:29:31 +0200 |
---|---|---|
committer | Alexandre Flament <alex@al-f.net> | 2020-10-01 11:29:31 +0200 |
commit | 507896c1159ae72dc1e45a4d0cf40f4654209ec0 (patch) | |
tree | 28b991a13f5ce9b562c33d6c4554834911dde083 /searx | |
parent | fd5fe369844e481aecc0d731b08ee8b29c9b47e6 (diff) | |
download | searxng-507896c1159ae72dc1e45a4d0cf40f4654209ec0.tar.gz searxng-507896c1159ae72dc1e45a4d0cf40f4654209ec0.zip |
[mod] preferences.py: check language setting with a regex instead of match_language
Diffstat (limited to 'searx')
-rw-r--r-- | searx/preferences.py | 7 | ||||
-rw-r--r-- | searx/query.py | 4 | ||||
-rw-r--r-- | searx/webadapter.py | 3 | ||||
-rw-r--r-- | searx/webutils.py | 2 |
4 files changed, 8 insertions, 8 deletions
diff --git a/searx/preferences.py b/searx/preferences.py index 3042636a6..f149dc976 100644 --- a/searx/preferences.py +++ b/searx/preferences.py @@ -10,7 +10,7 @@ from urllib.parse import parse_qs, urlencode from searx import settings, autocomplete from searx.languages import language_codes as languages -from searx.utils import match_language +from searx.webutils import VALID_LANGUAGE_CODE COOKIE_MAX_AGE = 60 * 60 * 24 * 365 * 5 # 5 years @@ -162,9 +162,7 @@ class SearchLanguageSetting(EnumStringSetting): """Available choices may change, so user's value may not be in choices anymore""" def _validate_selection(self, selection): - if selection != "" and not match_language( - # pylint: disable=no-member - selection, self.choices, fallback=None): + if selection != '' and not VALID_LANGUAGE_CODE.match(selection): raise ValidationException('Invalid language code: "{0}"'.format(selection)) def parse(self, data): @@ -181,6 +179,7 @@ class SearchLanguageSetting(EnumStringSetting): data = lang else: data = self.value + self._validate_selection(data) self.value = data diff --git a/searx/query.py b/searx/query.py index 2d5a72bcb..a9f343944 100644 --- a/searx/query.py +++ b/searx/query.py @@ -22,9 +22,7 @@ import re from searx.languages import language_codes from searx.engines import categories, engines, engine_shortcuts from searx.search import EngineRef - - -VALID_LANGUAGE_CODE = re.compile(r'^[a-z]{2,3}(-[a-zA-Z]{2})?$') +from searx.webutils import VALID_LANGUAGE_CODE class RawTextQuery: diff --git a/searx/webadapter.py b/searx/webadapter.py index 835cf2276..b9764c9ee 100644 --- a/searx/webadapter.py +++ b/searx/webadapter.py @@ -1,6 +1,7 @@ from typing import Dict, List, Optional, Tuple from searx.exceptions import SearxParameterException -from searx.query import RawTextQuery, VALID_LANGUAGE_CODE +from searx.webutils import VALID_LANGUAGE_CODE +from searx.query import RawTextQuery from searx.engines import categories, engines from searx.search import SearchQuery, EngineRef from searx.preferences import Preferences diff --git a/searx/webutils.py b/searx/webutils.py index 2900c0edd..6dd0243d8 100644 --- a/searx/webutils.py +++ b/searx/webutils.py @@ -11,6 +11,8 @@ from codecs import getincrementalencoder from searx import logger +VALID_LANGUAGE_CODE = re.compile(r'^[a-z]{2,3}(-[a-zA-Z]{2})?$') + logger = logger.getChild('webutils') |