[Checkins] SVN: ZODB/trunk/src/ZODB/DemoStorage. Added an option to leave the base storage open when a demo storage is

Jim Fulton jim at zope.com
Tue Oct 28 20:11:59 EDT 2008


Log message for revision 92664:
  Added an option to leave the base storage open when a demo storage is
  closed.
  

Changed:
  U   ZODB/trunk/src/ZODB/DemoStorage.py
  U   ZODB/trunk/src/ZODB/DemoStorage.test

-=-
Modified: ZODB/trunk/src/ZODB/DemoStorage.py
===================================================================
--- ZODB/trunk/src/ZODB/DemoStorage.py	2008-10-29 00:11:56 UTC (rev 92663)
+++ ZODB/trunk/src/ZODB/DemoStorage.py	2008-10-29 00:11:59 UTC (rev 92664)
@@ -36,7 +36,9 @@
         ZODB.interfaces.IStorageIteration,
         )
 
-    def __init__(self, name=None, base=None, changes=None):
+    def __init__(self, name=None, base=None, changes=None,
+                 keep_base_open=False):
+        self._keep_base_open = keep_base_open
         if base is None:
             base = ZODB.MappingStorage.MappingStorage()
         self.base = base
@@ -71,7 +73,8 @@
         self.changes.cleanup()
 
     def close(self):
-        self.base.close()
+        if not self._keep_base_open:
+            self.base.close()
         self.changes.close()
         if getattr(self, '_blob_dir', ''):
             ZODB.blob.remove_committed_dir(self._blob_dir)

Modified: ZODB/trunk/src/ZODB/DemoStorage.test
===================================================================
--- ZODB/trunk/src/ZODB/DemoStorage.test	2008-10-29 00:11:56 UTC (rev 92663)
+++ ZODB/trunk/src/ZODB/DemoStorage.test	2008-10-29 00:11:59 UTC (rev 92664)
@@ -2,10 +2,8 @@
 DemoStorage demo (doctest)
 ==========================
 
-Note that most people will configure the storage through ZConfig.  If
-you are one of those people, you may want to stop here. :)  The
-examples below show you how to use the storage from Python, but they
-also exercise lots of details you might not be interested in.
+DemoStorages provide a way to provide incremental updates to an
+existing, base, storage without updating the storage.
 
 To see how this works, we'll start by creating a base storage and
 puting an object (in addition to the root object) in it:
@@ -122,8 +120,38 @@
     ...  ]
     [True, True, True, True]
 
+
+Normally, when we close a demo storage, the changes and base storages
+are closed:
+
     >>> db.close()
+    >>> base._file.closed
+    True
+    >>> changes._file.closed
+    True
 
+A common use case is to stack multiple DemoStorages, returning to a
+previous state by popping a DemoStorage off the stack.  In this case,
+we want to leave the base storage open:
+
+    >>> base = FileStorage('base.fs', read_only=True)
+    >>> storage = DemoStorage(base=base, keep_base_open=True)
+
+Here, we didn't specify a changes storage.  A MappingStorage was
+automatically created:
+
+    >>> type(storage.changes).__name__
+    'MappingStorage'
+
+Because we specified the keep_base_open option, the base storage is
+left open when we close the DemoStorage:
+
+    >>> storage.close()
+    >>> base._file.closed
+    False
+    >>> storage.changes.opened()
+    False
+
 Blob Support
 ============
 



More information about the Checkins mailing list