[Zope-Checkins] CVS: Zope/lib/python/Products/Transience - Transience.py:1.34

Jim Fulton cvs-admin at zope.org
Fri Nov 28 11:46:42 EST 2003


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

Modified Files:
	Transience.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/Transience/Transience.py 1.33 => 1.34 ===
--- Zope/lib/python/Products/Transience/Transience.py:1.33	Tue Nov 18 08:17:08 2003
+++ Zope/lib/python/Products/Transience/Transience.py	Fri Nov 28 11:46:11 2003
@@ -427,8 +427,16 @@
             # our "__len__" is the length of _index.
             # we need to maintain the length of the index structure separately
             # because getting the length of a BTree is very expensive.
-            try: self.__len__.set(0)
-            except AttributeError: self.__len__ = self.getLen = Length()
+            # Note that it is a mistake to use the __len__ attr this way,
+            # because length methods are cached in C slots and out instance
+            # attr won't be used for len(foo) in new-style classes.
+            # See the __len__ method below. I (Jim) am not changing this now
+            # on account of ols instances. With some effort, we could fix this,
+            # bit I'm not up for it now.
+            try:
+                self.__len__.set(0)
+            except AttributeError:
+                self.__len__ = Length()
 
             # set up last_timeslice and deindex_next integer pointers
             # we set them to the current timeslice as it's the only sane
@@ -437,6 +445,12 @@
             self._deindex_next=Increaser(self._getCurrentTimeslice())
         finally:
             self.lock.release()
+
+    def __len__(self):
+        return self.__dict__['__len__']()
+
+    def getLen(self):
+        return self.__len__
 
     def _getCurrentBucket(self):
         """




More information about the Zope-Checkins mailing list