Ejemplo n.º 1
0
 def wrapper(self, request, suffix=''):
     """The wrapper function `json_handler` returns."""
     if request.method != "POST":
         return JsonHandlerError(405, "Method must be POST").get_response(allow=["POST"])
     try:
         request_json = json.loads(request.body)
     except ValueError:
         return JsonHandlerError(400, "Invalid JSON").get_response()
     try:
         response_json = json.dumps(func(self, request_json, suffix))
     except JsonHandlerError as e:
         return e.get_response()
     return Response(response_json, content_type='application/json')
Ejemplo n.º 2
0
 def wrapper(self, request, suffix=''):
     """The wrapper function `json_handler` returns."""
     if request.method != "POST":
         return JsonHandlerError(
             405, "Method must be POST").get_response(allow=["POST"])
     try:
         request_json = json.loads(request.body)
     except ValueError:
         return JsonHandlerError(400, "Invalid JSON").get_response()
     try:
         response_json = json.dumps(func(self, request_json, suffix))
     except JsonHandlerError as e:
         return e.get_response()
     return Response(response_json, content_type='application/json')
Ejemplo n.º 3
0
 def wrapper(self, request, suffix=""):
     """The wrapper function `json_handler` returns."""
     if request.method != "POST":
         return JsonHandlerError(405, "Method must be POST").get_response(allow=["POST"])
     try:
         request_json = json.loads(request.body)
     except ValueError:
         return JsonHandlerError(400, "Invalid JSON").get_response()
     try:
         response = func(self, request_json, suffix)
     except JsonHandlerError as err:
         return err.get_response()
     if isinstance(response, Response):
         return response
     else:
         return Response(json.dumps(response), content_type="application/json")
Ejemplo n.º 4
0
 def wrapper(self, request, suffix=''):
     """The wrapper function `json_handler` returns."""
     request_json = json.loads(request.body)
     response_json = json.dumps(func(self, request_json, suffix))
     return Response(response_json, content_type='application/json')
Ejemplo n.º 5
0
 def wrapper(self, request):
     request_json = json.loads(request.body)
     response_json = json.dumps(fn(self, request_json))
     return Response(response_json, content_type='application/json')
Ejemplo n.º 6
0
 def wrapper(self, request, suffix=''):
     """The wrapper function `json_handler` returns."""
     request_json = json.loads(request.body)
     response_json = json.dumps(func(self, request_json, suffix))
     return Response(response_json, content_type='application/json')
Ejemplo n.º 7
0
 def wrapper(self, request):
     request_json = json.loads(request.body)
     response_json = json.dumps(fn(self, request_json))
     return Response(response_json, content_type='application/json')