on master help sign in
[pylint] Startpage engine
a6184acMarkus Heiser
searx/engines/startpage.py+25−13
@@ -1,17 +1,20 @@
1# SPDX-License-Identifier: AGPL-3.0-or-later
1# SPDX-License-Identifier: AGPL-3.0-or-later
2+# lint: pylint
3+"""Startpage (Web)
4+
2"""
5"""
3− Startpage (Web)
6+
4−"""
7+import re
5
8
6from urllib.parse import urlencode
9from urllib.parse import urlencode
10+from unicodedata import normalize, combining
11+from datetime import datetime, timedelta
7
12
8−from lxml import html
9from dateutil import parser
13from dateutil import parser
10−from datetime import datetime, timedelta
11−import re
14+from lxml import html
12−from unicodedata import normalize, combining
13from babel import Locale
15from babel import Locale
14from babel.localedata import locale_identifiers
16from babel.localedata import locale_identifiers
17+
15from searx.utils import extract_text, eval_xpath, match_language
18from searx.utils import extract_text, eval_xpath, match_language
16
19
17# about
20# about
@@ -140,10 +143,11 @@ def response(resp):
140
143
141# get supported languages from their site
144# get supported languages from their site
142def _fetch_supported_languages(resp):
145def _fetch_supported_languages(resp):
143− # startpage's language selector is a mess
146+ # startpage's language selector is a mess each option has a displayed name
144− # each option has a displayed name and a value, either of which may represent the language name
147+ # and a value, either of which may represent the language name in the native
145− # in the native script, the language name in English, an English transliteration of the native name,
148+ # script, the language name in English, an English transliteration of the
146− # the English name of the writing script used by the language, or occasionally something else entirely.
149+ # native name, the English name of the writing script used by the language,
150+ # or occasionally something else entirely.
147
151
148 # this cases are so special they need to be hardcoded, a couple of them are mispellings
152 # this cases are so special they need to be hardcoded, a couple of them are mispellings
149 language_names = {
153 language_names = {
@@ -157,7 +161,15 @@ def _fetch_supported_languages(resp):
157 }
161 }
158
162
159 # get the English name of every language known by babel
163 # get the English name of every language known by babel
164+ language_names.update(
165+ {
166+ # fmt: off
167+ name.lower(): lang_code
168+ # pylint: disable=protected-access
160− language_names.update({name.lower(): lang_code for lang_code, name in Locale('en')._data['languages'].items()})
169+ for lang_code, name in Locale('en')._data['languages'].items()
170+ # fmt: on
171+ }
172+ )
161
173
162 # get the native name of every language known by babel
174 # get the native name of every language known by babel
163 for lang_code in filter(lambda lang_code: lang_code.find('_') == -1, locale_identifiers()):
175 for lang_code in filter(lambda lang_code: lang_code.find('_') == -1, locale_identifiers()):
@@ -182,8 +194,8 @@ def _fetch_supported_languages(resp):
182 if isinstance(lang_code, str):
194 if isinstance(lang_code, str):
183 supported_languages[lang_code] = {'alias': sp_option_value}
195 supported_languages[lang_code] = {'alias': sp_option_value}
184 elif isinstance(lang_code, list):
196 elif isinstance(lang_code, list):
185− for lc in lang_code:
197+ for _lc in lang_code:
186− supported_languages[lc] = {'alias': sp_option_value}
198+ supported_languages[_lc] = {'alias': sp_option_value}
187 else:
199 else:
188 print('Unknown language option in Startpage: {} ({})'.format(sp_option_value, sp_option_text))
200 print('Unknown language option in Startpage: {} ({})'.format(sp_option_value, sp_option_text))
189
201