[Zope3-Users] Adapting a builtin?

Michael Howitz mh at gocept.com
Wed Dec 7 02:58:51 EST 2005

On Tue, 2005-12-06 at 18:44 -0500, Paul Winkler wrote:
> Hi,
> Is it possible to register an adapter for a builtin type
> such as str?  All the adapter examples I see use an interface for the
> "for" attribute.
> Something like:
>   <adapter for="str"
>     provides=".interfaces.IHTTPConnection"
>     factory="httplib.HTTPConnection"
>   />


in plain Zope3 (I'm not using Five, but it may be similar there.) you
can declare an interface for the buitin: (e.g. in interfaces.py)

class interface IStr(Interface):
   # define the methods here which you need to access
   def upper():
       "upper ... as an example"

In configure.zcml, you declare the interface for the builtin:

<class class="str">
   <implements interface=".interfaces.IStr" />


Then you can do:
  IHTTPConnection('string') to get the adapter.


More information about the Zope3-users mailing list