[Twisted-Python] adapt from more than one interface

Esteve Fernandez esteve at sindominio.net
Sun Apr 12 11:11:12 EDT 2009

On Sunday 12 April 2009 15:16:04 glyph at divmod.com wrote:
> Sorry for that; it certainly wasn't my intention.  I meant just what I
> said: I find it difficult to communicate about.  Perhaps I should have
> said, "trust me, my experience suggests that it is".

I'm too thin-skinned sometimes, so just forget what I said :-)

> And this is why the explanation of its wrong-ness is difficult.  I know
> that you could get the same effect by doing (IFoo, IUsernamePassword) ->
> IBar and (IFoo, IHostnamePath).

Actually I just discovered some of those flaws in Zope's adapter registry, so 
you're right that multi-adapters are not that easy to implement.

> Would the specifics of your application allow you to introduce an
> intermediary IProtocolFactoryConfigurer interface, with .config* methods
> that would return the actual ProtocolFactory, as with my IBarFactory
> above?  "IBar" here would be IProtocolFactory; sorry for the confusion
> with the word "factory".

I guess that would be sufficient, an "adapter factory" in some sense. In fact, 
I already came up with something similar, but found it too cumbersome 
(attached). Maybe, instead of supporting multi-adapters, a recipe like yours 
could be added to the documentation.

> So ConfigurationObject is purely for the IFooFactory implementation?

Yep. In our case, AMQP protocol instances require some arguments to be passed 
(e.g. username and password for connecting to the broker). BTW, I just 
realized that we should use usage.Options instead of our own config object.

> Thanks for that link, by the way, that's a great introduction to
> zope.component.  Not one I'd seen before.

It covers pretty much everything about adapters and interfaces, I found it 
very detailed and useful.

> I'm still not a big fan of multi-adapters, but the code's so short, and
> so non-invasive (in particular I don't believe it'll affect the
> performance of "normal", single adaptation), that I probably wouldn't
> argue too hard against it.  Feel free to file that ticket, although I
> won't promise that somebody *else* won't come along and object.  In any
> case, you can start using it right away if it suits you :).

It's very simple and elegant, I like it :-) I think it's a good idea to 
include it, or maybe add an entry to the FAQ.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: multi.py
Type: application/x-python
Size: 1668 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20090412/fb95139d/attachment.bin 

More information about the Twisted-Python mailing list