Re: [Zope-dev] Can't return / publish object of a dictionary?
Jeff Rush wrote: Yeah, the new property type in Python 2.2 is pretty cool, but out of range for use under Zope at the moment. The ExtensionClass requirement for persistence eliminates using it with new style Python classes. Why? I can't see why ExtensionClass should not work with the new property type. Or is the problem specifically to do with persisting a property? In any case, it is certainly out of range for Zope since Zope does not yet officially support python 2.2 - I just mentioned it out of interest. Cheers, seb ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] Can't return / publish object of a dictionary?
Yeah, the new property type in Python 2.2 is pretty cool, but out of range for use under Zope at the moment. The ExtensionClass requirement for persistence eliminates using it with new style Python classes. Plus... the Lars, the original poster, said he was a Python newbie and he certainly doesn't need to get lost wandering around in bleeding edge versions. I think Zope 2.7 or 3.0 is supposed to support new style classes and persistence. But not today... -Jeff Leonardo Rochael Almeida wrote: On Sat, 2003-01-18 at 17:44, Seb Bacon wrote: Jeff Rush wrote: I use a form of the following to compute dynamic titles for Zope objects, where the 'title' attribute is the result of a method call. Modifying it slightly for your case... from ComputedAttribute import ComputedAttribute Class B(A): def getMyObjects(self): ... myObjects = ComputedAttribute(lambda self: self.getMyObjects()) In Python 2.2 (which is unfortunately not yet an option unless you are using a bleeding edge Zope) you can also use the new property type: I might be wrong but I believe class properties only work with new-style classes, and I don't know if Zope ExtensionClass-based objects qualify... Cheers, Leo ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] Can't return / publish object of a dictionary?
On Sat, 2003-01-18 at 17:44, Seb Bacon wrote: > Jeff Rush wrote: > > I use a form of the following to compute dynamic titles for Zope > > objects, where the 'title' attribute is the result of a method call. > > Modifying it slightly for your case... > > > > from ComputedAttribute import ComputedAttribute > > > > Class B(A): > > def getMyObjects(self): > > ... > > myObjects = ComputedAttribute(lambda self: self.getMyObjects()) > > > > In Python 2.2 (which is unfortunately not yet an option unless you are > using a bleeding edge Zope) you can also use the new property type: I might be wrong but I believe class properties only work with new-style classes, and I don't know if Zope ExtensionClass-based objects qualify... Cheers, Leo ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] Can't return / publish object of a dictionary?
Jeff Rush wrote: I use a form of the following to compute dynamic titles for Zope objects, where the 'title' attribute is the result of a method call. Modifying it slightly for your case... from ComputedAttribute import ComputedAttribute Class B(A): def getMyObjects(self): ... myObjects = ComputedAttribute(lambda self: self.getMyObjects()) In Python 2.2 (which is unfortunately not yet an option unless you are using a bleeding edge Zope) you can also use the new property type: http://www.python.org/doc/2.2.1/whatsnew/sect-rellinks.html#SECTION00034 seb ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] Can't return / publish object of a dictionary?
Thousand thanks for ComputedAttribute! You saved not only my day, but my whole week!!! -- Lars Heber T-Systems GEI GmbH Hausanschrift: Clausstrasse 3, 09126 Chemnitz Postanschrift: Clausstrasse 3, 09126 Chemnitz Telefon : (+49 371) 5359-271 Fax : (+49 371) 5359-133 E-Mail : [EMAIL PROTECTED] Internet: http://www.t-systems.de ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] Can't return / publish object of a dictionary?
Lars Heber wrote: I've got two other questions: 1. Say we have a Class A with an attribute myObjects which is just a list. Now, I'd like to write my own Class B(A) - it extends A. But, in Class B, myObjects has to be a method because it has to be rebuild everytime it is called. So, how can I do something like: myObjects = getMyObjects() ? I tried to do this in the class itself, didn't work. Also tried self.myObjects = self.getMyObjects() - result wasn't what I wanted, myObjects got (of course) the resulting list of getMyObjects(), but I need myObjects to be a reference to getMyObjects() I use a form of the following to compute dynamic titles for Zope objects, where the 'title' attribute is the result of a method call. Modifying it slightly for your case... from ComputedAttribute import ComputedAttribute Class B(A): def getMyObjects(self): ... myObjects = ComputedAttribute(lambda self: self.getMyObjects()) 2. Class A has another attribute, say data, which I want to control in Class B(A), i. e. everytime data is accessed (reading or writing), I want to intercept those actions. If it was just reading, I could use the strategy from 1., but I also want to control made changes to that attribute. Do I absolutely have to rewrite all the methods which access the wanted attribute, or is there another possibility with some kind of references, perhaps similar to software interrupts in DOS? I'm not sure about this one, but I suspect an override of the __getattr__() method will let you intercept the lookup of the 'data' attribute, do any pre/post actions you wish, then return the real 'data'. You might try a ComputedAttribute arrangement instead and see if it works for your case since that would be easier. __getattr__ overrides can get into infinite loops w/o careful designs. Jeff Rush ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] Can't return / publish object of a dictionary?
Thanks for the tips, it was the missing wrapper. I'm quite a newbie in Python programming, so please forgive me. I've got two other questions: 1. Say we have a Class A with an attribute myObjects which is just a list. Now, I'd like to write my own Class B(A) - it extends A. But, in Class B, myObjects has to be a method because it has to be rebuild everytime it is called. So, how can I do something like: myObjects = getMyObjects() ? I tried to do this in the class itself, didn't work. Also tried self.myObjects = self.getMyObjects() - result wasn't what I wanted, myObjects got (of course) the resulting list of getMyObjects(), but I need myObjects to be a reference to getMyObjects() How to do this? 2. Class A has another attribute, say data, which I want to control in Class B(A), i. e. everytime data is accessed (reading or writing), I want to intercept those actions. If it was just reading, I could use the strategy from 1., but I also want to control made changes to that attribute. Do I absolutely have to rewrite all the methods which access the wanted attribute, or is there another possibility with some kind of references, perhaps similar to software interrupts in DOS? Thanks for your patience! Lars -- Lars Heber T-Systems GEI GmbH Hausanschrift: Clausstrasse 3, 09126 Chemnitz Postanschrift: Clausstrasse 3, 09126 Chemnitz Telefon : (+49 371) 5359-271 Fax : (+49 371) 5359-133 E-Mail : [EMAIL PROTECTED] Internet: http://www.t-systems.de ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] Can't return / publish object of a dictionary?
Lars, I believe that for security validation to work the object you return has to be acquisition wrapped. Try something like (untested): def _getOb(self, id): return self._secretList[id].__of__(self) HTH, Stefan --On Donnerstag, 16. Jänner 2003 16:51 +0100 Lars Heber <[EMAIL PROTECTED]> wrote: Hi zopers, my class has a list with several objects in it. When calling my self written _getOb() method, I want to return one of these objects. But I get an Unauthorized... When I put an object of the same type into a normal class attribute (self.dummyObject), return of that object from _getOb() works perfectly. What am I doing wrong? Thanks a lot! -- Those who write software only for pay should go hurt some other field. /Erik Naggum/ ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] Can't return / publish object of a dictionary?
Sounds like an acquisition problem to me. Are the objects wrapped? Try def _getOb(..): ... return someobject.__of__(self) Lars Heber wrote: Hi zopers, my class has a list with several objects in it. When calling my self written _getOb() method, I want to return one of these objects. But I get an Unauthorized... When I put an object of the same type into a normal class attribute (self.dummyObject), return of that object from _getOb() works perfectly. What am I doing wrong? Thanks a lot! ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
[Zope-dev] Can't return / publish object of a dictionary?
Hi zopers, my class has a list with several objects in it. When calling my self written _getOb() method, I want to return one of these objects. But I get an Unauthorized... When I put an object of the same type into a normal class attribute (self.dummyObject), return of that object from _getOb() works perfectly. What am I doing wrong? Thanks a lot! -- Lars Heber T-Systems GEI GmbH Hausanschrift: Clausstrasse 3, 09126 Chemnitz Postanschrift: Clausstrasse 3, 09126 Chemnitz Telefon : (+49 371) 5359-271 Fax : (+49 371) 5359-133 E-Mail : [EMAIL PROTECTED] Internet: http://www.t-systems.de ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )