[reportlab-users] canvas.drawImage with unicode string

Robin Becker robin at reportlab.com
Sat Nov 4 07:54:41 EST 2006

pier carteri wrote:
> 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))
>        else:
>            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'')]:
> or
>        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!
> Regards
> Pier

Perhaps it does, but many operating systems don't accept unicode as an 
input to open etc so we prefer utf8 which is equivalent for most 
purposes. In practice I'm guessing we could substitute

	isinstance(image,basestring) for the type test.

if the os accepts the unicode then fine.
Robin Becker

More information about the reportlab-users mailing list