[Zope3-checkins] CVS: Zope3/src/zope/app/services - registration.py:1.19

Jim Fulton cvs-admin at zope.org
Fri Nov 21 12:10:27 EST 2003


Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv29980/src/zope/app/services

Modified Files:
	registration.py 
Log Message:
Fixed bugs in activation and deactivation notification.
Registrations were being notified too soon.


=== Zope3/src/zope/app/services/registration.py 1.18 => 1.19 ===
--- Zope3/src/zope/app/services/registration.py:1.18	Thu Oct 30 16:55:15 2003
+++ Zope3/src/zope/app/services/registration.py	Fri Nov 21 12:09:56 2003
@@ -153,9 +153,12 @@
         data = self._data
         if data:
             if data[0] == cid:
+                data = data[1:]
+                self._data = data
+
                 # Tell it that it is no longer active
                 registration.deactivated()
-                data = data[1:]
+
                 if data and data[0] is not None:
                     # Activate the newly active component
                     sm = zapi.getServiceManager(self)
@@ -169,8 +172,7 @@
                 if data and data[-1] is None:
                     data = data[:-1]
 
-            # Write data back
-            self._data = data
+                self._data = data
 
     def registered(self, registration):
         cid = self._id(registration)
@@ -187,16 +189,10 @@
             return # already in the state we want
 
         if cid is None or cid in data:
-
-            if data[0] == cid:
+            old = data[0]
+            if old == cid:
                 return # already active
 
-            if data[0] is not None:
-                # Deactivate the currently active component
-                sm = zapi.getServiceManager(self)
-                old = zapi.traverse(sm, data[0])
-                old.deactivated()
-
             # Insert it in front, removing it from back
             data = (cid, ) + tuple([item for item in data if item != cid])
 
@@ -207,6 +203,12 @@
             # Write data back
             self._data = data
 
+            if old is not None:
+                # Deactivated the currently active component
+                sm = zapi.getServiceManager(self)
+                old = zapi.traverse(sm, old)
+                old.deactivated()
+
             if registration is not None:
                 # Tell it that it is now active
                 registration.activated()
@@ -228,9 +230,6 @@
         if data[0] != cid:
             return # already inactive
 
-        # Tell it that it is no longer active
-        registration.deactivated()
-
         if None not in data:
             # Append None
             data += (None,)
@@ -238,15 +237,18 @@
         # Move it to the end
         data = data[1:] + data[:1]
 
+        # Write data back
+        self._data = data
+
+        # Tell it that it is no longer active
+        registration.deactivated()
+
         if data[0] is not None:
             # Activate the newly active component
             sm = zapi.getServiceManager(self)
             new = zapi.traverse(sm, data[0])
             new.activated()
 
-        # Write data back
-        self._data = data
-
     def active(self):
         if self._data:
             path = self._data[0]
@@ -283,6 +285,15 @@
 
         return result
 
+class NotifyingRegistrationStack(RegistrationStack):
+
+    def activate(self, registration):
+        RegistrationStack.activate(self, registration)
+        self.__parent__.notifyActivated(self, registration)
+
+    def deactivate(self, registration):
+        RegistrationStack.deactivate(self, registration)
+        self.__parent__.notifyDeactivated(self, registration)
 
 class SimpleRegistration(Persistent, Contained):
     """Registration objects that just contain registration data




More information about the Zope3-Checkins mailing list