def decode(cls, rawstring): """Factory method. Decodes A-ASSOCIATE-RQ PDU instance from raw string. :param rawstring: rawstring containing binary representation of the A-ASSOCIATE-RQ PDU :return decoded PDU """ def iter_items(): item_type = next_type(stream) while item_type: if item_type == 0x10: yield ApplicationContextItem.decode(stream) elif item_type == 0x20: yield PresentationContextItemRQ.decode(stream) elif item_type == 0x21: yield PresentationContextItemAC.decode(stream) elif item_type == 0x50: yield UserInformationItem.decode(stream) else: raise exceptions.PDUProcessingError('Invalid variable item') item_type = next_type(stream) stream = cStringIO(rawstring) values = cls.header.unpack(stream.read(74)) _, reserved1, _, protocol_version, reserved2, \ called_ae_title, calling_ae_title = values[:7] reserved3 = values[7:] called_ae_title = called_ae_title.strip(b'\0').decode() calling_ae_title = calling_ae_title.strip(b'\0').decode() variable_items = list(iter_items()) return cls(called_ae_title=called_ae_title, calling_ae_title=calling_ae_title, variable_items=variable_items, protocol_version=protocol_version, reserved1=reserved1, reserved2=reserved2, reserved3=reserved3)
def decode(cls, rawstring): """Factory method. Decodes A-RELEASE-* PDU instance from raw string. :param rawstring: rawstring containing binary representation of the A-RELEASE-* PDU :return: decoded PDU """ stream = cStringIO(rawstring) _, reserved1, _, reserved2 = cls.format.unpack(stream.read(10)) return cls(reserved1=reserved1, reserved2=reserved2)
def __init__(self, message, source, node=None): if node is not None: # Compute a pretty printed version of the source code indicating the # terminating line of execution that leads to the error. content = six.cStringIO() for lineno, line in enumerate(source.split('\n')): content.write('%s %s\n' % ('>' if lineno == int(node.coord.line) else ' ', line)) super(LockProtocolError, self).__init__('%s\n%s' % (message, content.getvalue())) else: super(LockProtocolError, self).__init__(message)
def decode(cls, rawstring): """Factory method. Decodes A-ASSOCIATE-RJ PDU instance from raw string. :param rawstring: rawstring containing binary representation of the A-ASSOCIATE-RJ PDU :return: decoded PDU """ stream = cStringIO(rawstring) _, reserved1, _, reserved2, result, source, \ reason_diag = cls.format.unpack(stream.read(10)) return cls(result=result, source=source, reason_diag=reason_diag, reserved1=reserved1, reserved2=reserved2)
def decode(cls, rawstring): """Factory method. Decodes A-ABORT PDU instance from raw string. :param rawstring: rawstring containing binary representation of the A-ABORT PDU :return: decoded PDU """ stream = cStringIO(rawstring) _, reserved1, _, reserved2, reserved3, abort_source, \ reason_diag = cls.format.unpack(stream.read(10)) return cls(reserved1=reserved1, reserved2=reserved2, reserved3=reserved3, source=abort_source, reason_diag=reason_diag)
def decode(cls, rawstring): """Factory method. Decodes P-DATA-TF PDU instance from raw string. :param rawstring: rawstring containing binary representation of the P-DATA-TF PDU :return: decoded PDU """ def iter_items(): length_read = 0 while length_read != pdu_length: item = PresentationDataValueItem.decode(stream) length_read += item.total_length() yield item stream = cStringIO(rawstring) pdu_type, reserved, pdu_length = cls.header.unpack(stream.read(6)) data_value_items = list(iter_items()) return cls(data_value_items, reserved)
def decode(cls, rawstring): """Factory method. Decodes A-ASSOCIATE-RQ PDU instance from raw string. :param rawstring: rawstring containing binary representation of the A-ASSOCIATE-RQ PDU :return decoded PDU """ def iter_items(): item_type = next_type(stream) while item_type: if item_type == 0x10: yield ApplicationContextItem.decode(stream) elif item_type == 0x20: yield PresentationContextItemRQ.decode(stream) elif item_type == 0x21: yield PresentationContextItemAC.decode(stream) elif item_type == 0x50: yield UserInformationItem.decode(stream) else: raise exceptions.PDUProcessingError( 'Invalid variable item') item_type = next_type(stream) stream = cStringIO(rawstring) values = cls.header.unpack(stream.read(74)) _, reserved1, _, protocol_version, reserved2, \ called_ae_title, calling_ae_title = values[:7] reserved3 = values[7:] called_ae_title = called_ae_title.strip(b'\0').decode() calling_ae_title = calling_ae_title.strip(b'\0').decode() variable_items = list(iter_items()) return cls(called_ae_title=called_ae_title, calling_ae_title=calling_ae_title, variable_items=variable_items, protocol_version=protocol_version, reserved1=reserved1, reserved2=reserved2, reserved3=reserved3)
def decode_and_compare_sub_item(self, item): encoded = item.encode() stream = cStringIO(encoded) item2 = type(item).decode(stream) self.assertIsInstance(item, item2.__class__) self.assertEqual(item.__dict__, item2.__dict__)
def decode(rawstr, is_implicit_vr, is_little_endian): s = cStringIO(rawstr) return _dicom.read_dataset(s, is_implicit_vr, is_little_endian)