1
0
mirror of https://github.com/searxng/searxng.git synced 2024-11-19 02:40:11 +01:00

[fix] bing unicode encode error - fixes #408

This commit is contained in:
Adam Tauber 2015-08-28 14:51:32 +02:00
parent b9c8039d74
commit 604f32f672
6 changed files with 18 additions and 18 deletions

View File

@ -52,7 +52,7 @@ def request(query, params):
def response(resp): def response(resp):
results = [] results = []
dom = html.fromstring(resp.content) dom = html.fromstring(resp.text)
# parse results # parse results
for result in dom.xpath('//div[@class="sa_cc"]'): for result in dom.xpath('//div[@class="sa_cc"]'):

View File

@ -63,7 +63,7 @@ def request(query, params):
def response(resp): def response(resp):
results = [] results = []
dom = html.fromstring(resp.content) dom = html.fromstring(resp.text)
# init regex for yaml-parsing # init regex for yaml-parsing
p = re.compile('({|,)([a-z]+):(")') p = re.compile('({|,)([a-z]+):(")')

View File

@ -68,7 +68,7 @@ def request(query, params):
def response(resp): def response(resp):
results = [] results = []
rss = etree.fromstring(resp.content) rss = etree.fromstring(resp.text)
ns = rss.nsmap ns = rss.nsmap

View File

@ -29,10 +29,10 @@ class TestBingEngine(SearxTestCase):
self.assertRaises(AttributeError, bing.response, '') self.assertRaises(AttributeError, bing.response, '')
self.assertRaises(AttributeError, bing.response, '[]') self.assertRaises(AttributeError, bing.response, '[]')
response = mock.Mock(content='<html></html>') response = mock.Mock(text='<html></html>')
self.assertEqual(bing.response(response), []) self.assertEqual(bing.response(response), [])
response = mock.Mock(content='<html></html>') response = mock.Mock(text='<html></html>')
self.assertEqual(bing.response(response), []) self.assertEqual(bing.response(response), [])
html = """ html = """
@ -54,7 +54,7 @@ class TestBingEngine(SearxTestCase):
</div> </div>
</div> </div>
""" """
response = mock.Mock(content=html) response = mock.Mock(text=html)
results = bing.response(response) results = bing.response(response)
self.assertEqual(type(results), list) self.assertEqual(type(results), list)
self.assertEqual(len(results), 1) self.assertEqual(len(results), 1)
@ -81,7 +81,7 @@ class TestBingEngine(SearxTestCase):
</div> </div>
</li> </li>
""" """
response = mock.Mock(content=html) response = mock.Mock(text=html)
results = bing.response(response) results = bing.response(response)
self.assertEqual(type(results), list) self.assertEqual(type(results), list)
self.assertEqual(len(results), 1) self.assertEqual(len(results), 1)

View File

@ -31,10 +31,10 @@ class TestBingImagesEngine(SearxTestCase):
self.assertRaises(AttributeError, bing_images.response, '') self.assertRaises(AttributeError, bing_images.response, '')
self.assertRaises(AttributeError, bing_images.response, '[]') self.assertRaises(AttributeError, bing_images.response, '[]')
response = mock.Mock(content='<html></html>') response = mock.Mock(text='<html></html>')
self.assertEqual(bing_images.response(response), []) self.assertEqual(bing_images.response(response), [])
response = mock.Mock(content='<html></html>') response = mock.Mock(text='<html></html>')
self.assertEqual(bing_images.response(response), []) self.assertEqual(bing_images.response(response), [])
html = """ html = """
@ -52,7 +52,7 @@ oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%2
</div> </div>
""" """
html = html.replace('\r\n', '').replace('\n', '').replace('\r', '') html = html.replace('\r\n', '').replace('\n', '').replace('\r', '')
response = mock.Mock(content=html) response = mock.Mock(text=html)
results = bing_images.response(response) results = bing_images.response(response)
self.assertEqual(type(results), list) self.assertEqual(type(results), list)
self.assertEqual(len(results), 1) self.assertEqual(len(results), 1)
@ -75,7 +75,7 @@ oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%2
style="height:144px;" width="178" height="144"/> style="height:144px;" width="178" height="144"/>
</a> </a>
""" """
response = mock.Mock(content=html) response = mock.Mock(text=html)
results = bing_images.response(response) results = bing_images.response(response)
self.assertEqual(type(results), list) self.assertEqual(type(results), list)
self.assertEqual(len(results), 0) self.assertEqual(len(results), 0)
@ -263,7 +263,7 @@ oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%2
</div> </div>
""" """
html = html.replace('\r\n', '').replace('\n', '').replace('\r', '') html = html.replace('\r\n', '').replace('\n', '').replace('\r', '')
response = mock.Mock(content=html) response = mock.Mock(text=html)
results = bing_images.response(response) results = bing_images.response(response)
self.assertEqual(type(results), list) self.assertEqual(type(results), list)
self.assertEqual(len(results), 10) self.assertEqual(len(results), 10)

View File

@ -28,10 +28,10 @@ class TestBingNewsEngine(SearxTestCase):
self.assertRaises(AttributeError, bing_news.response, '') self.assertRaises(AttributeError, bing_news.response, '')
self.assertRaises(AttributeError, bing_news.response, '[]') self.assertRaises(AttributeError, bing_news.response, '[]')
response = mock.Mock(content='<html></html>') response = mock.Mock(text='<html></html>')
self.assertEqual(bing_news.response(response), []) self.assertEqual(bing_news.response(response), [])
response = mock.Mock(content='<html></html>') response = mock.Mock(text='<html></html>')
self.assertEqual(bing_news.response(response), []) self.assertEqual(bing_news.response(response), [])
html = """<?xml version="1.0" encoding="utf-8" ?> html = """<?xml version="1.0" encoding="utf-8" ?>
@ -66,7 +66,7 @@ class TestBingNewsEngine(SearxTestCase):
</item> </item>
</channel> </channel>
</rss>""" # noqa </rss>""" # noqa
response = mock.Mock(content=html) response = mock.Mock(text=html)
results = bing_news.response(response) results = bing_news.response(response)
self.assertEqual(type(results), list) self.assertEqual(type(results), list)
self.assertEqual(len(results), 2) self.assertEqual(len(results), 2)
@ -105,7 +105,7 @@ class TestBingNewsEngine(SearxTestCase):
</item> </item>
</channel> </channel>
</rss>""" # noqa </rss>""" # noqa
response = mock.Mock(content=html) response = mock.Mock(text=html)
results = bing_news.response(response) results = bing_news.response(response)
self.assertEqual(type(results), list) self.assertEqual(type(results), list)
self.assertEqual(len(results), 1) self.assertEqual(len(results), 1)
@ -128,11 +128,11 @@ class TestBingNewsEngine(SearxTestCase):
</channel> </channel>
</rss>""" # noqa </rss>""" # noqa
response = mock.Mock(content=html) response = mock.Mock(text=html)
results = bing_news.response(response) results = bing_news.response(response)
self.assertEqual(type(results), list) self.assertEqual(type(results), list)
self.assertEqual(len(results), 0) self.assertEqual(len(results), 0)
html = """<?xml version="1.0" encoding="utf-8" ?>gabarge""" html = """<?xml version="1.0" encoding="utf-8" ?>gabarge"""
response = mock.Mock(content=html) response = mock.Mock(text=html)
self.assertRaises(lxml.etree.XMLSyntaxError, bing_news.response, response) self.assertRaises(lxml.etree.XMLSyntaxError, bing_news.response, response)