Commit f7c4b516 authored by Florent Guillaume's avatar Florent Guillaume

Collector #934: Image and File objects are now always internally

split into small chunks even when initialized from a string.
parent 3e3d5cba
...@@ -34,6 +34,9 @@ Zope Changes ...@@ -34,6 +34,9 @@ Zope Changes
Bugs fixed 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 - 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 the docutils package except some GPLed files which can not be included
with the Zope distribution due to license constraints on svn.zope.org. with the Zope distribution due to license constraints on svn.zope.org.
......
...@@ -479,8 +479,10 @@ class File(Persistent, Implicit, PropertyManager, ...@@ -479,8 +479,10 @@ class File(Persistent, Implicit, PropertyManager,
if type(file) is StringType: if type(file) is StringType:
size=len(file) size=len(file)
if size < n: return file, size if size < n: return file, size
return Pdata(file), size # Big string: cut it into smaller chunks
elif isinstance(file, FileUpload) and not file: file = StringIO(file)
if isinstance(file, FileUpload) and not file:
raise ValueError, 'File not specified' raise ValueError, 'File not specified'
if hasattr(file, '__class__') and file.__class__ is Pdata: if hasattr(file, '__class__') and file.__class__ is Pdata:
......
...@@ -132,6 +132,16 @@ class FileTests(unittest.TestCase): ...@@ -132,6 +132,16 @@ class FileTests(unittest.TestCase):
self.assertEqual(len(s), len(str(data))) self.assertEqual(len(s), len(str(data)))
self.assertEqual(len(s), size) 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): def testManageEditWithFileData(self):
self.file.manage_edit('foobar', 'text/plain', filedata='ASD') self.file.manage_edit('foobar', 'text/plain', filedata='ASD')
self.assertEqual(self.file.title, 'foobar') self.assertEqual(self.file.title, 'foobar')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment