[CMF-checkins] CVS: CMF - Image.py:1.6
Jeffrey Shell
jeffrey@digicool.com
Mon, 21 May 2001 09:49:38 -0400 (EDT)
Update of /cvs-repository/CMF/CMFDefault
In directory korak.digicool.com:/home/jeffrey/InstanceHomes/cmf-dev/CMF/CMFDefault
Modified Files:
Image.py
Log Message:
Added _isNotEmpty() check which should fix tracker issue 271, "File
edit not accepting empty file argument".
--- Updated File Image.py in package CMF --
--- Image.py 2001/04/08 19:18:18 1.5
+++ Image.py 2001/05/21 13:49:38 1.6
@@ -211,15 +211,29 @@
PortalContent.manage_beforeDelete(self, item, container)
OFS.Image.Image.manage_beforeDelete(self, item, container)
+ def _isNotEmpty(self, file):
+ """ Do various checks on 'file' to try to determine non emptiness. """
+ if not file:
+ return 0 # Catches None, Missing.Value, ''
+ elif file and (type(file) is type('')):
+ return 1
+ elif getattr(file, 'filename', None):
+ return 1
+ elif not hasattr(file, 'read'):
+ return 0
+ else:
+ file.seek(0,2) # 0 bytes back from end of file
+ t = file.tell() # Report the location
+ file.seek(0) # and return pointer back to 0
+ if t: return 1
+ else: return 0
def edit(self, precondition='', file=''):
- """
- Update image.
- """
+ """ Update image. """
if precondition: self.precondition = precondition
elif self.precondition: del self.precondition
- if file.filename != '' and file.read() != '':
+ if self._isNotEmpty(file):
self.manage_upload(file)
self.setFormat(self.content_type)