[Zope3-Users] fine grained subscriber

FB fbo2 at gmx.net
Wed Mar 28 06:50:15 EDT 2007


Hi,

On Wed, Mar 28, 2007 at 12:16:23PM +0200, Lorenzo Gil Sanchez wrote:

[snip]

> But I'd like to avoid the if clause inside my subscriber function by
> doing something similar to this:
> 
> def intIdRemovedSubscriber(obj, event):
>   # do some stuff with obj, which is garanteed to provide IMyInterface
> 
> <subscriber
>      handler=".intIdRemovedSubscriber"
>      for=".interfaces.IMyInterface
>           zope.app.intid.interfaces.IIntIdRemovedEvent"
>      />

[snip]

> So the question is: why the intid package is succesful in registering a
> subscriber only for ILocation objects and I can't do the same with
> IMyInterface objects?
> 
> I want to avoid a lot of calls to my subscriber which will happend
> everytime an IntId is removed from *any* object.

[snip]

You need a dispatcher - a quite common concept in zope3:

[events.py, not tested]
from zope.event import notify

def removeIntId(event):
	notify(event.object,event)

def addIntId(event):
	notify(event.object,event)



[configure.zcml, not tested]
   [...]
	<subscriber for="zope.app.intid.interfaces.IntIdAddedEvent"
		handler=".event.addIntId"
	/>
	<subscriber for="zope.app.intid.interfaces.IntIdRemovedEvent"
		handler=".events.removeIntId"
	/>
   [...]

Thanks to zope3's component infrastructure, a package (like intid) doesn't
have to provide the dispatcher - a different package providing the dispatcher
is perfectly fine.

Regards,

Frank


More information about the Zope3-users mailing list