From e9ba2366fa53bbfdcade657c692d037f095a75d0 Mon Sep 17 00:00:00 2001 From: Nicolas Gelot Date: Fri, 11 Jan 2019 09:31:23 +0100 Subject: [PATCH] Revert wrong encoding changes This patch reverts some wrong changes about encoding from 2cc4bf3eaa5cbab007b56ad4ac287d56fc57f5ae. --- searx/engines/bing_news.py | 2 +- searx/engines/wolframalpha_api.py | 2 +- tests/unit/engines/test_bing_news.py | 12 ++++++------ tests/unit/engines/test_wolframalpha_api.py | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/searx/engines/bing_news.py b/searx/engines/bing_news.py index 1a71aed6d..39048a1fc 100644 --- a/searx/engines/bing_news.py +++ b/searx/engines/bing_news.py @@ -82,7 +82,7 @@ def request(query, params): def response(resp): results = [] - rss = etree.fromstring(resp.content.encode()) + rss = etree.fromstring(resp.content) ns = rss.nsmap diff --git a/searx/engines/wolframalpha_api.py b/searx/engines/wolframalpha_api.py index 383d8c3b3..a5cebeec8 100644 --- a/searx/engines/wolframalpha_api.py +++ b/searx/engines/wolframalpha_api.py @@ -65,7 +65,7 @@ def replace_pua_chars(text): def response(resp): results = [] - search_results = etree.XML(resp.text.encode()) + search_results = etree.XML(resp.text) # return empty array if there are no results if search_results.xpath(failure_xpath): diff --git a/tests/unit/engines/test_bing_news.py b/tests/unit/engines/test_bing_news.py index a02e75e5e..33cf2629f 100644 --- a/tests/unit/engines/test_bing_news.py +++ b/tests/unit/engines/test_bing_news.py @@ -33,13 +33,13 @@ class TestBingNewsEngine(TestCase): self.assertRaises(AttributeError, bing_news.response, '') self.assertRaises(AttributeError, bing_news.response, '[]') - response = mock.Mock(content='') + response = mock.Mock(content=b'') self.assertEqual(bing_news.response(response), []) - response = mock.Mock(content='') + response = mock.Mock(content=b'') self.assertEqual(bing_news.response(response), []) - html = """ + html = b""" python - Bing News @@ -84,7 +84,7 @@ class TestBingNewsEngine(TestCase): self.assertEqual(results[1]['content'], 'Another Article Content') self.assertNotIn('img_src', results[1]) - html = """ + html = b""" python - Bing News @@ -119,7 +119,7 @@ class TestBingNewsEngine(TestCase): self.assertEqual(results[0]['content'], 'Article Content') self.assertEqual(results[0]['img_src'], 'http://another.bing.com/image') - html = """ + html = b""" python - Bing News @@ -138,6 +138,6 @@ class TestBingNewsEngine(TestCase): self.assertEqual(type(results), list) self.assertEqual(len(results), 0) - html = """gabarge""" + html = b"""gabarge""" response = mock.Mock(content=html) self.assertRaises(lxml.etree.XMLSyntaxError, bing_news.response, response) diff --git a/tests/unit/engines/test_wolframalpha_api.py b/tests/unit/engines/test_wolframalpha_api.py index 586f9061f..192d32045 100644 --- a/tests/unit/engines/test_wolframalpha_api.py +++ b/tests/unit/engines/test_wolframalpha_api.py @@ -32,14 +32,14 @@ class TestWolframAlphaAPIEngine(TestCase): request = Request(headers={'Referer': referer_url}) # test failure - xml = ''' + xml = b''' ''' response = mock.Mock(text=xml) self.assertEqual(wolframalpha_api.response(response), []) # test basic case - xml = """ + xml = b""" + xml = b"""