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-1714            http://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

Reply via email to