[Checkins] SVN: zc.beforestorage/trunk/src/zc/beforestorage/ Added blob support.

Jim Fulton jim at zope.com
Mon Dec 1 12:47:23 EST 2008


Log message for revision 93499:
  Added blob support.
  

Changed:
  U   zc.beforestorage/trunk/src/zc/beforestorage/README.txt
  U   zc.beforestorage/trunk/src/zc/beforestorage/__init__.py

-=-
Modified: zc.beforestorage/trunk/src/zc/beforestorage/README.txt
===================================================================
--- zc.beforestorage/trunk/src/zc/beforestorage/README.txt	2008-12-01 17:47:21 UTC (rev 93498)
+++ zc.beforestorage/trunk/src/zc/beforestorage/README.txt	2008-12-01 17:47:23 UTC (rev 93499)
@@ -40,6 +40,23 @@
 Change history
 ==============
 
+0.3.0 (2008-12-01)
+******************
+
+Added Blob support.
+
+0.2.0 (2008-03-05)
+******************
+
+Added support for "now" and "startup" values to the before option when
+using ZConfig.  The "now" value indicates that the before storage should
+provide a view of the base storage as of the time the storage is created.
+The "startup" value indicates that the before storage should provide a
+view of the base stoage as of process startup time. The later is
+especially useful when setting up more than once before storage in a
+single application, as it allows you to arrange that all of the
+storages provide consistent views without having to specify a time.
+
 0.1.1 (2008-02-07)
 ******************
 
@@ -325,12 +342,54 @@
     >>> len(rootnow)
     10
 
+    >>> dbnow.close()
+
 The timestamp may be passed directory, or as an ISO time.  For
 example:
 
+    >>> fs = ZODB.FileStorage.FileStorage('Data.fs')
     >>> b5 = zc.beforestorage.Before(fs, '2008-01-21T18:23:04')
     >>> db5 = DB(b5)
     >>> conn5 = db5.open()
     >>> root5 = conn5.root()
     >>> len(root5)
     4
+
+    >>> b5.close()
+
+Blob Support
+------------
+
+Before storage supports blobs if the storage it wraps supports blobs,
+and, in fact, it simply exposes the underlying storages loadBlob and
+temporaryDirectory methods.
+
+    >>> fs = ZODB.FileStorage.FileStorage('Data.fs')
+    >>> import ZODB.blob
+    >>> bs = ZODB.blob.BlobStorage('blobs', fs)
+    >>> db = ZODB.DB(bs)
+    >>> conn = db.open()
+    >>> conn.root()['blob'] = ZODB.blob.Blob()
+    >>> conn.root()['blob'].open('w').write('data1')
+    >>> transaction.commit()
+
+    >>> bnow = zc.beforestorage.Before(bs)
+    >>> dbnow = DB(bnow)
+    >>> connnow = dbnow.open()
+    >>> rootnow = connnow.root()
+
+    >>> conn.root()['blob'].open('w').write('data2')
+    >>> transaction.commit()
+    
+    >>> rootnow['blob'].open().read()
+    'data1'
+
+    >>> bnow.temporaryDirectory() == bs.temporaryDirectory()
+    True
+
+    >>> import ZODB.interfaces, zope.interface.verify
+    >>> zope.interface.verify.verifyObject(
+    ...     ZODB.interfaces.IBlobStorage, bnow)
+    True
+
+    >>> bnow.close()

Modified: zc.beforestorage/trunk/src/zc/beforestorage/__init__.py
===================================================================
--- zc.beforestorage/trunk/src/zc/beforestorage/__init__.py	2008-12-01 17:47:21 UTC (rev 93498)
+++ zc.beforestorage/trunk/src/zc/beforestorage/__init__.py	2008-12-01 17:47:23 UTC (rev 93499)
@@ -17,6 +17,8 @@
 import ZODB.POSException
 import ZODB.TimeStamp
 import ZODB.utils
+import ZODB.interfaces
+import zope.interface
 
 def time_stamp():
     t = time.time()
@@ -47,6 +49,11 @@
                 before = repr(ZODB.TimeStamp.TimeStamp(*d))
         self.storage = storage
         self.before = before
+        if ZODB.interfaces.IBlobStorage.providedBy(storage):
+            self.loadBlob = storage.loadBlob
+            self.temporaryDirectory = storage.temporaryDirectory
+            zope.interface.alsoProvides(self, ZODB.interfaces.IBlobStorage)
+            
 
     def close(self):
         self.storage.close()
@@ -131,6 +138,10 @@
     def store(self, oid, serial, data, version, transaction):
         raise ZODB.POSException.StorageTransactionError(self, transaction)
 
+    def storeBlob(self, oid, oldserial, data, blobfilename, version,
+                  transaction):
+        raise ZODB.POSException.StorageTransactionError(self, transaction)
+
     def tpc_abort(self, transaction):
         pass
 



More information about the Checkins mailing list