[Zope-Checkins] CVS: Zope/lib/python/Products/ZCatalog - Catalog.py:1.115.2.1

Jim Fulton cvs-admin at zope.org
Thu Nov 27 10:34:28 EST 2003


Update of /cvs-repository/Zope/lib/python/Products/ZCatalog
In directory cvs.zope.org:/tmp/cvs-serv7869/lib/python/Products/ZCatalog

Modified Files:
      Tag: Zope-2_8-devel-branch
	Catalog.py 
Log Message:
Got tests to pass except test that was previously (and still) failing
on head.


=== Zope/lib/python/Products/ZCatalog/Catalog.py 1.115 => 1.115.2.1 ===
--- Zope/lib/python/Products/ZCatalog/Catalog.py:1.115	Tue Nov 18 08:17:09 2003
+++ Zope/lib/python/Products/ZCatalog/Catalog.py	Thu Nov 27 10:33:57 2003
@@ -76,7 +76,13 @@
         # object unique identifier to the rid, and self.paths is a
         # mapping of the rid to the unique identifier.
 
-        self.__len__=BTrees.Length.Length()
+        # Note that it was unfortunate to use __len__ as the attribute
+        # name here. New-style classes cache slot methods in C slot
+        # pointers. The result is that instances can't override slots.
+        # This is not easy to change on account of old objects with
+        # __len__ attr.
+
+        self.__len__ = BTrees.Length.Length()
         self.clear()
 
         if brains is not None:
@@ -84,6 +90,14 @@
 
         self.updateBrains()
 
+    def __len__(self):
+        try:
+            return self.__dict__['__len__']()
+        except KeyError:
+            # Fallback for *really* old catalogs that don't have
+            # Length objects. 
+            return len(self.data)
+
     def clear(self):
         """ clear catalog """
 
@@ -121,11 +135,6 @@
         for index in self.indexes.values():
             if hasattr(index, '__of__'): index=index.__of__(self)
             index._convertBTrees(threshold)
-
-    def __len__(self):
-        # NOTE, this is never called for new catalogs, since
-        # each instance overrides this.
-        return len(self.data)
 
     def updateBrains(self):
         self.useBrains(self._v_brains)




More information about the Zope-Checkins mailing list