[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/common
- UnIndex.py:1.21
Jim Fulton
cvs-admin at zope.org
Fri Nov 28 11:46:41 EST 2003
Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/common
In directory cvs.zope.org:/tmp/cvs-serv5257/lib/python/Products/PluginIndexes/common
Modified Files:
UnIndex.py
Log Message:
With new-style classes, is is no longer possible to override slots
(special '__' methods) on an instance-by instance basis. Changed the
handling of the length so that the __len__ method looks for a __len__
dictionary key. It would be better not to use a __len__ attribute name
for the BTree length object, but such a change would be problematic
for old instances.
=== Zope/lib/python/Products/PluginIndexes/common/UnIndex.py 1.20 => 1.21 ===
--- Zope/lib/python/Products/PluginIndexes/common/UnIndex.py:1.20 Tue Jun 17 15:01:08 2003
+++ Zope/lib/python/Products/PluginIndexes/common/UnIndex.py Fri Nov 28 11:46:11 2003
@@ -21,8 +21,6 @@
from Globals import Persistent
from Acquisition import Implicit
-import BTree
-import IOBTree
from zLOG import LOG, ERROR
from BTrees.OOBTree import OOBTree, OOSet
@@ -95,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
@@ -139,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