Beispiel #1
0
    def _get_response_message(self):
        """
Returns the IPC response message read from the socket.

:param timeout: Alternative timeout value

:return: (object) Message instance
:since:  v0.3.00
        """

        # pylint: disable=broad-except

        if (self.log_handler is not None): self.log_handler.debug("#echo(__FILEPATH__)# -{0!r}._get_message()- (#echo(__LINE__)#)", self, context = "pas_bus")

        data_unread = 16
        message_data = Binary.BYTES_TYPE()
        message_size = 0
        timeout_time = time() + self.timeout

        while ((data_unread > 0 or message_size == 0) and time() < timeout_time):
            select([ self.socket.fileno() ], [ ], [ ], self.timeout)
            data = self.socket.recv(data_unread)

            if (len(data) > 0):
                message_data += data

                if (message_size < 1):
                    try:
                        message_size = Message.get_marshaled_message_size(message_data)
                        data_unread = (message_size - len(message_data))
                    except IOException: pass
                else: data_unread -= len(data)
            #
        #

        if (message_size == 0): raise IOException("Timeout occurred before message size was calculable")
        elif (len(message_data) < message_size): raise IOException("Timeout occurred before expected message size of {0:d} bytes was received".format(message_size))

        return Message.unmarshal(message_data)
    def test_simple_marshaled_data(self):
        test_data = Binary.bytes(
            "l\x01\x03\x01\x03\x00\x00\x00\x01\x00\x00\x00\x03\x00\x00\x00\x01\x01o\x00\x02\x00\x00\x00/t\x00\x00\x00\x00\x00\x00\x03\x01s\x00\x04\x00\x00\x00test\x00\x00\x00\x00\x08\x01g\x00\x03yyy\x00llo"
        )

        self.assertEqual(60, Message.get_marshaled_message_size(test_data))

        result_data = Message.unmarshal_data("yyyyuua(yv)yyy", test_data, True)

        self.assertEqual(10, len(result_data))
        self.assertIs(list, type(result_data[6]))
        self.assertEqual(3, len(result_data[6]))
        self.assertIs(list, type(result_data[6][0]))
        self.assertEqual(2, len(result_data[6][0]))
        self.assertEqual(Message.HEADER_FIELD_PATH, result_data[6][0][0])
        self.assertEqual("/t", Binary.str(result_data[6][0][1]))

        message = Message.unmarshal(test_data)
        self.assertEqual(Message.TYPE_METHOD_CALL, message.get_type())
        self.assertEqual((Message.FLAG_NO_REPLY_EXPECTED | Message.FLAG_NO_AUTO_START), message.get_flags())
        self.assertEqual("/t", message.get_object_path())
        self.assertEqual("test", message.get_object_member())
        self.assertEqual(1, message.get_serial())