[Zope-dev] Re: default view

Dieter Maurer dieter at handshake.de
Thu Jun 22 13:23:38 EDT 2006


Philipp von Weitershausen wrote at 2006-6-22 09:03 +0200:
>Dieter Maurer wrote:
> ...
>> If you are working on it, then you should implement a
>> means that "__bobo_traverse__" can tell the caller that
>> it should use the normal default.
> ...
>> In our private Zope version, I have used an exception
>> ("UseTraversalDefault") for this purpose.
>
>I think that __bobo_traverse__ can raise AttributeError currently to
>indicate that it has failed to look up an attribute and that traversal
>should try other options. Apart from being a more explicit spelling,
>what advantage would UseTraversalDefault have?

First of all, I had expected that you were in favour
of "explicit is better than implicit" (usually, I am not). In this case,
you should be happy with a "more explicit spelling" ;-)


I do not know the current code in Zope 2.10, but earlier
it looked like:

                if hasattr(object,'__bobo_traverse__'):
                    try:
                        subobject=object.__bobo_traverse__(request,entry_name)
			...
                    except (AttributeError, KeyError):
                        if debug_mode:
                            return response.debugError(
                                "Cannot locate object at: %s" % URL)
                        else:
                            return response.notFoundError(URL)


With this code, you were only partially right:

  "__bobo_traverse__" could indeed raise an "AttributeError"
  to do something special -- but not to get the default
  traversal but to get a "NotFound" or a "DebugError" exception.

  That's quite different from what I proposed ;-)


Should you prefer the implicit use of "AttributeError"
over a more explicit use (the "UseTraversalDefault" was only
some possibility; I am happy, if you find something better
-- but equally explicit) to get the default traversal,
I would not be completely unhappy
but think: not optimal but better than nothing ;-)


-- 
Dieter


More information about the Zope-Dev mailing list