wrapping unexistent objects
Hi all, I've a little bit tricky problem: How could I wrap a request of an inexistent object and handle request in a transparent way using a defined method? I've searched about __before_publishing_traverse__ and __bobo_traverse__ but them are too few documented (or I didn't understand them). Better explain: I'd like to build a generic product which permit to call undefined function with parameters using dtml as any other python script but this functions aren't define and will be handled by product. Does anyone has some suggestion/Doc about this? TIA, baux
If you want an object to be able to handle calls to undefined methods, you'll probably need to use a __getattr__ hook. They can be a little tricky to get right (you want to filter out names that start with "_" or "aq" or else you'll be in trouble), and they don't have access to acquisition, but they will allow you to intercept calls to arbitrary names on an object. __bobo_traverse__ and __before_publishing_traverse__ are hooks for URL traversal inside ZPublisher. They won't work for calls made inside DTML. -Casey On Monday 02 December 2002 11:00 am, Maurizio Boriani wrote:
Hi all, I've a little bit tricky problem: How could I wrap a request of an inexistent object and handle request in a transparent way using a defined method? I've searched about __before_publishing_traverse__ and __bobo_traverse__ but them are too few documented (or I didn't understand them).
Better explain: I'd like to build a generic product which permit to call undefined function with parameters using dtml as any other python script but this functions aren't define and will be handled by product.
Does anyone has some suggestion/Doc about this?
TIA, baux
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org 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 )
"Casey" == Casey Duncan <casey@zope.com> writes:
Casey> If you want an object to be able to handle calls to Casey> undefined methods, you'll probably need to use a Casey> __getattr__ hook. They can be a little tricky to get right Casey> (you want to filter out names that start with "_" or "aq" Casey> or else you'll be in trouble), and they don't have access Casey> to acquisition, but they will allow you to intercept calls Casey> to arbitrary names on an object. have you some examples or docs about this? I'm tring using it but my product felt in an unfinisched loop. Any suggestion Casey> -Casey TIA, baux
Its easy to create an infinite loop. To avoid these, do attribute lookups from the instance __dict__ rather than directly from self: IOW, don't do: foo = self.foo or getattr(self, 'foo') (This can trigger another __getattr__ call) Instead do: foo = self.__dict__['foo'] (This won't cause another getattr call) As for examples, there is a complex one in the CMF Skinnable module and a simpler one in the Document module of my DocumentLibrary product. -Casey On Tuesday 03 December 2002 10:58 am, Maurizio Boriani wrote:
"Casey" == Casey Duncan <casey@zope.com> writes:
Casey> If you want an object to be able to handle calls to Casey> undefined methods, you'll probably need to use a Casey> __getattr__ hook. They can be a little tricky to get right Casey> (you want to filter out names that start with "_" or "aq" Casey> or else you'll be in trouble), and they don't have access Casey> to acquisition, but they will allow you to intercept calls Casey> to arbitrary names on an object.
have you some examples or docs about this? I'm tring using it but my product felt in an unfinisched loop. Any suggestion
Casey> -Casey
TIA, baux
"Casey" == Casey Duncan <casey@zope.com> writes:
Casey> Its easy to create an infinite loop. To avoid these, do Casey> attribute lookups from the instance __dict__ rather than Casey> directly from self: Casey> IOW, don't do: Casey> foo = self.foo Casey> or getattr(self, 'foo') Casey> (This can trigger another __getattr__ call) Casey> Instead do: Casey> foo = self.__dict__['foo'] in my case foo is a method not a properties Casey> (This won't cause another getattr call) Casey> As for examples, there is a complex one in the CMF Casey> Skinnable module and a simpler one in the Document module Casey> of my DocumentLibrary product. I tried this too but zope return an error ('Type Error, unsubscriptable object'). Exactly this is my case: I've a class called, for example, pippo. This cotain another class called pluto. So wath I'd like to do is: <dtml-with pippo> <dtml-with pluto> <dtml-var expr="ciccio('parameter')"> </dtml-with> </dtml-with> the expr or method ciccio doesn't exist in pluto but I'd like to pass to a defined method the expr and its parameters. A big thanks anymore for your help bye, baux
Can you just use acquisition? On Tuesday 03 December 2002 01:11 pm, Maurizio Boriani wrote:
"Casey" == Casey Duncan <casey@zope.com> writes:
Casey> Its easy to create an infinite loop. To avoid these, do Casey> attribute lookups from the instance __dict__ rather than Casey> directly from self:
Casey> IOW, don't do:
Casey> foo = self.foo
Casey> or getattr(self, 'foo')
Casey> (This can trigger another __getattr__ call)
Casey> Instead do:
Casey> foo = self.__dict__['foo']
in my case foo is a method not a properties
Casey> (This won't cause another getattr call)
Casey> As for examples, there is a complex one in the CMF Casey> Skinnable module and a simpler one in the Document module Casey> of my DocumentLibrary product.
I tried this too but zope return an error ('Type Error, unsubscriptable object').
Exactly this is my case:
I've a class called, for example, pippo. This cotain another class called pluto.
So wath I'd like to do is: <dtml-with pippo> <dtml-with pluto> <dtml-var expr="ciccio('parameter')"> </dtml-with> </dtml-with>
the expr or method ciccio doesn't exist in pluto but I'd like to pass to a defined method the expr and its parameters.
A big thanks anymore for your help
bye, baux
"Casey" == Casey Duncan <casey@zope.com> writes:
Casey> Can you just use acquisition? But how could I without knowing wich method will be call? -- Maurizio Boriani -- Debian Developer E-mail address: baux@debian.org GPG key: 0xCC0FBF8F fingerprint => E429 A37C 5259 763C 9DEE FC8B 5D61 C796 CC0F BF8F <= fingerprint
participants (3)
-
Casey Duncan -
Maurizio Boriani -
Maurizio Boriani