[reportlab-users] On file (and image) reading generally

Andy Robinson reportlab-users@reportlab.com
Wed, 17 Mar 2004 20:52:08 -0000


At present we are working on tools to bundle up
"report projects" - or indeed whole apps - as single
file deployments that run out of zip files (or other
compact places), along with all their attached resources.  
This will be available to open source and commercial
users who follow the guidelines when we publish them.

The idea is to make sure that if you have code in your
app which does this somewhere...

   canv.drawImage('images/logo.gif')

...the code can still work even if the whole app is inside
a zip file or frozen DLL.  Ditto for included PDF pages
and DTDs in our commercial products, and for all manner of
Python plug-in files like charts.

To do this, the first thing we need to do is make sure all
'file read' operations go through one place in the library,
so we can intercept them and replace the default behaviour
with something which loads out of the right kind of archive.

There have long been two functions in reportlab/lib/utils:
  open_for_read(fn, mode='b') and open_and_read(fn, mode='b')
We're going to try and use these consistently.  

At present, we don't consistently use this hook. So, you will
see lots of tiny changes in the next couple of weeks to make
sure our code goes through this 'funnel 'whenever it reads from
disk, prior to introducing and new magic.  

With images you will see something similar.  The idea is that
(for Jython compatibility) you only talk to an ImageReader
object, which knows whether to create and use PIL (on Cpython)
or java.awt.image on Jython.    We'll try to make it so you
can pass a PIL Image object in safely, but our own pattern
will be to pass filenames or file objects to ImageReader
and let the 'file opening hook' deal with them.

Best Regards,

Andy Robinson