[TransWarp] New interfaces

Phillip J. Eby pje at telecommunity.com
Wed May 14 18:52:10 EDT 2003

At 09:47 PM 5/14/03 +0400, Oleg Broytmann wrote:
>On Wed, May 14, 2003 at 01:12:46PM -0400, Phillip J. Eby wrote:
> > At 06:33 PM 5/14/03 +0400, Oleg Broytmann wrote:
> > >     if _factory.__dict__.has_key("__implements__"):
> > >         _provides = _factory.__implements__
> > >
> > >   How can I do this now?
> >
> > You don't.  We're specifically deprecating interface introspection.  Use
> > adaptation instead.  In other words, every place in PEAK where we used to
> > do this:
> >
> > if IFoo.isImplementedBy(ob):
> >     spamFoo(ob)
> > elif IBar.isImplementedBy(ob):
> >     spamBar(ob)
> > ...
> >
> > We now do this:
> >
> > adapt(ob,ISpam).spam()
> > If you have code that accesses __implements__ in order to examine an
> > object's interfaces as metadata
>    No, I did it to register the object as a provider:
>                     if _factory.__dict__.has_key("__implements__"):
>                         _provides = _factory.__implements__
>             # if the component provides something, register provider
>             if _provides:
>                 self.__class_provides__.register(_provides, _cname)
>    Now confg.findUtility() can find the object by its interface. How should I
>register providers now?

Ah, I think maybe I see what you're doing.  It sounds like you're trying to 
register things as utility providers, for whatever interfaces the class 
implements.  But I don't understand *why* you're doing it.  PEAK did this a 
long time ago, and it turned out to be a bad idea, because it led to 
unexpected consequences.  Just because you have a component, doesn't mean 
you want to provide it to all your children as an implementation of 
whatever things it does.

In any case, '__class_provides__' is an internal detail; you shouldn't be 
touching it directly.  Use the metadata provided by binding attribute 
definitions, or else use the 'registerProvider()' method of the component 
to explicitly publish the item.

If for some reason you want to create some kind of agressive component that 
wants to make itself a provider for something, you can also create a 
'binding.whenAssembled(...)' function that causes it to go and try to 
register itself as a provider once it has been installed in a component 
hierarchy.  Again, though, I'm not sure I see why this is a good idea.

Perhaps you could explain your use case a bit more, so I can tell whether 
there is an existing capability for what you need, or if perhaps I have 
overlooked a use case?  Thanks.

More information about the PEAK mailing list