[fix] unicode and pep8 fixes

This commit is contained in:
asciimoo 2014-02-07 02:45:12 +01:00
parent 4d878993bd
commit 9eb31c0186
3 changed files with 11 additions and 8 deletions

View File

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

View File

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

View File

@ -120,8 +120,10 @@ def index():
search.paging = True search.paging = True
if search.request_data.get('format', 'html') == 'html': if search.request_data.get('format', 'html') == 'html':
if 'content' in result: if 'content' in result:
result['content'] = highlight_content(result['content'], search.query) result['content'] = highlight_content(result['content'],
result['title'] = highlight_content(result['title'], search.query) search.query.encode('utf-8')) # noqa
result['title'] = highlight_content(result['title'],
search.query.encode('utf-8'))
else: else:
if 'content' in result: if 'content' in result:
result['content'] = html_to_text(result['content']).strip() result['content'] = html_to_text(result['content']).strip()
@ -139,7 +141,8 @@ def index():
result['favicon'] = engine result['favicon'] = engine
if search.request_data.get('format') == 'json': if search.request_data.get('format') == 'json':
return Response(json.dumps({'query': search.query, 'results': search.results}), return Response(json.dumps({'query': search.query,
'results': search.results}),
mimetype='application/json') mimetype='application/json')
elif search.request_data.get('format') == 'csv': elif search.request_data.get('format') == 'csv':
csv = UnicodeWriter(cStringIO.StringIO()) csv = UnicodeWriter(cStringIO.StringIO())
@ -151,8 +154,8 @@ def index():
csv.writerow([row.get(key, '') for key in keys]) csv.writerow([row.get(key, '') for key in keys])
csv.stream.seek(0) csv.stream.seek(0)
response = Response(csv.stream.read(), mimetype='application/csv') response = Response(csv.stream.read(), mimetype='application/csv')
content_disp = 'attachment;Filename=searx_-_{0}.csv'.format(search.query) cont_disp = 'attachment;Filename=searx_-_{0}.csv'.format(search.query)
response.headers.add('Content-Disposition', content_disp) response.headers.add('Content-Disposition', cont_disp)
return response return response
elif search.request_data.get('format') == 'rss': elif search.request_data.get('format') == 'rss':
response_rss = render( response_rss = render(