[Zope3-checkins] SVN: Zope3/branches/jim-adapter/src/zope/ Move
event dispatcher and object event subscriber to zope.component.
Philipp von Weitershausen
philikon at philikon.de
Thu Apr 6 15:49:21 EDT 2006
Log message for revision 66611:
Move event dispatcher and object event subscriber to zope.component.
Changed:
U Zope3/branches/jim-adapter/src/zope/app/event/__init__.py
U Zope3/branches/jim-adapter/src/zope/app/event/configure.zcml
D Zope3/branches/jim-adapter/src/zope/app/event/dispatching.py
U Zope3/branches/jim-adapter/src/zope/app/event/objectevent.py
U Zope3/branches/jim-adapter/src/zope/app/event/tests/placelesssetup.py
D Zope3/branches/jim-adapter/src/zope/app/event/tests/test_dispatching.py
U Zope3/branches/jim-adapter/src/zope/app/event/tests/test_objectevent.py
A Zope3/branches/jim-adapter/src/zope/component/event.py
U Zope3/branches/jim-adapter/src/zope/component/tests.py
-=-
Modified: Zope3/branches/jim-adapter/src/zope/app/event/__init__.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/event/__init__.py 2006-04-06 19:33:10 UTC (rev 66610)
+++ Zope3/branches/jim-adapter/src/zope/app/event/__init__.py 2006-04-06 19:49:20 UTC (rev 66611)
@@ -16,5 +16,3 @@
$Id$
"""
__docformat__ = 'restructuredtext'
-
-from dispatching import publish
Modified: Zope3/branches/jim-adapter/src/zope/app/event/configure.zcml
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/event/configure.zcml 2006-04-06 19:33:10 UTC (rev 66610)
+++ Zope3/branches/jim-adapter/src/zope/app/event/configure.zcml 2006-04-06 19:49:20 UTC (rev 66611)
@@ -1,11 +1,5 @@
-<configure
- xmlns="http://namespaces.zope.org/zope"
- xmlns:event="http://namespaces.zope.org/event"
- >
+<configure xmlns="http://namespaces.zope.org/zope">
-<subscriber
- for="zope.component.interfaces.IObjectEvent"
- handler=".objectevent.objectEventNotify"
- />
+ <subscriber handler="zope.component.event.objectEventNotify" />
</configure>
Deleted: Zope3/branches/jim-adapter/src/zope/app/event/dispatching.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/event/dispatching.py 2006-04-06 19:33:10 UTC (rev 66610)
+++ Zope3/branches/jim-adapter/src/zope/app/event/dispatching.py 2006-04-06 19:49:20 UTC (rev 66611)
@@ -1,74 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (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.
-#
-##############################################################################
-"""Implement zope-specific event dispatching, based on subscription adapters
-
-This package installs an event dispatcher that calls event handlers,
-registered as subscription adapters providing ``None``.
-
-So, to subscribe to an event, use a subscription adapter to ``None``:
-
- >>> from zope.app.testing.placelesssetup import setUp, tearDown
- >>> setUp()
-
- >>> class E1(object):
- ... pass
-
- >>> class E2(E1):
- ... pass
-
- >>> called = []
- >>> def handler1(event):
- ... called.append(1)
-
- >>> def handler2(event):
- ... called.append(2)
-
- >>> from zope.app.testing import ztapi
- >>> from zope.interface import implementedBy
- >>> ztapi.subscribe([implementedBy(E1)], None, handler1) # old way
- >>> ztapi.subscribe((E2,), None, handler2) # new way
-
- >>> from zope.event import notify
-
- >>> notify(E1())
- >>> called
- [1]
-
- >>> del called[:]
- >>> notify(E2())
- >>> called.sort()
- >>> called
- [1, 2]
-
- >>> tearDown()
-
-$Id$
-"""
-__docformat__ = 'restructuredtext'
-
-from warnings import warn
-from zope.component import subscribers
-import zope.event
-
-def dispatch(*event):
- # iterating over subscribers assures they get executed
- for ignored in subscribers(event, None):
- pass
-
-zope.event.subscribers.append(dispatch)
-
-def publish(context, event):
- warn("Use zope.event.notify rather than zope.app.event.publish",
- DeprecationWarning, 2)
- zope.event.notify(event)
Modified: Zope3/branches/jim-adapter/src/zope/app/event/objectevent.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/event/objectevent.py 2006-04-06 19:33:10 UTC (rev 66610)
+++ Zope3/branches/jim-adapter/src/zope/app/event/objectevent.py 2006-04-06 19:49:20 UTC (rev 66611)
@@ -171,10 +171,3 @@
def __init__(self, object, original):
super(ObjectCopiedEvent, self).__init__(object)
self.original = original
-
-
-def objectEventNotify(event):
- """Event subscriber to dispatch ObjectEvents to interested adapters."""
- adapters = subscribers((event.object, event), None)
- for adapter in adapters:
- pass # getting them does the work
Modified: Zope3/branches/jim-adapter/src/zope/app/event/tests/placelesssetup.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/event/tests/placelesssetup.py 2006-04-06 19:33:10 UTC (rev 66610)
+++ Zope3/branches/jim-adapter/src/zope/app/event/tests/placelesssetup.py 2006-04-06 19:49:20 UTC (rev 66611)
@@ -15,11 +15,9 @@
$Id$
"""
+import zope.component
+from zope.component.event import objectEventNotify
-from zope.component.interfaces import IObjectEvent
-from zope.app.event.objectevent import objectEventNotify
-from zope.app.testing import ztapi
-
events = []
def getEvents(event_type=None, filter=None):
@@ -39,8 +37,8 @@
class PlacelessSetup(object):
def setUp(self):
- ztapi.subscribe([None], None, events.append)
- ztapi.subscribe([IObjectEvent], None, objectEventNotify)
+ zope.component.provideHandler(events.append, (None,))
+ zope.component.provideHandler(objectEventNotify)
clearEvents()
import zope.testing.cleanup
Deleted: Zope3/branches/jim-adapter/src/zope/app/event/tests/test_dispatching.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/event/tests/test_dispatching.py 2006-04-06 19:33:10 UTC (rev 66610)
+++ Zope3/branches/jim-adapter/src/zope/app/event/tests/test_dispatching.py 2006-04-06 19:49:20 UTC (rev 66611)
@@ -1,29 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (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.
-#
-##############################################################################
-"""Test the event dispatching code
-
-$Id$
-"""
-import unittest
-from zope.testing.doctestunit import DocTestSuite
-
-
-def test_suite():
- return unittest.TestSuite((
- DocTestSuite('zope.app.event.dispatching'),
- ))
-
-if __name__ == '__main__':
- unittest.main(defaultTest='test_suite')
-
Modified: Zope3/branches/jim-adapter/src/zope/app/event/tests/test_objectevent.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/event/tests/test_objectevent.py 2006-04-06 19:33:10 UTC (rev 66610)
+++ Zope3/branches/jim-adapter/src/zope/app/event/tests/test_objectevent.py 2006-04-06 19:49:20 UTC (rev 66611)
@@ -16,6 +16,7 @@
$Id$
"""
import unittest
+import zope.component.event
from zope.testing import doctest
from zope.component.interfaces import IObjectEvent
from zope.annotation.interfaces import IAnnotations, IAnnotatable
@@ -25,7 +26,6 @@
from zope.app.dublincore.interfaces import IZopeDublinCore
from zope.app.dublincore.annotatableadapter import ZDCAnnotatableAdapter
from zope.app.event.objectevent import ObjectModifiedEvent
-from zope.app.event import objectevent
from zope.app.container.contained import Contained, ObjectRemovedEvent
from zope.app.container.interfaces import IContained, IObjectRemovedEvent
from zope.app.container.sample import SampleContainer
@@ -59,7 +59,7 @@
item = Contained()
event = ObjectRemovedEvent(item)
- objectevent.objectEventNotify(event)
+ zope.component.event.objectEventNotify(event)
self.assertEqual([(item, event)], events)
def testNotifyNobody(self):
@@ -68,11 +68,11 @@
events = []
item = Contained()
evt = ObjectRemovedEvent(item)
- objectevent.objectEventNotify(evt)
+ zope.component.event.objectEventNotify(evt)
self.assertEqual([], events)
def testVeto(self):
- ztapi.subscribe([IObjectEvent], None, objectevent.objectEventNotify)
+ zope.component.provideHandler(zope.component.event.objectEventNotify)
container = SampleContainer()
item = Contained()
Copied: Zope3/branches/jim-adapter/src/zope/component/event.py (from rev 66532, Zope3/branches/jim-adapter/src/zope/app/event/dispatching.py)
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/event/dispatching.py 2006-04-05 13:52:36 UTC (rev 66532)
+++ Zope3/branches/jim-adapter/src/zope/component/event.py 2006-04-06 19:49:20 UTC (rev 66611)
@@ -0,0 +1,35 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""Implement Component Architecture-specific event dispatching, based
+on subscription adapters / handlers.
+
+$Id$
+"""
+__docformat__ = 'restructuredtext'
+
+import zope.component.interfaces
+import zope.event
+
+def dispatch(*event):
+ # iterating over subscribers assures they get executed
+ for ignored in zope.component.subscribers(event, None):
+ pass
+zope.event.subscribers.append(dispatch)
+
+ at zope.component.adapter(zope.component.interfaces.IObjectEvent)
+def objectEventNotify(event):
+ """Event subscriber to dispatch ObjectEvents to interested adapters."""
+ adapters = zope.component.subscribers((event.object, event), None)
+ for adapter in adapters:
+ pass # getting them does the work
Modified: Zope3/branches/jim-adapter/src/zope/component/tests.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/component/tests.py 2006-04-06 19:33:10 UTC (rev 66610)
+++ Zope3/branches/jim-adapter/src/zope/component/tests.py 2006-04-06 19:49:20 UTC (rev 66611)
@@ -809,6 +809,7 @@
setUp=setUp, tearDown=tearDown),
doctest.DocFileSuite('registry.txt', checker=checker,
tearDown=tearDownRegistryTests),
+ doctest.DocFileSuite('event.txt'),
))
if __name__ == "__main__":
More information about the Zope3-Checkins
mailing list