[Checkins] SVN: zope.file/trunk/s refactored zope.file for the
latest blob changes
Christian Zagrodnick
cz at gocept.com
Thu Jun 21 08:32:05 EDT 2007
Log message for revision 76894:
refactored zope.file for the latest blob changes
Changed:
U zope.file/trunk/setup.py
U zope.file/trunk/src/zope/file/README.txt
U zope.file/trunk/src/zope/file/browser.txt
U zope.file/trunk/src/zope/file/configure.zcml
U zope.file/trunk/src/zope/file/contenttype.py
U zope.file/trunk/src/zope/file/download.txt
U zope.file/trunk/src/zope/file/file.py
U zope.file/trunk/src/zope/file/ftests.py
U zope.file/trunk/src/zope/file/interfaces.py
U zope.file/trunk/src/zope/file/upload.py
-=-
Modified: zope.file/trunk/setup.py
===================================================================
--- zope.file/trunk/setup.py 2007-06-21 11:22:01 UTC (rev 76893)
+++ zope.file/trunk/setup.py 2007-06-21 12:32:05 UTC (rev 76894)
@@ -9,6 +9,7 @@
include_package_data=True,
zip_safe = False,
install_requires=['setuptools',
+ 'ZODB3>=3.8.0b1',
'zope.app.appsetup',
'zope.app.publication',
'zope.app.wsgi',
Modified: zope.file/trunk/src/zope/file/README.txt
===================================================================
--- zope.file/trunk/src/zope/file/README.txt 2007-06-21 11:22:01 UTC (rev 76893)
+++ zope.file/trunk/src/zope/file/README.txt 2007-06-21 12:32:05 UTC (rev 76894)
@@ -43,12 +43,13 @@
access to content data through accessor objects that provide (subsets
of) Python's file API.
-A file that hasn't been written to is empty. We can get a reader by
-calling `open()`::
+A file that hasn't been written to is empty. We can get a reader by calling
+`open()`. Note that all blobs are binary, thus the mode always contains a
+'b'::
>>> r = f.open("r")
>>> r.mode
- 'r'
+ 'rb'
The `read()` method can be called with a non-negative integer argument
to specify how many bytes to read, or with a negative or omitted
@@ -76,7 +77,7 @@
>>> w = f.open("w")
>>> w.mode
- 'w'
+ 'wb'
The `write()` method is used to add data to the file, but note that
the data may be buffered in the writer::
Modified: zope.file/trunk/src/zope/file/browser.txt
===================================================================
--- zope.file/trunk/src/zope/file/browser.txt 2007-06-21 11:22:01 UTC (rev 76893)
+++ zope.file/trunk/src/zope/file/browser.txt 2007-06-21 12:32:05 UTC (rev 76894)
@@ -27,7 +27,7 @@
Let's add some content to the file::
- >>> w = f.open('wb')
+ >>> w = f.open('w')
>>> w.write("some text")
>>> w.close()
Modified: zope.file/trunk/src/zope/file/configure.zcml
===================================================================
--- zope.file/trunk/src/zope/file/configure.zcml 2007-06-21 11:22:01 UTC (rev 76893)
+++ zope.file/trunk/src/zope/file/configure.zcml 2007-06-21 12:32:05 UTC (rev 76894)
@@ -17,7 +17,7 @@
/>
<require
permission="zope.ManageContent"
- attributes="openDetached open"
+ attributes="open openDetached"
/>
<implements
interface="
@@ -30,10 +30,10 @@
<adapter factory=".adapters.ReadFileAdapter" />
<adapter factory=".adapters.WriteFileAdapter" />
- <class class="ZODB.Blobs.Blob.BlobFile">
+ <class class="ZODB.blob.BlobFile">
<require
permission="zope.View"
- attributes="read openDetached"
+ attributes="read"
/>
<require
permission="zope.ManageContent"
Modified: zope.file/trunk/src/zope/file/contenttype.py
===================================================================
--- zope.file/trunk/src/zope/file/contenttype.py 2007-06-21 11:22:01 UTC (rev 76893)
+++ zope.file/trunk/src/zope/file/contenttype.py 2007-06-21 12:32:05 UTC (rev 76894)
@@ -51,7 +51,7 @@
if iface.extends(mimetype.interfaces.IContentTypeEncoded):
# Need to test that this codec can be used for this
# document:
- f = file.open("rb")
+ f = file.open("r")
content_data = f.read()
f.close()
try:
Modified: zope.file/trunk/src/zope/file/download.txt
===================================================================
--- zope.file/trunk/src/zope/file/download.txt 2007-06-21 11:22:01 UTC (rev 76893)
+++ zope.file/trunk/src/zope/file/download.txt 2007-06-21 12:32:05 UTC (rev 76894)
@@ -19,8 +19,11 @@
Let's start by creating a file object we can use to demonstrate the
download support::
+ >>> import transaction
>>> from zope.file.file import File
>>> f = File()
+ >>> getRootFolder()['file'] = f
+ >>> transaction.commit()
Headers
-------
@@ -34,10 +37,10 @@
Since there's no suggested download filename on the file, the
Content-Disposition header doesn't specify one, but does indicate that
the response body be treated as a file to save rather than to apply
-the default handler for the content type.
+the default handler for the content type::
>>> sorted(headers)
- [('Content-Disposition', 'attachment'),
+ [('Content-Disposition', 'attachment; filename="file"'),
('Content-Length', '0'),
('Content-Type', 'application/octet-stream')]
@@ -51,7 +54,7 @@
>>> f.mimeType = "text/plain"
>>> headers = getHeaders(f, contentDisposition='attachment')
>>> sorted(headers)
- [('Content-Disposition', 'attachment'),
+ [('Content-Disposition', 'attachment; filename="file"'),
('Content-Length', '0'),
('Content-Type', 'text/plain')]
@@ -60,7 +63,7 @@
>>> headers = getHeaders(f, contentType="text/xml",
... contentDisposition='attachment')
>>> sorted(headers)
- [('Content-Disposition', 'attachment'),
+ [('Content-Disposition', 'attachment; filename="file"'),
('Content-Length', '0'),
('Content-Type', 'text/xml')]
@@ -69,7 +72,7 @@
>>> headers = getHeaders(f, contentDisposition='attachment')
>>> sorted(headers)
- [('Content-Disposition', 'attachment'),
+ [('Content-Disposition', 'attachment; filename="file"'),
('Content-Length', '0'),
('Content-Type', 'text/plain')]
@@ -88,7 +91,7 @@
>>> headers = getHeaders(f, contentDisposition="inline")
>>> sorted(headers)
- [('Content-Disposition', 'inline'),
+ [('Content-Disposition', 'inline; filename="file"'),
('Content-Length', '0'),
('Content-Type', 'text/plain')]
@@ -105,8 +108,9 @@
----
We use DownloadResult to deliver the content to the browser. Since
-there's no data in this file, there are no body chunks:
-
+there's no data in this file, there are no body chunks::
+
+ >>> transaction.commit()
>>> from zope.file.download import DownloadResult
>>> result = DownloadResult(f)
>>> list(result)
@@ -115,10 +119,11 @@
We still need to see how non-empty files are handled. Let's write
some data to our file object::
- >>> w = f.open("wb")
+ >>> w = f.open("w")
>>> w.write("some text")
>>> w.flush()
>>> w.close()
+ >>> transaction.commit()
Now we can create a result object and see if we get the data we
expect::
@@ -131,10 +136,11 @@
If the body content is really large, the iterator may provide more
than one chunk of data::
- >>> w = f.open("wb")
+ >>> w = f.open("w")
>>> w.write("*" * 1024 * 1024)
>>> w.flush()
>>> w.close()
+ >>> transaction.commit()
>>> result = DownloadResult(f)
>>> L = list(result)
@@ -160,10 +166,10 @@
>>> w = f.open("w")
>>> w.write("some text")
>>> w.close()
+ >>> transaction.commit()
>>> getRootFolder()["abcdefg"] = f
- >>> import transaction
>>> transaction.commit()
Now, let's request the download view of the file object and check the
@@ -189,7 +195,7 @@
Note that browsers may decide not to display the image when this view
is used and there is not page that it's being loaded into: if this
view is being referenced directly via the URL, the browser may show
-nothing.
+nothing::
>>> print http("""
... GET /abcdefg/@@inline HTTP/1.1
@@ -208,7 +214,7 @@
This view is similar to the download and inline views, but no content
disposition is specified at all. This lets the browser's default
-handling of the data in the current context to be applied.
+handling of the data in the current context to be applied::
>>> print http("""
... GET /abcdefg/@@display HTTP/1.1
Modified: zope.file/trunk/src/zope/file/file.py
===================================================================
--- zope.file/trunk/src/zope/file/file.py 2007-06-21 11:22:01 UTC (rev 76893)
+++ zope.file/trunk/src/zope/file/file.py 2007-06-21 12:32:05 UTC (rev 76894)
@@ -24,7 +24,7 @@
import zope.file.interfaces
import zope.interface
-from ZODB.Blobs.Blob import Blob
+from ZODB.blob import Blob
class File(persistent.Persistent):
@@ -55,7 +55,7 @@
return self._data.open(mode)
def openDetached(self):
- return self._data.openDetached()
+ return file(self._data.committed(), 'rb')
@property
def size(self):
Modified: zope.file/trunk/src/zope/file/ftests.py
===================================================================
--- zope.file/trunk/src/zope/file/ftests.py 2007-06-21 11:22:01 UTC (rev 76893)
+++ zope.file/trunk/src/zope/file/ftests.py 2007-06-21 12:32:05 UTC (rev 76894)
@@ -24,7 +24,7 @@
import transaction
from ZODB.DB import DB
from ZODB.DemoStorage import DemoStorage
-from ZODB.Blobs.BlobStorage import BlobStorage
+from ZODB.blob import BlobStorage
from zope.testing import doctest
import zope.app.testing.functional
from zope.app.component.hooks import setSite
Modified: zope.file/trunk/src/zope/file/interfaces.py
===================================================================
--- zope.file/trunk/src/zope/file/interfaces.py 2007-06-21 11:22:01 UTC (rev 76893)
+++ zope.file/trunk/src/zope/file/interfaces.py 2007-06-21 12:32:05 UTC (rev 76894)
@@ -30,9 +30,8 @@
def open(mode="r"):
"""Return an object providing access to the file data.
- Allowed values for `mode` are 'r' and 'rb' (read); 'w' and
- 'wb' (write); and 'w+', 'w+b', 'wb+', 'r+', 'r+b', and 'rb+' (both).
- Other values cause `ValueError` to be raised.
+ Allowed values for `mode` are 'r' (read); 'w' (write); 'a' (append) and
+ 'r+' (read/write). Other values cause `ValueError` to be raised.
If the file is opened in read mode, an object with an API (but
not necessarily interface) of `IFileReader` is returned; if
@@ -43,9 +42,10 @@
All readers and writers operate in 'binary' mode.
"""
+
def openDetached():
"""Return file data disconnected from database connection.
-
+
Read access only.
"""
Modified: zope.file/trunk/src/zope/file/upload.py
===================================================================
--- zope.file/trunk/src/zope/file/upload.py 2007-06-21 11:22:01 UTC (rev 76893)
+++ zope.file/trunk/src/zope/file/upload.py 2007-06-21 12:32:05 UTC (rev 76894)
@@ -157,6 +157,6 @@
else:
ob.mimeType = mimeType
ob.parameters = {}
- w = ob.open("wb")
+ w = ob.open("w")
w.write(data)
w.close()
More information about the Checkins
mailing list