fileobject with Agg

Hi All,

I'm striving to understand how I ca stuff a file object (e.g. StringIO) to
print_figure for an Agg backend. backend_agg.py states : "If filename is a
fileobject, write png to file object (thus you can, for example, write the png
to stdout".

I tried :

        canvas = FigureCanvasAgg(fig)
        data = StringIO.StringIO()
        canvas.print_figure(data, dpi=150)
        return data.get_value()

But that returns an error from backend_agg.py line 383 (matplotlib v. - 0.76) :
StringIO instance has no attribute 'rfind'.

I've decided to use tempfile, but that leads to something hefty and I hate
writing to disk :

        tempplotfilename = tempfile.mkstemp(suffix='.png')
        canvas.print_figure(tempplotfilename[1], dpi=150)
        data = os.read(tempplotfilename[0],os.fstat(tempplotfilename[0]).st_size)
# self.REQUEST.RESPONSE.setHeader('Content-Length',
os.fstat(tempplotfilename[0]).st_size)
# self.REQUEST.RESPONSE.setHeader('Pragma', 'no-cache')
        self.REQUEST.RESPONSE.setHeader('Content-Type', 'image/png')
# os.close(tempplotfilename[0])
# os.unlink(tempplotfilename[1])
         return data

Can this be done ?

Thank you,

Yves Moisan