[Zope3-checkins]
SVN: Zope3/branches/jim-simplifyevents/src/zope/app/
Changed subscribers to be handlers, meaning that most event handlers
Jim Fulton
jim at zope.com
Wed May 26 11:09:27 EDT 2004
Log message for revision 25011:
Changed subscribers to be handlers, meaning that most event handlers
are now just simple handler functions.
-=-
Modified: Zope3/branches/jim-simplifyevents/src/zope/app/broken/configure.zcml
===================================================================
--- Zope3/branches/jim-simplifyevents/src/zope/app/broken/configure.zcml 2004-05-26 14:34:09 UTC (rev 25010)
+++ Zope3/branches/jim-simplifyevents/src/zope/app/broken/configure.zcml 2004-05-26 15:09:27 UTC (rev 25011)
@@ -1,15 +1,12 @@
-<configure
- xmlns="http://namespaces.zope.org/zope"
- xmlns:event="http://namespaces.zope.org/event"
- >
+<configure xmlns="http://namespaces.zope.org/zope">
<content class=".broken.Broken">
<allow interface="zope.app.annotation.interfaces.IAnnotations" />
</content>
- <event:subscribe
- subscriber=".broken.installBrokenSubscriber"
- event_types="zope.app.appsetup.IDatabaseOpenedEvent"
+ <subscriber
+ factory=".broken.installBrokenSubscriber"
+ for="zope.app.appsetup.IDatabaseOpenedEvent"
/>
<include file="browser.zcml" />
Modified: Zope3/branches/jim-simplifyevents/src/zope/app/component/configure.zcml
===================================================================
--- Zope3/branches/jim-simplifyevents/src/zope/app/component/configure.zcml 2004-05-26 14:34:09 UTC (rev 25010)
+++ Zope3/branches/jim-simplifyevents/src/zope/app/component/configure.zcml 2004-05-26 15:09:27 UTC (rev 25011)
@@ -1,7 +1,4 @@
-<configure
- xmlns="http://namespaces.zope.org/zope"
- xmlns:event="http://namespaces.zope.org/event"
- >
+<configure xmlns="http://namespaces.zope.org/zope">
<serviceType
id="Utilities"
@@ -52,14 +49,14 @@
provides="zope.component.IServiceService"
for="zope.interface.Interface" />
- <event:subscribe
- subscriber=".localservice.threadSiteSubscriber"
- event_types="zope.app.publication.interfaces.IBeforeTraverseEvent"
+ <subscriber
+ factory=".localservice.threadSiteSubscriber"
+ for="zope.app.publication.interfaces.IBeforeTraverseEvent"
/>
- <event:subscribe
- subscriber=".localservice.clearThreadSiteSubscriber"
- event_types="zope.app.publication.interfaces.IEndRequestEvent"
+ <subscriber
+ factory==".localservice.clearThreadSiteSubscriber"
+ for="zope.app.publication.interfaces.IEndRequestEvent"
/>
</configure>
Modified: Zope3/branches/jim-simplifyevents/src/zope/app/generations/subscriber.zcml
===================================================================
--- Zope3/branches/jim-simplifyevents/src/zope/app/generations/subscriber.zcml 2004-05-26 14:34:09 UTC (rev 25010)
+++ Zope3/branches/jim-simplifyevents/src/zope/app/generations/subscriber.zcml 2004-05-26 15:09:27 UTC (rev 25011)
@@ -1,28 +1,28 @@
-<configure xmlns="http://namespaces.zope.org/event">
+<configure xmlns="http://namespaces.zope.org/zope">
<!--
-<subscribe
- subscriber=".generations.evolveSubscriber"
- event_types="zope.app.appsetup.IDatabaseOpenedEvent"
+<subscriber
+ factory=".generations.evolveSubscriber"
+ for="zope.app.appsetup.IDatabaseOpenedEvent"
>
Evolve to current generation on startup
-</subscribe>
+</subscriber>
-->
<!--
-<subscribe
- subscriber=".generations.evolveNotSubscriber"
- event_types="zope.app.appsetup.IDatabaseOpenedEvent"
+<subscriber
+ factory=".generations.evolveNotSubscriber"
+ for="zope.app.appsetup.IDatabaseOpenedEvent"
>
Don't evolve, but check for minimum generations on startup
-</subscribe>
+</subscriber>
-->
-<subscribe
- subscriber=".generations.evolveMinimumSubscriber"
- event_types="zope.app.appsetup.IDatabaseOpenedEvent"
+<subscriber
+ factory=".generations.evolveMinimumSubscriber"
+ for="zope.app.appsetup.IDatabaseOpenedEvent"
>
Only evolve to minimum generations on startup
-</subscribe>
+</subscriber>
</configure>
Modified: Zope3/branches/jim-simplifyevents/src/zope/app/pluggableauth/configure.zcml
===================================================================
--- Zope3/branches/jim-simplifyevents/src/zope/app/pluggableauth/configure.zcml 2004-05-26 14:34:09 UTC (rev 25010)
+++ Zope3/branches/jim-simplifyevents/src/zope/app/pluggableauth/configure.zcml 2004-05-26 15:09:27 UTC (rev 25011)
@@ -27,10 +27,9 @@
</content>
<subscriber
- factory=".PluggableAuthenticationServiceAddSubscriber"
for=".interfaces.IPluggableAuthenticationService
zope.app.container.interfaces.IObjectAddedEvent"
- provides="zope.app.event.interfaces.ISubscriber"
+ factory=".PluggableAuthenticationServiceAddSubscriber"
/>
<content class=".BTreePrincipalSource">
Modified: Zope3/branches/jim-simplifyevents/src/zope/app/presentation/configure.zcml
===================================================================
--- Zope3/branches/jim-simplifyevents/src/zope/app/presentation/configure.zcml 2004-05-26 14:34:09 UTC (rev 25010)
+++ Zope3/branches/jim-simplifyevents/src/zope/app/presentation/configure.zcml 2004-05-26 15:09:27 UTC (rev 25011)
@@ -32,14 +32,12 @@
factory=".presentation.PageRegistrationAddSubscriber"
for=".presentation.IPageRegistration
zope.app.container.interfaces.IObjectAddedEvent"
- provides="zope.app.event.interfaces.ISubscriber"
/>
<subscriber
factory=".presentation.PageRegistrationRemoveSubscriber"
for=".presentation.IPageRegistration
zope.app.container.interfaces.IObjectRemovedEvent"
- provides="zope.app.event.interfaces.ISubscriber"
/>
<include file="pagefolder.zcml" />
Modified: Zope3/branches/jim-simplifyevents/src/zope/app/publication/tests/test_zopepublication.py
===================================================================
--- Zope3/branches/jim-simplifyevents/src/zope/app/publication/tests/test_zopepublication.py 2004-05-26 14:34:09 UTC (rev 25010)
+++ Zope3/branches/jim-simplifyevents/src/zope/app/publication/tests/test_zopepublication.py 2004-05-26 15:09:27 UTC (rev 25011)
@@ -440,40 +440,29 @@
def testSiteEvents(self):
from zope.app.publication.interfaces import IBeforeTraverseEvent
from zope.app.publication.interfaces import IEndRequestEvent
- from zope.app.event.interfaces import ISubscriber
- from zope.app.servicenames import EventPublication
- from zope.app.event.localservice import EventService
- class Subscriber:
- implements(ISubscriber)
- def __init__(self):
- self.events = []
- def notify(self, event):
- self.events.append(event)
+ set = []
+ clear = []
+ ztapi.handle(IBeforeTraverseEvent, set.append)
+ ztapi.handle(IEndRequestEvent, clear.append)
- events = zapi.getService(EventPublication)
- set = Subscriber()
- clear = Subscriber()
- events.globalSubscribe(set, IBeforeTraverseEvent)
- events.globalSubscribe(clear, IEndRequestEvent)
-
ob = object()
# This should fire the BeforeTraverseEvent
self.publication.callTraversalHooks(self.request, ob)
- self.assertEqual(len(set.events), 1)
- self.assertEqual(len(clear.events), 0)
- self.assertEqual(set.events[0].object, ob)
+ self.assertEqual(len(set), 1)
+ self.assertEqual(len(clear), 0)
+ self.assertEqual(set[0].object, ob)
ob2 = object()
# This should fire the EndRequestEvent
self.publication.endRequest(self.request, ob2)
- self.assertEqual(len(set.events), 1)
- self.assertEqual(len(clear.events), 1)
- self.assertEqual(clear.events[0].object, ob2)
+ self.assertEqual(len(set), 1)
+ self.assertEqual(len(clear), 1)
+ self.assertEqual(clear[0].object, ob2)
def test_suite():
Modified: Zope3/branches/jim-simplifyevents/src/zope/app/registration/configure.zcml
===================================================================
--- Zope3/branches/jim-simplifyevents/src/zope/app/registration/configure.zcml 2004-05-26 14:34:09 UTC (rev 25010)
+++ Zope3/branches/jim-simplifyevents/src/zope/app/registration/configure.zcml 2004-05-26 15:09:27 UTC (rev 25011)
@@ -41,28 +41,24 @@
<subscriber
factory=".registration.SimpleRegistrationRemoveSubscriber"
- provides="zope.app.event.interfaces.ISubscriber"
for=".interfaces.IRegistration
zope.app.container.interfaces.IObjectRemovedEvent"
/>
<subscriber
factory=".registration.ComponentRegistrationRemoveSubscriber"
- provides="zope.app.event.interfaces.ISubscriber"
for=".interfaces.IComponentRegistration
zope.app.container.interfaces.IObjectRemovedEvent"
/>
<subscriber
factory=".registration.ComponentRegistrationAddSubscriber"
- provides="zope.app.event.interfaces.ISubscriber"
for=".interfaces.IComponentRegistration
zope.app.container.interfaces.IObjectAddedEvent"
/>
<subscriber
factory=".registration.RegistrationManagerRemoveSubscriber"
- provides="zope.app.event.interfaces.ISubscriber"
for=".interfaces.IRegistrationManager
zope.app.container.interfaces.IObjectRemovedEvent"
/>
Modified: Zope3/branches/jim-simplifyevents/src/zope/app/registration/registration.py
===================================================================
--- Zope3/branches/jim-simplifyevents/src/zope/app/registration/registration.py 2004-05-26 14:34:09 UTC (rev 25010)
+++ Zope3/branches/jim-simplifyevents/src/zope/app/registration/registration.py 2004-05-26 15:09:27 UTC (rev 25011)
@@ -30,7 +30,6 @@
from zope.app.container.contained import Contained
from zope.app.container.contained import setitem, contained, uncontained
from zope.app.dependable.interfaces import IDependable, DependencyError
-from zope.app.event.interfaces import ISubscriber
from zope.app.module.interfaces import IModuleManager
from zope.app.registration import interfaces
@@ -515,27 +514,20 @@
registration.deactivated()
self.__parent__.notifyDeactivated(self, registration)
-class SimpleRegistrationRemoveSubscriber:
+def SimpleRegistrationRemoveSubscriber(registration, event):
+ """Receive notification of remove event."""
+ objectstatus = registration.status
- implements(ISubscriber)
+ if objectstatus == interfaces.ActiveStatus:
+ try:
+ objectpath = zapi.getPath(registration)
+ except: # XXX
+ objectpath = str(registration)
+ raise DependencyError("Can't delete active registration (%s)"
+ % objectpath)
+ elif objectstatus == interfaces.RegisteredStatus:
+ registration.status = interfaces.UnregisteredStatus
- def __init__(self, simple_registration, event):
- self.registration = simple_registration
-
- def notify(self, event):
- """Receive notification of remove event."""
- objectstatus = self.registration.status
-
- if objectstatus == interfaces.ActiveStatus:
- try:
- objectpath = zapi.getPath(self.registration)
- except: # XXX
- objectpath = str(self.registration)
- raise DependencyError("Can't delete active registration (%s)"
- % objectpath)
- elif objectstatus == interfaces.RegisteredStatus:
- self.registration.status = interfaces.UnregisteredStatus
-
class SimpleRegistration(Persistent, Contained):
"""Registration objects that just contain registration data"""
@@ -623,40 +615,28 @@
return component
-class ComponentRegistrationRemoveSubscriber(object):
- implements(ISubscriber)
-
- def __init__(self, component_registration, event):
- self.component_registration = component_registration
+def ComponentRegistrationRemoveSubscriber(component_registration, event):
+ """Receive notification of remove event."""
+ component = component_registration.getComponent()
+ dependents = IDependable(component)
+ objectpath = zapi.getPath(self.component_registration)
+ dependents.removeDependent(objectpath)
+ # Also update usage, if supported
+ adapter = interfaces.IRegistered(component, None)
+ if adapter is not None:
+ adapter.removeUsage(zapi.getPath(component_registration))
- def notify(self, event):
- """Receive notification of remove event."""
- component = self.component_registration.getComponent()
- dependents = IDependable(component)
- objectpath = zapi.getPath(self.component_registration)
- dependents.removeDependent(objectpath)
- # Also update usage, if supported
- adapter = interfaces.IRegistered(component, None)
- if adapter is not None:
- adapter.removeUsage(zapi.getPath(self.component_registration))
+def ComponentRegistrationAddSubscriber(component_registration, event):
+ """Receive notification of add event."""
+ component = component_registration.getComponent()
+ dependents = IDependable(component)
+ objectpath = zapi.getPath(self.component_registration)
+ dependents.addDependent(objectpath)
+ # Also update usage, if supported
+ adapter = interfaces.IRegistered(component, None)
+ if adapter is not None:
+ adapter.addUsage(objectpath)
-class ComponentRegistrationAddSubscriber(object):
- implements(ISubscriber)
-
- def __init__(self, component_registration, event):
- self.component_registration = component_registration
-
- def notify(self, event):
- """Receive notification of add event."""
- component = self.component_registration.getComponent()
- dependents = IDependable(component)
- objectpath = zapi.getPath(self.component_registration)
- dependents.addDependent(objectpath)
- # Also update usage, if supported
- adapter = interfaces.IRegistered(component, None)
- if adapter is not None:
- adapter.addUsage(objectpath)
-
from zope.app.dependable import PathSetAnnotation
class Registered(PathSetAnnotation):
@@ -681,17 +661,10 @@
return [zapi.traverse(self.context, path)
for path in self.getPaths()]
-class RegistrationManagerRemoveSubscriber:
- """Subscriber for RegistrationManager remove events."""
- implements(ISubscriber)
-
- def __init__(self, registration_manager, event):
- self.registration_manager = registration_manager
-
- def notify(self, event):
- """Receive notification of remove event."""
- for name in self.registration_manager:
- del self.registration_manager[name]
+def RegistrationManagerRemoveSubscriber(registration_manager, event):
+ """Receive notification of remove event."""
+ for name in registration_manager:
+ del registration_manager[name]
class RegistrationManager(Persistent, Contained):
"""Registration manager
Modified: Zope3/branches/jim-simplifyevents/src/zope/app/registration/tests/test_registrationmanager.py
===================================================================
--- Zope3/branches/jim-simplifyevents/src/zope/app/registration/tests/test_registrationmanager.py 2004-05-26 14:34:09 UTC (rev 25010)
+++ Zope3/branches/jim-simplifyevents/src/zope/app/registration/tests/test_registrationmanager.py 2004-05-26 15:09:27 UTC (rev 25011)
@@ -18,7 +18,8 @@
from doctest import DocTestSuite
from zope.app.registration.interfaces import IRegistrationManager
from zope.app.registration.registration import RegistrationManager
-from zope.app.registration.registration import RegistrationManagerRemoveSubscriber
+from zope.app.registration.registration \
+ import RegistrationManagerRemoveSubscriber
from zope.app.site.tests import placefulsetup
from zope.app.tests.placelesssetup import PlacelessSetup
from zope.app.traversing.api import traverse
@@ -354,18 +355,17 @@
First create a dummy registration manager with some
initial data.
- >>> regmgr = DummyRM()
- >>> regmgr['foo'] = 'bar'
+ >>> regmgr = DummyRM()
+ >>> regmgr['foo'] = 'bar'
- Create an adapter for it.
- >>> adapter = RegistrationManagerRemoveSubscriber(regmgr, None)
+ Notify:
- Trigger the event.
- >>> adapter.notify(None)
+ >>> RegistrationManagerRemoveSubscriber(regmgr, None)
Check the results.
- >>> regmgr
- {}
+
+ >>> regmgr
+ {}
"""
Modified: Zope3/branches/jim-simplifyevents/src/zope/app/registration/tests/test_registrations.py
===================================================================
--- Zope3/branches/jim-simplifyevents/src/zope/app/registration/tests/test_registrations.py 2004-05-26 14:34:09 UTC (rev 25010)
+++ Zope3/branches/jim-simplifyevents/src/zope/app/registration/tests/test_registrations.py 2004-05-26 15:09:27 UTC (rev 25011)
@@ -34,7 +34,6 @@
from zope.app.tests import ztapi
from zope.app.registration.interfaces import IRegistration
from zope.app.container.interfaces import IObjectRemovedEvent
-from zope.app.event.interfaces import ISubscriber
from zope.app.registration.registration import \
SimpleRegistrationRemoveSubscriber, \
ComponentRegistrationRemoveSubscriber, \
@@ -82,15 +81,15 @@
def test_RemoveSubscriber(self):
reg = DummyRegistration()
- adapter = SimpleRegistrationRemoveSubscriber(reg, None)
+ reg.status = ActiveStatus
# test that removal fails with Active status
- reg.status = ActiveStatus
- self.assertRaises(DependencyError, adapter.notify, None)
+ self.assertRaises(DependencyError,
+ SimpleRegistrationRemoveSubscriber, reg, None)
# test that removal succeeds with Registered status
reg.status = RegisteredStatus
- adapter.notify(None)
+ SimpleRegistrationRemoveSubscriber(reg, None)
self.assertEquals(reg.status, UnregisteredStatus)
@@ -140,40 +139,43 @@
class TestComponentRegistrationEvents:
def test_addNotify(self):
"""
- First we create a dummy registration and an adapter for it.
+ First we create a dummy registration
- >>> reg = DummyRegistration()
- >>> adapter = ComponentRegistrationAddSubscriber(reg, None)
+ >>> reg = DummyRegistration()
Now call notification
- >>> adapter.notify(None)
+ >>> ComponentRegistrationAddSubscriber(reg, None)
+
Check to make sure the adapter added the path
- >>> reg.dependents()
- ('dummy!',)
+
+ >>> reg.dependents()
+ ('dummy!',)
"""
def test_removeNotify_dependents(self):
"""
- First we create a dummy registration and an adapter for it.
+ First we create a dummy registration
- >>> reg = DummyRegistration()
- >>> adapter = ComponentRegistrationAddSubscriber(reg, None)
+ >>> reg = DummyRegistration()
Now call notification
- >>> adapter.notify(None)
+ >>> ComponentRegistrationAddSubscriber(reg, None)
+
Check to make sure the adapter added the path
- >>> reg.dependents()
- ('dummy!',)
- Now create a removal adapter and call it.
- >>> removal_adapter = ComponentRegistrationRemoveSubscriber(reg, None)
- >>> removal_adapter.notify(None)
+ >>> reg.dependents()
+ ('dummy!',)
+ Now remove notify:
+
+ >>> ComponentRegistrationRemoveSubscriber(reg, None)
+
Check to make sure the adapter removed the dependencie(s).
- >>> reg.dependents()
- ()
+
+ >>> reg.dependents()
+ ()
"""
Modified: Zope3/branches/jim-simplifyevents/src/zope/app/workflow/stateful/configure.zcml
===================================================================
--- Zope3/branches/jim-simplifyevents/src/zope/app/workflow/stateful/configure.zcml 2004-05-26 14:34:09 UTC (rev 25010)
+++ Zope3/branches/jim-simplifyevents/src/zope/app/workflow/stateful/configure.zcml 2004-05-26 15:09:27 UTC (rev 25011)
@@ -130,7 +130,6 @@
<subscriber
for="..interfaces.IProcessInstanceContainerAdaptable
zope.app.event.objectevent.IObjectCreatedEvent"
- provides="zope.app.event.interfaces.ISubscriber"
factory=".contentworkflow.NewObjectProcessInstanceCreator"
>
More information about the Zope3-Checkins
mailing list