From ca593728af10751fb0a313e2219e9091434d1035 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Mon, 26 Oct 2020 19:25:28 +0100 Subject: [mod] duckduckgo_definitions: display only user friendly attributes / URL various bug fixes --- searx/utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'searx/utils.py') diff --git a/searx/utils.py b/searx/utils.py index 1c10585cf..9e43c67f0 100644 --- a/searx/utils.py +++ b/searx/utils.py @@ -481,6 +481,16 @@ def ecma_unescape(s): return s +def get_string_replaces_function(replaces): + rep = {re.escape(k): v for k, v in replaces.items()} + pattern = re.compile("|".join(rep.keys())) + + def f(text): + return pattern.sub(lambda m: rep[re.escape(m.group(0))], text) + + return f + + def get_engine_from_settings(name): """Return engine configuration from settings.yml of a given engine name""" -- cgit v1.2.3