[zope2-tracker] [Bug 374810] Re: [DM] Simplify __bobo_traverse__ implementations by centralizing ZPublisher responsibilities.
Christian Zagrodnick
cz at gocept.com
Mon Jun 21 09:26:23 EDT 2010
** Description changed:
2. Introduction
Zope2 allows objects to customize traversal by defining the method
__bobo_traverse__.
__bobo_traverse__ is used in two quite different contexts: ZPublisher
traversal and OFS traversal.
ZPublisher requires that its traversal steps return
webdav.NullResource.NullResource instances and must not use acquisition
under some (quite difficult to understand and to check) conditions. This
requirement poses a heavy burden on __bobo_traverse__ authors and leads
to very volatile implementations. In Archetypes, for example, three
rounds of bug fixing were necessary before a rather simple
__bobo_traverse__ (it checks whether an object can be found in the
session) finally adhered to the ZPublisher requirements. The special
ZPublisher logic (to not use acquisition and to return NullResource in
some cases) should be in ZPublisher alone and not be duplicated in all
kinds of __bobo_traverse__ implementations.
3. Feature
Give __bobo_traverse__ a way to concentrate on special cases only and
defer to standard traversal in all other cases.
To this end, ZPublisher defines an exception UseTraversalDefault. If a
call to __bobo_traverse__ raises this exception, the normal traversal
(including all special casing in case of ZPublisher) is performed.
The implementation requires modifications in
ZPublisher.BaseRequest.DefaultPublishTraverse.publishTraverse and
OFS.Traversable.unrestrictedTraverse.
I define UseTraversalDefault in ZPublisher.exceptions. This introduces a
dependence of OFS.Traversable from ZPublisher.
4. Example Use Cases
The Archetypes __bobo_traverse__ can simply look whether the object is
found in the session, and return it in this case. Otherwise, it raises
UseTraversalDefault. The complete difficult logic to guess whether
__bobo_traverse__ was called from ZPublisher and to determine whether or
not to allow acquisition and to return NullResource in some failure
cases goes away.
Other __bobo_traverse__ implementations gains in simplicity and
robustness in a similar way.
5. Notes
- * Probably other traversal hooks, too, should be allowed to
- o use this traversal default.
+ * Probably other traversal hooks, too, should be allowed to use this
+ traversal default.
** Changed in: zope2
Assignee: (unassigned) => Christian Zagrodnick (zagy)
--
[DM] Simplify __bobo_traverse__ implementations by centralizing ZPublisher responsibilities.
https://bugs.launchpad.net/bugs/374810
You received this bug notification because you are a member of Zope 2
Developers, which is subscribed to Zope 2.
More information about the zope2-tracker
mailing list