Totaly dynamic path?
Can anybody tell me how I can construct a dynamic path with attributes in a python product? my situation is: I get the classname, methodname and attributes by a dynamic form. They are strings and the names and attributes are dynamic. I do a iteration over the request an split the names and attributes. Example after iteration over the request: object = 'personManager' method = 'getData().addPerson' attribute1, firstname = 'max' attribute2, lastname = 'miller' how can I construct a dynamic path like: getattr(self, 'personManager').getData().addPerson( firstname='max', lastname='miller') Mit freundlichen GrĂ¼ssen Roger Ineichen ___________________________ Projekt01 GmbH www.projekt01.ch Langackerstrasse 8 6330 Cham phone +41 (0)41 781 01 78 mobile +41 (0)79 340 52 32 fax +41 (0)41 781 00 78 email r.ineichen@projekt01.ch ___________________________ END OF MESSAGE
Roger wrote:
how can I construct a dynamic path like: getattr(self, 'personManager').getData().addPerson( firstname='max', lastname='miller')
I think you got it backwards how you usually do it in Zope. Normally you would create a product, and then you would create a function in that product that is a constructor, ie. it constructs new instances of your product in Zope. You then register that function in Zope, If you try to do it your way, you need to create your own security mechanism end other things that Zope do for you otherwise. See the minimal product for more info about how it works. regards Max Miller -- "Sorry I would Really Like To Help More On This Project, But Am To Busy Doing Paid Work On A Tight Deadline" Max M
Roger writes:
... how can I construct a dynamic path like: getattr(self, 'personManager').getData().addPerson( firstname='max', lastname='miller') This does not like a path for me...
Okay, lets see: * you already know "getattr". It resolves simple attributes given by an expression * you can handle keyword parameters (your "firstname", "lastname") via a dictionary and the "apply" method (see Python library documentation: built-in function "apply"). * the difficult part is "getData().addPerson". You need to parse this and use "getattr", and "function call" to resolve this. Inside an External Method, you could use "eval" (as an alternative). But be caseful! Big security risk. You should probably use some from of "safe_eval" (--> search the archive). Dieter
participants (3)
-
Dieter Maurer -
Max M -
Roger