[Zope] how to get info about an object (dir/type)

2005-06-30 Thread gabor

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
___
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 )


Re: [Zope] how to get info about an object (dir/type)

2005-06-30 Thread gabor

Andreas Jung wrote:



--On 30. Juni 2005 13:48:19 +0200 gabor [EMAIL PROTECTED] 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
___
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 )


Re: [Zope] how to get info about an object (dir/type)

2005-06-30 Thread Jonathan


- Original Message - 
From: gabor [EMAIL PROTECTED]

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 



___
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 )


Re: [Zope] how to get info about an object (dir/type)

2005-06-30 Thread Andreas Jung



--On 30. Juni 2005 14:04:14 +0200 gabor [EMAIL PROTECTED] wrote:


Andreas Jung wrote:



--On 30. Juni 2005 13:48:19 +0200 gabor [EMAIL PROTECTED] 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

pgpyFqkQef3xE.pgp
Description: PGP signature
___
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 )


Re: [Zope] how to get info about an object (dir/type)

2005-06-30 Thread Peter Bengtsson
 
 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
___
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 )


Re: [Zope] how to get info about an object (dir/type)

2005-06-30 Thread Nikko Wolf

See: http://epydoc.sourceforge.net/  (which I have not yet used).

Andreas Jung wrote:

--On 30. Juni 2005 13:48:19 +0200 gabor [EMAIL PROTECTED] 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
___
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 )


Re: [Zope] how to get info about an object (dir/type)

2005-06-30 Thread Andy McKay

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
___
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 )


Re: [Zope] how to get info about an object (dir/type)

2005-06-30 Thread Dieter Maurer
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
___
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 )


Re: [Zope] how to get info about an object (dir/type)

2005-06-30 Thread Dieter Maurer
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
___
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 )