[Zope-Checkins] SVN: Zope/trunk/ Collector #934: Image and File objects are now always internally

Florent Guillaume fg at nuxeo.com
Fri Nov 5 10:56:13 EST 2004


Log message for revision 28344:
  Collector #934: Image and File objects are now always internally
  split into small chunks even when initialized from a string.
  

Changed:
  U   Zope/trunk/doc/CHANGES.txt
  U   Zope/trunk/lib/python/OFS/Image.py
  U   Zope/trunk/lib/python/OFS/tests/testFileAndImage.py

-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt	2004-11-05 15:14:57 UTC (rev 28343)
+++ Zope/trunk/doc/CHANGES.txt	2004-11-05 15:56:13 UTC (rev 28344)
@@ -34,6 +34,9 @@
 
     Bugs fixed
 
+      - Collector #934: Image and File objects are now always internally
+        split into small chunks even when initialized from a string.
+
       - docutils: updated to V 0.3.5. The Zope core now contains a full copy of
         the docutils package except some GPLed files which can not be included
         with the Zope distribution due to license constraints on svn.zope.org.

Modified: Zope/trunk/lib/python/OFS/Image.py
===================================================================
--- Zope/trunk/lib/python/OFS/Image.py	2004-11-05 15:14:57 UTC (rev 28343)
+++ Zope/trunk/lib/python/OFS/Image.py	2004-11-05 15:56:13 UTC (rev 28344)
@@ -479,8 +479,10 @@
         if type(file) is StringType:
             size=len(file)
             if size < n: return file, size
-            return Pdata(file), size
-        elif isinstance(file, FileUpload) and not file:
+            # Big string: cut it into smaller chunks
+            file = StringIO(file)
+
+        if isinstance(file, FileUpload) and not file:
             raise ValueError, 'File not specified'
 
         if hasattr(file, '__class__') and file.__class__ is Pdata:

Modified: Zope/trunk/lib/python/OFS/tests/testFileAndImage.py
===================================================================
--- Zope/trunk/lib/python/OFS/tests/testFileAndImage.py	2004-11-05 15:14:57 UTC (rev 28343)
+++ Zope/trunk/lib/python/OFS/tests/testFileAndImage.py	2004-11-05 15:56:13 UTC (rev 28344)
@@ -132,6 +132,16 @@
         self.assertEqual(len(s), len(str(data)))
         self.assertEqual(len(s), size)
 
+    def testBigPdata(self):
+        # Test that a big enough string is split into several Pdata
+        # From a file
+        s = "a" * (1 << 16) * 3
+        data, size = self.file._read_data(StringIO(s))
+        self.failIfEqual(data.next, None)
+        # From a string
+        data, size = self.file._read_data(s)
+        self.failIfEqual(data.next, None)
+
     def testManageEditWithFileData(self):
         self.file.manage_edit('foobar', 'text/plain', filedata='ASD')
         self.assertEqual(self.file.title, 'foobar')



More information about the Zope-Checkins mailing list