[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Content/File - File.py:1.4 I18nFile.py:1.3

Marius Gedminas mgedmin@delfi.lt
Tue, 25 Jun 2002 07:27:50 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Content/File
In directory cvs.zope.org:/tmp/cvs-serv2165/lib/python/Zope/App/OFS/Content/File

Modified Files:
	File.py I18nFile.py 
Log Message:
Ignore empty FileUpload objects in edit


=== Zope3/lib/python/Zope/App/OFS/Content/File/File.py 1.3 => 1.4 ===
 from FileChunk import FileChunk
 from IFile import IFile
+from Zope.Publisher.Browser.BrowserRequest import FileUpload
 
 # set the size of the chunks
 MAXCHUNKSIZE = 1 << 16
@@ -66,7 +67,11 @@
         
         if contentType is not None:
             self._contentType = contentType
-        self.setData(data)
+        if hasattr(data, '__class__') and data.__class__ is FileUpload \
+           and not data.filename:
+           data = None          # Ignore empty files
+        if data is not None:
+            self.setData(data)
 
 
     def getData(self):
@@ -93,7 +98,7 @@
             self._data, self._size = FileChunk(data), size
             return None
 
-        # Handle case when data is a string
+        # Handle case when data is None
         if isinstance(data, NoneType):
             self._data, self._size = None, 0
             return None


=== Zope3/lib/python/Zope/App/OFS/Content/File/I18nFile.py 1.2 => 1.3 ===
 from Zope.I18n.II18nAware import II18nAware
 from File import File
+from Zope.Publisher.Browser.BrowserRequest import FileUpload
 
 
 class II18nFile(IFile, II18nAware):
@@ -106,7 +107,11 @@
 
         if contentType is not None:
             self.setContentType(contentType)
-        self.setData(data, language)
+        if hasattr(data, '__class__') and data.__class__ is FileUpload \
+           and not data.filename:
+           data = None          # Ignore empty files
+        if data is not None:
+            self.setData(data, language)
 
 
     def getData(self, language=None):