[Zope3-dev] Re: adapter registration question

Philipp von Weitershausen philipp at weitershausen.de
Mon Nov 13 12:18:15 EST 2006


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.

> 2. I was to register the "function" str as an adapter for, say, the 
> "class" int to the "class" str, so there's not factory for the adapter, 
> since it's a function
> 
>> Let's create a marker interface that promises everything that 'str' does:
>>
>> class IString(zope.interface.Interface):
>>     """A marker for the 'str' interface."""
> 
> As discussed elsewhere, you shouldn't need the marker interface, as you 
> can adapt classes.

Right, as an *input* of the adaption it's ok just to specify a class. 
But the output obviously always has to be specified by an interface. 
Otherwise the whole point of using of adaption is perverted...

> However, given the edge-case nature of this, I can 
> believe there might be "bugs" to be found here...
> 
>> Now, you can setup your adapter like this:
>>
>> <adapter
>>     for="int"
>>     provides=".interfaces.IString"
>>     factory="str"/>
> 
> Well, that's not right ;-)
> 
> should be:
> 
> provide="str"

Wtf? Then why do you need an adapter? I thought you wanted to say 
IString(1) instead of str(1) to be more flexible...?

> ...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).


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


More information about the Zope3-dev mailing list