Browse Source

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

Adam Tauber 7 years ago
parent
commit
8db527c1d2
2 changed files with 7 additions and 7 deletions
  1. 1
    1
      searx/engines/bing_news.py
  2. 6
    6
      tests/unit/engines/test_bing_news.py

+ 1
- 1
searx/engines/bing_news.py View File

85
 def response(resp):
85
 def response(resp):
86
     results = []
86
     results = []
87
 
87
 
88
-    rss = etree.fromstring(resp.text)
88
+    rss = etree.fromstring(resp.content)
89
 
89
 
90
     ns = rss.nsmap
90
     ns = rss.nsmap
91
 
91
 

+ 6
- 6
tests/unit/engines/test_bing_news.py View File

36
         self.assertRaises(AttributeError, bing_news.response, '')
36
         self.assertRaises(AttributeError, bing_news.response, '')
37
         self.assertRaises(AttributeError, bing_news.response, '[]')
37
         self.assertRaises(AttributeError, bing_news.response, '[]')
38
 
38
 
39
-        response = mock.Mock(text='<html></html>')
39
+        response = mock.Mock(content='<html></html>')
40
         self.assertEqual(bing_news.response(response), [])
40
         self.assertEqual(bing_news.response(response), [])
41
 
41
 
42
-        response = mock.Mock(text='<html></html>')
42
+        response = mock.Mock(content='<html></html>')
43
         self.assertEqual(bing_news.response(response), [])
43
         self.assertEqual(bing_news.response(response), [])
44
 
44
 
45
         html = """<?xml version="1.0" encoding="utf-8" ?>
45
         html = """<?xml version="1.0" encoding="utf-8" ?>
74
         </item>
74
         </item>
75
     </channel>
75
     </channel>
76
 </rss>"""  # noqa
76
 </rss>"""  # noqa
77
-        response = mock.Mock(text=html.encode('utf-8'))
77
+        response = mock.Mock(content=html.encode('utf-8'))
78
         results = bing_news.response(response)
78
         results = bing_news.response(response)
79
         self.assertEqual(type(results), list)
79
         self.assertEqual(type(results), list)
80
         self.assertEqual(len(results), 2)
80
         self.assertEqual(len(results), 2)
113
         </item>
113
         </item>
114
     </channel>
114
     </channel>
115
 </rss>"""  # noqa
115
 </rss>"""  # noqa
116
-        response = mock.Mock(text=html.encode('utf-8'))
116
+        response = mock.Mock(content=html.encode('utf-8'))
117
         results = bing_news.response(response)
117
         results = bing_news.response(response)
118
         self.assertEqual(type(results), list)
118
         self.assertEqual(type(results), list)
119
         self.assertEqual(len(results), 1)
119
         self.assertEqual(len(results), 1)
136
     </channel>
136
     </channel>
137
 </rss>"""  # noqa
137
 </rss>"""  # noqa
138
 
138
 
139
-        response = mock.Mock(text=html.encode('utf-8'))
139
+        response = mock.Mock(content=html.encode('utf-8'))
140
         results = bing_news.response(response)
140
         results = bing_news.response(response)
141
         self.assertEqual(type(results), list)
141
         self.assertEqual(type(results), list)
142
         self.assertEqual(len(results), 0)
142
         self.assertEqual(len(results), 0)
143
 
143
 
144
         html = """<?xml version="1.0" encoding="utf-8" ?>gabarge"""
144
         html = """<?xml version="1.0" encoding="utf-8" ?>gabarge"""
145
-        response = mock.Mock(text=html.encode('utf-8'))
145
+        response = mock.Mock(content=html.encode('utf-8'))
146
         self.assertRaises(lxml.etree.XMLSyntaxError, bing_news.response, response)
146
         self.assertRaises(lxml.etree.XMLSyntaxError, bing_news.response, response)