1
from cStringIO import StringIO
2
from twisted.internet.protocol import FileWrapper
5
"""Utility to pump data between clients and servers for protocol testing.
7
Perhaps this is a utility worthy of being in protocol.py?
9
def __init__(self, client, server, clientIO, serverIO):
12
self.clientIO = clientIO
13
self.serverIO = serverIO
16
"Pump until there is no more input or output."
21
"""Move data back and forth.
23
Returns whether any data was moved.
27
cData = self.clientIO.read()
28
sData = self.serverIO.read()
31
self.clientIO.truncate()
32
self.serverIO.truncate()
34
self.server.dataReceived(byte)
36
self.client.dataReceived(byte)
43
def returnConnected(server, client):
44
"""Take two Protocol instances and connect them.
48
client.makeConnection(FileWrapper(cio))
49
server.makeConnection(FileWrapper(sio))
50
pump = IOPump(client, server, cio, sio)
51
# Challenge-response authentication: