Commit 6cf56ff5 authored by Christian Theune's avatar Christian Theune

parent 6b77b82d
...@@ -26,11 +26,11 @@ class Blob(Persistent): ...@@ -26,11 +26,11 @@ class Blob(Persistent):
_p_blob_uncommitted = None _p_blob_uncommitted = None
_p_blob_data = None _p_blob_data = None
def open(self, mode): def open(self, mode="r"):
"""Returns a file(-like) object for handling the blob data.""" """Returns a file(-like) object for handling the blob data."""
result = None result = None
if mode == "r": if (mode.startswith("r") or mode=="U"):
if self._current_filename() is None: if self._current_filename() is None:
raise BlobError, "Blob does not exist." raise BlobError, "Blob does not exist."
...@@ -38,9 +38,9 @@ class Blob(Persistent): ...@@ -38,9 +38,9 @@ class Blob(Persistent):
raise BlobError, "Already opened for writing." raise BlobError, "Already opened for writing."
self._p_blob_readers += 1 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: if self._p_blob_readers != 0:
raise BlobError, "Already opened for reading." raise BlobError, "Already opened for reading."
...@@ -48,9 +48,9 @@ class Blob(Persistent): ...@@ -48,9 +48,9 @@ class Blob(Persistent):
self._p_blob_uncommitted = utils.mktemp() self._p_blob_uncommitted = utils.mktemp()
self._p_blob_writers += 1 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: if self._current_filename() is None:
raise BlobError, "Blob does not exist." raise BlobError, "Blob does not exist."
...@@ -60,12 +60,12 @@ class Blob(Persistent): ...@@ -60,12 +60,12 @@ class Blob(Persistent):
if self._p_blob_uncommitted is None: if self._p_blob_uncommitted is None:
# Create a new working copy # Create a new working copy
self._p_blob_uncommitted = utils.mktmp() 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) utils.cp(file(self._p_blob_data), uncommitted)
uncommitted.seek(0) uncommitted.seek(0)
else: else:
# Re-use existing working copy # 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 self._p_blob_writers +=1
result = uncommitted result = uncommitted
......
...@@ -118,3 +118,12 @@ We can truncate a blob: ...@@ -118,3 +118,12 @@ We can truncate a blob:
>>> f8.read() >>> f8.read()
'' ''
>>> f8.close() >>> f8.close()
We can explicitly open Blobs in the different modified modes:
>>> f9 = myblob.open("rb")
>>> f9.mode
'rb'
>>> f9.close()
- Support database import/export
- Support selection of text/binary mode for opening blobs
- Generic wrapper configuration for BlobStorage
Tests Tests
----- -----
......
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