[Checkins] SVN: zc.catalog/trunk/src/zc/catalog/ make sure that setting "family" explicitly clears out old structures

Fred L. Drake, Jr. fdrake at gmail.com
Mon Apr 30 15:52:52 EDT 2007


Log message for revision 74942:
  make sure that setting "family" explicitly clears out old structures

Changed:
  U   zc.catalog/trunk/src/zc/catalog/index.py
  U   zc.catalog/trunk/src/zc/catalog/legacy.txt

-=-
Modified: zc.catalog/trunk/src/zc/catalog/index.py
===================================================================
--- zc.catalog/trunk/src/zc/catalog/index.py	2007-04-30 19:34:14 UTC (rev 74941)
+++ zc.catalog/trunk/src/zc/catalog/index.py	2007-04-30 19:52:52 UTC (rev 74942)
@@ -41,6 +41,8 @@
         if instance is None:
             return self
         d = instance.__dict__
+        if "family" in d:
+            return d["family"]
         if "btreemodule" in d:
             iftype = d["btreemodule"].split(".")[-1][:2]
             if iftype == "IF":
@@ -50,14 +52,25 @@
             else:
                 raise ValueError("can't determine btree family based on"
                                  " btreemodule of %r" % (iftype,))
-            del d["btreemodule"]
-            if "IOBTree" in d:
-                del d["IOBTree"]
         else:
             d["family"] = BTrees.family32
+        self._clear_old_cruft(instance)
         return d["family"]
 
+    def __set__(self, instance, value):
+        instance.__dict__["family"] = value
+        self._clear_old_cruft(instance)
 
+    def _clear_old_cruft(self, instance):
+        d = instance.__dict__
+        if "btreemodule" in d:
+            del d["btreemodule"]
+        if "IOBTree" in d:
+            del d["IOBTree"]
+        if "BTreeAPI" in d:
+            del d["BTreeAPI"]
+
+
 class AbstractIndex(persistent.Persistent):
 
     interface.implements(zope.index.interfaces.IInjection,

Modified: zc.catalog/trunk/src/zc/catalog/legacy.txt
===================================================================
--- zc.catalog/trunk/src/zc/catalog/legacy.txt	2007-04-30 19:34:14 UTC (rev 74941)
+++ zc.catalog/trunk/src/zc/catalog/legacy.txt	2007-04-30 19:52:52 UTC (rev 74942)
@@ -96,6 +96,8 @@
   False
   >>> "IOBTree" in vi32.__dict__
   False
+  >>> "BTreeAPI" in vi64.__dict__
+  False
 
 Accessing these attributes as attributes provides the proper values
 anyway::
@@ -136,6 +138,8 @@
   False
   >>> "IOBTree" in vi64.__dict__
   False
+  >>> "BTreeAPI" in vi64.__dict__
+  False
 
   >>> vi64.btreemodule
   'BTrees.LFBTree'
@@ -146,3 +150,38 @@
 
   >>> vi64._p_changed
   False
+
+Now, if we have a legacy structure and explicitly set the ``family``
+attribute, the old data structures will be cleared and replaced with
+the new structure.  If the object is associated with a data manager,
+the changed flag will be set as well::
+
+  >>> class DataManager(object):
+  ...     def register(self, ob):
+  ...         pass
+
+  >>> vi64 = pickle.loads(legacy64_pickle)
+  >>> vi64._p_jar = DataManager()
+  >>> vi64.family = BTrees.family64
+
+  >>> vi64._p_changed
+  True
+
+  >>> "btreemodule" in vi64.__dict__
+  False
+  >>> "IOBTree" in vi64.__dict__
+  False
+  >>> "BTreeAPI" in vi64.__dict__
+  False
+
+  >>> "family" in vi64.__dict__
+  True
+  >>> vi64.family is BTrees.family64
+  True
+
+  >>> vi64.btreemodule
+  'BTrees.LFBTree'
+  >>> vi64.IOBTree
+  <type 'BTrees.LOBTree.LOBTree'>
+  >>> vi64.BTreeAPI
+  <module 'BTrees.LFBTree' from ...>



More information about the Checkins mailing list