def make_response(self, output: dict, format: str = "json", code: int = 200, meta: str = "meta") -> Response: """ Returns the output string based on format param """ output = self.format_dict(output) if "error" in output and meta not in output: output["timestamp"] = datetime.utcnow() if self.note: if meta not in output: output[meta] = {} output[meta]["note"] = self.note if format == "xml": root = self.report_type.upper() if self.report_type else "AVWX" resp = Response(fxml(output, custom_root=root), mimetype="text/xml") elif format == "yaml": resp = Response(yaml.dump(output, default_flow_style=False), mimetype="text/x-yaml") else: resp = jsonify(output) resp.status_code = code resp.headers["X-Robots-Tag"] = "noindex" return resp
def make_response( self, output: dict, # pylint: disable=redefined-builtin format: str = "json", code: int = 200, meta: str = "meta", root: str = "AVWX", ) -> Response: """Returns the output string based on format param""" output = self.format_output(output) if "error" in output and meta not in output: output["timestamp"] = datetime.now(tz=timezone.utc) if self.note and isinstance(output, dict): if meta not in output: output[meta] = {} output[meta]["note"] = self.note if format == "xml": resp = Response(fxml(output, custom_root=root.upper()), mimetype="text/xml") elif format == "yaml": resp = Response(yaml.dump(output, default_flow_style=False), mimetype="text/x-yaml") else: resp = jsonify(output) resp.status_code = code resp.headers["X-Robots-Tag"] = "noindex" return resp
def format_response(output: dict, format: str, rtype: str) -> Response: """Returns the output string based on format param""" if format == 'xml': return Response(fxml(output, custom_root=rtype.upper()), mimetype='text/xml') elif format == 'yaml': return Response(yaml.dump(output, default_flow_style=False), mimetype='text/x-yaml') return jsonify(output)
def format_response(self, output: dict, format: str, meta: str = 'meta') -> Response: """ Returns the output string based on format param """ if self.note: if meta not in output: output[meta] = {} output[meta]['note'] = self.note if format == 'xml': return Response(fxml(output, custom_root=self.report_type.upper()), mimetype='text/xml') elif format == 'yaml': return Response(yaml.dump(output, default_flow_style=False), mimetype='text/x-yaml') return jsonify(output)
def format_response( self, output: dict, format: str, meta: str = "meta" ) -> Response: """ Returns the output string based on format param """ output = self.format_dict(output) if self.note: if meta not in output: output[meta] = {} output[meta]["note"] = self.note if format == "xml": return Response( fxml(output, custom_root=self.report_type.upper()), mimetype="text/xml" ) elif format == "yaml": return Response( yaml.dump(output, default_flow_style=False), mimetype="text/x-yaml" ) return jsonify(output)