logo

searx

My custom branche(s) on searx, a meta-search engine
commit: 8db527c1d233888b197bd2e8b2fbda8e88d0c60d
parent: 259735f30901ae884f8234f1f138c28a9e59713a
Author: Adam Tauber <asciimoo@gmail.com>
Date:   Mon, 22 May 2017 15:36:52 +0200

[fix] use raw response with etree.parsefromstring - Unicode strings with encoding declaration are not supported

Diffstat:

Msearx/engines/bing_news.py2+-
Mtests/unit/engines/test_bing_news.py12++++++------
2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/searx/engines/bing_news.py b/searx/engines/bing_news.py @@ -85,7 +85,7 @@ def request(query, params): def response(resp): results = [] - rss = etree.fromstring(resp.text) + rss = etree.fromstring(resp.content) ns = rss.nsmap diff --git a/tests/unit/engines/test_bing_news.py b/tests/unit/engines/test_bing_news.py @@ -36,10 +36,10 @@ class TestBingNewsEngine(SearxTestCase): 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), []) - response = mock.Mock(text='<html></html>') + response = mock.Mock(content='<html></html>') self.assertEqual(bing_news.response(response), []) html = """<?xml version="1.0" encoding="utf-8" ?> @@ -74,7 +74,7 @@ class TestBingNewsEngine(SearxTestCase): </item> </channel> </rss>""" # noqa - response = mock.Mock(text=html.encode('utf-8')) + response = mock.Mock(content=html.encode('utf-8')) results = bing_news.response(response) self.assertEqual(type(results), list) self.assertEqual(len(results), 2) @@ -113,7 +113,7 @@ class TestBingNewsEngine(SearxTestCase): </item> </channel> </rss>""" # noqa - response = mock.Mock(text=html.encode('utf-8')) + response = mock.Mock(content=html.encode('utf-8')) results = bing_news.response(response) self.assertEqual(type(results), list) self.assertEqual(len(results), 1) @@ -136,11 +136,11 @@ class TestBingNewsEngine(SearxTestCase): </channel> </rss>""" # noqa - response = mock.Mock(text=html.encode('utf-8')) + response = mock.Mock(content=html.encode('utf-8')) results = bing_news.response(response) self.assertEqual(type(results), list) self.assertEqual(len(results), 0) 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)