Philipp von Weitershausen wrote:
 >>> from zope.component import provideAdapter
 >>> provideAdapter(str,(int,),str)
 >>> from zope.component import getAdapter
 >>> getAdapter(123,str)

Yay! That's _exactly_ what I want.

And that's exactly what I meant -- and wrote about half way up the thread. :)

Yeah, but the words were wrong, so I didn't grok it.
A simple example as above would probably have done it ;-)

 >>> provideAdapter(to_date,(str,int),DateTime)

This registers a multi adapter for (a_string, an_integer), like views are multi-adapters for (context, request). You want to say:

  >>> provideAdapter(to_date, (str,), DateTime)
  >>> provideAdapter(to_date, (int,), DateTime)

Ahhhh... okay, I had to guess from this:

>>> help(provideAdapter)
Help on function provideAdapter in module zope.component:

provideAdapter(factory, adapts=None, provides=None, name='')

>>> provideAdapter(str,int,str)
TypeError: iteration over non-sequence

I guessed the wrong use of the sequence :-(

Shame provideAdapter doesn't have a docstring ;-)

Okay, so now I can do what I want:

>>> getAdapter('2006/11/16',DateTime)


>>> getAdapter('moo',DateTime)
('moo', <class DateTime.DateTime.DateTime at 0x00E73600>, u'')

I'm guessing this is 'cos my adapter is returning None and that's a "special value" meaning "couldn't adapt", right?

How would I _really_ return None from an adapter?



Simplistix - Content Management, Zope & Python Consulting
Zope3-dev mailing list

Reply via email to