Work out multiple inheritance in event_handler_connector.py

This commit is contained in:
Kristóf Tóth 2018-01-29 16:02:52 +01:00
parent 6e6d775a05
commit 9760db7c5c

View File

@ -12,7 +12,7 @@ ioloop.install()
class EventHandlerDownlinkConnector(ZMQConnectorBase):
def __init__(self, zmq_context=None):
super().__init__(zmq_context)
super(EventHandlerDownlinkConnector, self).__init__(zmq_context)
self._zmq_pull_socket = self._zmq_context.socket(zmq.PULL)
self._zmq_pull_stream = ZMQStream(self._zmq_pull_socket)
address = 'tcp://*:{}'.format(RECEIVER_PORT)
@ -22,7 +22,7 @@ class EventHandlerDownlinkConnector(ZMQConnectorBase):
class EventHandlerUplinkConnector(ZMQConnectorBase):
def __init__(self, zmq_context=None):
super().__init__(zmq_context)
super(EventHandlerUplinkConnector, self).__init__(zmq_context)
self._zmq_pub_socket = self._zmq_context.socket(zmq.PUB)
address = 'tcp://*:{}'.format(PUBLISHER_PORT)
self._zmq_pub_socket.bind(address)
@ -31,19 +31,16 @@ class EventHandlerUplinkConnector(ZMQConnectorBase):
class EventHandlerConnector(EventHandlerDownlinkConnector, EventHandlerUplinkConnector):
def __init__(self, zmq_context=None):
self.downlink = EventHandlerDownlinkConnector(zmq_context)
self.uplink = EventHandlerUplinkConnector(zmq_context)
#EventHandlerDownlinkConnector.__init__(self, zmq_context) # TODO: solve this with multiple inheritance
#EventHandlerUplinkConnector.__init__(self, zmq_context)
super(EventHandlerConnector, self).__init__(zmq_context)
def register_callback(self, callback):
self.downlink._zmq_pull_stream.on_recv(callback)
self._zmq_pull_stream.on_recv(callback)
def send_message(self, message: str, anchor: str = None):
if not anchor:
anchor = parse_anchor_from_message(message)
encoded_message = [part.encode('utf-8') for part in (anchor, message)]
self.uplink._zmq_pub_socket.send_multipart(encoded_message)
self._zmq_pub_socket.send_multipart(encoded_message)
ehc = EventHandlerConnector()