[Zope3-checkins] CVS: Zope3/src/zope/app/event - __init__.py:1.2 configure.zcml:1.2 globaleventservice.py:1.2 logger.py:1.2 meta.zcml:1.2 metaconfigure.py:1.2 objectevent.py:1.2
Jim Fulton
jim@zope.com
Wed, 25 Dec 2002 09:13:52 -0500
Update of /cvs-repository/Zope3/src/zope/app/event
In directory cvs.zope.org:/tmp/cvs-serv15352/src/zope/app/event
Added Files:
__init__.py configure.zcml globaleventservice.py logger.py
meta.zcml metaconfigure.py objectevent.py
Log Message:
Grand renaming:
- Renamed most files (especially python modules) to lower case.
- Moved views and interfaces into separate hierarchies within each
project, where each top-level directory under the zope package
is a separate project.
- Moved everything to src from lib/python.
lib/python will eventually go away. I need access to the cvs
repository to make this happen, however.
There are probably some bits that are broken. All tests pass
and zope runs, but I haven't tried everything. There are a number
of cleanups I'll work on tomorrow.
=== Zope3/src/zope/app/event/__init__.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:52 2002
+++ Zope3/src/zope/app/event/__init__.py Wed Dec 25 09:12:51 2002
@@ -0,0 +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.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)
=== Zope3/src/zope/app/event/configure.zcml 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:52 2002
+++ Zope3/src/zope/app/event/configure.zcml Wed Dec 25 09:12:51 2002
@@ -0,0 +1,12 @@
+<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>
=== Zope3/src/zope/app/event/globaleventservice.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:52 2002
+++ Zope3/src/zope/app/event/globaleventservice.py Wed Dec 25 09:12:51 2002
@@ -0,0 +1,51 @@
+##############################################################################
+#
+# 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$
+"""
+
+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
=== Zope3/src/zope/app/event/logger.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:52 2002
+++ Zope3/src/zope/app/event/logger.py Wed Dec 25 09:12:51 2002
@@ -0,0 +1,50 @@
+##############################################################################
+#
+# 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$
+"""
+
+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())
=== Zope3/src/zope/app/event/meta.zcml 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:52 2002
+++ Zope3/src/zope/app/event/meta.zcml Wed Dec 25 09:12:51 2002
@@ -0,0 +1,10 @@
+<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>
=== Zope3/src/zope/app/event/metaconfigure.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:52 2002
+++ Zope3/src/zope/app/event/metaconfigure.py Wed Dec 25 09:12:51 2002
@@ -0,0 +1,55 @@
+##############################################################################
+#
+# 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$
+"""
+
+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)
+ )
+ ]
=== Zope3/src/zope/app/event/objectevent.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:52 2002
+++ Zope3/src/zope/app/event/objectevent.py Wed Dec 25 09:12:51 2002
@@ -0,0 +1,86 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Object lifetime events.
+
+$Id$
+"""
+
+__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 IObjectAnnotationsModifiedEvent
+from zope.app.interfaces.event import IObjectContentModifiedEvent
+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