[Twisted-Python] Twisted in Python STDLIB?

exarkun at divmod.com exarkun at divmod.com
Mon Oct 11 19:48:27 EDT 2004

On Mon, 11 Oct 2004 22:54:13 +0300, Tommi Virtanen <tv at twistedmatrix.com> wrote:
>Ed Suominen wrote:
> > I'd like to start a discussion on whether Twisted ought to be a part of 
> > Python's standard library. I understand some of the developers think it 
> > should not, but I personally don't like seeing far inferior networking 
> > code sitting there in stdlib. Inclusion in the stdlib carries an 
> > implied endorsement, and that endorsement should be going to Twisted, 
> > in my view.
> Exarkun pointed out some really good reasons why Twisted should not be
> in stdlib. I pretty much agree with him.
> However, there is something that could be done to stdlib:
> refactor the various networking things there so, that they are built
> out of modules that only implement protocol logic, and blocking
> "runners" for the protocol logic.
> That is, separate the socket calls from the protocol. The interface
> between them would probably look a lot like a twisted Protocol, and
> hopefully would enable code reuse (in either direction).

  I've always operated under the assumption that this is already almost trivally possible.  Let me explore this for a moment...

    class CrummyTCPTransport:
        disconnecting = False  # HAHAHA
        def __init__(self, socket, protocol):
            self.socket = socket
            self.protocol = protocol

        # Skip boring stuff like getHost etc
        def write(self, bytes):

        def writeSequence(self, iovec):

        def run(self):
            while True:
                b = self.socket.recv(1024)
                if not b:

    s = socket.socket()
    p = imap4.IMAP4Client()
    t = CrummyTCPTransport(s, p)

  Reasonable?  Crappy?  Anyway, that's how I've always seen a simplistic, reactorless program using Twisted protocols.  It's ugly, but I think it should work (and compare it to trying to make a stdlib protocol implementation work with Twisted!)

  Which of Twisted's protocol implementations are mature enough for the standard library though?  I can think of one, maybe (not counting all the  useless ones like ident), and I wrote it so I'm probably biased.


More information about the Twisted-Python mailing list