[Zope3-dev] Re: View lookup changes in Zope 3.2?

Jim Fulton jim at zope.com
Tue Dec 13 18:31:37 EST 2005


Jeff Shell wrote:
...
> Going through a lot of debugging, it looks as through it has to do
> with how things are ranked in
> zope.interface.adapter.AdapterLookup.lookup() for multi-adapters.

Yup.

> I haven't stepped through it in the debugger in Zope 3.1 yet, but I just
> got finished doing it in Zope 3.2 and these are my results:
> 
> 
> 
>>>>from zope.app.component.hooks import setSite
>>>>from zope.publisher.browser import TestRequest
>>>>from zope.app import zapi
>>>>from zope.publisher.interfaces.browser import ISkin, IDefaultSkin
>>>>conman = zapi.getUtility(ISkin, name='br.cms.skin.ContentManagement')
>>>>customer = debugger.root()['customer']
>>>>setSite(customer)
>>>>winter = customer['winter']
>>>>contents = zapi.queryMultiAdapter((winter,
> 
> TestRequest(skin=conman)), name='contents.html')
> 
>>>>contents.__class__.__bases__
> 
> (<class 'zope.app.container.browser.contents.Contents'>, <class
> 'zope.app.publisher.browser.viewmeta.simple'>)
> 
> So then I do a pdb.run("zapi.queryMultiAdapter((winter,
> TestRequest(skin=conman)), name='contents.html')") and it's inside
> AdapterLookup that I get the following. When all of the adapters for
> this container and the request with the name 'contents.html' are
> looked up:
> 
> (Pdb) pp byname.get(name)
> [((<InterfaceClass zope.app.folder.interfaces.IFolder>,
>    <InterfaceClass zope.publisher.interfaces.browser.IDefaultBrowserLayer>),
>   <class 'zope.app.publisher.browser.viewmeta.Contents'>),
>  ((<InterfaceClass br.cms.interfaces.IContentContainer>,
>    <InterfaceClass br.cms.skin.CMS>),
>   <class 'zope.app.publisher.browser.viewmeta.contents.html'>),
>  ((<InterfaceClass br.cms.interfaces.IContentFolder>,
>    <InterfaceClass zope.publisher.interfaces.browser.IDefaultBrowserLayer>),
>   <class 'zope.app.publisher.browser.viewmeta.Contents'>)]
> 
> The one the I want is the second set in this list, 'br.cms.skin.CMS'.
> Unfortunately, that's the one that loses out in the ranking algorithm
> that ranks based on interface's ranking in the spec resolution order.
> (NOTE: The IContentContainer there is different than the Zope
> IContentContainer! This has cause some confusion in house)
> 
> The first one (IFolder, IDefaultBrowserLayer) produces the rank: (4, 4)
> The second one, which I want, (IContentContainer, CMS) produces the rank (12, 2)
> The third one, which I'm suspecting is generated from a zcml
> containerViews directive, wins with the rank (3, 4).
> 
> It wins because the 'best' tuple is kept around. A rank wins 'best' by
> being less than the current 'best', and (3, 4) is less than all of
> them.
> 
> I understand why this is happening, but it's (obviously) not what I
> want to have happen. I want MY skin layer's declaration of
> 'contents.html' to win out. It actually works for all container types,
> so maybe I need to declare it for a root Zope container interface for
> my layer?

I don't know enough about the relationshipd between your content
interfaces, to comment directly, but I will note that the intent
was that content interface would have precedence over skin.  This
was not the case before due to a bug in  multi-adapter lookup.

> I've been living under the impression that the layer a view was
> assigned to had higher precedence than may have been intended,

Yup.

 > and
> maybe this is part of the discussion going on in the
> 'SimplifySkinning' proposal/thread

I hope not.

 > which I should take a closer look at.

Me too.

Jim

-- 
Jim Fulton           mailto:jim at zope.com       Python Powered!
CTO                  (540) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org


More information about the Zope3-dev mailing list