[Zope3-dev] Re: wildcard adapter
Tres Seaver
tseaver at palladion.com
Fri Jan 19 15:30:54 EST 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Chris Withers wrote:
> 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?
The "order" of your adapter registration is *one*, but you are trying to
look it up against *two* objects (like a view).
Tres.
- --
===================================================================
Tres Seaver +1 540-429-0999 tseaver at palladion.com
Palladion Software "Excellence by Design" http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFFsSp++gerLs4ltQ4RApjSAKCYZwOp8b7LlUYEdk5E54bMSStY+ACgzdRY
8ZKbrbRcpyGUhel5YXXeuw4=
=nAls
-----END PGP SIGNATURE-----
More information about the Zope3-dev
mailing list