[Zope-dev] Using zope.proxy for read-only instances

Andreas Jung lists at zopyx.com
Mon Dec 22 05:45:52 EST 2008


On 22.12.2008 11:34 Uhr, Andreas Kopecky wrote:
> Hi,
>
> My first question regarding that would be: why use zope.proxy for it.
> Personally - not knowing what exactly you have in mind ofc - i'd use
> something along the lines of
>
> class Proxy(object):
>
>      def __init__(self, obj):
>          self.obj = obj
>
>      def __getattr__(self, attribute):
>          return getattr(obj, attribute)
>
> maybe add a check of the returned attribute is callable or so.

Sorry, invalid answer. That's what zope.proxy is designed for and I am 
trying to get it working (unlikely it has no documentation and the
unittest don't give me much insight). In addition: your code won't work 
since you must refer to self.obj  not 'obj' within __getattr__. And 
using self.obj will lead to an infinite recursion. I also think that
__getattr__() is not used by new-styles classes. Instead you need to 
override __getattribute__().

Andreas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lists.vcf
Type: text/x-vcard
Size: 316 bytes
Desc: not available
Url : http://mail.zope.org/pipermail/zope-dev/attachments/20081222/7f23a956/attachment-0001.vcf 


More information about the Zope-Dev mailing list