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

2005-07-01 Thread Stephan Richter
On Friday 01 July 2005 10:22, Jim Fulton wrote:
> 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)

Yeah, that would be nice.

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] Re: [Z3lab-checkins] r24502 - in z3lab/cpsskins/trunk: . browser/editor browser/skin elements/formats

2005-07-01 Thread Jim Fulton

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/63.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:[EMAIL PROTECTED]   Python Powered!
CTO  (540) 361-1714http://www.python.org
Zope Corporation http://www.zope.com   http://www.zope.org
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


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

2005-07-01 Thread Jean-Marc Orliaguet
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, but:

 layout_renderer = IRenderer(layout, request)

returns a BrowserRequest object instead of the renderer implementing
IRenderer

and:

 layout_renderer = IRenderer((layout, request))

returns a TypeError saying 'Could not adapt'


/JM

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


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

2005-06-30 Thread Florent Guillaume
Jim Fulton  <[EMAIL PROTECTED]> wrote:
> Note that I prefer:
> 
> c = IMenuItems(content, None)
> if c is None:
>return ''
> 
> ...
> 
> > than testing directly for the provided interface, as it gives an  
> > opportunity for an adapter to do its job. It's probably slower  though, 
> > and maybe not a pattern generally used for marker interfaces.  Opinions ?
> 
> IMO, testing for an interface is sometimes preferable to using an adapter.
> Some people feel very strongly that you should never test for an interface
> -- I don't.
> 
> It seems silly to add an adapter just to avoid using a test
> (for religious reasons iow).
> 
> In particular, providing adapters to handle cases where an object
> doesn't provide some service and can't really be adapted to provide
> a service seems really silly to me.

I agree with that. My intent is more to provide "adaptation point" where
you are really allowing something to extend your framework
(aspect-oriented style).

Florent

-- 
Florent Guillaume, Nuxeo (Paris, France)   CTO, Director of R&D
+33 1 40 33 71 59   http://nuxeo.com   [EMAIL PROTECTED]
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


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

2005-06-29 Thread Jim Fulton

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 ''

   ...

than testing directly for the provided interface, as it gives an  
opportunity for an adapter to do its job. It's probably slower  though, 
and maybe not a pattern generally used for marker interfaces.  Opinions ?


IMO, testing for an interface is sometimes preferable to using an adapter.
Some people feel very strongly that you should never test for an interface
-- I don't.

It seems silly to add an adapter just to avoid using a test
(for religious reasons iow).

In particular, providing adapters to handle cases where an object
doesn't provide some service and can't really be adapted to provide
a service seems really silly to me.

Jim

--
Jim Fulton   mailto:[EMAIL PROTECTED]   Python Powered!
CTO  (540) 361-1714http://www.python.org
Zope Corporation http://www.zope.com   http://www.zope.org
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


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

2005-06-29 Thread Stephan Richter
On Wednesday 29 June 2005 04:17, 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 ...
>
> than testing directly for the provided interface, as it gives an  
> opportunity for an adapter to do its job. It's probably slower  
> though, and maybe not a pattern generally used for marker interfaces.  
> Opinions ?

Well, we did not have a solid opinion on this yet. Certainly, the style guide 
says nothing about this. But I agree we should start looking up adapters all 
of the time, instead of checking for provided interfaces. I think this is 
something we should bring up on zope3-dev.

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