Ignore:
Timestamp:
9 Jun 2011, 23:02:36 (14 years ago)
Author:
uli
Message:
  • Add a destructor that removes the bound file of the bound Blob when a WAeUPImageFile gets deleted. Otherwise for each once created WAeUPImageFile that was not stored into ZODB we would get a lingering copy of the file contents in the system temporary dir.
  • Update docs.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/image/image.py

    r6309 r6312  
    3232    """A file prepared for storing image files.
    3333
    34     This file type is built upon :class:`hurry.file.HurryFile`.
     34    This file type is built upon :class:`hurry.file.HurryFile`. It
     35    stores the file contents given by `data` in a ZODB Blob.
     36
     37    The `filename` passed can be retrieved later as the `filename`
     38    attribute although the contents of this parameter makes no
     39    difference for us.
    3540    """
    3641    implements(IWAeUPImageFile)
     
    4146        self.headers = {}
    4247
     48    def __del__(self):
     49        """Remove the real filesystem file bound to the blob.
     50
     51        Blob content is initially written to some real filesystem
     52        file. This file might linger around in temporary dirs when
     53        :class:`WAeUPImageFile` instances are created without storing
     54        them in ZODB afterwards. This often happens in tests.
     55
     56        We remove that file too when we are about to be deleted.
     57        """
     58        if self._p_oid is not None or self._file._p_oid is not None:
     59            # Don't mess up internal ZODB structure
     60            return
     61        f = self._file.open('r')
     62        name = getattr(f, 'name', None)
     63        f.close()
     64        if name is not None and os.path.exists(name) and os.path.isfile(name):
     65            os.unlink(name)
     66        return
     67
    4368    def _getFile(self):
    4469        return self._file.open('r')
    4570
     71    #: A Python file-object already openend for reading containing the
     72    #: stored file.
    4673    file = property(_getFile)
    4774
    4875    @property
    4976    def size(self):
     77        """The size of the stored file in bytes.
     78        """
    5079        f = self._file.open('r')
    5180        size = int(os.fstat(f.fileno()).st_size)
     
    5584    @property
    5685    def data(self):
     86        """The contents of the stored file.
     87        """
    5788        f = self._file.open('r')
    5889        result = f.read()
Note: See TracChangeset for help on using the changeset viewer.