[Twisted-Python] zope.interface changes

Jim Fulton jim at zope.com
Mon May 1 11:23:07 EDT 2006


I hope this is the right list to post to.  Twisted-dev seems more aptly named, but
it doesn't seem to get a lot of traffic.

I've recently refactored the adapter-registration implementation in zope.interface.
There were a number of reasons for this, including performance and making it possible,
in the future, to implement a capability similar to Python's super builtin for calling
overridden adaptera.

The performance gains for the simple-adapter lookup used by Twisted was about 200%.
For Zope, the changes led to about a 15-30% performance improvement.

I expect the new interface version to be released in June.

While working on this, I discovered that Twisted was bypassing the public API to
try to determne of there was an adapter registered:

     for interfaceClass in interfaceClasses:
         factory = self.get(origInterface).selfImplied.get(interfaceClass, {}).get('')

where self is an adapter registry.  This is in python/components.py.

I've added an adapter-registry API specifically for Twisted's use:

     def registered(required, provided, name=u''):
         """Return the component registered for the given interfaces and name

         Unlike the lookup method, this methods won't retrieve
         components registered for more specific required interfaces or
         less specific provided interfaces.

         If no component was registered exactly for the given
         interfaces and name, then None is returned.

         """

I've also added a backward-compatibility hack:

     def get(self, _):
         class XXXTwistedFakeOut:
             selfImplied = {}
         return XXXTwistedFakeOut

This makes Zope's tests pass. Not sure about Twisted's.

Obviously, it would be good for Twisted to move to the new public API.
In the future, if you need a new API, please feel free to ask. :)

Jim

-- 
Jim Fulton           mailto:jim at zope.com       Python Powered!
CTO                  (540) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org




More information about the Twisted-Python mailing list