Re: [Zope3-Users] very simple problem with getUtility

2007-01-07 Thread Stephan Richter
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.

Regards,
Stephan
-- 
Stephan Richter
CBU Physics  Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] very simple problem with getUtility

2007-01-07 Thread Christophe Combelles

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


___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users