[Zope3-dev] Re: Duplicated zope.decorator in zope.app.container
Jim Fulton
jim at zope.com
Mon Sep 25 10:41:33 EDT 2006
On Sep 25, 2006, at 3:25 AM, Wolfgang Schnerring wrote:
> [moving to the list because it might be of wider interest]
>
> * Jim Fulton <jim at zope.com> [2006-09-22 07:27]:
>> On Sep 22, 2006, at 4:23 AM, Wolfgang Schnerring wrote:
>>> Hi Jim,
>>>
>>> Theuni and I refactored zope.decorator and put its contents into
>>> zope.proxy and zope.security, respectively.
>>>
>>> The same code also exists in duplicate in
>>> zope.app.container.contained, but (you know there's always a
>>> but ;-),
>>> it refuses to let itself be removed: When I try to remove the
>>> DecoratorSpecificationDescriptor from contained.py and import the
>>> "new" one from zope.proxy.decorator instead, the tests break --
>>> although the code of the duplicated decorator is exactly the same!
>>> Theuni and I suspect that it might have something to do with the
>>> ProxyBase C-module, but that's just a guess.
>>>
>>> Do you have any insights into this?
>>
>> Ah, that explains the apparent, but not real duplication. They use
>> different proxy methods. This is quire intentional. I remember now
>> that, for example, we don't want zope.proxy.getProciedObject, to peal
>> away container proxy. The container proxies reuse zope.proxy C code
>> at the source level, rather than through inheritence to keep a
>> separate notion of proxiness. Of course, that means that the
>> decorators use different proxy methods and are different even though
>> they have the same source.
>>
>> You can't get rid of the separate decorators. You could probably get
>> rid of the duplicated code by turning the different versions of
>> getProxiedObject into a class variables and making one set of
>> deecriptors inherit from the other.
>
> I see. It is rather nasty to get different behaviour because of
> differently imported global functions.
> I do have the impression that getProxiedObject should be an instance
> method of the proxy object, and not a global function -- this way, the
> ContainedProxy could just override the method to do whatever it wants.
> Then again, I know next to nothing about the whole proxying stuff. ;-)
> Is there a reason getProxiedObject is a global function instead of an
> instance method?
Yes, now that you mention it. Proxies should be as transparent as
possible. As such, they shouldn't add additional attributes if they
can avoid it. I think it's best to leave things as they are, with a
comment pointing out that the difference is in the version of
getProciedObject used.
Jim
--
Jim Fulton mailto:jim at zope.com Python Powered!
CTO (540) 361-1714 http://www.python.org
Zope Corporation http://www.zope.com http://www.zope.org
More information about the Zope3-dev
mailing list