[Zope-Checkins] CVS: Zope3/lib/python/Zope/Event - EventChannel.py:1.1.2.1 EventService.py:1.1.2.1 ISubscribable.py:1.1.2.4 ISubscriber.py:1.1.2.4
Chris Withers
chrisw@nipltd.com
Fri, 22 Feb 2002 16:26:16 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Event
In directory cvs.zope.org:/tmp/cvs-serv32429
Modified Files:
Tag: Zope-3x-branch
ISubscribable.py ISubscriber.py
Added Files:
Tag: Zope-3x-branch
EventChannel.py EventService.py
Log Message:
JF/CW - It doesn't pass the tests (quite spectacularly ;-) but it smells okay.
=== Added File Zope3/lib/python/Zope/Event/EventChannel.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 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
#
##############################################################################
"""
Revision information:
$Id: EventChannel.py,v 1.1.2.1 2002/02/22 21:26:15 chrisw Exp $
"""
from IEventChannel import IEventChannel
from Zope.ComponentArchitecture.IToIRegistry import TypeRegistry
from Zope.Exceptions import NotFoundError
class EventChannel:
__implements__ = IEventChannel
def __init__(self):
self._registry = TypeRegistry()
self._subscribers = {}
def subscribe(self, subscriber, event_types=(None,), filter=None):
subs = self._subscribers
for event_type in event_types:
subscribers = self._registry.getJustForType(event_type)
if subscribers is None:
subscribers = []
self._registry.register(event_type, subscribers)
subscribers.append((subscriber, filter))
sub_types = subs.get(subscriber)
if sub_types is None:
sub_types={}
subs[subscriber]=sub_types
sub_types[event_type]=1
def unsubscribe(self, subscriber):
try:
subs_set = self._subscribers[subscriber]
except KeyError:
raise NotFoundError, subscriber
for event_type in subs_set:
subscriptions = self._registry.getJustForType(event_type)
subscriptions[:] = [sub
for sub in subscriptions
if sub[0] is not subscriber]
def notify(self, event):
subscriptionses = self._registry.getAllForObject(event)
for subscriptions in subscriptionses:
for subscriber,filter in subscriptions:
if filter is not None and not filter(event):
continue
subscriber.notify(event)
=== Added File Zope3/lib/python/Zope/Event/EventService.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 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
#
##############################################################################
"""
Revision information:
$Id: EventService.py,v 1.1.2.1 2002/02/22 21:26:15 chrisw Exp $
"""
from IEventService import IEventService
from EventChannel import EventChannel
from Zope.ComponentArchitecture.IToIRegistry import TypeRegistry
from Zope.Exceptions import NotFoundError
class EventService(EventChannel):
__implements__ = IEventService
def publish(self, event):
self.notify(event)
=== Zope3/lib/python/Zope/Event/ISubscribable.py 1.1.2.3 => 1.1.2.4 ===
filter, if supplied, must implement IEventFilter; subscriber
will be notified of events only if they pass.
+
+ A subscriber may subscribe more than once, even if it has
+ already been subscribed with the same event types and
+ filter. In this case the subscriber will receive multiple
+ calls to its notify method.
"""
def unsubscribe(subscriber):
=== Zope3/lib/python/Zope/Event/ISubscriber.py 1.1.2.3 => 1.1.2.4 ===
This method must not block!
- This method may raise an exception to veto the event
+ This method may raise an exception to veto the event.
"""