Commit 62d662d3 authored by Jim Fulton's avatar Jim Fulton

The Blob open method now supports a new mode, 'c', to open committed

data for reading as an ordinary file, rather than as a blob file.
The ordinary file may be used outside the current transaction and
even after the blob's database connection has been closed.
parent 901af395
......@@ -22,7 +22,18 @@ New Features
XXX There are known issues with this implementation that need to be
sorted out before it is "released".
3.9.0a6 (2008-11-??)
3.9.0a6 (2008-12-??)
====================
New Features
------------
- The Blob open method now supports a new mode, 'c', to open committed
data for reading as an ordinary file, rather than as a blob file.
The ordinary file may be used outside the current transaction and
even after the blob's database connection has been closed.
3.9.0a6 (2008-11-30)
====================
New Features
......
......@@ -45,7 +45,7 @@ SAVEPOINT_SUFFIX = ".spb"
LAYOUT_MARKER = '.layout'
LAYOUTS = {}
valid_modes = 'r', 'w', 'r+', 'a'
valid_modes = 'r', 'w', 'r+', 'a', 'c'
# Threading issues:
# We want to support closing blob files when they are destroyed.
......@@ -119,6 +119,9 @@ class Blob(persistent.Persistent):
if mode not in valid_modes:
raise ValueError("invalid mode", mode)
if mode == 'c':
return open(self.committed(), 'rb')
if self.writers:
raise BlobError("Already opened for writing.")
......
......@@ -978,7 +978,12 @@ class IBlob(Interface):
Returns a file(-like) object for handling the blob data.
mode: Mode to open the file with. Possible values: r,w,r+,a
mode: Mode to open the file with. Possible values: r,w,r+,a,c
The mode 'c' is similar to 'r', except that an orinary file
object is returned and may be used in a separate transaction
and after the blob's database connection has been closed.
"""
def committed():
......
......@@ -306,6 +306,27 @@ file that can be opened.
>>> open(blob.committed()).read()
"I'm a happy blob."
We can also read committed data by calling open with a 'c' flag:
>>> f = blob.open('c')
This just returns a regular file object:
>>> type(f)
<type 'file'>
and doesn't prevent us from opening the blob for writing:
>>> blob.open('w').write('x')
>>> blob.open().read()
'x'
>>> f.read()
"I'm a happy blob."
>>> f.close()
>>> transaction.abort()
An exception is raised if we call committed on a blob that has
uncommitted changes:
......@@ -315,6 +336,11 @@ uncommitted changes:
...
BlobError: Uncommitted changes
>>> blob.open('c')
Traceback (most recent call last):
...
BlobError: Uncommitted changes
>>> blob.open('w').write("I'm a happy blob.")
>>> root6['blob6'] = blob
>>> blob.committed()
......@@ -322,12 +348,22 @@ uncommitted changes:
...
BlobError: Uncommitted changes
>>> blob.open('c')
Traceback (most recent call last):
...
BlobError: Uncommitted changes
>>> s = transaction.savepoint()
>>> blob.committed()
Traceback (most recent call last):
...
BlobError: Uncommitted changes
>>> blob.open('c')
Traceback (most recent call last):
...
BlobError: Uncommitted changes
>>> transaction.commit()
>>> open(blob.committed()).read()
"I'm a happy blob."
......
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