[Zope-Checkins] CVS: Zope/lib/python/Products/ZCatalog -
Catalog.py:1.116
Jim Fulton
cvs-admin at zope.org
Fri Nov 28 11:46:42 EST 2003
Update of /cvs-repository/Zope/lib/python/Products/ZCatalog
In directory cvs.zope.org:/tmp/cvs-serv5257/lib/python/Products/ZCatalog
Modified Files:
Catalog.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/ZCatalog/Catalog.py 1.115 => 1.116 ===
--- Zope/lib/python/Products/ZCatalog/Catalog.py:1.115 Tue Nov 18 08:17:09 2003
+++ Zope/lib/python/Products/ZCatalog/Catalog.py Fri Nov 28 11:46:12 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