[BlueBream] Chaining Adaptors

Justin Ryan justin.ryan at reliefgarden.org
Wed Jul 7 18:07:54 EDT 2010


On Wed, Jul 7, 2010 at 4:27 AM, Mike Rhodes <mike at netsight.co.uk> wrote:
> Hi,
>

Howdy, Mike!

> I've a question about whether the ZCA will chain adapters when trying to
> adapt from one type to another. I couldn't see a specific Zope Toolkit
> mailing list, so if this is the wrong list please feel free to berate me
> and point me toward the correct one!
>

This is a great question.  I know that PyProtocols builds dynamic
chained adapters and caches them in memory at runtime, as well as
being compatible with zope.interface.  I've often considered testing
whether Zope can actually do this on its' own, but never got around to
it..

> The easiest way to explain my question is probably with some code.
>
> Essentially what I am trying to do is to work out whether the ZCA can
> "chain" adapters together when required to satisfy an adaptation
> request. In my example, you need to chain together two adapters: A->B
> then B->C.
>
> ==========================

.. snip example code which looks like documentation of PyProtocols .. ;)

>
> ==========================
>
> When you try to run the last line you get the error:
>
> Traceback (most recent call last):
>   File "zca_demo.py", line 44, in <module>
>     c_like = IInterfaceC(objectA)
> TypeError: ('Could not adapt', <__main__.ClassA object at 0x100686a10>,
> <InterfaceClass __main__.IInterfaceC>)
>
>
> I thought that the ZCA could do this, so I'm wondering if there is
> something wrong with the above code which is prevent the ZCA doing it
> (e.g., is the shorthand IInterfaceC(objectA) incorrect?)
>

Again, a great question.  I'd like to work with you to wrap this into
a failing test for zope.component or something.

I'm not sure this is heavily being used by anyone, but there's no
great reason it shouldn't work.


More information about the bluebream mailing list