[Zope3-Users] very simple problem with getUtility

Christophe Combelles ccomb at free.fr
Sun Jan 7 12:05:38 EST 2007


Stephan Richter a écrit :
> On Sunday 07 January 2007 08:17, Christophe Combelles wrote:
>> - I start zope with an empty zodb
>> - I add a Folder
>> - I go to the registration tab and register it for IFolder as 'foo'
>> - I stop zope, and start debugzope:
> 
> These steps are okay.
> 
>>  >>> from zope.component import getUtility
>>  >>> from zope.app.folder.interfaces import IFolder
>>  >>> getUtility(IFolder, 'foo')
>> Traceback (most recent call last):
>>    File "<stdin>", line 1, in ?
>>    File "/usr/lib/python2.4/site-packages/zope/component/_api.py", line
>> 207, in getUtility
>>      raise ComponentLookupError(interface, name)
>> zope.component.interfaces.ComponentLookupError: (<InterfaceClass
>> zope.app.folder.interfaces.IFolder>, 'foo')
> 
> The registration is done locally. You have to set the site first or pass it as 
> the context.

Yes, of course. Thanks. I forgot the context. I'm tired today.

So the correct session is:

 >>> from zope.app.folder.interfaces import IFolder
 >>> from zope.component import getUtility
 >>> getUtility(IFolder, 'foo', root)
<zope.app.folder.folder.Folder object at 0xb6c68b2c>


But what did you mean as "set the site"?
do you mean with hooks.setSite() ?

Christophe




More information about the Zope3-users mailing list