- Timestamp:
- 9 Jun 2011, 23:02:36 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/image/image.py
r6309 r6312 32 32 """A file prepared for storing image files. 33 33 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. 35 40 """ 36 41 implements(IWAeUPImageFile) … … 41 46 self.headers = {} 42 47 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 43 68 def _getFile(self): 44 69 return self._file.open('r') 45 70 71 #: A Python file-object already openend for reading containing the 72 #: stored file. 46 73 file = property(_getFile) 47 74 48 75 @property 49 76 def size(self): 77 """The size of the stored file in bytes. 78 """ 50 79 f = self._file.open('r') 51 80 size = int(os.fstat(f.fileno()).st_size) … … 55 84 @property 56 85 def data(self): 86 """The contents of the stored file. 87 """ 57 88 f = self._file.open('r') 58 89 result = f.read()
Note: See TracChangeset for help on using the changeset viewer.