[Zope-CVS] CVS: Products/Transience - Transience.py:1.4

Matthew T. Kromer matt@zope.com
Mon, 22 Oct 2001 16:00:36 -0400


Update of /cvs-repository/Products/Transience
In directory cvs.zope.org:/tmp/cvs-serv12593

Modified Files:
	Transience.py 
Log Message:
Fixup callbacks somewhat


=== Products/Transience/Transience.py 1.3 => 1.4 ===
         self[key] = item
 
-        self.notifyAdd(item)
-
         return item
         
 
@@ -283,15 +281,27 @@
         self._delCallback = f
 
     def notifyAdd(self, item):
-        if self._addCallback:
+
+        callback = self._addCallback
+
+        if type(callback) is type(''):
+            callback = self.aq_parent.unrestrictedTraverse(callback)
+
+        if callable(callback):
             try:
-                self._addCallback(item, self)   # Use self as context
+                callback(item, self)            # Use self as context
             except: pass                        # Eat all errors 
 
     def notifyDestruct(self, item):
-        if self._delCallback:
+
+        callback = self._delCallback
+
+        if type(callback) is type(''):
+            callback = self.aq_parent.unrestrictedTraverse(callback)
+
+        if callable(callback):
             try:
-                self._delCallback(item, self)   # Use self as context
+                callback(item, self)            # Use self as context
             except: pass                        # Eat all errors 
 
     # -----------------------------------------------------------------
@@ -423,11 +433,12 @@
         #        if d != last:
         #            mgr = self.aq_parent.unrestrictedTraverse(d)
         #            last = d
+        #
         #    if callable(f): f(mgr)
 
         for k, v in list(index.items()):
             if v is b:
-                self.notifyDestruct(index[k])
+                self.notifyDestruct(index[k][k])
                 del index[k]
         b.clear()
 
@@ -454,6 +465,7 @@
         if b is None:
             # this is a new key
             index[k] = current
+            self.notifyAdd(v)
         elif b is not current:
             # this is an old key that isn't in the current bucket.
             del b[k] # delete it from the old bucket