[Zodb-checkins]
SVN: ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/
- Explicitly allow the different modes to be selected when
opening a blob file.
Christian Theune
ct at gocept.com
Thu Mar 24 03:14:01 EST 2005
Log message for revision 29662:
- Explicitly allow the different modes to be selected when opening a blob file.
Changed:
U ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/Blob.py
U ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/Blob.txt
U ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/TODO.txt
-=-
Modified: ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/Blob.py
===================================================================
--- ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/Blob.py 2005-03-24 08:13:36 UTC (rev 29661)
+++ ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/Blob.py 2005-03-24 08:14:01 UTC (rev 29662)
@@ -26,11 +26,11 @@
_p_blob_uncommitted = None
_p_blob_data = None
- def open(self, mode):
+ def open(self, mode="r"):
"""Returns a file(-like) object for handling the blob data."""
result = None
- if mode == "r":
+ if (mode.startswith("r") or mode=="U"):
if self._current_filename() is None:
raise BlobError, "Blob does not exist."
@@ -38,9 +38,9 @@
raise BlobError, "Already opened for writing."
self._p_blob_readers += 1
- result = BlobFile(self._current_filename(), "rb", self)
+ result = BlobFile(self._current_filename(), mode, self)
- if mode == "w":
+ if mode.startswith("w"):
if self._p_blob_readers != 0:
raise BlobError, "Already opened for reading."
@@ -48,9 +48,9 @@
self._p_blob_uncommitted = utils.mktemp()
self._p_blob_writers += 1
- result = BlobFile(self._p_blob_uncommitted, "wb", self)
+ result = BlobFile(self._p_blob_uncommitted, mode, self)
- if mode =="a":
+ if mode.startswith("a"):
if self._current_filename() is None:
raise BlobError, "Blob does not exist."
@@ -60,12 +60,12 @@
if self._p_blob_uncommitted is None:
# Create a new working copy
self._p_blob_uncommitted = utils.mktmp()
- uncommitted = BlobFile(self._p_blob_uncommitted, "wb", self)
+ uncommitted = BlobFile(self._p_blob_uncommitted, mode, self)
utils.cp(file(self._p_blob_data), uncommitted)
uncommitted.seek(0)
else:
# Re-use existing working copy
- uncommitted = BlobFile(self._p_blob_uncommitted, "ab", self)
+ uncommitted = BlobFile(self._p_blob_uncommitted, mode, self)
self._p_blob_writers +=1
result = uncommitted
Modified: ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/Blob.txt
===================================================================
--- ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/Blob.txt 2005-03-24 08:13:36 UTC (rev 29661)
+++ ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/Blob.txt 2005-03-24 08:14:01 UTC (rev 29662)
@@ -118,3 +118,12 @@
>>> f8.read()
''
>>> f8.close()
+
+We can explicitly open Blobs in the different modified modes:
+
+ >>> f9 = myblob.open("rb")
+ >>> f9.mode
+ 'rb'
+ >>> f9.close()
+
+
Modified: ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/TODO.txt
===================================================================
--- ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/TODO.txt 2005-03-24 08:13:36 UTC (rev 29661)
+++ ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/TODO.txt 2005-03-24 08:14:01 UTC (rev 29662)
@@ -1,10 +1,4 @@
-- Support database import/export
-
-- Support selection of text/binary mode for opening blobs
-
-- Generic wrapper configuration for BlobStorage
-
Tests
-----
More information about the Zodb-checkins
mailing list