[Zope3-checkins] CVS: Zope3/lib/python/Zope/Event - GlobalEventService.py:1.5 IEventService.py:1.6 __init__.py:1.5 metaConfigure.py:1.4

Steve Alexander steve@cat-box.net
Thu, 5 Dec 2002 12:20:29 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/Event
In directory cvs.zope.org:/tmp/cvs-serv3454/lib/python/Zope/Event

Modified Files:
	GlobalEventService.py IEventService.py __init__.py 
	metaConfigure.py 
Log Message:
Refactored global event service to have a different interface than the
placeful event service.

Now, you must use a different method to subscribe to the global service.
This stops inadvertant subscriptions of persistent placeful objects
to the global event service. Such a subscription would be bad, because
the subscription would not be remembered on a zope restart.


=== Zope3/lib/python/Zope/Event/GlobalEventService.py 1.4 => 1.5 ===
--- Zope3/lib/python/Zope/Event/GlobalEventService.py:1.4	Sun Dec  1 05:32:29 2002
+++ Zope3/lib/python/Zope/Event/GlobalEventService.py	Thu Dec  5 12:20:29 2002
@@ -17,17 +17,24 @@
 $Id$
 """
 
-from IEventService import IEventService
+from IEventService import IGlobalEventService
 from Subscribable import Subscribable
 
 class GlobalEventService(Subscribable):
     
-    __implements__ = IEventService
-        
+    __implements__ = IGlobalEventService
+
+    def globalSubscribe(self, *args, **kw):
+        super(GlobalEventService, self).subscribe(*args, **kw)
+
+    def subscribe(self, subscriber, event_type=None, filter=None):
+        """Don't allow regular persistent subscriptions."""
+        raise NotImplementedError("You cannot subscribe to the "
+            "GlobalEventService. Use the 'globalSubscribe' method instead.")
+
     def publish(self, event):
         
         for subscriptions in self.subscriptionsForEvent(event):
-            
             for subscriber, filter in subscriptions:
                 if filter is not None and not filter(event):
                     continue
@@ -35,7 +42,6 @@
     
 
 eventService = GlobalEventService()
-
 
 _clear = eventService._clear
 


=== Zope3/lib/python/Zope/Event/IEventService.py 1.5 => 1.6 ===
--- Zope3/lib/python/Zope/Event/IEventService.py:1.5	Sun Dec  1 05:32:29 2002
+++ Zope3/lib/python/Zope/Event/IEventService.py	Thu Dec  5 12:20:29 2002
@@ -18,6 +18,7 @@
 """
 
 from ISubscribable import ISubscribable
+from IEvent import IEvent
 
 class IEventService(ISubscribable):
     """The EventService service is the 'root channel'.
@@ -34,3 +35,19 @@
         Events will often be propagated to higher level IEventServices;
         This is a policy decision for the IEventService.
         """
+
+class IGlobalEventService(IEventService):
+    """The global event-service does not allow normal subscriptions.
+
+    Subscriptions to the global event-service are not persistent.
+    If you want to subscribe to the global event-service, you need
+    to use the 'globalSubscribe' method instead of the 'subscribe'
+    method.
+    """
+
+    def subscribe(subscriber, event_type=IEvent, filter=None):
+        """Raises NotImplementedError."""
+
+    def globalSubscribe(subscriber, event_type=IEvent, filter=None):
+        """Add subscriber to the list of subscribers for the channel."""
+


=== Zope3/lib/python/Zope/Event/__init__.py 1.4 => 1.5 ===
--- Zope3/lib/python/Zope/Event/__init__.py:1.4	Sun Dec  1 05:32:29 2002
+++ Zope3/lib/python/Zope/Event/__init__.py	Thu Dec  5 12:20:29 2002
@@ -28,15 +28,31 @@
     return getEventService(context).publish(event)
 
 def subscribe(subscriber, event_type=IEvent, filter=None, context=None):
-    if context is None: context=subscriber
+    if context is None:
+        context = subscriber
     return getEventService(context).subscribe(
         subscriber, event_type, filter)
 
-def subscribeMany(subscriber, event_types=(IEvent,), filter=None, context=None):
+def subscribeMany(subscriber, event_types=(IEvent,),
+                  filter=None, context=None):
+    if context is None:
+        context = subscriber
+    subscribe = getEventService(context).subscribe
+    for event_type in event_types:
+        subscribe(subscriber, event_type, filter)
+
+def globalSubscribe(subscriber, event_type=IEvent, filter=None, context=None):
+    if context is None:
+        context = subscriber
+    return getEventService(None).globalSubscribe(
+        subscriber, event_type, filter)
+
+def globalSubscribeMany(subscriber, event_types=(IEvent,),
+                        filter=None, context=None):
     if context is None: context=subscriber
-    es= getEventService(context).subscribe
+    subscribe_func = getEventService(None).globalSubscribe
     for event_type in event_types:
-        es(subscriber, event_type, filter)
+        subscribe_func(subscriber, event_type, filter)
 
 def unsubscribe(subscriber, event_type=None, filter=None, context=None):
     if context is None: context=subscriber


=== Zope3/lib/python/Zope/Event/metaConfigure.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/Event/metaConfigure.py:1.3	Tue Nov 19 18:25:15 2002
+++ Zope3/lib/python/Zope/Event/metaConfigure.py	Thu Dec  5 12:20:29 2002
@@ -19,7 +19,7 @@
 
 from Zope.Configuration.Action import Action
 
-from Zope.Event import subscribeMany
+from Zope.Event import globalSubscribeMany
 from Zope.Event.IEvent import IEvent
 from Interface import Interface
 
@@ -43,12 +43,12 @@
         Action(
              # subscriptions can never conflict
              discriminator = ('subscribe', counter),
-             callable = subscribeMany,
+             callable = globalSubscribeMany,
              args = (subscriber, event_types, filter)
              ),
         Action(
             discriminator = None,
-            callable = subscribeMany,
+            callable = globalSubscribeMany,
             args = ('Interfaces', 'provideInterface',
                     type.__module__+'.'+type.__name__, type)
               )