Pārlūkot izejas kodu

[fix] bing unicode encode error - fixes #408

Adam Tauber 9 gadus atpakaļ
vecāks
revīzija
604f32f672

+ 1
- 1
searx/engines/bing.py Parādīt failu

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

+ 1
- 1
searx/engines/bing_images.py Parādīt failu

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

+ 1
- 1
searx/engines/bing_news.py Parādīt failu

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

+ 4
- 4
searx/tests/engines/test_bing.py Parādīt failu

@@ -29,10 +29,10 @@ class TestBingEngine(SearxTestCase):
29 29
         self.assertRaises(AttributeError, bing.response, '')
30 30
         self.assertRaises(AttributeError, bing.response, '[]')
31 31
 
32
-        response = mock.Mock(content='<html></html>')
32
+        response = mock.Mock(text='<html></html>')
33 33
         self.assertEqual(bing.response(response), [])
34 34
 
35
-        response = mock.Mock(content='<html></html>')
35
+        response = mock.Mock(text='<html></html>')
36 36
         self.assertEqual(bing.response(response), [])
37 37
 
38 38
         html = """
@@ -54,7 +54,7 @@ class TestBingEngine(SearxTestCase):
54 54
             </div>
55 55
         </div>
56 56
         """
57
-        response = mock.Mock(content=html)
57
+        response = mock.Mock(text=html)
58 58
         results = bing.response(response)
59 59
         self.assertEqual(type(results), list)
60 60
         self.assertEqual(len(results), 1)
@@ -81,7 +81,7 @@ class TestBingEngine(SearxTestCase):
81 81
             </div>
82 82
         </li>
83 83
         """
84
-        response = mock.Mock(content=html)
84
+        response = mock.Mock(text=html)
85 85
         results = bing.response(response)
86 86
         self.assertEqual(type(results), list)
87 87
         self.assertEqual(len(results), 1)

+ 5
- 5
searx/tests/engines/test_bing_images.py Parādīt failu

@@ -31,10 +31,10 @@ class TestBingImagesEngine(SearxTestCase):
31 31
         self.assertRaises(AttributeError, bing_images.response, '')
32 32
         self.assertRaises(AttributeError, bing_images.response, '[]')
33 33
 
34
-        response = mock.Mock(content='<html></html>')
34
+        response = mock.Mock(text='<html></html>')
35 35
         self.assertEqual(bing_images.response(response), [])
36 36
 
37
-        response = mock.Mock(content='<html></html>')
37
+        response = mock.Mock(text='<html></html>')
38 38
         self.assertEqual(bing_images.response(response), [])
39 39
 
40 40
         html = """
@@ -52,7 +52,7 @@ oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%2
52 52
         </div>
53 53
         """
54 54
         html = html.replace('\r\n', '').replace('\n', '').replace('\r', '')
55
-        response = mock.Mock(content=html)
55
+        response = mock.Mock(text=html)
56 56
         results = bing_images.response(response)
57 57
         self.assertEqual(type(results), list)
58 58
         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
75 75
             style="height:144px;" width="178" height="144"/>
76 76
         </a>
77 77
         """
78
-        response = mock.Mock(content=html)
78
+        response = mock.Mock(text=html)
79 79
         results = bing_images.response(response)
80 80
         self.assertEqual(type(results), list)
81 81
         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
263 263
         </div>
264 264
         """
265 265
         html = html.replace('\r\n', '').replace('\n', '').replace('\r', '')
266
-        response = mock.Mock(content=html)
266
+        response = mock.Mock(text=html)
267 267
         results = bing_images.response(response)
268 268
         self.assertEqual(type(results), list)
269 269
         self.assertEqual(len(results), 10)

+ 6
- 6
searx/tests/engines/test_bing_news.py Parādīt failu

@@ -28,10 +28,10 @@ class TestBingNewsEngine(SearxTestCase):
28 28
         self.assertRaises(AttributeError, bing_news.response, '')
29 29
         self.assertRaises(AttributeError, bing_news.response, '[]')
30 30
 
31
-        response = mock.Mock(content='<html></html>')
31
+        response = mock.Mock(text='<html></html>')
32 32
         self.assertEqual(bing_news.response(response), [])
33 33
 
34
-        response = mock.Mock(content='<html></html>')
34
+        response = mock.Mock(text='<html></html>')
35 35
         self.assertEqual(bing_news.response(response), [])
36 36
 
37 37
         html = """<?xml version="1.0" encoding="utf-8" ?>
@@ -66,7 +66,7 @@ class TestBingNewsEngine(SearxTestCase):
66 66
         </item>
67 67
     </channel>
68 68
 </rss>"""  # noqa
69
-        response = mock.Mock(content=html)
69
+        response = mock.Mock(text=html)
70 70
         results = bing_news.response(response)
71 71
         self.assertEqual(type(results), list)
72 72
         self.assertEqual(len(results), 2)
@@ -105,7 +105,7 @@ class TestBingNewsEngine(SearxTestCase):
105 105
         </item>
106 106
     </channel>
107 107
 </rss>"""  # noqa
108
-        response = mock.Mock(content=html)
108
+        response = mock.Mock(text=html)
109 109
         results = bing_news.response(response)
110 110
         self.assertEqual(type(results), list)
111 111
         self.assertEqual(len(results), 1)
@@ -128,11 +128,11 @@ class TestBingNewsEngine(SearxTestCase):
128 128
     </channel>
129 129
 </rss>"""  # noqa
130 130
 
131
-        response = mock.Mock(content=html)
131
+        response = mock.Mock(text=html)
132 132
         results = bing_news.response(response)
133 133
         self.assertEqual(type(results), list)
134 134
         self.assertEqual(len(results), 0)
135 135
 
136 136
         html = """<?xml version="1.0" encoding="utf-8" ?>gabarge"""
137
-        response = mock.Mock(content=html)
137
+        response = mock.Mock(text=html)
138 138
         self.assertRaises(lxml.etree.XMLSyntaxError, bing_news.response, response)