From 72459b246be8dbf7f237b48677b0dfecb60d43ef Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Wed, 16 Oct 2019 14:52:57 +0200 Subject: [fix] convert bytes type to string in language detection (fixes dictzone) --- searx/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'searx/utils.py') diff --git a/searx/utils.py b/searx/utils.py index d88bc9897..eb5da2fa7 100644 --- a/searx/utils.py +++ b/searx/utils.py @@ -308,14 +308,15 @@ def int_or_zero(num): def is_valid_lang(lang): is_abbr = (len(lang) == 2) + lang = lang.lower().decode('utf-8') if is_abbr: for l in language_codes: - if l[0][:2] == lang.lower(): + if l[0][:2] == lang: return (True, l[0][:2], l[3].lower()) return False else: for l in language_codes: - if l[1].lower() == lang.lower(): + if l[1].lower() == lang or l[3].lower() == lang: return (True, l[0][:2], l[3].lower()) return False -- cgit v1.2.3 From a6f20caf32af463b57a026ee7cb7ed6317db6b8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mi=20V=C3=A1nyi?= Date: Mon, 23 Sep 2019 17:14:32 +0200 Subject: add initial support for offline engines && command engine --- searx/utils.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'searx/utils.py') diff --git a/searx/utils.py b/searx/utils.py index eb5da2fa7..4029cf2ae 100644 --- a/searx/utils.py +++ b/searx/utils.py @@ -435,3 +435,18 @@ def ecma_unescape(s): # "%20" becomes " ", "%F3" becomes "รณ" s = ecma_unescape2_re.sub(lambda e: unichr(int(e.group(1), 16)), s) return s + + +def get_engine_from_settings(name): + """Return engine configuration from settings.yml of a given engine name""" + + if 'engines' not in settings: + return {} + + for engine in settings['engines']: + if 'name' not in engine: + continue + if name == engine['name']: + return engine + + return {} -- cgit v1.2.3 From 5796dc60c9de4f8c54452bb0bd64ed993378e503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mi=20V=C3=A1nyi?= Date: Mon, 30 Sep 2019 14:27:13 +0200 Subject: fix pep 8 check --- searx/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'searx/utils.py') diff --git a/searx/utils.py b/searx/utils.py index 4029cf2ae..e61a134f7 100644 --- a/searx/utils.py +++ b/searx/utils.py @@ -443,7 +443,7 @@ def get_engine_from_settings(name): if 'engines' not in settings: return {} - for engine in settings['engines']: + for engine in settings['engines']: if 'name' not in engine: continue if name == engine['name']: -- cgit v1.2.3 From 85b37233458c21b775bf98568c0a5c9260aa14fe Mon Sep 17 00:00:00 2001 From: Dalf Date: Fri, 15 Nov 2019 09:31:37 +0100 Subject: [mod] speed optimization compile XPath only once avoid redundant call to urlparse get_locale(webapp.py): avoid useless call to request.accept_languages.best_match --- searx/utils.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'searx/utils.py') diff --git a/searx/utils.py b/searx/utils.py index e61a134f7..5ea9dc89c 100644 --- a/searx/utils.py +++ b/searx/utils.py @@ -13,6 +13,7 @@ from numbers import Number from os.path import splitext, join from io import open from random import choice +from lxml.etree import XPath import sys import json @@ -51,6 +52,7 @@ ecma_unescape2_re = re.compile(r'%([0-9a-fA-F]{2})', re.UNICODE) useragents = json.loads(open(os.path.dirname(os.path.realpath(__file__)) + "/data/useragents.json", 'r', encoding='utf-8').read()) +xpath_cache = dict() lang_to_lc_cache = dict() @@ -450,3 +452,16 @@ def get_engine_from_settings(name): return engine return {} + + +def get_xpath(xpath_str): + result = xpath_cache.get(xpath_str, None) + if result is None: + result = XPath(xpath_str) + xpath_cache[xpath_str] = result + return result + + +def eval_xpath(element, xpath_str): + xpath = get_xpath(xpath_str) + return xpath(element) -- cgit v1.2.3