Пример #1
0
 def convert_chart_svg(self, request: Request):
     vert_bar_chart_max_label = int(
         request.args.get('vertBarChartMaxLabel', '10'))
     chart_type = request.args.get('chartType')
     if chart_type in ('bar', 'time', 'timescatter'):
         svg_src = normalize_bar_chart_svg(request.get_data(),
                                           vert_bar_chart_max_label)
     else:
         svg_src = normalize_wcloud_svg(request.get_data())
     if request.args.get('outFormat', '') == 'png':
         self._response.set_header('Content-Type', 'image/png')
         return svg2png(bytestring=svg_src,
                        output_width=1200,
                        background_color='#FFFFFF')
     elif request.args.get('outFormat', '') == 'png-print':
         self._response.set_header('Content-Type', 'image/png')
         return svg2png(bytestring=svg_src,
                        output_width=4961,
                        background_color='#FFFFFF')
     elif request.args.get('outFormat', '') == 'svg':
         self._response.set_header('Content-Type', 'image/svg+xml')
         return svg2svg(bytestring=svg_src,
                        scale=5,
                        background_color='#FFFFFF')
     elif request.args.get('outFormat', '') == 'pdf':
         self._response.set_header('Content-Type', 'application/pdf')
         return svg2pdf(bytestring=svg_src,
                        scale=5,
                        background_color='#FFFFFF')
     else:
         raise UserActionException('Invalid data format', code=422)
Пример #2
0
    def _rpc_handle(self, request: werkzeug.Request) -> werkzeug.Response:
        """
        Handles JSON-RPC request.

        :returns: werkzeug response
        """

        if request.content_type not in pjrpc.common.REQUEST_CONTENT_TYPES:
            raise exceptions.UnsupportedMediaType()

        try:
            request_text = request.get_data(as_text=True)
        except UnicodeDecodeError as e:
            raise exceptions.BadRequest() from e

        response_text = self._dispatcher.dispatch(request_text,
                                                  context=request)
        if response_text is None:
            return werkzeug.Response()
        else:
            return werkzeug.Response(
                response_text, mimetype=pjrpc.common.DEFAULT_CONTENT_TYPE)