<s> """<STR_LIT>""" <EOL> import socket <EOL> from lantz import Driver <EOL> from lantz . drivers . legacy . textual import TextualMixin <EOL> from lantz . errors import LantzTimeoutError <EOL> class LantzSocketTimeoutError ( socket . timeout , LantzTimeoutError ) : <EOL> pass <EOL> class TCPRawDriver ( Driver ) : <EOL> """<STR_LIT>""" <EOL> RECV_TERMINATION = '<STR_LIT:\n>' <EOL> SEND_TERMINATION = '<STR_LIT:\n>' <EOL> RECV_CHUNK = <NUM_LIT> <EOL> def __init__ ( self , host = '<STR_LIT:localhost>' , port = <NUM_LIT> , * args , ** kwargs ) : <EOL> super ( ) . __init__ ( * args , ** kwargs ) <EOL> self . socket = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) <EOL> self . host_port = ( host , port ) <EOL> def raw_send ( self , data ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . socket . send ( data ) <EOL> except socket . timeout as e : <EOL> raise LantzSocketTimeoutError ( str ( e ) ) <EOL> def raw_recv ( self , size ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return self . socket . recv ( size ) <EOL> except socket . timeout as e : <EOL> raise LantzSocketTimeoutError ( str ( e ) ) <EOL> def initialize ( self ) : <EOL> self . log_debug ( '<STR_LIT>' , self . host_port ) <EOL> return self . socket . connect ( self . host_port ) <EOL> def finalize ( self ) : <EOL> self . log_debug ( '<STR_LIT>' , self . host_port ) <EOL> return self . socket . close ( ) <EOL> def is_open ( self ) : <EOL> return self . socket . isOpen ( ) <EOL> class TCPDriver ( TCPRawDriver , TextualMixin ) : <EOL> """<STR_LIT>""" <EOL> RECV_TERMINATION = '<STR_LIT:\n>' <EOL> SEND_TERMINATION = '<STR_LIT:\n>' <EOL> RECV_CHUNK = <NUM_LIT> </s>
