Re: [Zope] Getting information about current method
No, I'm sorry; I only get system paths. Ole 2005/6/17, Peter Bengtsson <peterbe@gmail.com>:
On 6/17/05, Jan-Ole Esleben <esleben@gmail.com> wrote:
Unforunately, this just gives me the pythonic path to the method; what I need for a TALES expression is the ZOPE path - i.e. what I get from the stack frame is ... E:\zope\Extensions\req.py ... but what I need is ... http://localhost:8080/ReqTest ...
Ok, maybe inspect.stack()[1] was the wrong one. Can't remember nor test it for you but try any of the others in that list. Eg. inspect.stack()[0] or inspect.stack()[2]
You can maybe find something by going through REQUEST.PARENTS
Ole
2005/6/17, Peter Bengtsson <peterbe@gmail.com>:
Then, in your External method, try::
import inspect print inspect.stack()[1]
On 6/17/05, Jan-Ole Esleben <esleben@gmail.com> wrote:
I want to know the name (and path) of the _External Method_ from inside it. What I _can_ get is the name of the DTML method.
I want to build generic scaffolding code for functions that conditionally redispatch as asynchronous calls (via ZASync); that part, however, isn't a problem at all - everything works fine as long as I use an HTTP request directly and redispatch with information from the REQUEST. The problem is that I need a TALES expression to call the function again (asynchronously this time), and for that I need the ZOPE path to it.
Ole
2005/6/17, Peter Bengtsson <peterbe@gmail.com>:
is there a generic way to find out from Python code which method has been called (in other words: find out where the current method is located in the ZOPE hierarchy and what its name is)? If I call an External Method via a DTML method, of course the REQUEST object contains the path to the DTML method because the External Method hasn't been called via HTTP. I haven't been able to figure out any other way of getting this information.
I don't get it. Do you want to know the name of the DTML method from inside the External method? Perhaps I'll be able to help if you tell us more about the intention of this code.
Thanks in advance, Ole _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
On 6/17/05, Jan-Ole Esleben <esleben@gmail.com> wrote:
No, I'm sorry; I only get system paths.
And what about REQUEST.PARENTS? (or is that just the http request)
Ole
2005/6/17, Peter Bengtsson <peterbe@gmail.com>:
On 6/17/05, Jan-Ole Esleben <esleben@gmail.com> wrote:
Unforunately, this just gives me the pythonic path to the method; what I need for a TALES expression is the ZOPE path - i.e. what I get from the stack frame is ... E:\zope\Extensions\req.py ... but what I need is ... http://localhost:8080/ReqTest ...
Ok, maybe inspect.stack()[1] was the wrong one. Can't remember nor test it for you but try any of the others in that list. Eg. inspect.stack()[0] or inspect.stack()[2]
You can maybe find something by going through REQUEST.PARENTS
Ole
2005/6/17, Peter Bengtsson <peterbe@gmail.com>:
Then, in your External method, try::
import inspect print inspect.stack()[1]
On 6/17/05, Jan-Ole Esleben <esleben@gmail.com> wrote:
I want to know the name (and path) of the _External Method_ from inside it. What I _can_ get is the name of the DTML method.
I want to build generic scaffolding code for functions that conditionally redispatch as asynchronous calls (via ZASync); that part, however, isn't a problem at all - everything works fine as long as I use an HTTP request directly and redispatch with information from the REQUEST. The problem is that I need a TALES expression to call the function again (asynchronously this time), and for that I need the ZOPE path to it.
Ole
2005/6/17, Peter Bengtsson <peterbe@gmail.com>:
> is there a generic way to find out from Python code which method has > been called (in other words: find out where the current method is > located in the ZOPE hierarchy and what its name is)? If I call an > External Method via a DTML method, of course the REQUEST object > contains the path to the DTML method because the External Method > hasn't been called via HTTP. I haven't been able to figure out any > other way of getting this information. > I don't get it. Do you want to know the name of the DTML method from inside the External method? Perhaps I'll be able to help if you tell us more about the intention of this code.
> Thanks in advance, > Ole > _______________________________________________ > Zope maillist - Zope@zope.org > http://mail.zope.org/mailman/listinfo/zope > ** No cross posts or HTML encoding! ** > (Related lists - > http://mail.zope.org/mailman/listinfo/zope-announce > http://mail.zope.org/mailman/listinfo/zope-dev ) >
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
It's an application instance wrapped in a list; it seems to be identical to self, actually - self.REQUEST['URL'] and self.REQUEST.PARENTS[0].REQUEST['URL'] are the same. However, the two REQUESTs are not the identical object (== returns False). Ole 2005/6/17, Peter Bengtsson <peterbe@gmail.com>:
On 6/17/05, Jan-Ole Esleben <esleben@gmail.com> wrote:
No, I'm sorry; I only get system paths.
And what about REQUEST.PARENTS? (or is that just the http request)
Ole
2005/6/17, Peter Bengtsson <peterbe@gmail.com>:
On 6/17/05, Jan-Ole Esleben <esleben@gmail.com> wrote:
Unforunately, this just gives me the pythonic path to the method; what I need for a TALES expression is the ZOPE path - i.e. what I get from the stack frame is ... E:\zope\Extensions\req.py ... but what I need is ... http://localhost:8080/ReqTest ...
Ok, maybe inspect.stack()[1] was the wrong one. Can't remember nor test it for you but try any of the others in that list. Eg. inspect.stack()[0] or inspect.stack()[2]
You can maybe find something by going through REQUEST.PARENTS
Ole
2005/6/17, Peter Bengtsson <peterbe@gmail.com>:
Then, in your External method, try::
import inspect print inspect.stack()[1]
On 6/17/05, Jan-Ole Esleben <esleben@gmail.com> wrote:
I want to know the name (and path) of the _External Method_ from inside it. What I _can_ get is the name of the DTML method.
I want to build generic scaffolding code for functions that conditionally redispatch as asynchronous calls (via ZASync); that part, however, isn't a problem at all - everything works fine as long as I use an HTTP request directly and redispatch with information from the REQUEST. The problem is that I need a TALES expression to call the function again (asynchronously this time), and for that I need the ZOPE path to it.
Ole
2005/6/17, Peter Bengtsson <peterbe@gmail.com>: > > is there a generic way to find out from Python code which method has > > been called (in other words: find out where the current method is > > located in the ZOPE hierarchy and what its name is)? If I call an > > External Method via a DTML method, of course the REQUEST object > > contains the path to the DTML method because the External Method > > hasn't been called via HTTP. I haven't been able to figure out any > > other way of getting this information. > > > I don't get it. Do you want to know the name of the DTML method from > inside the External method? > Perhaps I'll be able to help if you tell us more about the intention > of this code. > > > Thanks in advance, > > Ole > > _______________________________________________ > > Zope maillist - Zope@zope.org > > http://mail.zope.org/mailman/listinfo/zope > > ** No cross posts or HTML encoding! ** > > (Related lists - > > http://mail.zope.org/mailman/listinfo/zope-announce > > http://mail.zope.org/mailman/listinfo/zope-dev ) > > > > -- > Peter Bengtsson, > work www.fry-it.com > home www.peterbe.com > hobby www.issuetrackerproduct.com > _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
On 6/17/05, Jan-Ole Esleben <esleben@gmail.com> wrote:
It's an application instance wrapped in a list; it seems to be identical to self, actually - self.REQUEST['URL'] and self.REQUEST.PARENTS[0].REQUEST['URL'] are the same. However, the two REQUESTs are not the identical object (== returns False).
Then I don't know. (The application instance is none other than zope itself. ) I can honestly not think of a way to extract this information. I've even tried setting up a simple example method and I couldn't get hold of the zodb name of the external method that is called. Perhaps Andreas or Dieter can help us here??
Ole
2005/6/17, Peter Bengtsson <peterbe@gmail.com>:
On 6/17/05, Jan-Ole Esleben <esleben@gmail.com> wrote:
No, I'm sorry; I only get system paths.
And what about REQUEST.PARENTS? (or is that just the http request)
Ole
2005/6/17, Peter Bengtsson <peterbe@gmail.com>:
On 6/17/05, Jan-Ole Esleben <esleben@gmail.com> wrote:
Unforunately, this just gives me the pythonic path to the method; what I need for a TALES expression is the ZOPE path - i.e. what I get from the stack frame is ... E:\zope\Extensions\req.py ... but what I need is ... http://localhost:8080/ReqTest ...
Ok, maybe inspect.stack()[1] was the wrong one. Can't remember nor test it for you but try any of the others in that list. Eg. inspect.stack()[0] or inspect.stack()[2]
You can maybe find something by going through REQUEST.PARENTS
Ole
2005/6/17, Peter Bengtsson <peterbe@gmail.com>:
Then, in your External method, try::
import inspect print inspect.stack()[1]
On 6/17/05, Jan-Ole Esleben <esleben@gmail.com> wrote: > I want to know the name (and path) of the _External Method_ from > inside it. What I _can_ get is the name of the DTML method. > > I want to build generic scaffolding code for functions that > conditionally redispatch as asynchronous calls (via ZASync); that > part, however, isn't a problem at all - everything works fine as long > as I use an HTTP request directly and redispatch with information from > the REQUEST. The problem is that I need a TALES expression to call the > function again (asynchronously this time), and for that I need the > ZOPE path to it. > > Ole > > 2005/6/17, Peter Bengtsson <peterbe@gmail.com>: > > > is there a generic way to find out from Python code which method has > > > been called (in other words: find out where the current method is > > > located in the ZOPE hierarchy and what its name is)? If I call an > > > External Method via a DTML method, of course the REQUEST object > > > contains the path to the DTML method because the External Method > > > hasn't been called via HTTP. I haven't been able to figure out any > > > other way of getting this information. > > > > > I don't get it. Do you want to know the name of the DTML method from > > inside the External method? > > Perhaps I'll be able to help if you tell us more about the intention > > of this code. > > > > > Thanks in advance, > > > Ole > > > _______________________________________________ > > > Zope maillist - Zope@zope.org > > > http://mail.zope.org/mailman/listinfo/zope > > > ** No cross posts or HTML encoding! ** > > > (Related lists - > > > http://mail.zope.org/mailman/listinfo/zope-announce > > > http://mail.zope.org/mailman/listinfo/zope-dev ) > > > > > > > -- > > Peter Bengtsson, > > work www.fry-it.com > > home www.peterbe.com > > hobby www.issuetrackerproduct.com > > > _______________________________________________ > Zope maillist - Zope@zope.org > http://mail.zope.org/mailman/listinfo/zope > ** No cross posts or HTML encoding! ** > (Related lists - > http://mail.zope.org/mailman/listinfo/zope-announce > http://mail.zope.org/mailman/listinfo/zope-dev ) >
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
Well, thanks anyway for your suggestions; I hope someone else can suggest something; my intuition is that it isn't possible (without going really low level), and that would really be bad... Ole 2005/6/17, Peter Bengtsson <peterbe@gmail.com>:
On 6/17/05, Jan-Ole Esleben <esleben@gmail.com> wrote:
It's an application instance wrapped in a list; it seems to be identical to self, actually - self.REQUEST['URL'] and self.REQUEST.PARENTS[0].REQUEST['URL'] are the same. However, the two REQUESTs are not the identical object (== returns False).
Then I don't know. (The application instance is none other than zope itself. ) I can honestly not think of a way to extract this information. I've even tried setting up a simple example method and I couldn't get hold of the zodb name of the external method that is called.
Perhaps Andreas or Dieter can help us here??
Ole
2005/6/17, Peter Bengtsson <peterbe@gmail.com>:
On 6/17/05, Jan-Ole Esleben <esleben@gmail.com> wrote:
No, I'm sorry; I only get system paths.
And what about REQUEST.PARENTS? (or is that just the http request)
Ole
2005/6/17, Peter Bengtsson <peterbe@gmail.com>:
On 6/17/05, Jan-Ole Esleben <esleben@gmail.com> wrote:
Unforunately, this just gives me the pythonic path to the method; what I need for a TALES expression is the ZOPE path - i.e. what I get from the stack frame is ... E:\zope\Extensions\req.py ... but what I need is ... http://localhost:8080/ReqTest ...
Ok, maybe inspect.stack()[1] was the wrong one. Can't remember nor test it for you but try any of the others in that list. Eg. inspect.stack()[0] or inspect.stack()[2]
You can maybe find something by going through REQUEST.PARENTS
Ole
2005/6/17, Peter Bengtsson <peterbe@gmail.com>: > Then, in your External method, try:: > > import inspect > print inspect.stack()[1] > > > On 6/17/05, Jan-Ole Esleben <esleben@gmail.com> wrote: > > I want to know the name (and path) of the _External Method_ from > > inside it. What I _can_ get is the name of the DTML method. > > > > I want to build generic scaffolding code for functions that > > conditionally redispatch as asynchronous calls (via ZASync); that > > part, however, isn't a problem at all - everything works fine as long > > as I use an HTTP request directly and redispatch with information from > > the REQUEST. The problem is that I need a TALES expression to call the > > function again (asynchronously this time), and for that I need the > > ZOPE path to it. > > > > Ole > > > > 2005/6/17, Peter Bengtsson <peterbe@gmail.com>: > > > > is there a generic way to find out from Python code which method has > > > > been called (in other words: find out where the current method is > > > > located in the ZOPE hierarchy and what its name is)? If I call an > > > > External Method via a DTML method, of course the REQUEST object > > > > contains the path to the DTML method because the External Method > > > > hasn't been called via HTTP. I haven't been able to figure out any > > > > other way of getting this information. > > > > > > > I don't get it. Do you want to know the name of the DTML method from > > > inside the External method? > > > Perhaps I'll be able to help if you tell us more about the intention > > > of this code. > > > > > > > Thanks in advance, > > > > Ole > > > > _______________________________________________ > > > > Zope maillist - Zope@zope.org > > > > http://mail.zope.org/mailman/listinfo/zope > > > > ** No cross posts or HTML encoding! ** > > > > (Related lists - > > > > http://mail.zope.org/mailman/listinfo/zope-announce > > > > http://mail.zope.org/mailman/listinfo/zope-dev ) > > > > > > > > > > -- > > > Peter Bengtsson, > > > work www.fry-it.com > > > home www.peterbe.com > > > hobby www.issuetrackerproduct.com > > > > > _______________________________________________ > > Zope maillist - Zope@zope.org > > http://mail.zope.org/mailman/listinfo/zope > > ** No cross posts or HTML encoding! ** > > (Related lists - > > http://mail.zope.org/mailman/listinfo/zope-announce > > http://mail.zope.org/mailman/listinfo/zope-dev ) > > > > -- > Peter Bengtsson, > work www.fry-it.com > home www.peterbe.com > hobby www.issuetrackerproduct.com > _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
Peter Bengtsson wrote at 2005-6-17 18:25 +0100:
... Then I don't know. (The application instance is none other than zope itself. ) I can honestly not think of a way to extract this information. I've even tried setting up a simple example method and I couldn't get hold of the zodb name of the external method that is called.
Perhaps Andreas or Dieter can help us here??
Unlike "PythonScript", "ExternalMethod" is not prepared to provide access to itself inside its body. Thus, there is no general solution. In special cases, you can find out information about the "ExternalMethod", e.g. via "REQUEST.PUBLISHED" (in case the "ExternalMethod" was called directly via the Web). However, I would forget "ExternalMethod" and instead use my "TrustedExecutables" product. It provides trusted "PythonScript"s. You can use what you are familiar with in "PythonScript"s but there are no security restrictions (as in "ExternalMethod"). By default, "TrustedExecutables" only provides file system based trusted "PythonScript" ("TrustedFSPythonScript"). The "TrustedPythonScript" is there, but it is not registered -- for security reasons. I suggest, you keep it this way. The best way to use "TrustedFSPythonScript" seems to be to install "CMFCore" (which gives you "DirectoryView") and my "SkinnedFolder". You find my products on <http://www.dieter.handshake.de/pyprojects/zope> -- Dieter
Peter Bengtsson <peter@fry-it.com> wrote:
On 6/17/05, Jan-Ole Esleben <esleben@gmail.com> wrote:
It's an application instance wrapped in a list; it seems to be identical to self, actually - self.REQUEST['URL'] and self.REQUEST.PARENTS[0].REQUEST['URL'] are the same. However, the two REQUESTs are not the identical object (== returns False).
Then I don't know. (The application instance is none other than zope itself. ) I can honestly not think of a way to extract this information. I've even tried setting up a simple example method and I couldn't get hold of the zodb name of the external method that is called.
You can go the low-level route: Using the inspect module, you can get to the stack frames of your callers, and then inspect the local variables there. There must be one that can get you the information you want. See the docstrings of the functions in the inspect module for details. Florent -- Florent Guillaume, Nuxeo (Paris, France) CTO, Director of R&D +33 1 40 33 71 59 http://nuxeo.com fg@nuxeo.com
Then I don't know. (The application instance is none other than zope itself. ) I can honestly not think of a way to extract this information. I've even tried setting up a simple example method and I couldn't get hold of the zodb name of the external method that is called.
You can go the low-level route: Using the inspect module, you can get to the stack frames of your callers, and then inspect the local variables there. There must be one that can get you the information you want.
We tried that but no luck.
See the docstrings of the functions in the inspect module for details.
Florent
-- Florent Guillaume, Nuxeo (Paris, France) CTO, Director of R&D +33 1 40 33 71 59 http://nuxeo.com fg@nuxeo.com
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
participants (4)
-
Dieter Maurer -
Florent Guillaume -
Jan-Ole Esleben -
Peter Bengtsson