[Zope3-Users] Error in annotations example

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Jun 19 18:30:22 EDT 2007


On Friday 08 June 2007 12:01, Zanotti Michele wrote:
> I am reading about annotations in "web component development with zope
> 3", but I have an error in the following interactive interpreter session
> that I don't understand.
>
> PythonWin 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)]
> on win32. Portions Copyright 1994-2006 Mark Hammond - see 'Help/About
> PythonWin' for further copyright information.
>
> >>> class Recipe(object):
>
> ...     pass
> ...
>
> >>> meatloaf=Recipe()
> >>> from zope.annotation.interfaces import IAnnotations
> >>> from zope.interface import alsoProvides
> >>> from zope.annotation.interfaces import IAttributeAnnotatable
> >>> alsoProvides(meatloaf, IAttributeAnnotatable)
> >>> annotations=IAnnotations(meatloaf)
>
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
> TypeError: ('Could not adapt', <__main__.Recipe object at 0x00D5F570>,
> <InterfaceClass zope.annotation.interfaces.IAnnotations>)
>
>
> Excuse me if the question is trivial, but where I'm wrong? Thanks

You have not registered an adaper from meatloaf to IAnnotations. Since 
meatloaf provides "IAttributeAnnotatable", you need to register the adapter 
from "IAttributeAnnotatable" to "IAnnotations":

>>> import zope.component
>>> from zope.annotation.attribute import AttributeAnnotations
>>> zope.component.provideAdapter(AttributeAnnotations)

Regards,
Stephan
-- 
Stephan Richter
CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training


More information about the Zope3-users mailing list