<s> from cStringIO import StringIO <EOL> from twisted . internet . protocol import FileWrapper <EOL> class IOPump : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , client , server , clientIO , serverIO ) : <EOL> self . client = client <EOL> self . server = server <EOL> self . clientIO = clientIO <EOL> self . serverIO = serverIO <EOL> def flush ( self ) : <EOL> "<STR_LIT>" <EOL> while self . pump ( ) : <EOL> pass <EOL> def pump ( self ) : <EOL> """<STR_LIT>""" <EOL> self . clientIO . seek ( <NUM_LIT:0> ) <EOL> self . serverIO . seek ( <NUM_LIT:0> ) <EOL> cData = self . clientIO . read ( ) <EOL> sData = self . serverIO . read ( ) <EOL> self . clientIO . seek ( <NUM_LIT:0> ) <EOL> self . serverIO . seek ( <NUM_LIT:0> ) <EOL> self . clientIO . truncate ( ) <EOL> self . serverIO . truncate ( ) <EOL> for byte in cData : <EOL> self . server . dataReceived ( byte ) <EOL> for byte in sData : <EOL> self . client . dataReceived ( byte ) <EOL> if cData or sData : <EOL> return <NUM_LIT:1> <EOL> else : <EOL> return <NUM_LIT:0> <EOL> def returnConnected ( server , client ) : <EOL> """<STR_LIT>""" <EOL> cio = StringIO ( ) <EOL> sio = StringIO ( ) <EOL> client . makeConnection ( FileWrapper ( cio ) ) <EOL> server . makeConnection ( FileWrapper ( sio ) ) <EOL> pump = IOPump ( client , server , cio , sio ) <EOL> pump . flush ( ) <EOL> pump . flush ( ) <EOL> return pump </s>
