mirror of https://github.com/searxng/searxng.git
[fix] use raw response with etree.parsefromstring - Unicode strings with encoding declaration are not supported
This commit is contained in:
parent
259735f309
commit
8db527c1d2
|
@ -85,7 +85,7 @@ def request(query, params):
|
||||||
def response(resp):
|
def response(resp):
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
rss = etree.fromstring(resp.text)
|
rss = etree.fromstring(resp.content)
|
||||||
|
|
||||||
ns = rss.nsmap
|
ns = rss.nsmap
|
||||||
|
|
||||||
|
|
|
@ -36,10 +36,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(text='<html></html>')
|
response = mock.Mock(content='<html></html>')
|
||||||
self.assertEqual(bing_news.response(response), [])
|
self.assertEqual(bing_news.response(response), [])
|
||||||
|
|
||||||
response = mock.Mock(text='<html></html>')
|
response = mock.Mock(content='<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" ?>
|
||||||
|
@ -74,7 +74,7 @@ class TestBingNewsEngine(SearxTestCase):
|
||||||
</item>
|
</item>
|
||||||
</channel>
|
</channel>
|
||||||
</rss>""" # noqa
|
</rss>""" # noqa
|
||||||
response = mock.Mock(text=html.encode('utf-8'))
|
response = mock.Mock(content=html.encode('utf-8'))
|
||||||
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)
|
||||||
|
@ -113,7 +113,7 @@ class TestBingNewsEngine(SearxTestCase):
|
||||||
</item>
|
</item>
|
||||||
</channel>
|
</channel>
|
||||||
</rss>""" # noqa
|
</rss>""" # noqa
|
||||||
response = mock.Mock(text=html.encode('utf-8'))
|
response = mock.Mock(content=html.encode('utf-8'))
|
||||||
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)
|
||||||
|
@ -136,11 +136,11 @@ class TestBingNewsEngine(SearxTestCase):
|
||||||
</channel>
|
</channel>
|
||||||
</rss>""" # noqa
|
</rss>""" # noqa
|
||||||
|
|
||||||
response = mock.Mock(text=html.encode('utf-8'))
|
response = mock.Mock(content=html.encode('utf-8'))
|
||||||
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(text=html.encode('utf-8'))
|
response = mock.Mock(content=html.encode('utf-8'))
|
||||||
self.assertRaises(lxml.etree.XMLSyntaxError, bing_news.response, response)
|
self.assertRaises(lxml.etree.XMLSyntaxError, bing_news.response, response)
|
||||||
|
|
Loading…
Reference in New Issue