[z3-five] Re: Traversal issue [was: 0.2 release]
Philipp von Weitershausen
philipp at weitershausen.de
Fri Oct 1 23:28:53 MEST 2004
Janko Hauser wrote:
> Philipp von Weitershausen wrote:
>
>
>>The code in Sidnei's branch raises NotFoundError now except when it
>>thinks it's being called from ZPT pathexpressions; then it returns None.
>>As explained above, this is not correct behaviour. I suggested to solve
>>the issue by implementing the following:
>>
>>- __bobo_traverse__ always raises AttributeError when it cannot
>>traverse. This seems to be the overall expected behaviour.
>>
>>- for the ZPublisher, we don't want AttributeError showing but NotFound.
>>To achieve this, we wrap __bobo_traverse__ in a descriptor that does the
>>funky frame introspection and converts AttributeErrors into NotFound.
>>That way the magic is at least contained in that descriptor.
>>
>>Objections?
>>
>
> I saw your remark on irc, do you think this would work with
> ExtensionClass based objects? To overwrite this later in some classes
> these need to be new_style?
Yes. I was confusing simple method descriptors with the fancy 'property'
descriptor. 'property' only works on new-style classes. Standard
descriptors are quite simple. The one I'm suggesting would look like this:
def ZPublisherCompatibleTraverser(meth):
def func(self, REQUEST, name):
# XXX do some actual inspecting here
if calledFromZPublisher:
try:
return meth(self, REQUEST, name)
except (AttributeError, KeyError):
return REQUEST.RESPONSE.notFoundError(name)
else:
return meth(self, REQUEST, name)
return func
Then Products.Five.traversable.Traversable would look like:
class Traversable:
def __fallback_traverse(self, REQUEST, name):
raise AttributeError, name
__fallback_traverse__ =
ZPublisherCompatibleTraverser(__fallback_traverse__)
This way Traversable.__fallback_traverse__ is a regular function object
(the 'func' function from inside ZPublisherCompatibleTraverser). Since
it doesn't matter whether you have an UnboundMethodType or a
FunctionType on a class and ExtensionClasses allow us to monkey with
them anyway, it should work :)
Maybe Sidnei can take this code and add his frame magic where I put the
comment and then check it into his branch. Then we'll know for sure.
Philipp
More information about the z3-five
mailing list