[Zope] Introspection and Zope

Douwe Osinga dmo@oberon.nl
Tue, 27 Nov 2001 13:09:35 +0100


Hi All,

One of the things I like about python is introspection. Zope does seem to
support most features, but I run into some problems.

I want to create a method that prints the items in a folder in tabular
format. On each row, I want the title of the object in the folder and some
properties. These properties should either be direct properties or methods.

My code:

01  if context.hasProperty(propname):
02      return context.getProperty(propname)
03  else:
04      if hasattr(context,propname) and
callable(getattr(context,propname)):
05          return context[propname]()
06      else:
07          return defaultvalue

I first check whether context has the property requested, if so, I return it
with getProperty.
Than, if it has the property as attribute and the property is callable,
there is a method and
I call that (the kind of methods I look for do not require paramaters). If
nothing of the kind
can be found, I return the defaultvalue.

Now, if I pass 'absolute_url' as propname, this works as a dream. But if I
pass getParent, a
method I created in the base class of the object where context was derived
from, the thing
crashes with 'Resource not found'. Debuging points out that line 04 goes
okay, ie. it can
find the property as attribute and determines that it is indeed callable,
but the actual calling
then fails with a resource not found.

So, what am I doing wrong? Is there another way to call a method of a zope
object if you only
have the name of the method in a string variable?

Any help is appreciated,

Douwe