def test_roundtrip(self):
     """
     """
     
     for cls in [C_STORE_RQ, C_STORE_RSP, C_GET_RQ, C_GET_RSP, 
                 C_FIND_RQ, C_FIND_RSP, C_MOVE_RQ, C_MOVE_RSP, C_ECHO_RQ, C_ECHO_RSP, 
                 N_EVENT_REPORT_RQ, N_EVENT_REPORT_RSP, N_GET_RQ, N_GET_RSP, 
                 N_SET_RQ, N_SET_RSP, N_ACTION_RQ, N_ACTION_RSP, 
                 N_DELETE_RQ, N_DELETE_RSP, N_CREATE_RQ, N_CREATE_RSP, C_CANCEL_RQ]:
         for obj in tf_DIMSE(cls):
             p = obj.pack()
             rp = cls()
             pd = unpack_dataset(p)
             rp.unpack(pd)
             prp = rp.pack()
             self.assertEqual(pd.CommandField, commands[cls])
             self.assertEqual(obj.__dict__, rp.__dict__)
             self.assertEqual(p, prp)
示例#2
0
    def test_roundtrip(self):
        """
        """

        for cls in [
                C_STORE_RQ, C_STORE_RSP, C_GET_RQ, C_GET_RSP, C_FIND_RQ,
                C_FIND_RSP, C_MOVE_RQ, C_MOVE_RSP, C_ECHO_RQ, C_ECHO_RSP,
                N_EVENT_REPORT_RQ, N_EVENT_REPORT_RSP, N_GET_RQ, N_GET_RSP,
                N_SET_RQ, N_SET_RSP, N_ACTION_RQ, N_ACTION_RSP, N_DELETE_RQ,
                N_DELETE_RSP, N_CREATE_RQ, N_CREATE_RSP, C_CANCEL_RQ
        ]:
            for obj in tf_DIMSE(cls):
                p = obj.pack()
                rp = cls()
                pd = unpack_dataset(p)
                rp.unpack(pd)
                prp = rp.pack()
                self.assertEqual(pd.CommandField, commands[cls])
                self.assertEqual(obj.__dict__, rp.__dict__)
                self.assertEqual(p, prp)
示例#3
0
    def P_DATA_indicated(self, data_values):
        for val in data_values:
            msg_ctrl_hdr, = struct.unpack("B", val[1][0])
            if self.dimse_presentation_context_id != None:
                if val[0] != self.dimse_presentation_context_id:
                    log.err(
                        "Got unexpected interleaved presentation contexts in data stream"
                    )
                    self.A_ABORT_request_received(None, reason=6)
                    return

            accepted = [
                pci.result_reason == 0
                for pci in self.presentation_contexts_accepted
                if pci.presentation_context_id == val[0]
            ]

            if accepted != [True]:
                self.A_ABORT_request_received(None, reason=6)
                return

            self.dimse_presentation_context_id = val[0]

            ts = [
                pci.transfer_syntaxes[0].transfer_syntax_name
                for pci in self.presentation_contexts_requested
                if pci.presentation_context_id ==
                self.dimse_presentation_context_id
            ][0]
            if self.dimse_is_reading_command:
                assert msg_ctrl_hdr & 1, "Got data type pdv while reading command!"
                self.dimse_command_buffer += val[1][1:]
                if msg_ctrl_hdr & 2:  # End of command
                    self.dimse_command = dimsemessages.unpack_dataset(
                        self.dimse_command_buffer)
                    if do_log:
                        log.msg("revcommand: %s" % (dimsemessages.revcommands[
                            self.dimse_command.CommandField], ))
                    if getattr(self.dimse_command, 'CommandDataSetType',
                               0) == 0x101:
                        self.dimse_is_reading_command = True
                        cmd = dimsemessages.unpack_dimse_command(
                            self.dimse_command)
                        self.DIMSE_command_received(
                            self.dimse_presentation_context_id, cmd, None)
                        self.dimse_command_buffer = ""
                        self.dimse_command = None
                        self.dimse_presentation_context_id = None
                    else:
                        self.dimse_is_reading_command = False
            else:
                assert not msg_ctrl_hdr & 1, "Got command type pdv while reading data!"
                self.dimse_data_buffer += val[1][1:]
                if msg_ctrl_hdr & 2:  # End of data
                    dimse_data = dimsemessages.unpack_dataset(
                        self.dimse_data_buffer, ts)
                    cmd = dimsemessages.unpack_dimse_command(
                        self.dimse_command)
                    self.DIMSE_command_received(
                        self.dimse_presentation_context_id, cmd, dimse_data)
                    self.dimse_command_buffer = ""
                    self.dimse_command = None
                    self.dimse_data_buffer = ""
                    self.dimse_is_reading_command = True
                    self.dimse_presentation_context_id = None