[Zope-dev] Re: No events in zope.annotation

Stephan Richter srichter at cosmos.phy.tufts.edu
Wed Jul 16 10:45:04 EDT 2008


On Wednesday 16 July 2008, Fred Drake wrote:
> On Wed, Jul 16, 2008 at 10:26 AM, Stephan Richter
>
> <srichter at cosmos.phy.tufts.edu> wrote:
> > I agree. I realized only later that those events are defined in the
> > zope.app.container package. In this case I would just create new
> > annotation-specific events based on ObjectEvent, which is defined in
> > zope.component, and zope.component is already a dependency.
>
> Hmm.  Would these be fired by the IAnnotations adapter or by the
> factory?  There might be some interesting tradeoffs there.  Many
> annotations are just simple data types (strings, tuples,
> dictionaries); those can be used with object events, but it seems a
> little non-intuitive.

I do not think that I have a single annotation that is a simple type. I cannot 
even think of a quick example where any of the Zope 3 core packages have/use 
simple type annotations.

But I agree. The system supports simple type and that is one of the use cases. 
While I originally wanted to add at least 2 of the events to the IAnnotations 
adapter itself, I agree with you that the overhead penalty might be too 
severe.

With this in mind, I am modifying my proposal to add 2 event notifications to 
the factory only to produce a function like this (it is the result of calling 
the annotation factory):

def myFactory(context):
    key = '...'
    annotations = zope.annotation.interfaces.IAnnotations(context)
    try:
        result = annotations[key]
    except KeyError:
        result = Approval()
        zope.event.notify(zope.lifecycleevent.ObjectCreatedEvent(result))
        annotations[key] = result
    located_result = zope.location.location.located(result, context, key)
    zope.event.notify(AnnotationAddedEvent(located_result))
    return located_result

I am torn whether the created event should be a annotation specific or not, 
because an object is not an annotation until it has been added as one.

Regards,
Stephan
-- 
Stephan Richter
Web Software Design, Development and Training
Google me. "Zope Stephan Richter"


More information about the Zope-Dev mailing list