[reportlab-users] Problem with reportlab.lib.utils.ImageReader and deepcopy

Roberto Alsina ralsina at netmanagers.com.ar
Thu Jul 1 10:47:24 EDT 2010

For complicated reasons (which means, I am not sure I am doing something
smart), I need to deepcopy some reportlab flowables.

I run into some problems when copying paragraphs that contain inline JPG
images in them, like <img src="blah.jpg">.

I get this:

* File "/usr/lib/python2.6/copy.py", line 162, in deepcopy
* y = copier(x, memo)
* File "/usr/lib/python2.6/copy.py", line 255, in _deepcopy_dict
* y[deepcopy(key, memo)] = deepcopy(value, memo)
* File "/usr/lib/python2.6/copy.py", line 189, in deepcopy
* y = _reconstruct(x, rv, 1, memo)
* File "/usr/lib/python2.6/copy.py", line 323, in _reconstruct
* y = callable(*args)
* File "/usr/lib/python2.6/copy_reg.py", line 93, in __newobj__
* return cls.__new__(cls, *args)
* TypeError: instancemethod expected at least 2 arguments, got 0

The object that is not being copied right is this one:

<class 'reportlab.lib.utils.ImageReader'>
{'fp': <open file
mode 'rb' at 0x9ded3e8>, 'jpeg_fh': <bound method ImageReader._jpeg_fh of
<reportlab.lib.utils.ImageReader object at 0x9bcf26c>>, '_height': 16,
'_width': 16, '_transparent': None, '_image':
<PIL.JpegImagePlugin.JpegImageFile image mode=L size=16x16 at 0x9BCF40C>,
'_data': None, 'fileName':

As a very ugly workaround, adding this seems to cause no side effects on
rst2pdf's test suite:

reportlab.lib.utils.ImageReader.__deepcopy__ = lambda self,*x: copy(self)

More information about the reportlab-users mailing list