[Zope-CMF] Events/Future of CMF?

Sidnei da Silva sidnei at awkly.org
Wed Oct 13 14:21:55 EDT 2004


Hello,

Is there any concrete plan for adding Events to CMF? It would be
really nice if we could somehow use Five for that, but given all the
constraints, what options we have?

I've implemented a very simple event registry, highly based on Zope3
events, which I think would be more than enough for most of the use
cases. Would anyone be interested in adding this into CMF while we
wait for the day some Zope3 stuff gets merged into Zope2?

Doctest attached. The implementation is about the same number of lines
as the doctest *wink*.

-- 
Sidnei da Silva <sidnei at awkly.org>
http://awkly.org - dreamcatching :: making your dreams come true
http://www.enfoldsystems.com
http://plone.org/about/team#dreamcatcher

Lisp Users:
Due to the holiday next Monday, there will be no garbage collection.
-------------- next part --------------
Mini Event Framework
====================

We have a stripped down event framework here, highly based on Zope 3's
event subsystem.

Basically, we have event objects which implement an interface, and
subscribers which are registered for an interface. When an event is
published, all subscribers of all interfaces implemented by the event
are notified.

A very simple example:

  >>> from Interface import Interface
  >>> from Products.EnSimpleStaging import event
  >>> from Products.EnSimpleStaging.interfaces import IEvent

  >>> class IDummyEvent(IEvent):
  ...     """Dummy Event"""

  >>> class DummyEvent:
  ...    __implements__ = IDummyEvent
  ...    def __init__(self, obj):
  ...        self.object = obj

  >>> def dummyfy(obj):
  ...     event.publish(DummyEvent(obj))

  >>> def dummySubscriber(event):
  ...     print event.object

  >>> event.subscribe(IDummyEvent, dummySubscriber)

  >>> s = 'I am a object'
  >>> dummyfy(s)
  I am a object

Subscribing to a base IEvent interface also works:

  >>> def baseDummySubscriber(event):
  ...     print 'BASE:', event.object

  >>> event.subscribe(IEvent, baseDummySubscriber)
  >>> dummyfy(s)
  I am a object
  BASE: I am a object

Subscribing the same subscriber twice will not register it twice, but
instead replace the existing subscriber:

  >>> event.subscribe(IEvent, baseDummySubscriber)
  >>> dummyfy(s)
  I am a object
  BASE: I am a object

Trying to subscribe to a non-IEvent interface will raise an exception:

  >>> event.subscribe(Interface, dummySubscriber)
  Traceback (most recent call last):
  ...
  TypeError: Interface._Interface.Interface is not an IEvent

Cleanup after ourselves:

  >>> event.clear()


More information about the Zope-CMF mailing list