[reportlab-users] canvas.drawImage with unicode string

pier carteri pier.carteri at gmail.com
Sat Nov 4 07:22:57 EST 2006

Hi to all,
[I'm not sure if this is the correct place to post this, but I've not
found any infos on reportlab.org on  where reportig a bug. If there is
a better place, let me know!]

the method drawImage of canvas class accepts a path or an ImageReader object.
To determine  what type of resource it receives there is :

[line 580 of canvas.py]
        if type(image) == type(''):
            #filename, use it
            name = _digester('%s%s' % (image, mask))
            rawdata = image.getRGBData()

but the check fails if you pass it an  unicode string, and so the
program wrongly recognise the input as an ImageReader.

I suggest a check like
        if type(image) in [type(''), type(u'')]:
        if type(image) == type('') or type(image) == type(u''):

The use of unicode string for path may seems uncommon but it isn't.
For example my program gets paths from an xml file parsed using
elementtree. Elementtree returns unicode strings.

Hope this helps!



More information about the reportlab-users mailing list