<s> from __future__ import absolute_import <EOL> from . base import BytestreamDataSource , DataSourceError <EOL> import socket <EOL> class SocketDataSource ( BytestreamDataSource ) : <EOL> def read ( self ) : <EOL> try : <EOL> line = "<STR_LIT>" <EOL> while '<STR_LIT:\x00>' not in line : <EOL> line += self . socket . recv ( <NUM_LIT:1> ) <EOL> except ( OSError , socket . error , IOError ) as e : <EOL> raise DataSourceError ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( self . host , self . port , e ) ) <EOL> if not line : <EOL> raise DataSourceError ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( self . host , self . port ) ) <EOL> return line <EOL> def write_bytes ( self , data ) : <EOL> return self . socket . send ( data ) </s>
