summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpotato <mail@crazypotato.tk>2016-09-06 14:12:46 +0200
committerpotato <mail@crazypotato.tk>2016-09-06 14:12:46 +0200
commitbc806bfab1cc75279dc912bf443dc39178a872dd (patch)
tree83cf3fcce4ff06a47e2cf16470c24b79e0b3cfb8
parent5416f0f248e1c8072c69b4a272af07bd4c0d8e5e (diff)
downloadsearxng-bc806bfab1cc75279dc912bf443dc39178a872dd.tar.gz
searxng-bc806bfab1cc75279dc912bf443dc39178a872dd.zip
[fix] no lambda anymore, cgi.escape
-rw-r--r--searx/engines/dictzone.py43
1 files changed, 22 insertions, 21 deletions
diff --git a/searx/engines/dictzone.py b/searx/engines/dictzone.py
index b255463aa..f68f44887 100644
--- a/searx/engines/dictzone.py
+++ b/searx/engines/dictzone.py
@@ -1,6 +1,7 @@
import re
from urlparse import urljoin
from lxml import html
+from cgi import escape
from searx.engines.xpath import extract_text
from searx.languages import language_codes
@@ -12,6 +13,19 @@ parser_re = re.compile(u'.*?([a-z]+)-([a-z]+) (.+)', re.I)
results_xpath = './/table[@id="r"]/tr'
+def is_valid_lang(lang):
+ is_abbr = (len(lang) == 2)
+ if is_abbr:
+ for l in language_codes:
+ if l[0][:2] == lang.lower():
+ return (True, l[1].lower())
+ return False
+ else:
+ for l in language_codes:
+ if l[1].lower() == lang.lower():
+ return (True, l[1].lower())
+ return False
+
def request(query, params):
m = parser_re.match(unicode(query, 'utf8'))
if not m:
@@ -19,28 +33,15 @@ def request(query, params):
from_lang, to_lang, query = m.groups()
- if len(from_lang) == 2:
- lan = filter(lambda x: x[0][:2] == from_lang, language_codes)
- if lan:
- from_lang = lan[0][1].lower()
- else:
- return params
- elif from_lang.lower() not in [x[1].lower() for x in language_codes]:
- return params
-
+ from_lang = is_valid_lang(from_lang)
+ to_lang = is_valid_lang(to_lang)
- if len(to_lang) == 2:
- lan = filter(lambda x: x[0][:2] == to_lang, language_codes)
- if lan:
- to_lang = lan[0][1].lower()
- else:
- return params
- elif to_lang.lower() not in [x[1].lower() for x in language_codes]:
+ if not from_lang or not to_lang:
return params
- params['url'] = url.format(from_lang=from_lang, to_lang=to_lang,query=query)
- params['from_lang'] = from_lang
- params['to_lang'] = to_lang
+ params['url'] = url.format(from_lang=from_lang[1], to_lang=to_lang[1],query=query)
+ params['from_lang'] = from_lang[1]
+ params['to_lang'] = to_lang[1]
params['query'] = query
return params
@@ -64,8 +65,8 @@ def response(resp):
results.append({
'url': urljoin(resp.url, '?%d' % k),
- 'title': from_result.text_content(),
- 'content': '; '.join(to_results)
+ 'title': escape(from_result.text_content()),
+ 'content': escape('; '.join(to_results))
})
return results