how to get info about an object (dir/type)
hi, while working with zope, i many times have the following problem: i find a method that i can use, and the documentation (for example) says: "returns the current user". ok, but what kind of object is it? what methods does it have? usually i would simply call dir() or type() on the result object, but those are forbidden in zope. how do you usually solve this? gabor
--On 30. Juni 2005 13:48:19 +0200 gabor <gabor@nekomancer.net> wrote:
hi,
while working with zope, i many times have the following problem:
i find a method that i can use, and the documentation (for example) says: "returns the current user".
ok, but what kind of object is it? what methods does it have?
lib/python/AccessControl/User.py is your friend. -aj
Andreas Jung wrote:
--On 30. Juni 2005 13:48:19 +0200 gabor <gabor@nekomancer.net> wrote:
hi,
while working with zope, i many times have the following problem:
i find a method that i can use, and the documentation (for example) says: "returns the current user".
ok, but what kind of object is it? what methods does it have?
lib/python/AccessControl/User.py is your friend.
thanks for your help, but .. it is not about this specific issue (about the current user).. generally.. if i have a reference to an object. how do i find out what his methods are? gabor
--On 30. Juni 2005 14:04:14 +0200 gabor <gabor@nekomancer.net> wrote:
Andreas Jung wrote:
--On 30. Juni 2005 13:48:19 +0200 gabor <gabor@nekomancer.net> wrote:
hi,
while working with zope, i many times have the following problem:
i find a method that i can use, and the documentation (for example) says: "returns the current user".
ok, but what kind of object is it? what methods does it have?
lib/python/AccessControl/User.py is your friend.
thanks for your help,
but .. it is not about this specific issue (about the current user)..
generally.. if i have a reference to an object. how do i find out what his methods are?
By determining its class or meta_type and then by checking the related documentation, source code of the class or its base classes? Of course type() does not work in RestrictedPython. Bascially you should know the objects you're dealing with...otherwise this sounds like a problem with your application to me :-) Otherwise use type() from within unrestricted code. -aj
See: http://epydoc.sourceforge.net/ (which I have not yet used). Andreas Jung wrote:
--On 30. Juni 2005 13:48:19 +0200 gabor <gabor@nekomancer.net> wrote:
generally.. if i have a reference to an object. how do i find out what his methods are?
By determining its class or meta_type and then by checking the related documentation, source code of the class or its base classes? Of course type() does not work in RestrictedPython. Bascially you should know the objects you're dealing with...otherwise this sounds like a problem with your application to me :-) Otherwise use type() from within unrestricted code.
While this may be the most direct answer, on my system there are ~2200 Python source files for Zope+Plone. Most of the objects I've tried to inspect through source code have had multiple parent classes, and some of the parent classes did, too. Consequently it can be a long and tedious undertaking to simply find out which method or attribute name to use, eg: title, Title, getTitle(), get_title(), Title() ... etc. Peter Bengtsson wrote:
usually i would simply call dir() or type() on the result object, but those are forbidden in zope.
how do you usually solve this?
External methods. You might even want to have a general debugging script lying around that you can use to exploit dir() and type() and __class__.__name__ from your zope. Bare in mind that there's a security reason why these aren't available in zope but if it's only you using the tools, it's safe.
Peter (or anyone else) -- do you have an Extension that you'd be willing to share? Or is there one already on Zope.org that I missed? Nikko
----- Original Message ----- From: "gabor" <gabor@nekomancer.net> To: <zope@zope.org> Sent: Thursday, June 30, 2005 7:48 AM Subject: [Zope] how to get info about an object (dir/type)
while working with zope, i many times have the following problem:
i find a method that i can use, and the documentation (for example) says: "returns the current user".
ok, but what kind of object is it? what methods does it have?
usually i would simply call dir() or type() on the result object, but those are forbidden in zope.
You can create a small utility external method to call dir() and type() (very useful!) Jonathan
usually i would simply call dir() or type() on the result object, but those are forbidden in zope.
how do you usually solve this?
External methods. You might even want to have a general debugging script lying around that you can use to exploit dir() and type() and __class__.__name__ from your zope. Bare in mind that there's a security reason why these aren't available in zope but if it's only you using the tools, it's safe.
gabor _______________________________________________ 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-30 13:36 +0100:
... External methods. You might even want to have a general debugging script lying around that you can use to exploit dir() and type() and __class__.__name__ from your zope. Bare in mind that there's a security reason why these aren't available in zope but if it's only you using the tools, it's safe.
You can also use your favorite tools in an interactive Python interpreter session. Under *nix, it looks like: bin/zopectl debug obj = app.unrestrictedTraverse(path_to_some_interesting_object) dir(obj); type(obj) u = obj.getUser(...) dir(u) ... You must either use ZEO or shut down you Zope while you access it like shown above... -- Dieter
gabor wrote:
hi,
while working with zope, i many times have the following problem:
i find a method that i can use, and the documentation (for example) says: "returns the current user".
ok, but what kind of object is it? what methods does it have?
usually i would simply call dir() or type() on the result object, but those are forbidden in zope.
Use of the debug prompt is your friend. On Linux you can do zopectl debug, get the object and then dir(), type() it all you want. We recently released PloneShell which is not actually Plone specific, but might be of help: http://www.enfoldsystems.com/Products/Open/PloneShell All you need is wxPython and you are up and running ;) -- Andy McKay Enfold Systems, LLC http://www.enfoldsystems.com
gabor wrote at 2005-6-30 13:48 +0200:
while working with zope, i many times have the following problem:
i find a method that i can use, and the documentation (for example) says: "returns the current user".
ok, but what kind of object is it? what methods does it have?
usually i would simply call dir() or type() on the result object, but those are forbidden in zope.
"DocFinder" can help you. You might need a small script that obtains the object you are interested in and than calls "DocFinder" with it. <http://www.dieter.handshake.de/pyprojects/zope> -- Dieter
participants (7)
-
Andreas Jung -
Andy McKay -
Dieter Maurer -
gabor -
Jonathan -
Nikko Wolf -
Peter Bengtsson