[Zope3-dev] Re: adapter registration question

Philipp von Weitershausen philipp at weitershausen.de
Tue Nov 14 04:27:46 EST 2006


Chris Withers wrote:
> Philipp von Weitershausen wrote:
>> Chris Withers wrote:
>>> Christian Theune wrote:
>>>> The problem you have is to provide a specification for the 'str' 
>>>> interface.
>>>
>>> There are a couple of problems here...
>>>
>>> 1. str is both a "function" and a "class"
>>
>> Nope. It's a class since Python 2.2.
> 
> ...hence the quotes. It's a "function" in that I want to use it as an 
> adapter that doesn't need to be instantiated by a factory before being 
> used.

All adapters need to be instantiated. A function can serve as much as an 
adapter factory as a class.

>>> ...and factory="str" is wrong for the reasons given above, or, put 
>>> differently, because str()(1) will tell you that strings aren't 
>>> callable ;-)
>>
>> Huh? You got that wrong. IString(1) will call str(1) if 
>> provideAdapter(str, (int,), IString).
> 
> right, but factory="" registers and adapter factory, not an adapter and 
> provideAdapter registers an adapter directly, correct?

No. You always register a factory which is called upon lookup. That's 
because adapters are context-dependent and thus need to be instantiated 
every time you look them up.


-- 
http://worldcookery.com -- Professional Zope documentation and training


More information about the Zope3-dev mailing list