From 58a6c045c81a84abfb8a29368e7d5453efc5f2fa Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Wed, 2 Nov 2016 14:52:22 +0100 Subject: [PATCH] [mod] replace references request.request_data (GET or POST parameters) by request.form (based on merge of POST and GET parameters) --- searx/search.py | 12 ++++++------ searx/webapp.py | 24 +++++++----------------- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/searx/search.py b/searx/search.py index a8de143b0..4c4a6a2f0 100644 --- a/searx/search.py +++ b/searx/search.py @@ -128,7 +128,7 @@ def make_callback(engine_name, callback, params, result_container): return process_callback -def get_search_query_from_webapp(preferences, request_data): +def get_search_query_from_webapp(preferences, form): query = None query_engines = [] query_categories = [] @@ -147,11 +147,11 @@ def get_search_query_from_webapp(preferences, request_data): query_safesearch = preferences.get_value('safesearch') # TODO better exceptions - if not request_data.get('q'): + if not form.get('q'): raise Exception('noquery') # set pagenumber - pageno_param = request_data.get('pageno', '1') + pageno_param = form.get('pageno', '1') if not pageno_param.isdigit() or int(pageno_param) < 1: pageno_param = 1 @@ -159,7 +159,7 @@ def get_search_query_from_webapp(preferences, request_data): # parse query, if tags are set, which change # the serch engine or search-language - raw_text_query = RawTextQuery(request_data['q'], disabled_engines) + raw_text_query = RawTextQuery(form['q'], disabled_engines) raw_text_query.parse_query() # set query @@ -170,7 +170,7 @@ def get_search_query_from_webapp(preferences, request_data): if len(raw_text_query.languages): query_lang = raw_text_query.languages[-1] - query_time_range = request_data.get('time_range') + query_time_range = form.get('time_range') query_engines = raw_text_query.engines @@ -185,7 +185,7 @@ def get_search_query_from_webapp(preferences, request_data): else: # set categories/engines load_default_categories = True - for pd_name, pd in request_data.items(): + for pd_name, pd in form.items(): if pd_name == 'categories': query_categories.extend(categ for categ in map(unicode.strip, pd.split(',')) if categ in categories) elif pd_name == 'engines': diff --git a/searx/webapp.py b/searx/webapp.py index 7c3cb7e9b..d3d5bb51e 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -364,16 +364,6 @@ def render(template_name, override_theme=None, **kwargs): @app.before_request def pre_request(): - # request.request_data - if request.method == 'POST': - request_data = request.form - elif request.method == 'GET': - request_data = request.args - else: - request_data = {} - - request.request_data = request_data - # merge GET, POST vars preferences = Preferences(themes, categories.keys(), engines, plugins) try: @@ -416,7 +406,7 @@ def index(): search_query = None result_container = None try: - search_query = get_search_query_from_webapp(request.preferences, request.request_data) + search_query = get_search_query_from_webapp(request.preferences, request.form) # search = Search(search_query) # without plugins search = SearchWithPlugins(search_query, request) result_container = search.search() @@ -428,8 +418,8 @@ def index(): results = result_container.get_ordered_results() # UI - advanced_search = request.request_data.get('advanced_search', None) - output_format = request.request_data.get('format', 'html') + advanced_search = request.form.get('advanced_search', None) + output_format = request.form.get('format', 'html') if output_format not in ['html', 'csv', 'json', 'rss']: output_format = 'html' @@ -490,7 +480,7 @@ def index(): response_rss = render( 'opensearch_response_rss.xml', results=results, - q=request.request_data['q'], + q=request.form['q'], number_of_results=number_of_results, base_url=get_base_url() ) @@ -499,7 +489,7 @@ def index(): return render( 'results.html', results=results, - q=request.request_data['q'], + q=request.form['q'], selected_categories=search_query.categories, pageno=search_query.pageno, time_range=search_query.time_range, @@ -531,7 +521,7 @@ def autocompleter(): disabled_engines = request.preferences.engines.get_disabled() # parse query - raw_text_query = RawTextQuery(request.request_data.get('q', '').encode('utf-8'), disabled_engines) + raw_text_query = RawTextQuery(request.form.get('q', '').encode('utf-8'), disabled_engines) raw_text_query.parse_query() # check if search query is set @@ -564,7 +554,7 @@ def autocompleter(): results.append(raw_text_query.getFullQuery()) # return autocompleter results - if request.request_data.get('format') == 'x-suggestions': + if request.form.get('format') == 'x-suggestions': return Response(json.dumps([raw_text_query.query, results]), mimetype='application/json')