[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/Event - GlobalEventService.py:1.1 IGlobalEventService.py:1.1 IObjectEvent.py:1.1 Logger.py:1.1 ObjectEvent.py:1.1 __init__.py:1.2 configure.zcml:1.2 metaConfigure.py:1.2
Gary Poster
gary@zope.com
Sat, 21 Dec 2002 10:33:16 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Event
In directory cvs.zope.org:/tmp/cvs-serv30423/lib/python/Zope/App/Event
Modified Files:
__init__.py configure.zcml metaConfigure.py
Added Files:
GlobalEventService.py IGlobalEventService.py IObjectEvent.py
Logger.py ObjectEvent.py
Log Message:
Moves ObjectEvent, GlobalEventService, and Logger from the Zope.Event package to the Zope.App.Event package.
Does *not* redesign/refactor LocalEventService to accept paths and hubids and reject non-wrapped objects. Maybe later.
This checkin may require you to hose your Data.fs.
For quadruple checking, I'll send a note to zope3-dev when I've confirmed that a fresh checkout works.
=== Added File Zope3/lib/python/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 2002/12/21 15:32:45 poster Exp $
"""
from Zope.App.Event.IGlobalEventService 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/lib/python/Zope/App/Event/IGlobalEventService.py ===
##############################################################################
#
# Copyright (c) 2002, 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.
#
##############################################################################
"""
Revision information:
$Id: IGlobalEventService.py,v 1.1 2002/12/21 15:32:45 poster Exp $
"""
from Zope.Event.IEvent import IEvent
from Zope.Event.IEventService import IEventService
class IGlobalEventService(IEventService):
"""The global event-service does not allow normal subscriptions.
Subscriptions to the global event-service are not persistent.
If you want to subscribe to the global event-service, you need
to use the 'globalSubscribe' method instead of the 'subscribe'
method.
"""
def subscribe(subscriber, event_type=IEvent, filter=None):
"""Raises NotImplementedError."""
def globalSubscribe(subscriber, event_type=IEvent, filter=None):
"""Add subscriber to the list of subscribers for the channel."""
=== Added File Zope3/lib/python/Zope/App/Event/IObjectEvent.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: IObjectEvent.py,v 1.1 2002/12/21 15:32:45 poster Exp $
"""
from Zope.Event.IEvent import IEvent
from Interface.Attribute import Attribute
class IObjectEvent(IEvent):
"""Something has happened to an object.
The object that generated this event is not necessarily the object
refered to by location.
"""
object = Attribute("The subject of the event.")
location = Attribute("An optional object location.")
class IObjectCreatedEvent(IObjectEvent):
"""An object has been created.
The location will usually be None for this event."""
class IObjectAddedEvent(IObjectEvent):
"""An object has been added to a container."""
class IObjectModifiedEvent(IObjectEvent):
"""An object has been modified"""
class IObjectAnnotationsModifiedEvent(IObjectModifiedEvent):
"""An object's annotations have been modified"""
class IObjectContentModifiedEvent(IObjectModifiedEvent):
"""An object's content has been modified"""
class IObjectRemovedEvent(IObjectEvent):
"""An object has been removed from a container"""
class IObjectMovedEvent(IObjectEvent):
"""An object has been moved"""
fromLocation = Attribute("The old location for the object.")
=== Added File Zope3/lib/python/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 2002/12/21 15:32:45 poster Exp $
"""
import logging
import pprint
from StringIO import StringIO
from Zope.Event.ISubscriber 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/lib/python/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 2002/12/21 15:32:45 poster Exp $
"""
__metaclass__ = type
from IObjectEvent import IObjectEvent, IObjectCreatedEvent
from IObjectEvent import IObjectAddedEvent, IObjectModifiedEvent
from IObjectEvent import IObjectRemovedEvent, IObjectMovedEvent
from IObjectEvent \
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
=== Zope3/lib/python/Zope/App/Event/__init__.py 1.1 => 1.2 ===
--- Zope3/lib/python/Zope/App/Event/__init__.py:1.1 Wed Dec 18 18:36:58 2002
+++ Zope3/lib/python/Zope/App/Event/__init__.py Sat Dec 21 10:32:45 2002
@@ -1 +1,34 @@
+##############################################################################
#
+# 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$
+"""
+
+from Zope.Event.IEvent 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)
=== Zope3/lib/python/Zope/App/Event/configure.zcml 1.1 => 1.2 ===
--- Zope3/lib/python/Zope/App/Event/configure.zcml:1.1 Wed Dec 18 18:36:58 2002
+++ Zope3/lib/python/Zope/App/Event/configure.zcml Sat Dec 21 10:32:45 2002
@@ -7,6 +7,6 @@
interface='Zope.Event.IEventService.' />
<service serviceType='Events'
- component='Zope.Event.GlobalEventService.eventService' />
+ component='Zope.App.Event.GlobalEventService.eventService' />
</zopeConfigure>
=== Zope3/lib/python/Zope/App/Event/metaConfigure.py 1.1 => 1.2 ===
--- Zope3/lib/python/Zope/App/Event/metaConfigure.py:1.1 Wed Dec 18 18:36:58 2002
+++ Zope3/lib/python/Zope/App/Event/metaConfigure.py Sat Dec 21 10:32:45 2002
@@ -19,7 +19,7 @@
from Zope.Configuration.Action import Action
-from Zope.Event import globalSubscribeMany
+from Zope.App.Event import globalSubscribeMany
from Zope.Event.IEvent import IEvent
from Interface import Interface