[Zope3-Users] Re: [Z3lab-checkins] r24502 - in z3lab/cpsskins/trunk: . browser/editor browser/skin elements/formats

Jim Fulton jim at zope.com
Fri Jul 1 10:22:56 EDT 2005


Jean-Marc Orliaguet wrote:
> Jim Fulton wrote:
> 
> 
>>Florent Guillaume wrote:
>>...
>>
>>
>>>>+################################################################
>>>>+
>>>>+def renderItems(content, start='', repeat='%s', separator='', 
>>>>end='', **kw):
>>>>+    if IMenuItems.providedBy(content):
>>>>+        items_markup = [start]
>>>>+        items_append = items_markup.append
>>>>+        for item in content:
>>>>+            items_append(repeat % (item['url'], item['title']))
>>>>+            items_append(separator)
>>>>+        items_append(end)
>>>>+        return ''.join(items_markup)
>>>>+    else:
>>>>+        return ''
>>>
>>>
>>>
>>>In general in Zope 3 it's my understanding that it's better to do
>>>
>>>try:
>>>    c = IMenuItems(content)
>>>except ComponentLookupError:
>>>    return ''
>>>... c used as iterable ...
>>>return ...
>>
>>
>>
>>Note that I prefer:
>>
>>   c = IMenuItems(content, None)
>>   if c is None:
>>      return ''
>>
>>   ...
>>
> 
> 
> 
> here is a trival question but what is the syntax for multi-adapters?
> 
>         layout_renderer = getMultiAdapter((layout, request),  IRenderer)
> 
> works,

Right.  That's the way to do it.

 > but:
> 
>          layout_renderer = IRenderer(layout, request)
> 
> returns a BrowserRequest object instead of the renderer implementing
> IRenderer

Right, interface call only does single-adapter lookup.  The second argument
is the default.

> and:
> 
>          layout_renderer = IRenderer((layout, request))
> 
> returns a TypeError saying 'Could not adapt'

Yup. You are trying to look up an adapter for a tuple.

Note that I've wanted to be able to do multi-adapter lookup using interface
call.  I've reluctantly come to the conclusion that it isn't a good idea.
See:

   http://mail.zope.org/pipermail/interface-dev/2004-August/000063.html

FWIW, One idea I've had is to be able to compute adapter factories from
interfaces that then provide a nice syntax.  Something like:

   getRenderer = component.adapterFactory(IRenderer)
   ...

   layoutRendered = getRenderer(layout, request)

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-users mailing list