<s> from __future__ import absolute_import <EOL> import six <EOL> import zmq <EOL> from . import ServerTransport , ClientTransport <EOL> class ZmqServerTransport ( ServerTransport ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , socket ) : <EOL> self . socket = socket <EOL> def receive_message ( self ) : <EOL> msg = self . socket . recv_multipart ( ) <EOL> return msg [ : - <NUM_LIT:1> ] , msg [ - <NUM_LIT:1> ] <EOL> def send_reply ( self , context , reply ) : <EOL> if six . PY3 and isinstance ( reply , six . string_types ) : <EOL> reply = reply . encode ( ) <EOL> self . socket . send_multipart ( context + [ reply ] ) <EOL> @ classmethod <EOL> def create ( cls , zmq_context , endpoint ) : <EOL> """<STR_LIT>""" <EOL> socket = zmq_context . socket ( zmq . ROUTER ) <EOL> socket . bind ( endpoint ) <EOL> return cls ( socket ) <EOL> class ZmqClientTransport ( ClientTransport ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , socket ) : <EOL> self . socket = socket <EOL> def send_message ( self , message , expect_reply = True ) : <EOL> if six . PY3 and isinstance ( message , six . string_types ) : <EOL> message = message . encode ( ) <EOL> self . socket . send ( message ) <EOL> if expect_reply : <EOL> return self . socket . recv ( ) <EOL> @ classmethod <EOL> def create ( cls , zmq_context , endpoint ) : <EOL> """<STR_LIT>""" <EOL> socket = zmq_context . socket ( zmq . REQ ) <EOL> socket . connect ( endpoint ) <EOL> return cls ( socket ) </s>
