[Zope] Getting inherited classes

Dieter Maurer dieter@handshake.de
Thu, 9 Jan 2003 23:02:23 +0100


Michele Ruberl wrote at 2003-1-8 18:37 +0100:
 > a quick question: how could I (in a python script) get a list of all 
 > inherited classes from an object's meta_type? My aim's is to get the 
 > first object implementing ObjectManager while going up in the PARENTS 
 > hierarchy, whith something like that:
 > 
 > parents = request.PARENTS
 > for i in range(len(parents)):
 >     if parents[i].meta_type ********:    ### if it implements ObjectManagers
 >         return parents[i]
You cannot get the inherited classes in TTW code (the access would
be "object.aq_base.__class__.__bases__; neither "aq_base" nor
"__class__" or "__bases__" are availabe in TTW code).

But "OFS.ObjectManager" defines the attribute "isAnObjectManager=1",
such you can check for it.
Your only problem: you must avoid acquisition.
In most cases, "aq_explicit" does this but it is not safe.

When you need a safe solution, search the Collector for
my "hasattr_unacquired" patch.


Dieter