Re: [Zope-dev] Using zope.proxy for read-only instances
Hi, Well if it's invalid i won't bother with it but say: - i forgot a self - that is true - if added it does NOT loop infinitely - its not my example its taken from python cookbook - it works with new style objects - __getattribute__ does something different But frankly i was only trying to understand better what you want to do and be helpful - which obviously is neither needed nor wanted. Andreas > 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 signature.asc Description: OpenPGP digital signature ___ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] Using zope.proxy for read-only instances
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 begin:vcard fn:Andreas Jung n:Jung;Andreas org:ZOPYX Ltd. & Co. KG adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany email;internet:i...@zopyx.com title:CEO tel;work:+49-7071-793376 tel;fax:+49-7071-7936840 tel;home:+49-7071-793257 x-mozilla-html:FALSE url:www.zopyx.com version:2.1 end:vcard ___ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] Using zope.proxy for read-only instances
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. Andreas Andreas Jung wrote: > Hi there, > > I am trying to figure out how to use zope.proxy for creating read-only > proxy objects of arbitrary Python objects where only attributes can be > accessed read-only (no write access to attributes, no calling of > methods). Anyone with some example code? > > Andreas > > ___ > Zope-Dev maillist - Zope-Dev@zope.org > http://mail.zope.org/mailman/listinfo/zope-dev > ** No cross posts or HTML encoding! ** > (Related lists - > http://mail.zope.org/mailman/listinfo/zope-announce > http://mail.zope.org/mailman/listinfo/zope ) signature.asc Description: OpenPGP digital signature ___ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )