on master help sign in
Merge pull request #621 from stepshal/anomalous-backslash-in-string

Fix anomalous backslash in string

commitaa09f963eb8220f866334779f61741da8926fcf2 authorAdam Tauber <asciimoo@gmail.com> dateMon 18 Jul 2016, 22:27 (10 years ago) parent21c5fb1b3ab221
21 files changed+47−47
searx/engines/currency_convert.py+1−1 searx/engines/deviantart.py+1−1 searx/engines/google.py+2−2 searx/engines/startpage.py+5−5 searx/engines/swisscows.py+4−4 searx/engines/tokyotoshokan.py+1−1 searx/engines/www500px.py+1−1 searx/engines/yahoo_news.py+1−1 searx/plugins/https_rewrite.py+1−1 searx/results.py+1−1 searx/utils.py+1−1 tests/unit/engines/test_dailymotion.py+1−1 tests/unit/engines/test_deezer.py+2−2 tests/unit/engines/test_flickr.py+5−5 tests/unit/engines/test_flickr_noapi.py+1−1 tests/unit/engines/test_ina.py+12−12 tests/unit/engines/test_mediawiki.py+1−1 tests/unit/engines/test_mixcloud.py+1−1 tests/unit/engines/test_searchcode_code.py+1−1 tests/unit/engines/test_searchcode_doc.py+1−1 tests/unit/engines/test_wolframalpha_noapi.py+3−3
searx/engines/currency_convert.py+1−1
@@ -9,7 +9,7 @@ categories = []
99url = 'https://download.finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s={query}=X'
1010weight = 100
1111
12−parser_re = re.compile(u'.*?(\d+(?:\.\d+)?) ([^.0-9]+) (?:in|to) ([^.0-9]+)', re.I) # noqa
12+parser_re = re.compile(u'.*?(\\d+(?:\\.\\d+)?) ([^.0-9]+) (?:in|to) ([^.0-9]+)', re.I) # noqa
1313
1414db = 1
1515
searx/engines/deviantart.py+1−1
@@ -47,7 +47,7 @@ def response(resp):
4747
4848 dom = html.fromstring(resp.text)
4949
50− regex = re.compile('\/200H\/')
50+ regex = re.compile(r'\/200H\/')
5151
5252 # parse results
5353 for result in dom.xpath('//div[contains(@class, "tt-a tt-fh")]'):
searx/engines/google.py+2−2
@@ -300,9 +300,9 @@ def parse_map_detail(parsed_url, result, google_hostname):
300300 results = []
301301
302302 # try to parse the geoloc
303− m = re.search('@([0-9\.]+),([0-9\.]+),([0-9]+)', parsed_url.path)
303+ m = re.search(r'@([0-9\.]+),([0-9\.]+),([0-9]+)', parsed_url.path)
304304 if m is None:
305− m = re.search('ll\=([0-9\.]+),([0-9\.]+)\&z\=([0-9]+)', parsed_url.query)
305+ m = re.search(r'll\=([0-9\.]+),([0-9\.]+)\&z\=([0-9]+)', parsed_url.query)
306306
307307 if m is not None:
308308 # geoloc found (ignored)
searx/engines/startpage.py+5−5
@@ -68,15 +68,15 @@ def response(resp):
6868 url = link.attrib.get('href')
6969
7070 # block google-ad url's
71− if re.match("^http(s|)://(www\.)?google\.[a-z]+/aclk.*$", url):
71+ if re.match(r"^http(s|)://(www\.)?google\.[a-z]+/aclk.*$", url):
7272 continue
7373
7474 # block startpage search url's
75− if re.match("^http(s|)://(www\.)?startpage\.com/do/search\?.*$", url):
75+ if re.match(r"^http(s|)://(www\.)?startpage\.com/do/search\?.*$", url):
7676 continue
7777
7878 # block ixquick search url's
79− if re.match("^http(s|)://(www\.)?ixquick\.com/do/search\?.*$", url):
79+ if re.match(r"^http(s|)://(www\.)?ixquick\.com/do/search\?.*$", url):
8080 continue
8181
8282 title = escape(extract_text(link))
@@ -89,7 +89,7 @@ def response(resp):
8989 published_date = None
9090
9191 # check if search result starts with something like: "2 Sep 2014 ... "
92− if re.match("^([1-9]|[1-2][0-9]|3[0-1]) [A-Z][a-z]{2} [0-9]{4} \.\.\. ", content):
92+ if re.match(r"^([1-9]|[1-2][0-9]|3[0-1]) [A-Z][a-z]{2} [0-9]{4} \.\.\. ", content):
9393 date_pos = content.find('...') + 4
9494 date_string = content[0:date_pos - 5]
9595 published_date = parser.parse(date_string, dayfirst=True)
@@ -98,7 +98,7 @@ def response(resp):
9898 content = content[date_pos:]
9999
100100 # check if search result starts with something like: "5 days ago ... "
101− elif re.match("^[0-9]+ days? ago \.\.\. ", content):
101+ elif re.match(r"^[0-9]+ days? ago \.\.\. ", content):
102102 date_pos = content.find('...') + 4
103103 date_string = content[0:date_pos - 5]
104104
searx/engines/swisscows.py+4−4
@@ -25,10 +25,10 @@ base_url = 'https://swisscows.ch/'
2525search_string = '?{query}&page={page}'
2626
2727# regex
28−regex_json = re.compile('initialData: {"Request":(.|\n)*},\s*environment')
29−regex_json_remove_start = re.compile('^initialData:\s*')
30−regex_json_remove_end = re.compile(',\s*environment$')
31−regex_img_url_remove_start = re.compile('^https?://i\.swisscows\.ch/\?link=')
28+regex_json = re.compile(r'initialData: {"Request":(.|\n)*},\s*environment')
29+regex_json_remove_start = re.compile(r'^initialData:\s*')
30+regex_json_remove_end = re.compile(r',\s*environment$')
31+regex_img_url_remove_start = re.compile(r'^https?://i\.swisscows\.ch/\?link=')
3232
3333
3434# do search-request
searx/engines/tokyotoshokan.py+1−1
@@ -48,7 +48,7 @@ def response(resp):
4848 return []
4949
5050 # regular expression for parsing torrent size strings
51− size_re = re.compile('Size:\s*([\d.]+)(TB|GB|MB|B)', re.IGNORECASE)
51+ size_re = re.compile(r'Size:\s*([\d.]+)(TB|GB|MB|B)', re.IGNORECASE)
5252
5353 # processing the results, two rows at a time
5454 for i in xrange(0, len(rows), 2):
searx/engines/www500px.py+1−1
@@ -41,7 +41,7 @@ def response(resp):
4141 results = []
4242
4343 dom = html.fromstring(resp.text)
44− regex = re.compile('3\.jpg.*$')
44+ regex = re.compile(r'3\.jpg.*$')
4545
4646 # parse results
4747 for result in dom.xpath('//div[@class="photo"]'):
searx/engines/yahoo_news.py+1−1
@@ -55,7 +55,7 @@ def request(query, params):
5555
5656def sanitize_url(url):
5757 if ".yahoo.com/" in url:
58− return re.sub(u"\;\_ylt\=.+$", "", url)
58+ return re.sub(u"\\;\\_ylt\\=.+$", "", url)
5959 else:
6060 return url
6161
searx/plugins/https_rewrite.py+1−1
@@ -87,7 +87,7 @@ def load_single_https_ruleset(rules_path):
8787
8888 # convert host-rule to valid regex
8989 host = ruleset.attrib.get('host')\
90− .replace('.', '\.').replace('*', '.*')
90+ .replace('.', r'\.').replace('*', '.*')
9191
9292 # append to host list
9393 hosts.append(host)
searx/results.py+1−1
@@ -5,7 +5,7 @@ from threading import RLock
55from urlparse import urlparse, unquote
66from searx.engines import engines
77
8−CONTENT_LEN_IGNORED_CHARS_REGEX = re.compile('[,;:!?\./\\\\ ()-_]', re.M | re.U)
8+CONTENT_LEN_IGNORED_CHARS_REGEX = re.compile(r'[,;:!?\./\\\\ ()-_]', re.M | re.U)
99WHITESPACE_REGEX = re.compile('( |\t|\n)+', re.M | re.U)
1010
1111
searx/utils.py+1−1
@@ -63,7 +63,7 @@ def highlight_content(content, query):
6363 regex_parts = []
6464 for chunk in query.split():
6565 if len(chunk) == 1:
66− regex_parts.append(u'\W+{0}\W+'.format(re.escape(chunk)))
66+ regex_parts.append(u'\\W+{0}\\W+'.format(re.escape(chunk)))
6767 else:
6868 regex_parts.append(u'{0}'.format(re.escape(chunk)))
6969 query_regex = u'({0})'.format('|'.join(regex_parts))
tests/unit/engines/test_dailymotion.py+1−1
@@ -62,7 +62,7 @@ class TestDailymotionEngine(SearxTestCase):
6262 self.assertEqual(results[0]['content'], 'Description')
6363 self.assertIn('x2fit7q', results[0]['embedded'])
6464
65− json = """
65+ json = r"""
6666 {"toto":[
6767 {"id":200,"name":"Artist Name",
6868 "link":"http:\/\/www.dailymotion.com\/artist\/1217","type":"artist"}
tests/unit/engines/test_deezer.py+2−2
@@ -27,7 +27,7 @@ class TestDeezerEngine(SearxTestCase):
2727 response = mock.Mock(text='{"data": []}')
2828 self.assertEqual(deezer.response(response), [])
2929
30− json = """
30+ json = r"""
3131 {"data":[
3232 {"id":100, "title":"Title of track",
3333 "link":"https:\/\/www.deezer.com\/track\/1094042","duration":232,
@@ -45,7 +45,7 @@ class TestDeezerEngine(SearxTestCase):
4545 self.assertEqual(results[0]['content'], 'Artist Name &bull; Album Title &bull; Title of track')
4646 self.assertTrue('100' in results[0]['embedded'])
4747
48− json = """
48+ json = r"""
4949 {"data":[
5050 {"id":200,"name":"Artist Name",
5151 "link":"https:\/\/www.deezer.com\/artist\/1217","type":"artist"}
tests/unit/engines/test_flickr.py+5−5
@@ -27,7 +27,7 @@ class TestFlickrEngine(SearxTestCase):
2727 response = mock.Mock(text='{"data": []}')
2828 self.assertEqual(flickr.response(response), [])
2929
30− json = """
30+ json = r"""
3131 { "photos": { "page": 1, "pages": "41001", "perpage": 100, "total": "4100032",
3232 "photo": [
3333 { "id": "15751017054", "owner": "66847915@N08",
@@ -55,7 +55,7 @@ class TestFlickrEngine(SearxTestCase):
5555 self.assertTrue('Owner' in results[0]['content'])
5656 self.assertTrue('Description' in results[0]['content'])
5757
58− json = """
58+ json = r"""
5959 { "photos": { "page": 1, "pages": "41001", "perpage": 100, "total": "4100032",
6060 "photo": [
6161 { "id": "15751017054", "owner": "66847915@N08",
@@ -79,7 +79,7 @@ class TestFlickrEngine(SearxTestCase):
7979 self.assertTrue('Owner' in results[0]['content'])
8080 self.assertTrue('Description' in results[0]['content'])
8181
82− json = """
82+ json = r"""
8383 { "photos": { "page": 1, "pages": "41001", "perpage": 100, "total": "4100032",
8484 "photo": [
8585 { "id": "15751017054", "owner": "66847915@N08",
@@ -103,7 +103,7 @@ class TestFlickrEngine(SearxTestCase):
103103 self.assertTrue('Owner' in results[0]['content'])
104104 self.assertTrue('Description' in results[0]['content'])
105105
106− json = """
106+ json = r"""
107107 { "photos": { "page": 1, "pages": "41001", "perpage": 100, "total": "4100032",
108108 "photo": [
109109 { "id": "15751017054", "owner": "66847915@N08",
@@ -130,7 +130,7 @@ class TestFlickrEngine(SearxTestCase):
130130 self.assertEqual(type(results), list)
131131 self.assertEqual(len(results), 0)
132132
133− json = """
133+ json = r"""
134134 {"toto":[
135135 {"id":200,"name":"Artist Name",
136136 "link":"http:\/\/www.flickr.com\/artist\/1217","type":"artist"}
tests/unit/engines/test_flickr_noapi.py+1−1
@@ -316,7 +316,7 @@ class TestFlickrNoapiEngine(SearxTestCase):
316316 self.assertEqual(len(results), 0)
317317
318318 # garbage test
319− json = """
319+ json = r"""
320320 {"toto":[
321321 {"id":200,"name":"Artist Name",
322322 "link":"http:\/\/www.flickr.com\/artist\/1217","type":"artist"}
tests/unit/engines/test_ina.py+12−12
@@ -33,23 +33,23 @@ class TestInaEngine(SearxTestCase):
3333 <div class=\\"search-results--list\\"><div class=\\"media\\">\\n\
3434 \\t\\t\\t\\t<a class=\\"media-left media-video premium xiti_click_action\\" \
3535 data-xiti-params=\\"recherche_v4::resultats_conference_de_presse_du_general_de_gaulle::N\\" \
36− href=\\"\/video\/CAF89035682\/conference-de-presse-du-general-de-gaulle-video.html\\">\\n\
37− <img src=\\"https:\/\/www.ina.fr\/images_v2\/140x105\/CAF89035682.jpeg\\" \
36+ href=\\"\\/video\\/CAF89035682\\/conference-de-presse-du-general-de-gaulle-video.html\\">\\n\
37+ <img src=\\"https:\\/\\/www.ina.fr\\/images_v2\\/140x105\\/CAF89035682.jpeg\\" \
3838 alt=\\"Conf\\u00e9rence de presse du G\\u00e9n\\u00e9ral de Gaulle \\">\\n\
39− \\t\\t\\t\\t\\t<\/a>\\n\
39+ \\t\\t\\t\\t\\t<\\/a>\\n\
4040 \\t\\t\\t\\t\\t<div class=\\"media-body\\">\\n\\t\\t\\t\\t\\t\\t<h3 class=\\"h3--title media-heading\\">\\n\
4141 \\t\\t\\t\\t\\t\\t\\t<a class=\\"xiti_click_action\\" \
4242 data-xiti-params=\\"recherche_v4::resultats_conference_de_presse_du_general_de_gaulle::N\\" \
43− href=\\"\/video\/CAF89035682\/conference-de-presse-du-general-de-gaulle-video.html\\">\
44− Conf\\u00e9rence de presse du G\\u00e9n\\u00e9ral de Gaulle <\/a>\\n\
45− <\/h3>\\n\
46− <div class=\\"media-body__info\\">\\n<span class=\\"broadcast\\">27\/11\/1967<\/span>\\n\
47− <span class=\\"views\\">29321 vues<\/span>\\n\
48− <span class=\\"duration\\">01h 33m 07s<\/span>\\n\
49− <\/div>\\n\
43+ href=\\"\\/video\\/CAF89035682\\/conference-de-presse-du-general-de-gaulle-video.html\\">\
44+ Conf\\u00e9rence de presse du G\\u00e9n\\u00e9ral de Gaulle <\\/a>\\n\
45+ <\\/h3>\\n\
46+ <div class=\\"media-body__info\\">\\n<span class=\\"broadcast\\">27\\/11\\/1967<\\/span>\\n\
47+ <span class=\\"views\\">29321 vues<\\/span>\\n\
48+ <span class=\\"duration\\">01h 33m 07s<\\/span>\\n\
49+ <\\/div>\\n\
5050 <p class=\\"media-body__summary\\">VERSION INTEGRALE DE LA CONFERENCE DE PRESSE DU GENERAL DE GAULLE . \
51− - PA le Pr\\u00e9sident DE GAULLE : il ouvre les bras et s'assied. DP journalis...<\/p>\\n\
52− <\/div>\\n<\/div><!-- \/.media -->\\n"
51+ - PA le Pr\\u00e9sident DE GAULLE : il ouvre les bras et s'assied. DP journalis...<\\/p>\\n\
52+ <\\/div>\\n<\\/div><!-- \\/.media -->\\n"
5353 }
5454 """
5555 response = mock.Mock(text=json)
tests/unit/engines/test_mediawiki.py+1−1
@@ -118,7 +118,7 @@ class TestMediawikiEngine(SearxTestCase):
118118 self.assertEqual(type(results), list)
119119 self.assertEqual(len(results), 0)
120120
121− json = """
121+ json = r"""
122122 {"toto":[
123123 {"id":200,"name":"Artist Name",
124124 "link":"http:\/\/www.mediawiki.com\/artist\/1217","type":"artist"}
tests/unit/engines/test_mixcloud.py+1−1
@@ -55,7 +55,7 @@ class TestMixcloudEngine(SearxTestCase):
5555 self.assertEqual(results[0]['content'], 'User')
5656 self.assertTrue('http://www.mixcloud.com/user/this-is-the-url/' in results[0]['embedded'])
5757
58− json = """
58+ json = r"""
5959 {"toto":[
6060 {"id":200,"name":"Artist Name",
6161 "link":"http:\/\/www.mixcloud.com\/artist\/1217","type":"artist"}
tests/unit/engines/test_searchcode_code.py+1−1
@@ -63,7 +63,7 @@ class TestSearchcodeCodeEngine(SearxTestCase):
6363 self.assertEqual(results[0]['repository'], 'https://repo')
6464 self.assertEqual(results[0]['code_language'], 'cpp')
6565
66− json = """
66+ json = r"""
6767 {"toto":[
6868 {"id":200,"name":"Artist Name",
6969 "link":"http:\/\/www.searchcode_code.com\/artist\/1217","type":"artist"}
tests/unit/engines/test_searchcode_doc.py+1−1
@@ -61,7 +61,7 @@ class TestSearchcodeDocEngine(SearxTestCase):
6161 self.assertIn('test', results[0]['content'])
6262 self.assertIn('Description', results[0]['content'])
6363
64− json = """
64+ json = r"""
6565 {"toto":[
6666 {"id":200,"name":"Artist Name",
6767 "link":"http:\/\/www.searchcode_doc.com\/artist\/1217","type":"artist"}
tests/unit/engines/test_wolframalpha_noapi.py+3−3
@@ -28,7 +28,7 @@ class TestWolframAlphaNoAPIEngine(SearxTestCase):
2828 request = Request(headers={'Referer': referer_url})
2929
3030 # test failure
31− json = '''
31+ json = r'''
3232 {"queryresult" : {
3333 "success" : false,
3434 "error" : false,
@@ -42,7 +42,7 @@ class TestWolframAlphaNoAPIEngine(SearxTestCase):
4242 self.assertEqual(wolframalpha_noapi.response(response), [])
4343
4444 # test basic case
45− json = '''
45+ json = r'''
4646 {"queryresult" : {
4747 "success" : true,
4848 "error" : false,
@@ -143,7 +143,7 @@ class TestWolframAlphaNoAPIEngine(SearxTestCase):
143143 self.assertEqual('Wolfram|Alpha', results[1]['title'])
144144
145145 # test calc
146− json = """
146+ json = r"""
147147 {"queryresult" : {
148148 "success" : true,
149149 "error" : false,