[Zope-Checkins] SVN: Zope/trunk/lib/python/Products/PluginIndexes/common/UnIndex.py removed __len__ as persistent attribute

Andreas Jung andreas at andreas-jung.com
Sun Jan 30 07:43:24 EST 2005


Log message for revision 28978:
  removed __len__ as persistent attribute
  

Changed:
  U   Zope/trunk/lib/python/Products/PluginIndexes/common/UnIndex.py

-=-
Modified: Zope/trunk/lib/python/Products/PluginIndexes/common/UnIndex.py
===================================================================
--- Zope/trunk/lib/python/Products/PluginIndexes/common/UnIndex.py	2005-01-30 11:54:12 UTC (rev 28977)
+++ Zope/trunk/lib/python/Products/PluginIndexes/common/UnIndex.py	2005-01-30 12:43:24 UTC (rev 28978)
@@ -88,30 +88,16 @@
         except:
             self.indexed_attrs = [ self.id ] 
         
-        # 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._length = BTrees.Length.Length()
         self.clear()
 
     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)
+        return self._length()
 
     def getId(self):
         return self.id
 
     def clear(self):
-        # inplace opportunistic conversion from old-style to new style BTrees
-        try: self.__len__.set(0)
-        except AttributeError: self.__len__=BTrees.Length.Length()
         self._index = OOBTree()
         self._unindex = IOBTree()
 
@@ -158,12 +144,12 @@
                 indexRow.remove(documentId)
                 if not indexRow:
                     del self._index[entry]
-                    try: self.__len__.change(-1)
+                    try: self._length.change(-1)
                     except AttributeError: pass # pre-BTrees-module instance
             except AttributeError:
                 # index row is an int
                 del self._index[entry]
-                try: self.__len__.change(-1)
+                try: self._length.change(-1)
                 except AttributeError: pass # pre-BTrees-module instance
             except:
                 LOG.error('%s: unindex_object could not remove '
@@ -190,7 +176,7 @@
         # an IntSet and stuff it in first.
         if indexRow is _marker:
             self._index[entry] = documentId
-            try:  self.__len__.change(1)
+            try:  self._length.change(1)
             except AttributeError: pass # pre-BTrees-module instance
         else:
             try: indexRow.insert(documentId)



More information about the Zope-Checkins mailing list