Browse Source

[fix] unicode and pep8 fixes

asciimoo 11 years ago
parent
commit
9eb31c0186
3 changed files with 11 additions and 8 deletions
  1. 1
    1
      searx/engines/__init__.py
  2. 2
    2
      searx/search.py
  3. 8
    5
      searx/webapp.py

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

@@ -205,7 +205,7 @@ def search(query, request, selected_engines, pageno=1, lang='all'):
205 205
         request_params['started'] = datetime.now()
206 206
         request_params['pageno'] = pageno
207 207
         request_params['language'] = lang
208
-        request_params = engine.request(query, request_params)
208
+        request_params = engine.request(query.encode('utf-8'), request_params)
209 209
 
210 210
         callback = make_callback(
211 211
             selected_engine['name'],

+ 2
- 2
searx/search.py View File

@@ -18,7 +18,7 @@ class Search(object):
18 18
         self.pageno = 1
19 19
         self.lang = 'all'
20 20
         if request.cookies.get('blocked_engines'):
21
-            self.blocked_engines = request.cookies['blocked_engines'].split(',')
21
+            self.blocked_engines = request.cookies['blocked_engines'].split(',')  # noqa
22 22
         else:
23 23
             self.blocked_engines = []
24 24
         self.results = []
@@ -70,7 +70,7 @@ class Search(object):
70 70
 
71 71
         if len(self.engines):
72 72
             self.categories = list(set(engine['category']
73
-                                           for engine in self.engines))
73
+                                       for engine in self.engines))
74 74
         else:
75 75
             for pd_name, pd in self.request_data.items():
76 76
                 if pd_name.startswith('category_'):

+ 8
- 5
searx/webapp.py View File

@@ -120,8 +120,10 @@ def index():
120 120
             search.paging = True
121 121
         if search.request_data.get('format', 'html') == 'html':
122 122
             if 'content' in result:
123
-                result['content'] = highlight_content(result['content'], search.query)
124
-            result['title'] = highlight_content(result['title'], search.query)
123
+                result['content'] = highlight_content(result['content'],
124
+                                                      search.query.encode('utf-8'))  # noqa
125
+            result['title'] = highlight_content(result['title'],
126
+                                                search.query.encode('utf-8'))
125 127
         else:
126 128
             if 'content' in result:
127 129
                 result['content'] = html_to_text(result['content']).strip()
@@ -139,7 +141,8 @@ def index():
139 141
                 result['favicon'] = engine
140 142
 
141 143
     if search.request_data.get('format') == 'json':
142
-        return Response(json.dumps({'query': search.query, 'results': search.results}),
144
+        return Response(json.dumps({'query': search.query,
145
+                                    'results': search.results}),
143 146
                         mimetype='application/json')
144 147
     elif search.request_data.get('format') == 'csv':
145 148
         csv = UnicodeWriter(cStringIO.StringIO())
@@ -151,8 +154,8 @@ def index():
151 154
                 csv.writerow([row.get(key, '') for key in keys])
152 155
         csv.stream.seek(0)
153 156
         response = Response(csv.stream.read(), mimetype='application/csv')
154
-        content_disp = 'attachment;Filename=searx_-_{0}.csv'.format(search.query)
155
-        response.headers.add('Content-Disposition', content_disp)
157
+        cont_disp = 'attachment;Filename=searx_-_{0}.csv'.format(search.query)
158
+        response.headers.add('Content-Disposition', cont_disp)
156 159
         return response
157 160
     elif search.request_data.get('format') == 'rss':
158 161
         response_rss = render(