[Zope-Checkins] CVS: Zope3/lib/python/Zope/Event - metaConfigure.py:1.1.2.1
Chris Withers
chrisw@nipltd.com
Sat, 23 Feb 2002 12:47:35 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Event
In directory cvs.zope.org:/tmp/cvs-serv29498
Added Files:
Tag: Zope-3x-branch
metaConfigure.py
Log Message:
Can now configure event subscriptions using ZCML.
=== Added File Zope3/lib/python/Zope/Event/metaConfigure.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: metaConfigure.py,v 1.1.2.1 2002/02/23 17:47:34 chrisw Exp $
"""
from Zope.Configuration.Action import Action
from Zope.Configuration.name import resolve
from Zope.Event import subscribe as eventSubscribe
counter = 0
def subscribe(subscriber, event_types=None, filter=None):
global counter
counter += 1
subscriber = resolve(subscriber)
if event_types is None:
event_types=(None,)
else:
event_type_names = event_types
event_types=[]
for event_type_name in [element.strip()
for element
in event_type_names.split(',')]:
event_types.append(resolve(event_type_name))
if filter is not None:
filter = resolve(filter)
return [
Action(
# subscriptions can never conflict
discriminator = ('subscribe', counter),
callable = eventSubscribe,
args = (subscriber, event_types, filter)
)
]