[Zope-Checkins] CVS: Zope3/lib/python/Zope/Event - event.zcml:1.1.2.1 EventChannel.py:1.1.2.6 EventService.py:1.1.2.4 __init__.py:1.1.2.4 hooks.py:1.1.2.4 metaConfigure.py:1.1.2.4

Gary Poster garyposter@earthlink.net
Mon, 22 Apr 2002 15:03:25 -0400


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

Modified Files:
      Tag: Zope-3x-branch
	EventChannel.py EventService.py __init__.py hooks.py 
	metaConfigure.py 
Added Files:
      Tag: Zope-3x-branch
	event.zcml 
Log Message:
1. As per ZopeTop discussion, moved Addable out of ZMI into the Services folder, and turned it into a true service (this involved a lot of small changes, particularly in the folders and a number of tests) and gave it some hooks
2. used SteveA's ContextWrapper.ContextMethod to make the ServiceManager and Services placefully look up to parent placeful equivalents
3. Made Event into a more standard service, and gave it some hooks
4. Built the beginning of a placeful EventService (will need tests, and views, and EventChannels, and more meat; just wanted to check this in for now)
5. made it so you can't add an item to a folder with a blank string id, and updated the folder interface
6. some typos fixed here and there
7. a few more tests here and there

I'm checking this in then checking it out again to check my work; also tagged previous version as gary-service_update.



=== Added File Zope3/lib/python/Zope/Event/event.zcml ===
<zopeConfigure
   xmlns='http://namespaces.zope.org/zope'
   xmlns:security='http://namespaces.zope.org/security'
   xmlns:zmi='http://namespaces.zope.org/zmi'
   xmlns:browser='http://namespaces.zope.org/browser'
>

<serviceType name='EventService' 
             interface='Zope.Event.IEventService.' />

<service name='EventService'
         component='Zope.Event.EventService.eventService' />

<hookable module=".hooks" name="getEventService" />
<hookable module=".hooks" name="publishEvent" />
<hookable module=".hooks" name="subscribe" />
<hookable module=".hooks" name="unsubscribe" />

</zopeConfigure>


=== Zope3/lib/python/Zope/Event/EventChannel.py 1.1.2.5 => 1.1.2.6 ===
     def subscribe(self, subscriber, event_types=(None,), filter=None):
     
-        # ICK!
-        # Why polute the base event channel with persistence stuff?
-        # XXX please make this go away ASAP ;-)
-        self._p_changed = 1
-        
         subs = self._subscribers
         
         for event_type in event_types:
@@ -53,6 +48,7 @@
                 sub_types={}
                 subs[subscriber]=sub_types
             sub_types[event_type]=1
+        self._registry=self._registry #trigger persistence, if pertinent
     
     def unsubscribe(self, subscriber):
         
@@ -60,17 +56,13 @@
             subs_set = self._subscribers[subscriber]
         except KeyError:
             raise NotFoundError, subscriber
-            
-        # ICK!
-        # Why polute the base event channel with persistence stuff?
-        # XXX please make this go away ASAP ;-)
-        self._p_changed = 1
         
         for event_type in subs_set:
             subscriptions = self._registry.getJustForType(event_type)
             subscriptions[:] = [sub
                                 for sub in subscriptions
                                 if sub[0] is not subscriber]
+        self._registry=self._registry #trigger persistence, if pertinent
         
     def notify(self, event):
         


=== Zope3/lib/python/Zope/Event/EventService.py 1.1.2.3 => 1.1.2.4 ===
 from IEventService import IEventService
 from EventChannel import EventChannel
-from Zope.ComponentArchitecture.IToIRegistry import TypeRegistry
-from Zope.Exceptions import NotFoundError
 
 class EventService(EventChannel):
     
@@ -31,4 +29,12 @@
         self.notify(event)
     
 
-    
+eventService = EventService()
+
+
+_clear = eventService._clear
+
+# Register our cleanup with Testing.CleanUp to make writing unit tests simpler.
+from Zope.Testing.CleanUp import addCleanUp
+addCleanUp(_clear)
+del addCleanUp


=== Zope3/lib/python/Zope/Event/__init__.py 1.1.2.3 => 1.1.2.4 ===
 from IEventService import IEventService
 
-from hooks import publishEvent, subscribe, unsubscribe
+from hooks import getEventService, publishEvent, subscribe, unsubscribe
 
 def _clear():
-    from hooks import _clear; _clear()
     from EventService import _clear; _clear()
 
-__implements__ = IEventService
+# __implements__ = IEventService # why do this? so you can treat the
+# package like the service? still, why? and this means we can't do the
+# contextual service hooks, because they in fact do not match the same
+# interface


=== Zope3/lib/python/Zope/Event/hooks.py 1.1.2.3 => 1.1.2.4 ===
 """
 
-from EventService import EventService
+from EventService import eventService
+from Zope.ComponentArchitecture import getService
 
-_eventService = EventService()
-publishEvent = _eventService.publishEvent
-subscribe = _eventService.subscribe
-unsubscribe = _eventService.unsubscribe
-
-_clear = _eventService._clear
-
-# Register our cleanup with Testing.CleanUp to make writing unit tests simpler.
-from Zope.Testing.CleanUp import addCleanUp
-addCleanUp(_clear)
-del addCleanUp
+## hookables
+
+def getEventService(context):
+    return getEventService_hook(context)
+
+def publishEvent(context, event):
+    return publishEvent_hook(context, event)
+
+def subscribe(context, subscriber, event_types=(None,), filter=None):
+    return subscribe_hook(context, subscriber, event_types, filter)
+
+def unsubscribe(context, subscriber):
+    return unsubscribe_hook(context, subscriber)
+
+## default hooks
+## because they delegate placeful behavior to getService, these may not
+## need to be replaced normally
+
+def getEventService_hook(context):
+    return getService(context, 'EventService')
+
+def publishEvent_hook(context, event):
+    return getEventService(context).publishEvent(event)
+
+def subscribe_hook(context, subscriber, event_types, filter):
+    return getEventService(context).subscribe(subscriber, event_types, filter)
+
+def unsubscribe_hook(context, subscriber):
+    return getEventService(context).unsubscribe(subscriber)
\ No newline at end of file


=== Zope3/lib/python/Zope/Event/metaConfigure.py 1.1.2.3 => 1.1.2.4 ===
              discriminator = ('subscribe', counter),
              callable = eventSubscribe,
-             args = (subscriber, event_types, filter)
+             args = (None, subscriber, event_types, filter)
              )
         ]