[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/common - UnIndex.py:1.20.26.2

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


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

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


=== Zope/lib/python/Products/PluginIndexes/common/UnIndex.py 1.20.26.1 => 1.20.26.2 ===
--- Zope/lib/python/Products/PluginIndexes/common/UnIndex.py:1.20.26.1	Tue Nov 25 15:17:36 2003
+++ Zope/lib/python/Products/PluginIndexes/common/UnIndex.py	Thu Nov 27 10:33:54 2003
@@ -93,11 +93,27 @@
         except:
             self.indexed_attrs = [ self.id ] 
         
-        
-        self.__len__=BTrees.Length.Length() # see __len__ method docstring
+        # It was a mistake to use a __len__ attribute here, but it's not
+        # worth changing at this point, as there is old data with this
+        # attribute name. :( See __len__ method docstring
+        self.__len__ = BTrees.Length.Length() 
+
         self.clear()
 
-    def getId(self): return self.id
+    def __len__(self):
+        """Return the number of objects indexed.
+        """
+
+        # The instance __len__ attr isn't effective because
+        # Python cached this method in a slot,
+        __len__ = self.__dict__.get('__len__')
+        if __len__ is not None:
+            return __len__() 
+        
+        return len(self._unindex)
+
+    def getId(self):
+        return self.id
 
     def clear(self):
         # inplace opportunistic conversion from old-style to new style BTrees
@@ -137,15 +153,6 @@
 
     def __nonzero__(self):
         return not not self._unindex
-
-    def __len__(self):
-        """Return the number of objects indexed.
-
-        This method is only called for indexes which have "old" BTrees,
-        and the *only* reason that UnIndexes maintain a __len__ is for
-        the searching code in the catalog during sorting.
-        """
-        return len(self._unindex)
 
     def histogram(self):
         """Return a mapping which provides a histogram of the number of




More information about the Zope-Checkins mailing list