[CMF-checkins] CVS: CMF - File.py:1.8
Jeffrey Shell
jeffrey@digicool.com
Mon, 21 May 2001 09:49:20 -0400 (EDT)
Update of /cvs-repository/CMF/CMFDefault
In directory korak.digicool.com:/home/jeffrey/InstanceHomes/cmf-dev/CMF/CMFDefault
Modified Files:
File.py
Log Message:
Added _isNotEmpty() check which should fix tracker issue 271, "File
edit not accepting empty file argument".
--- Updated File File.py in package CMF --
--- File.py 2001/05/03 18:27:03 1.7
+++ File.py 2001/05/21 13:49:20 1.8
@@ -214,14 +214,29 @@
PortalContent.manage_beforeDelete(self, item, container)
OFS.Image.File.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=''):
- """
- Perform changes for user
- """
+ """ Perform changes for user """
if precondition: self.precondition = precondition
- elif self.precondition: del self.precondition
+ elif precondition: del self.precondition
- if file.filename != '' and file.read() != '':
+ if self._isNotEmpty(file):
self.manage_upload(file)
self.setFormat(self.content_type)