Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: third_party/twisted_8_1/twisted/test/testutils.py

Issue 12261012: Remove third_party/twisted_8_1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 from cStringIO import StringIO
2 from twisted.internet.protocol import FileWrapper
3
4 class IOPump:
5 """Utility to pump data between clients and servers for protocol testing.
6
7 Perhaps this is a utility worthy of being in protocol.py?
8 """
9 def __init__(self, client, server, clientIO, serverIO):
10 self.client = client
11 self.server = server
12 self.clientIO = clientIO
13 self.serverIO = serverIO
14
15 def flush(self):
16 "Pump until there is no more input or output."
17 while self.pump():
18 pass
19
20 def pump(self):
21 """Move data back and forth.
22
23 Returns whether any data was moved.
24 """
25 self.clientIO.seek(0)
26 self.serverIO.seek(0)
27 cData = self.clientIO.read()
28 sData = self.serverIO.read()
29 self.clientIO.seek(0)
30 self.serverIO.seek(0)
31 self.clientIO.truncate()
32 self.serverIO.truncate()
33 for byte in cData:
34 self.server.dataReceived(byte)
35 for byte in sData:
36 self.client.dataReceived(byte)
37 if cData or sData:
38 return 1
39 else:
40 return 0
41
42
43 def returnConnected(server, client):
44 """Take two Protocol instances and connect them.
45 """
46 cio = StringIO()
47 sio = StringIO()
48 client.makeConnection(FileWrapper(cio))
49 server.makeConnection(FileWrapper(sio))
50 pump = IOPump(client, server, cio, sio)
51 # Challenge-response authentication:
52 pump.flush()
53 # Uh...
54 pump.flush()
55 return pump
OLDNEW
« no previous file with comments | « third_party/twisted_8_1/twisted/test/test_zshcomp.py ('k') | third_party/twisted_8_1/twisted/test/threading_latency.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698