A persistent content component storing binary file data
Let's test the constructor:
>>> file = File() >>> file.contentType '' >>> file.data ''
>>> file = File('Foobar') >>> file.contentType '' >>> file.data 'Foobar'
>>> file = File('Foobar', 'text/plain') >>> file.contentType 'text/plain' >>> file.data 'Foobar'
>>> file = File(data='Foobar', contentType='text/plain') >>> file.contentType 'text/plain' >>> file.data 'Foobar'
Let's test the mutators:
>>> file = File() >>> file.contentType = 'text/plain' >>> file.contentType 'text/plain'
>>> file.data = 'Foobar' >>> file.data 'Foobar'
>>> file.data = None Traceback (most recent call last): ... TypeError: Cannot set None data on a file.
Let's test large data input:
>>> file = File()
Insert as string:
>>> file.data = 'Foobar'*60000 >>> file.getSize() 360000 >>> file.data == 'Foobar'*60000 True
Insert data as FileChunk:
>>> fc = FileChunk('Foobar'*4000) >>> file.data = fc >>> file.getSize() 24000 >>> file.data == 'Foobar'*4000 True
Insert data from file object:
>>> import cStringIO >>> sio = cStringIO.StringIO() >>> sio.write('Foobar'*100000) >>> sio.seek(0) >>> file.data = sio >>> file.getSize() 600000 >>> file.data == 'Foobar'*100000 True
Last, but not least, verify the interface:
>>> from zope.interface.verify import verifyClass >>> interfaces.IFile.implementedBy(File) True >>> verifyClass(interfaces.IFile, File) True
data
(type:
property
)
<property object at 0x40d24d24>
getSize()
See IFile