<s> import zmq <EOL> from beaver . transports . base_transport import BaseTransport <EOL> class ZmqTransport ( BaseTransport ) : <EOL> def __init__ ( self , beaver_config , logger = None ) : <EOL> super ( ZmqTransport , self ) . __init__ ( beaver_config , logger = logger ) <EOL> zeromq_addresses = beaver_config . get ( '<STR_LIT>' ) <EOL> self . _ctx = zmq . Context ( ) <EOL> if beaver_config . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> self . _pub = self . _ctx . socket ( zmq . PUB ) <EOL> else : <EOL> self . _pub = self . _ctx . socket ( zmq . PUSH ) <EOL> zeromq_hwm = beaver_config . get ( '<STR_LIT>' ) <EOL> if zeromq_hwm : <EOL> if hasattr ( self . _pub , '<STR_LIT>' ) : <EOL> self . _pub . setsockopt ( zmq . HWM , zeromq_hwm ) <EOL> else : <EOL> self . _pub . setsockopt ( zmq . SNDHWM , zeromq_hwm ) <EOL> self . _pub . setsockopt ( zmq . RCVHWM , zeromq_hwm ) <EOL> if beaver_config . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> for addr in zeromq_addresses : <EOL> self . _pub . bind ( addr ) <EOL> else : <EOL> for addr in zeromq_addresses : <EOL> self . _pub . connect ( addr ) <EOL> def callback ( self , filename , lines , ** kwargs ) : <EOL> timestamp = self . get_timestamp ( ** kwargs ) <EOL> if kwargs . get ( '<STR_LIT>' , False ) : <EOL> del kwargs [ '<STR_LIT>' ] <EOL> for line in lines : <EOL> self . _pub . send ( self . format ( filename , line , timestamp , ** kwargs ) ) <EOL> def interrupt ( self ) : <EOL> self . _pub . close ( ) <EOL> self . _ctx . term ( ) <EOL> def unhandled ( self ) : <EOL> return True </s>
