[Zope3-checkins] CVS: Zope3/src/zope/app/event - function.py:1.1.2.1

Fred L. Drake, Jr. fred@zope.com
Mon, 23 Jun 2003 18:07:58 -0400


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

Added Files:
      Tag: fdrake-zconfig-in-zope-3-branch
	function.py 
Log Message:
Support ZConfig in Zope 3.

=== Added File Zope3/src/zope/app/event/function.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Class to create an event subscriber from a simple function.

$Id: function.py,v 1.1.2.1 2003/06/23 22:07:57 fdrake Exp $
"""

from zope.interface import implements
from zope.app.interfaces.event import ISubscriber


class Subscriber:
    """Event subscriber that calls a function when an event is received.

    This is especially useful for creating subscribers from global
    functions that can be registered from ZCML:

        from zope.app.event import function

        def startupEventHandler(event):
            # do something useful with event:
            pass

        startupEventHandler = function.Subscriber(startupEventHandler)

    And then use this ZCML:

        <event:subscribe
            subscriber='.module.startupEventHandler'
            event_types='zope.app.interfaces.event.IProcessStartingEvent'
            />
    """
    implements(ISubscriber)

    def __init__(self, function):
        self.notify = function