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

Chris McDonough chrism at plope.com
Sat May 15 14:03:18 EDT 2004


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

Modified Files:
      Tag: Zope-2_7-branch
	Transience.py 
Log Message:
Forward compatibility for HEAD: new-style classes don't respect the
assignment of __len__ as an instance variable.


=== Zope/lib/python/Products/Transience/Transience.py 1.32.12.3 => 1.32.12.4 ===
--- Zope/lib/python/Products/Transience/Transience.py:1.32.12.3	Fri May 14 18:52:12 2004
+++ Zope/lib/python/Products/Transience/Transience.py	Sat May 15 14:03:17 2004
@@ -181,11 +181,11 @@
             self._data[0] = OOBTree() # sentinel value for non-expiring data
             self._max_timeslice = Increaser(0)
 
-        # our "__len__" is the length of _index.
+        # our "_length" 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()
+        try: self._length.set(0)
+        except AttributeError: self._length = self.getLen = Length()
 
     def _getCurrentSlices(self, now):
         if self._timeout_slices:
@@ -337,7 +337,7 @@
                 raise MaxTransientObjectsExceeded, (
                  "%s exceeds maximum number of subobjects %s" %
                  (len(self), self._limit))
-            self.__len__.change(1)
+            self._length.change(1)
         current_bucket = self._data[current_ts]
         current_bucket[k] = v
         self.notifyAdd(v)
@@ -354,9 +354,12 @@
         item = self._move_item(k, current_ts)
         STRICT and _assert(self._data.has_key(current_ts))
         del self._data[current_ts][k]
-        self.__len__.change(-1)
+        self._length.change(-1)
         return current_ts, item
 
+    def __len__(self):
+        return self._length()
+
     security.declareProtected(ACCESS_TRANSIENTS_PERM, 'get')
     def get(self, k, default=None):
         if self._timeout_slices:
@@ -471,7 +474,7 @@
 
             for v in self._data[key].values():
                 to_notify.append(v)
-                self.__len__.change(-1)
+                self._length.change(-1)
 
             del self._data[key]
 
@@ -636,7 +639,7 @@
         # inplace upgrade for versions of Transience in Zope versions less
         # than 2.7.1, which used a different transience mechanism.  Note:
         # this will not work for upgrading versions older than 2.6.0,
-        # which used a very different transience implementation
+        # all of which used a very different transience implementation
         if not getattr(self, '_max_timeslice', None):
             new_slices = getTimeslices(getCurrentTimeslice(), SPARE_BUCKETS*2)
             for i in new_slices:
@@ -645,10 +648,15 @@
             # create an Increaser for max timeslice
             self._max_timeslice = Increaser(max(new_slices))
 
+        # can't make __len__ an instance variable in new-style classes
+        if not getattr(self, '_length', None):
+            length = self.__dict__.get('__len__', Length())
+            self._length = self.getLen = length
+
         # we should probably delete older attributes such as
-        # '_last_timeslice' and '_deindex_next' here but we leave
-        # them in order to allow people to switch between 2.7.0- and 2.7.1+
-        # as necessary (although that has not been tested)
+        # '_last_timeslice', '_deindex_next',and '__len__' here but we leave
+        # them in order to allow people to switch between 2.6.0->2.7.0 and
+        # 2.7.1+ as necessary (although that has not been tested)
     
 def getCurrentTimeslice():
     """




More information about the Zope-Checkins mailing list