Beispiel #1
0
    def get_figure(self):
        log.debug("running wmsvis.get_figure")
        
        # Use .copy() on params to get a *writeable* MultiDict instance
        params = request.params.copy()
        
        log.debug("params = %s" % (params,))
        
        # The response headers must be strings, not unicode, for modwsgi -
        # ensure that the format is a string, omitting any non-ASCII
        # characters.
        format = params.pop('figFormat', 'image/png')
        formatStr = format.encode('ascii', 'ignore')
        finalImage = build_figure(params)
        
        buffer = StringIO()
        finalImage.save(buffer, self._pilImageFormats[formatStr])
        
        response.headers['Content-Type'] = formatStr

        # Remove headers that prevent browser caching, otherwise IE will not
        # allow the image to be saved in its original format.
        if 'Cache-Control' in response.headers:
            del response.headers['Cache-Control']
        if 'Pragma' in response.headers:
            del response.headers['Pragma']

        return buffer.getvalue()
Beispiel #2
0
    def get_figure(self):
        """Creates and returns a figure.
        """
        log.debug("running viewdata.get_figure")
        
        # Use .copy() on params to get a writeable MultiDict instance
        params = request.params.copy()
        
        log.debug("params = %s" % (params,))
        
        # The response headers must be strings, not unicode, for modwsgi -
        # ensure that the format is a string, omitting any non-ASCII
        # characters.
        format = params.pop('figFormat', 'image/png')
        formatStr = format.encode('ascii', 'ignore')

        # Default to the "viewdata" style for captions.
        if not 'figure-style' in params:
            params['figure-style'] = 'viewdata'

        try:
            finalImage = build_figure(params, self._get_session_endpoint_data())

            buffer = StringIO()
            finalImage.save(buffer, self._pilImageFormats[formatStr])

            response.headers['Content-Type'] = formatStr

            # Remove headers that prevent browser caching, otherwise IE will not
            # allow the image to be saved in its original format.
            if 'Cache-Control' in response.headers:
                del response.headers['Cache-Control']
            if 'Pragma' in response.headers:
                del response.headers['Pragma']

            return buffer.getvalue()
        except Exception, exc:
            response.content_type = 'text/plain'
            return exc.__str__() + '\n'