[Zodb-checkins]
SVN: ZODB/branches/blob-merge-branch/src/ZODB/Blobs/
added tests for Blob.openDetached()
Wolfgang Schnerring
wosc at wosc.de
Mon Sep 25 07:34:08 EDT 2006
Log message for revision 70362:
added tests for Blob.openDetached()
Changed:
U ZODB/branches/blob-merge-branch/src/ZODB/Blobs/Blob.py
U ZODB/branches/blob-merge-branch/src/ZODB/Blobs/TODO.txt
U ZODB/branches/blob-merge-branch/src/ZODB/Blobs/tests/transaction.txt
-=-
Modified: ZODB/branches/blob-merge-branch/src/ZODB/Blobs/Blob.py
===================================================================
--- ZODB/branches/blob-merge-branch/src/ZODB/Blobs/Blob.py 2006-09-25 09:44:29 UTC (rev 70361)
+++ ZODB/branches/blob-merge-branch/src/ZODB/Blobs/Blob.py 2006-09-25 11:34:08 UTC (rev 70362)
@@ -216,6 +216,7 @@
if self.blob._p_blob_uncommitted is not None and \
os.path.exists(self.blob._p_blob_uncommitted):
os.unlink(self.blob._p_blob_uncommitted)
+ self.blob._p_blob_uncommitted = None
# IDataManager
Modified: ZODB/branches/blob-merge-branch/src/ZODB/Blobs/TODO.txt
===================================================================
--- ZODB/branches/blob-merge-branch/src/ZODB/Blobs/TODO.txt 2006-09-25 09:44:29 UTC (rev 70361)
+++ ZODB/branches/blob-merge-branch/src/ZODB/Blobs/TODO.txt 2006-09-25 11:34:08 UTC (rev 70362)
@@ -7,8 +7,6 @@
- Check cache-compatibility with shared network filesystems (mcdonc)
- - tests for openDetached
-
Far future
More options for blob directory structures (e.g. dirstorages
Modified: ZODB/branches/blob-merge-branch/src/ZODB/Blobs/tests/transaction.txt
===================================================================
--- ZODB/branches/blob-merge-branch/src/ZODB/Blobs/tests/transaction.txt 2006-09-25 09:44:29 UTC (rev 70361)
+++ ZODB/branches/blob-merge-branch/src/ZODB/Blobs/tests/transaction.txt 2006-09-25 11:34:08 UTC (rev 70362)
@@ -232,8 +232,59 @@
Traceback (most recent call last):
...
TypeError: ('Savepoints unsupported', <ZODB.Blobs.Blob.BlobDataManager instance at 0x...>)
+ >>> transaction.abort()
+Reading Blobs outside of a transaction
+--------------------------------------
+If you want to read from a Blob outside of transaction boundaries (e.g. to
+stream a file to the browser), you can use the openDetached() method:
+
+ >>> connection6 = database.open()
+ >>> root6 = connection6.root()
+ >>> blob = Blob()
+ >>> blob_fh = blob.open("wb")
+ >>> blob_fh.write("I'm a happy blob.")
+ >>> blob_fh.close()
+ >>> root6['blob'] = blob
+ >>> transaction.commit()
+ >>> blob.openDetached().read()
+ "I'm a happy blob."
+
+Of course, that doesn't work for empty blobs
+
+ >>> blob = Blob()
+ >>> blob.openDetached()
+ Traceback (most recent call last):
+ ...
+ BlobError: Blob does not exist.
+
+nor when the Blob is already opened for writing:
+
+ >>> blob = Blob()
+ >>> blob_fh = blob.open("wb")
+ >>> blob.openDetached()
+ Traceback (most recent call last):
+ ...
+ BlobError: Already opened for writing.
+
+It does work when the transaction was aborted, though:
+
+ >>> blob = Blob()
+ >>> blob_fh = blob.open("wb")
+ >>> blob_fh.write("I'm a happy blob.")
+ >>> blob_fh.close()
+ >>> root6['blob'] = blob
+ >>> transaction.commit()
+
+ >>> blob_fh = blob.open("wb")
+ >>> blob_fh.write("And I'm singing.")
+ >>> blob_fh.close()
+ >>> transaction.abort()
+ >>> blob.openDetached().read()
+ "I'm a happy blob."
+
+
Teardown
--------
More information about the Zodb-checkins
mailing list