[Zope-dev] Zope2.2.0b3 Image/File object create/upload bug (w/patch)

Adam Karpierz karpierz@itl.pl
Wed, 28 Jun 2000 11:32:48 +0200


Please, can you explain me why this bug and path was retracted from
Collector with message ?:

"Retracted by submitter (in Zope-Dev mailinglist, forgot to define
USE_EXTENSION_CLASS)."

This path intended for 'official' version 2.2.0b3, _not only_ for
version compiled from sources.
Please compare old good code(2.1.6), with buggy new code(2.2.0b3) for
clarification why new code is buggy:

lib/python/OFS/Image.py
----------old(2.1.6):-------------------
    def _read_data(self, file):

        n=1<<16

        if type(file) is StringType:
            size=len(file)
            if size < n: return file, size
            return Pdata(file), size

        seek=file.seek
        read=file.read
...
-------new buggy ('official' 2.2.0b3)-------------
    def _read_data(self, file):

        n=1<<16

        if type(file) is StringType:
            size=len(file)
            if size < n: return file, size
            return Pdata(file), size

        if file.__class__ is Pdata:  ## !!!    this new code is buggy because if type(file) is not 'instance',
            size=len(file)                    ## !!!    file variable don't have __class__ attribute (eg: if type(file) == FileType)
            return file, size                 ## !!!    First is needed check out if file is 'instance' type. Would be:
                                                      ## !!!    if type(file) is InstanceType and file.__class__ is Pdata:
        seek=file.seek
        read=file.read
...
------------------------------------------

This bug makes impossible to use code which works ok
with old Zope-s (prior 2.2.0) eg:

 f = open('path/image.gif', 'rb')
 OFS.Image.manage_addImage(root, 'logo', f, 'logo')
 f.close()

With Zope 2.2.0b3 this code produces bug with traceback eg:

"""
Zope Error
Zope has encountered an error while publishing this resource.

Error Type: AttributeError
Error Value: __class__

<!--
Traceback (innermost last):
  File C:\Program Files\Zope\lib\python\ZPublisher\Publish.py, line 222, in publish_module
  File C:\Program Files\Zope\lib\python\ZPublisher\Publish.py, line 187, in publish
  File C:\Program Files\Zope\lib\python\Zope\__init__.py, line 221, in zpublisher_exception_hook
  File C:\Program Files\Zope\lib\python\ZPublisher\Publish.py, line 171, in publish
  File C:\Program Files\Zope\lib\python\ZPublisher\mapply.py, line 160, in mapply
    (Object: manage_addEtailer)
  File C:\Program Files\Zope\lib\python\ZPublisher\Publish.py, line 112, in call_object
    (Object: manage_addEtailer)
  File C:\Program Files\Zope\lib\python\Products\Etailer\Etailer.py, line 99, in manage_addEtailer
  File C:\Program Files\Zope\lib\python\OFS\Image.py, line 414, in manage_addImage
    (Object: ElementWithAttributes)
  File C:\Program Files\Zope\lib\python\OFS\Image.py, line 263, in manage_upload
    (Object: logo)
  File C:\Program Files\Zope\lib\python\OFS\Image.py, line 292, in _read_data
    (Object: logo)
AttributeError: (see above)

-->
"""

Simple path which I was send to Collector avoid this problem.

Adam Karpierz
karpierz@itl.pl