Hi All, I have a situation where I want one object to alias methods that are actually provided by a different object. This is being done in __bobo_traverse__ in a Python product that subclasses Folder I can call another object's method easily enough, but when I do this, it will resolve all names in the context of the *calling* object, not the method's physical container. That makes a certain amount of sense, perhaps... but it isn't what I *want* to happen. I've tried various combinations like: obj.method obj.method.__of__(self) obj.method.__of__(obj) All with no joy... in each case, the method is the correct method but names are resolved by the *calling* object, not by the returned method's container. Any ideas how to make this work the way I want it to? TIA, Dylan
Dylan Reinhardt wrote:
Hi All,
I have a situation where I want one object to alias methods that are actually provided by a different object. This is being done in __bobo_traverse__ in a Python product that subclasses Folder
I can call another object's method easily enough, but when I do this, it will resolve all names in the context of the *calling* object, not the method's physical container. That makes a certain amount of sense, perhaps... but it isn't what I *want* to happen.
I've tried various combinations like:
obj.method obj.method.__of__(self) obj.method.__of__(obj)
All with no joy... in each case, the method is the correct method but names are resolved by the *calling* object, not by the returned method's container.
Any ideas how to make this work the way I want it to?
try: aq_base(obj.method).__of__(aq_base(self)) ...or some such. good luck, manaually building acquisition hierarchies is fun... Chris
On Tue, 2004-01-20 at 03:36, Chris Withers wrote: [snip]
All with no joy... in each case, the method is the correct method but names are resolved by the *calling* object, not by the returned method's container. try:
aq_base(obj.method).__of__(aq_base(self))
That didn't do it, but it did prompt me to go re-read "Acquisition Algebra" which is always a good time. :-) It seems like what I want is exactly what aq_inner() is supposed to do... return an object wrapped by containment only. But for some reason it's still not working with any combination of aq_base and/or aq_inner. Anyway, I settled on a workaround for now... for methods I'm going to wrap this way, I stuff the name of the container into REQUEST['traverse_from'] and add this code to the aliased methods: <dtml-if traverse_from> <dtml-call "REQUEST.set('me', restrictedTraverse(traverse_from))"> <dtml-else> <dtml-call "REQUEST.set('me', this())"> </dtml-if> And then call everything from the "me" object, ex: <dtml-var "me.getId()"> Seems to work fine, though I'm sure it's not as efficient as it could be. Thanks for your help. Dylan
Dylan Reinhardt wrote:
It seems like what I want is exactly what aq_inner() is supposed to do... return an object wrapped by containment only. But for some reason it's still not working with any combination of aq_base and/or aq_inner.
Try Shane's acquisition finder code and use it to print the acquisition heirarchy for your objects after you've rebuilt it's acquisition path: http://zope.org/Members/chrisw/showaq cheers, Chris
On Wed, 2004-01-21 at 01:23, Chris Withers wrote:
Dylan Reinhardt wrote:
It seems like what I want is exactly what aq_inner() is supposed to do... return an object wrapped by containment only. But for some reason it's still not working with any combination of aq_base and/or aq_inner.
Try Shane's acquisition finder code and use it to print the acquisition heirarchy for your objects after you've rebuilt it's acquisition path:
A most excellent tool. Oddly, that shows exactly the path I *want* but the behavior I'm seeing indicates that something else is going on. I'm beginning to suspect that the problem is lurking in some other place in my product code. Not sure exactly what that would be, but Zope seems to think it's working correctly and I've got objects that exist to traverses other objects. What are the odds? :-) Thanks for your help, Chris. Dylan
participants (2)
-
Chris Withers -
Dylan Reinhardt