[Zope3-checkins] SVN: Zope3/branches/jim-adapter/src/zope/component/event.txt forgot to check in doctest file.

Philipp von Weitershausen philikon at philikon.de
Thu Apr 6 18:34:43 EDT 2006


Log message for revision 66624:
  forgot to check in doctest file.
  

Changed:
  A   Zope3/branches/jim-adapter/src/zope/component/event.txt

-=-
Added: Zope3/branches/jim-adapter/src/zope/component/event.txt
===================================================================
--- Zope3/branches/jim-adapter/src/zope/component/event.txt	2006-04-06 22:09:24 UTC (rev 66623)
+++ Zope3/branches/jim-adapter/src/zope/component/event.txt	2006-04-06 22:34:43 UTC (rev 66624)
@@ -0,0 +1,56 @@
+Events
+======
+
+The Component Architecture provides a way to dispatch events to event
+handlers.  Event handlers are registered as *subscribers*
+a.k.a. *handlers*.
+
+Before we can start we need to import ``zope.component.event`` to make
+the dispatching effective:
+
+  >>> import zope.component.event
+
+Consider two event classes:
+
+  >>> class Event1(object):
+  ...     pass
+
+  >>> class Event2(Event1):
+  ...     pass
+
+Now consider two handlers for these event classes:
+
+  >>> called = []
+
+  >>> import zope.component
+  >>> @zope.component.adapter(Event1)
+  ... def handler1(event):
+  ...     called.append(1)
+
+  >>> @zope.component.adapter(Event2)
+  ... def handler2(event):
+  ...     called.append(2)
+
+We can register them with the Component Architecture:
+
+  >>> zope.component.provideHandler(handler1)
+  >>> zope.component.provideHandler(handler2)
+
+Now let's through the events.  We'll see that the handlers have been
+called accordingly:
+
+  >>> from zope.event import notify
+  >>> notify(Event1())
+  >>> called
+  [1]
+
+  >>> del called[:]
+  >>> notify(Event2())
+  >>> called.sort()
+  >>> called
+  [1, 2]
+
+Finally, let's clean up:
+
+  >>> from zope.testing.cleanup import cleanUp  
+  >>> cleanUp()


Property changes on: Zope3/branches/jim-adapter/src/zope/component/event.txt
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Zope3-Checkins mailing list