[Twisted-Python] Interfaces and adapters

Valentino Volonghi aka Dialtone dialtone at divmod.com
Sat Aug 27 07:47:58 EDT 2005

en.karpachov at ospaz.ru wrote:

>The question is, if the object doesn't declare itself provides the
>interface it adapts to, should this be considered as a bug? If so, then we
>have it with twisted.web.server.Session and nevow.guard.GuardSession (and
>probably the same situation with twisted.web2).
twisted.web2 is yet to come and also nevow working on it although
there's a branch in nevow
that works with it right now. So everything is in flux and yet to be

>There is another problem with it. The twisted.web.server.Session cannot
>declare itself implementing nevow.inevow.ISession as it doesn't know
>anything about nevow; but nevow registers it as default adapter from
>WovenContext to inevow.ISession. So we have a situation:
>    session = inevow.ISession(ctx)
>    assert inevow.ISession.providedBy(sess) # oops! it is no
>What use in the adaptation above then? It's not really an adapter to the
>interface we need but just some arbitrary function call, not related to
>interfaces at all, incidentally looking like an adapter.
Woah, wait a bit :)
If you want to really use sessions in nevow you have to use guard, if
you use guard the session
object will be GuardSession that knows about nevow and can implement
Currently GuardSession doesn't implement inevow.ISession but will in a
sec when I commit the fix.

If you don't use guard you are really getting a server.Session object
from twisted.web returned by
nevow.appserver.sessionFactory that calls NevowRequest.getSession()
which will return the GuardSession
if you are using guard or the other one if not (as I already said). Oh,
server.Session does suck.

>Probably, a decorator to the adapterFactory could help; even if all got a
>bit slower, we'll get more correct behaviour. Anyway, is it that slower?
>I've heard the nevow as well as Python are not about speed, but about
>building robust applications.
True, but doing more than what is really needed doesn't do good anyway.
Losing speed for free is not something
you really wish.

Valentino Volonghi aka Dialtone
Now Running MacOSX 10.4.1
Blog: http://vvolonghi.blogspot.com

More information about the Twisted-Python mailing list