[Twisted-Python] Switching Protocols and TLS

Tobias Oberstein tobias.oberstein at tavendo.de
Wed Aug 29 10:41:38 EDT 2012

> >Any hint how to track that down would be great!
> The `protocol´ attribute isn't part of the transport interface.  Some transports
> are implemented in a way such that changing that attribute to refer to a
> different protocol will produce the behavior you're after, but not all.  In
> particular, the transport implemented in twisted.protocols.tls (used to provide
> the transport whenever you use listenSSL, connectSSL, or startTLS) does not
> work this way.
> You should be able to work out which attribute needs to be mangled by looking
> at twisted/protocols/tls.py.  My initial guess would be `wrappedProtocol`, but
> that's *only* a guess.  And of course, whatever you find is not going to be part
> of any formal transport interface either, so it's not guaranteed to keep working
> in the future, or to work with any other transport you might end up using -
> hence the desire to resolve #3204.

You are great! ;)

It is indeed "wrappedProtocol" .. and by mangling this, it now works also for TLS!

Yes, I am fully aware that it's a bloody hack .. and I will change code when #3204 lands.

will need to have such a hack also.

Something that still bugs me: who should be responsible for calling start/stopFactory
on the factory that produces the protocol that gets switched over to?

I mean (in my case): I can't just derive from twisted.web.server.Site overriding
start/stopFactory, since there may be multiple Resources added to Site that
do switch protocol. Or should I iterate over the whole Resource tree of Site
finding the protocol switching Resources and call startFactory on them?

Thanks again!


More information about the Twisted-Python mailing list