[Zope3-checkins] CVS: Zope3/src/zope/app/event - __init__.py:1.1.2.1 configure.zcml:1.1.2.1 globaleventservice.py:1.1.2.1 logger.py:1.1.2.1 meta.zcml:1.1.2.1 metaconfigure.py:1.1.2.1 objectevent.py:1.1.2.1
Jim Fulton
jim@zope.com
Mon, 23 Dec 2002 14:31:35 -0500
Update of /cvs-repository/Zope3/src/zope/app/event
In directory cvs.zope.org:/tmp/cvs-serv19908/zope/app/event
Added Files:
Tag: NameGeddon-branch
__init__.py configure.zcml globaleventservice.py logger.py
meta.zcml metaconfigure.py objectevent.py
Log Message:
Initial renaming before debugging
=== Added File Zope3/src/zope/app/event/__init__.py ===
##############################################################################
#
# Copyright (c) 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: __init__.py,v 1.1.2.1 2002/12/23 19:31:34 jim Exp $
"""
from zope.interfaces.event import IEvent
from zope.event import getEventService
def globalSubscribe(subscriber, event_type=IEvent, filter=None, context=None):
if context is None:
context = subscriber
return getEventService(None).globalSubscribe(
subscriber, event_type, filter)
def globalSubscribeMany(subscriber, event_types=(IEvent,),
filter=None, context=None):
if context is None: context=subscriber
subscribe_func = getEventService(None).globalSubscribe
for event_type in event_types:
subscribe_func(subscriber, event_type, filter)
=== Added File Zope3/src/zope/app/event/configure.zcml ===
<zopeConfigure
xmlns='http://namespaces.zope.org/zope'
xmlns:browser='http://namespaces.zope.org/browser'
>
<serviceType id='Events'
interface='zope.interfaces.event.IEventService' />
<service serviceType='Events'
component='zope.app.event.globaleventservice.eventService' />
</zopeConfigure>
=== Added File Zope3/src/zope/app/event/globaleventservice.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: globaleventservice.py,v 1.1.2.1 2002/12/23 19:31:34 jim Exp $
"""
from zope.app.interfaces.event import IGlobalEventService
from zope.event.subscribable import Subscribable
class GlobalEventService(Subscribable):
__implements__ = IGlobalEventService
def globalSubscribe(self, *args, **kw):
super(GlobalEventService, self).subscribe(*args, **kw)
def subscribe(self, subscriber, event_type=None, filter=None):
"""Don't allow regular persistent subscriptions."""
raise NotImplementedError("You cannot subscribe to the "
"GlobalEventService. Use the 'globalSubscribe' method instead.")
def publish(self, event):
for subscriptions in self.subscriptionsForEvent(event):
for subscriber, filter in subscriptions:
if filter is not None and not filter(event):
continue
subscriber.notify(event)
eventService = GlobalEventService()
_clear = eventService._clear
# Register our cleanup with Testing.CleanUp to make writing unit tests simpler.
from zope.testing.cleanup import addCleanUp
addCleanUp(_clear)
del addCleanUp
=== Added File Zope3/src/zope/app/event/logger.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.
#
##############################################################################
"""Helper class to log all events sent out by an event service.
$Id: logger.py,v 1.1.2.1 2002/12/23 19:31:34 jim Exp $
"""
import logging
import pprint
from StringIO import StringIO
from zope.interfaces.event import ISubscriber
class Logger:
"""Helper class to log all events sent out by an event service.
This is an event subscriber that you can add via ZCML to log all
events sent out by Zope.
"""
__implements__ = ISubscriber
def __init__(self, severity=logging.INFO):
self.severity = severity
self.logger = logging.getLogger("Event.Logger")
def notify(self, event):
c = event.__class__
detail = StringIO()
if 0:
# XXX Apparently this doesn't work; why not?
data = event.__dict__.items()
data.sort()
pprint(data, detail)
else:
print >>detail, 'XXX detail temporarily disabled'
self.logger.log(self.severity, "%s.%s: %s",
c.__module__, c.__name__, detail.getvalue())
=== Added File Zope3/src/zope/app/event/meta.zcml ===
<zopeConfigure xmlns='http://namespaces.zope.org/zope'>
<directives namespace="http://namespaces.zope.org/event">
<directive name="subscribe" attributes="subscriber event_types filter"
handler="zope.app.event.metaconfigure.subscribe" />
</directives>
</zopeConfigure>
=== Added File Zope3/src/zope/app/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/12/23 19:31:34 jim Exp $
"""
from zope.configuration.action import Action
from zope.app.event import globalSubscribeMany
from zope.interfaces.event import IEvent
from zope.interface import Interface
counter = 0
def subscribe(_context, subscriber, event_types=(IEvent), filter=None):
global counter
counter += 1
subscriber = _context.resolve(subscriber)
event_type_names = event_types
event_types=[]
for event_type_name in event_type_names.split():
event_types.append(_context.resolve(event_type_name))
if filter is not None:
filter = _context.resolve(filter)
return [
Action(
# subscriptions can never conflict
discriminator = ('subscribe', counter),
callable = globalSubscribeMany,
args = (subscriber, event_types, filter)
),
Action(
discriminator = None,
callable = globalSubscribeMany,
args = ('Interfaces', 'provideInterface',
type.__module__+'.'+type.__name__, type)
)
]
=== Added File Zope3/src/zope/app/event/objectevent.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: objectevent.py,v 1.1.2.1 2002/12/23 19:31:34 jim Exp $
"""
__metaclass__ = type
from zope.app.interfaces.event import IObjectEvent, IObjectCreatedEvent
from zope.app.interfaces.event import IObjectAddedEvent, IObjectModifiedEvent
from zope.app.interfaces.event import IObjectRemovedEvent, IObjectMovedEvent
from zope.app.interfaces.event \
import IObjectContentModifiedEvent, IObjectAnnotationsModifiedEvent
from Zope.App.Traversing import getPhysicalPath
_marker = object()
class ObjectEvent:
"""Something has happened to an object"""
__implements__ = IObjectEvent
def _getLocation(self):
if self.__location is not _marker:
return self.__location
return getPhysicalPath(self.object)
location = property(_getLocation)
def __init__(self, object, location=_marker):
self.object = object
self.__location = location
class ObjectAddedEvent(ObjectEvent):
"""An object has been added to a container"""
__implements__ = IObjectAddedEvent
class ObjectCreatedEvent(ObjectEvent):
"""An object has been created"""
__implements__ = IObjectCreatedEvent
class ObjectModifiedEvent(ObjectEvent):
"""An object has been modified"""
__implements__ = IObjectModifiedEvent
class ObjectAnnotationsModifiedEvent(ObjectModifiedEvent):
"""An object's annotations have been modified"""
__implements__ = IObjectAnnotationsModifiedEvent
class ObjectContentModifiedEvent(ObjectModifiedEvent):
"""An object's content has been modified"""
__implements__ = IObjectContentModifiedEvent
class ObjectRemovedEvent(ObjectEvent):
"""An object has been removed from a container"""
__implements__ = IObjectRemovedEvent
class ObjectMovedEvent(ObjectAddedEvent):
"""An object has been moved"""
__implements__ = IObjectMovedEvent
fromLocation = None
def __init__(self, object, from_location, to_location):
super(ObjectMovedEvent, self).__init__(object, to_location)
self.fromLocation = from_location