Rocky Burt wrote:
> On Fri, 2006-10-11 at 08:00 +0000, Chris Withers wrote:
>> This is a toy example, but I need to do something similar and can't seem 
>> to get the registration right...
>> How can I register the str builtin as an adapter from python int objects 
>> to python str objects?
> I've personally found when I run into a situation where it seems like I
> need to adapt on the builtin str class, I should probably be using named
> adapters or named utilities instead.
> I use this technique for example to lookup mime type stuff in one of my
> apps.
> <adapter
>     for="*"
>     name="text/html"
>     factory=".somemodule.SomeClass"
>     provides=".interfaces.ISomeMimeTypeHandlerThingie"
>     />
> from zope import component
> component.getAdapter(randomobj, ISomeMimeTypeHandlerThingie,
> name='text/html')

Humm. Doesn't that totally work around the fact that the CA knows how to
lookup what you need? What does you code do if you adapt from something

The problem you have is to provide a specification for the 'str' interface.

Let's create a marker interface that promises everything that 'str' does:

class IString(zope.interface.Interface):
    """A marker for the 'str' interface."""

Now, you can setup your adapter like this:



gocept gmbh & co. kg - forsterstra├če 29 - 06112 halle/saale - germany - [EMAIL PROTECTED] - phone +49 345 122 9889 7 -
fax +49 345 122 9889 1 - zope and plone consulting and development

Attachment: signature.asc
Description: OpenPGP digital signature

Zope3-dev mailing list

Reply via email to