[TransWarp] Component hierarchy traversal

Radek Kanovsky rk at dat.cz
Wed Oct 1 12:34:20 EDT 2003

On Wed, Oct 01, 2003 at 12:05:28PM -0400, Phillip J. Eby wrote:

> >    def traverseComponents (comp, reg=None) :
> >        if reg is None :
> >            reg = {}
> >        yield (comp, binding.getComponentPath(comp))
> >        reg[comp] = 1
> >        for a,d in comp.__class__.__all_descriptors__.items() :
> >            if not isinstance(d, binding.Attribute) :
> >                continue
> Did you find that you needed the isinstance() check in practice?  I'm just 
> curious.

No, isinstance(d, binding.Attribute) seems useles now.

> >            i = comp._getBinding(a)
> And why access the attribute in the dictionary, instead of using 
> 'getattr()'?

With getattr call I am getting `__instance_offers__' infinitely looped
to other. It seem that __instance_offers__ are created on the fly:


> Right.  To be precise, all the parents above the items to be registered, 
> must be assembled.  That's not quite the whole hierarchy, unless every 
> object in the system needs to be registered.

> > Is there some pattern how to solve this?
> If you know the paths of the objects in advance, you can use something like:
>     allMyObjects = binding.Obtain(
>         ['path/to/item1', 'path/to/item2', .... ], uponAssembly=True
>     )
> in some object that needs the list; the 'allMyObjects' attribute will then 
> equal a tuple of the listed objects.

I know every path but want to avoid to configure this in some place.
One often forget to add new component to allMyObjects binding.
Application itself is assembled from components and change in one
components can affect many applications.

> Could you explain your application a little?  It may be that there are 
> additional ways to accomplish what you need.

There are some smart components that implements IResourceComponent
interface. They should manage their persistent resources on demand
(Create/Drop/Check/...): EntityDM can create database tables, ImageCache
can prepare directory sturcture, SQLConnection can create some global
sequences, etc.


More information about the PEAK mailing list