def send_message(self, msg): if msg['type'] in self.payload_types or '*' in self.payload_types: logging_msg = msg['payload'] elif msg['type'] in self.json_types or '*' in self.json_types: logging_msg = json.dumps(msg) else: # drop it return lvl = SEVERITY_MAP.get(msg['severity'], logging.WARN) self.logger.log(lvl, logging_msg)
def send_message(self, msg): if msg["type"] in self.payload_types or "*" in self.payload_types: logging_msg = msg["payload"] elif msg["type"] in self.json_types or "*" in self.json_types: logging_msg = json.dumps(msg) else: # drop it return lvl = SEVERITY_MAP.get(msg["severity"], logging.WARN) self.logger.log(lvl, logging_msg)
def get_response(self, **kwargs): """ Returns a Response object containing this object's status code and a JSON object containing the key "error" with the value of this object's error message in the body. Keyword args are passed through to the Response. """ return Response(json.dumps({"error": self.message}), status_code=self.status_code, content_type="application/json", **kwargs)
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')
def get_response(self, **kwargs): """ Returns a Response object containing this object's status code and a JSON object containing the key "error" with the value of this object's error message in the body. Keyword args are passed through to the Response. """ return Response( json.dumps({"error": self.message}), status_code=self.status_code, content_type="application/json", **kwargs )
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')
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")
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')
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')