[Zope3-Users] fine grained subscriber

Lorenzo Gil Sanchez lgs at sicem.biz
Wed Mar 28 06:16:23 EDT 2007


Hi,

I'm writing an event subscriber to the IIntIdRemoveEvent event type. It
looks like this:

def intIdRemovedSubscriber(event):
  if IMyInterface.providedBy(event.object):
     # do some stuff with event.object

and the zcml:

<subscriber
     handler=".intIdRemovedSubscriber"
     for="zope.app.intid.interfaces.IIntIdRemovedEvent"
     />

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"
     />

But when doing this second aproach my subscriber is not called. I
supposed I could do this by looking in the zope source code and finding
this in zope.app.intid.__init__.py

@adapter(ILocation, IObjectRemovedEvent)
def removeIntIdSubscriber(ob, event):
  # ....

and 

<subscriber handler=".removeIntIdSubscriber" />

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.

Thanks in advance

Lorenzo Gil



More information about the Zope3-users mailing list