SearXNG is a free internet metasearch engine which aggregates results from various search services and databases. Users are neither tracked nor profiled.
Python bingbravedegoogleduckduckgogooglemetasearchprivacypythonqwantsearchsearch-enginesearxsearxngstartpageyahoo
[enh] is_valid_lang moved to utils
potato983415bc3893
diff --git a/searx/engines/dictzone.py b/searx/engines/dictzone.pyindex 2c2ec3abc..5de6c5b98 100644--- a/searx/engines/dictzone.py+++ b/searx/engines/dictzone.py@@ -14,7 +14,7 @@ from urlparse import urljoinfrom lxml import htmlfrom cgi import escapefrom searx.engines.xpath import extract_text-from searx.languages import language_codes+from searx.utils import is_valid_langcategories = ['general']url = 'http://dictzone.com/{from_lang}-{to_lang}-dictionary/{query}'@@ -24,20 +24,6 @@ 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:@@ -51,8 +37,8 @@ def request(query, params):if not from_lang or not to_lang:return params- params['url'] = url.format(from_lang=from_lang[1],- to_lang=to_lang[1],+ params['url'] = url.format(from_lang=from_lang[2],+ to_lang=to_lang[2],query=query)return paramsdiff --git a/searx/engines/translated.py b/searx/engines/translated.pyindex 1b75e4f4e..3a077ae8e 100644--- a/searx/engines/translated.py+++ b/searx/engines/translated.py@@ -13,7 +13,7 @@ from urlparse import urljoinfrom lxml import htmlfrom cgi import escapefrom searx.engines.xpath import extract_text-from searx.languages import language_codes+from searx.utils import is_valid_langcategories = ['general']url = 'http://api.mymemory.translated.net/get?q={query}' \@@ -25,20 +25,6 @@ parser_re = re.compile(u'.*?([a-z]+)-([a-z]+) (.{2,})$', re.I)api_key = ''-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[0][:2], l[1].lower())- return False- else:- for l in language_codes:- if l[1].lower() == lang.lower():- return (True, l[0][:2], l[1].lower())- return False--def request(query, params):m = parser_re.match(unicode(query, 'utf8'))if not m:diff --git a/searx/utils.py b/searx/utils.pyindex 744142e36..b3806d3fd 100644--- a/searx/utils.py+++ b/searx/utils.py@@ -9,6 +9,7 @@ from HTMLParser import HTMLParserfrom random import choicefrom searx.version import VERSION_STRING+from searx.languages import language_codesfrom searx import settingsfrom searx import logger@@ -255,3 +256,17 @@ def get_torrent_size(filesize, filesize_multiplier):filesize = Nonereturn filesize+++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[0][:2], l[1].lower())+ return False+ else:+ for l in language_codes:+ if l[1].lower() == lang.lower():+ return (True, l[0][:2], l[1].lower())+ return False