Commits

WAKAYAMA shirou committed fd1c89a

make function which creates jsonp response.

Comments (0)

Files changed (1)

src/dipus/websetup.py

 conf = None
 
 
+def ret_jsonp(request, ret):
+    json_response = simplejson.dumps(ret)
+    response.content_type = 'application/json; charset=utf-8'
+
+    callback_function = request.GET.get('callback')
+    if callback_function:
+        json_response = ''.join([callback_function, '(', json_response, ')'])
+
+    return json_response
+
+
 def auth(password):
     ''' not implemented yet '''
     return True
         "hits": results
         }
 
-    # FIXME: duplicate code.
-    json_response = simplejson.dumps(ret)
-    response.content_type = 'application/json; charset=utf-8'
-
-    callback_function = request.GET.get('callback')
-    if callback_function:
-        json_response = ''.join([callback_function, '(', json_response, ')'])
-
-    return json_response
+    return ret_jsonp(request, ret)
 
 
 @app.route('/<_index>/_search')
         "hits": results
         }
 
-    json_response = simplejson.dumps(ret)
-    response.content_type = 'application/json; charset=utf-8'
-
-    callback_function = request.GET.get('callback')
-    if callback_function:
-        json_response = ''.join([callback_function, '(', json_response, ')'])
-
-    return json_response
+    return ret_jsonp(request, ret)
 
 
 if __name__ == '__main__':