[Checkins] SVN: zope.file/trunk/src/zope/file/adapters.txt Add tests for adapters module.
Ulrich Fouquet
cvs-admin at zope.org
Mon Jun 4 15:30:34 UTC 2012
Log message for revision 126564:
Add tests for adapters module.
Changed:
A zope.file/trunk/src/zope/file/adapters.txt
-=-
Added: zope.file/trunk/src/zope/file/adapters.txt
===================================================================
--- zope.file/trunk/src/zope/file/adapters.txt (rev 0)
+++ zope.file/trunk/src/zope/file/adapters.txt 2012-06-04 15:30:29 UTC (rev 126564)
@@ -0,0 +1,54 @@
+========
+Adapters
+========
+
+The `zope.file` package provides some adapters to adapt file-like
+objects to `zope.filerepresentation` conform objects. There is a
+read-file adapter and a write-file adapter available. We start with a
+regular `File` object:
+
+ >>> from zope.file.file import File
+ >>> f = File(parameters=dict(charset='utf-8'))
+ >>> f.open('w').write("hello")
+
+Now we can turn this file into a read-only file which we can read and
+whose size we can get:
+
+ >>> from zope.filerepresentation.interfaces import IReadFile, IWriteFile
+ >>> r = IReadFile(f)
+ >>> r.read()
+ 'hello'
+
+ >>> r.size()
+ 5
+
+Writing to this read-only file is impossible, as the interface does
+not require it:
+
+ >>> r.write("some more content")
+ Traceback (most recent call last):
+ AttributeError: 'ReadFileAdapter' object has no attribute 'write'
+
+With a write-file the opposite happens. We can write but not read:
+
+ >>> w = IWriteFile(f)
+ >>> w.write("some more content")
+ >>> w.read()
+ Traceback (most recent call last):
+ AttributeError: 'WriteFileAdapter' object has no attribute 'read'
+
+The delivered adapters really comply with the promised interfaces:
+
+ >>> from zope.interface.verify import verifyClass, verifyObject
+ >>> from zope.file.adapters import ReadFileAdapter, WriteFileAdapter
+ >>> verifyClass(IReadFile, ReadFileAdapter)
+ True
+
+ >>> verifyObject(IReadFile, r)
+ True
+
+ >>> verifyClass(IWriteFile, WriteFileAdapter)
+ True
+
+ >>> verifyObject(IWriteFile, w)
+ True
More information about the checkins
mailing list