[Zope3-dev] Re: wildcard adapter

Chris Withers chris at simplistix.co.uk
Fri Jan 19 03:12:04 EST 2007


Marius Gedminas wrote:
> Now when you try to adapt anything to ITest, zope.component will call
> your ``adapter`` function and then check the return value.  A return
> value of None means "the adapter is not available", and results in a
> TypeError you see here:

Yes, apologies, both you and Philipp are correct, I was trying to show a 
simple version of a problem and oversimplified.

Here's what I really meant:

 >>> from zope.component import provideAdapter
 >>> from zope.interface import Interface
 >>> from zope.component import getMultiAdapter
 >>> class ITest(Interface): pass
...
 >>> def adapter(*args): return args
...

 >>> provideAdapter(adapter,adapts=(None,),provides=ITest)
 >>> ITest(1)
(1,)

Yay, as expected...

 >>> getMultiAdapter((1,),ITest)
(1,)

Good, still works...

 >>> provideAdapter(adapter,adapts=(None,None),provides=ITest)
 >>> getMultiAdapter((1,1),ITest)
Traceback (most recent call last):
...
zope.component.interfaces.ComponentLookupError:
  ((1, 1), <InterfaceClass __main__.ITest>, u'')

Oh dear, what have I done wrong here?

cheers,

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
            - http://www.simplistix.co.uk



More information about the Zope3-dev mailing list