summaryrefslogtreecommitdiffstats
path: root/tools/buildbot/pylibs/twisted/test/testutils.py
diff options
context:
space:
mode:
authorinitial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-21 21:11:06 +0000
committerinitial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-21 21:11:06 +0000
commit01593319d061fa65811a30c0d37fff1755f9db62 (patch)
treefb1d9bd99b96eb239ea28f84f767ab21921c02d9 /tools/buildbot/pylibs/twisted/test/testutils.py
parent66aa1265b6ff166987ffc294b7796f827abd27bc (diff)
downloadchromium_src-01593319d061fa65811a30c0d37fff1755f9db62.zip
chromium_src-01593319d061fa65811a30c0d37fff1755f9db62.tar.gz
chromium_src-01593319d061fa65811a30c0d37fff1755f9db62.tar.bz2
Add tools/buildbot to the repository.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3685 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/buildbot/pylibs/twisted/test/testutils.py')
-rw-r--r--tools/buildbot/pylibs/twisted/test/testutils.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/tools/buildbot/pylibs/twisted/test/testutils.py b/tools/buildbot/pylibs/twisted/test/testutils.py
new file mode 100644
index 0000000..a310ea2
--- /dev/null
+++ b/tools/buildbot/pylibs/twisted/test/testutils.py
@@ -0,0 +1,55 @@
+from cStringIO import StringIO
+from twisted.internet.protocol import FileWrapper
+
+class IOPump:
+ """Utility to pump data between clients and servers for protocol testing.
+
+ Perhaps this is a utility worthy of being in protocol.py?
+ """
+ def __init__(self, client, server, clientIO, serverIO):
+ self.client = client
+ self.server = server
+ self.clientIO = clientIO
+ self.serverIO = serverIO
+
+ def flush(self):
+ "Pump until there is no more input or output."
+ while self.pump():
+ pass
+
+ def pump(self):
+ """Move data back and forth.
+
+ Returns whether any data was moved.
+ """
+ self.clientIO.seek(0)
+ self.serverIO.seek(0)
+ cData = self.clientIO.read()
+ sData = self.serverIO.read()
+ self.clientIO.seek(0)
+ self.serverIO.seek(0)
+ self.clientIO.truncate()
+ self.serverIO.truncate()
+ for byte in cData:
+ self.server.dataReceived(byte)
+ for byte in sData:
+ self.client.dataReceived(byte)
+ if cData or sData:
+ return 1
+ else:
+ return 0
+
+
+def returnConnected(server, client):
+ """Take two Protocol instances and connect them.
+ """
+ cio = StringIO()
+ sio = StringIO()
+ client.makeConnection(FileWrapper(cio))
+ server.makeConnection(FileWrapper(sio))
+ pump = IOPump(client, server, cio, sio)
+ # Challenge-response authentication:
+ pump.flush()
+ # Uh...
+ pump.flush()
+ return pump