예제 #1
0
 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
예제 #2
0
 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
예제 #3
0
 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)
예제 #4
0
 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)
예제 #5
0
 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)