Hi all Can I know the execution contexto of an object? I would like to know if the object is call by ZMI or DTML or Page Templates etc is it posible? Thank you
Garito wrote:
Can I know the execution contexto of an object?
I would like to know if the object is call by ZMI or DTML or Page Templates etc
is it posible?
Perhaps; I am not sure I can see why it would be *desirable*. Given that Scripts, DTMLMethods, etc., try pretty hard to push themselves onto the execution stack just as though they were methods, you could probably introspect the result of calling 'sys._getframe(1)' to figure out what kind of thing called you. From the Python Cookbook, #14.7: >>> def whoami(): ... """ Return the name of the calling function. ... """ ... import sys ... return sys._getframe(1).f_code.co_name ... >>> def foobar(): ... print whoami() ... >>> foobar() foobar Tres. -- =============================================================== Tres Seaver tseaver@zope.com Zope Corporation "Zope Dealers" http://www.zope.com
Thank you for your help I would like to overrite some properties in my product with a know property (Maestro) For example I define an object: ObjectA PropertyA PropertyB PropertyC Maestro -> this property has a transversal path to ObjectB ObjectB PropertyD Then I would like to call ObjectA.PropertyD -> these code calls ObjectB.Property With these code I would like to construct a soft link mechanism I try to override the __bobo_traverse__ with these code: def __bobo_traverse__(self, Request, Name): Maestro = getattr(self, '.Maestro', None) if Maestro is not None: obj = self.unrestrictedTraverse(Maestro.contenido) Acquirido = obj.__of__(self) return getattr(Acquirido, Name) return getattr(self, Name) these override works fine but is not recursive in the Maestro structures If I use these other override : def __bobo_traverse__(self, Request, Name): """Propiedad""" Obj = self Maestro = getattr(Obj, '.Maestro', None) Paso = 1 while Maestro is not None: Obj = self.restrictedTraverse(Maestro.contenido).__of__(self) Maestro = getattr(Obj, '.Maestro', None) Paso += 1 if Paso == 15: break if hasattr(Obj, Name): return getattr(Obj, Name) return getattr(self, Name) The recursive Maestro mechanism works fine but in the ZMI I obtain the object in the Maestro structure. For me is an error because I can't see the real content of the object Do you understand my problem? Thanks again!!! PD: sorry for my english! ----- Original Message ----- From: "Tres Seaver" <tseaver@zope.com> To: <zope-dev@zope.org> Sent: Wednesday, March 03, 2004 3:33 AM Subject: [Zope-dev] Re: Execution context
Garito wrote:
Can I know the execution contexto of an object?
I would like to know if the object is call by ZMI or DTML or Page Templates etc
is it posible?
Perhaps; I am not sure I can see why it would be *desirable*. Given that Scripts, DTMLMethods, etc., try pretty hard to push themselves onto the execution stack just as though they were methods, you could probably introspect the result of calling 'sys._getframe(1)' to figure out what kind of thing called you.
From the Python Cookbook, #14.7:
>>> def whoami(): ... """ Return the name of the calling function. ... """ ... import sys ... return sys._getframe(1).f_code.co_name ... >>> def foobar(): ... print whoami() ... >>> foobar() foobar
Tres. -- =============================================================== Tres Seaver tseaver@zope.com Zope Corporation "Zope Dealers" http://www.zope.com
_______________________________________________ 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 )
participants (2)
-
Garito -
Tres Seaver