def __init__(self, message_type, expected, received): super().__init__("{}: Expected {}, Got {}".format( to_protobuf_class(message_type).__name__, expected, received )) self.message_type_name = to_protobuf_class(message_type).__name__ self.expected = expected self.received = received
def __init__(self, message_type, expected, received): super().__init__("{}: Expected {}, Got {}".format( to_protobuf_class(message_type).__name__, expected, received )) self.message_type_name = to_protobuf_class(message_type).__name__ self.expected = expected self.received = received
def __init__(self, message_type, expected, received): super().__init__("{}: Expected {}({}):'{}', Got {}({}):'{}'".format( to_protobuf_class(message_type).__name__, to_protobuf_class(to_message_type(expected)), to_message_type(expected), str(expected).strip(), to_protobuf_class(to_message_type(received)), to_message_type(received), str(received).strip())) self.message_type_name = to_protobuf_class(message_type).__name__ self.expected = expected self.received = received
def __init__(self, message_type, expected, received): super().__init__("{}: Expected {}({}):'{}', Got {}({}):'{}'".format( to_protobuf_class(message_type).__name__, to_protobuf_class(to_message_type(expected)), to_message_type(expected), str(expected).strip(), to_protobuf_class(to_message_type(received)), to_message_type(received), str(received).strip() )) self.message_type_name = to_protobuf_class(message_type).__name__ self.expected = expected self.received = received
def expect(self, expected_content): """ Receive a message and compare its contents to that of `expected_content`. If the contents are the same, return the message. If not, raise an UnexpectedMessageException with the message. Note that this will do a direct `==` comparison. If a more complex comparison must be performed (for example if a payload must first be deserialized) a comparison function may be registered for a specific message type using, `register_comparator()`. """ # Receive a message message, _ = self.receive() # Parse the message content protobuf_class = to_protobuf_class(message.message_type) received_content = protobuf_class() received_content.ParseFromString(message.content) if not self._compare(received_content, expected_content): raise UnexpectedMessageException(message.message_type, expected_content, received_content) return message
def expect(self, expected_content): """ Receive a message and compare its contents to that of `expected_content`. If the contents are the same, return the message. If not, raise an UnexpectedMessageException with the message. Note that this will do a direct `==` comparison. If a more complex comparison must be performed (for example if a payload must first be deserialized) a comparison function may be registered for a specific message type using, `register_comparator()`. """ # Receive a message message, _ = self.receive() # Parse the message content protobuf_class = to_protobuf_class(message.message_type) received_content = protobuf_class() received_content.ParseFromString(message.content) if not self._compare(received_content, expected_content): raise UnexpectedMessageException( message.message_type, expected_content, received_content ) return message
async def _send(self, ident, message): """ (asyncio coroutine) Send the message and wait for a response. :param message (sawtooth_sdk.protobuf.Message) :param ident (str) the identity of the zmq.DEALER to send to """ LOGGER.debug("Sending %s(%s) to %s", str(to_protobuf_class(message.message_type).__name__), str(message.message_type), str(ident)) return await self._socket.send_multipart( [ident, message.SerializeToString()])
async def _send(self, ident, message): """ (asyncio coroutine) Send the message and wait for a response. :param message (sawtooth_protobuf.Message) :param ident (str) the identity of the zmq.DEALER to send to """ print("Sending {}({}) to {}".format( to_protobuf_class(message.message_type).__name__, message.message_type, ident)) return await self._socket.send_multipart( [ident, message.SerializeToString()])
def receive(self): """ Receive a message back. Does not parse the message content. """ ident, result = self._loop.run_until_complete(self._receive()) # Deconstruct the message message = Message() message.ParseFromString(result) print("Received {}({}) from {}".format( to_protobuf_class(message.message_type).__name__, message.message_type, ident)) return message, ident
def receive(self): """ Receive a message back. Does not parse the message content. """ ident, result = self._loop.run_until_complete(self._receive()) # Deconstruct the message message = Message() message.ParseFromString(result) LOGGER.info("Received %s(%s) from %s", str(to_protobuf_class(message.message_type).__name__), str(message.message_type), str(ident)) return message, ident
async def _send(self, ident, message): """ (asyncio coroutine) Send the message and wait for a response. :param message (sawtooth_protobuf.Message) :param ident (str) the identity of the zmq.DEALER to send to """ print("Sending {}({}) to {}".format( to_protobuf_class(message.message_type).__name__, message.message_type, ident )) return await self._socket.send_multipart([ ident, message.SerializeToString() ])
async def _send(self, ident, message): """ (asyncio coroutine) Send the message and wait for a response. :param message (sawtooth_sdk.protobuf.Message) :param ident (str) the identity of the zmq.DEALER to send to """ LOGGER.debug( "Sending %s(%s) to %s", str(to_protobuf_class(message.message_type).__name__), str(message.message_type), str(ident) ) return await self._socket.send_multipart([ ident, message.SerializeToString() ])
def receive(self): """ Receive a message back. Does not parse the message content. """ ident, result = self._loop.run_until_complete( self._receive() ) # Deconstruct the message message = Message() message.ParseFromString(result) print("Received {}({}) from {}".format( to_protobuf_class(message.message_type).__name__, message.message_type, ident )) return message, ident
def expect_one(self, expected_content_list): """ Receive a message and compare its contents to each item in the list. Upon finding a match, return the message and the index of the match as a tuple. If no match is found, raise an UnexpectedMessageException with the message. """ message = self.receive() # Parse the message content protobuf_class = to_protobuf_class(message.message_type) received_content = protobuf_class() received_content.ParseFromString(message.content) for exp_con in expected_content_list: if self._compare(exp_con, received_content): return message, expected_content_list.index(exp_con) raise UnexpectedMessageException(expected_content, received_content)
def expect_one(self, expected_content_list): """ Receive a message and compare its contents to each item in the list. Upon finding a match, return the message and the index of the match as a tuple. If no match is found, raise an UnexpectedMessageException with the message. """ message, _ = self.receive() # Parse the message content protobuf_class = to_protobuf_class(message.message_type) received_content = protobuf_class() received_content.ParseFromString(message.content) for exp_con in expected_content_list: if self._compare(exp_con, received_content): return message, expected_content_list.index(exp_con) raise UnexpectedMessageException( message.message_type, expected_content_list, received_content)
def receive(self): """ Receive a message back. Does not parse the message content. """ ident, result = self._loop.run_until_complete( self._receive() ) LOGGER.debug(result) LOGGER.debug("%s:%s", len(result), binascii.hexlify(result)) # Deconstruct the message message = Message() message.ParseFromString(result) LOGGER.debug( "Received %s(%s) from %s", str(to_protobuf_class(message.message_type).__name__), str(message.message_type), str(ident) ) return message, ident