[reportlab-users] canvas.drawImage with unicode string

Robin Becker robin at reportlab.com
Sat Nov 4 08:32:13 EST 2006


pier carteri wrote:
> 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
.......

OK I turned the test around since we're only allowed an ImageReader or a 
filename it gets used like

	if isinstance(image,ImageReader):
		rawdata = image.getRGBData()
		name = _digester(rawdata+str(mask))
	else:
		#filename, use it
		name = _digester('%s%s' % (image, mask))

-- 
Robin Becker


More information about the reportlab-users mailing list