def add_transfer_syntax(self, syntax): """Append a transfer syntax to the presentation context. Parameters ---------- syntax : pydicom.uid.UID, bytes or str The transfer syntax to add to the presentation context. """ if isinstance(syntax, str): syntax = UID(syntax) elif isinstance(syntax, bytes): syntax = UID(syntax.decode('ascii')) else: LOGGER.error("Attempted to add an invalid transfer syntax") return if syntax is not None and not validate_uid(syntax): LOGGER.error("'transfer_syntax' contains an invalid UID") raise ValueError("'transfer_syntax' contains an invalid UID") if syntax and not syntax.is_valid: LOGGER.warning( "The Transfer Syntax Name '{}' is non-conformant".format( syntax)) # If the transfer syntax is rejected we may add an empty str if syntax not in self._transfer_syntax and syntax != '': if not syntax.is_valid: LOGGER.warning("A non-conformant UID has been added " "to 'transfer_syntax'") if not syntax.is_private and not syntax.is_transfer_syntax: LOGGER.warning("A UID has been added to 'transfer_syntax' " "that is not a transfer syntax") self._transfer_syntax.append(syntax)
def abstract_syntax(self, uid): """Set the presentation context's *Abstract Syntax*. Parameters ---------- uid : str or bytes or pydicom.uid.UID The abstract syntax UIDs """ if isinstance(uid, bytes): uid = UID(uid.decode('ascii')) elif isinstance(uid, str): uid = UID(uid) else: raise TypeError("'abstract_syntax' must be str or bytes or UID") if not validate_uid(uid): LOGGER.error("'abstract_syntax' is an invalid UID") raise ValueError("'abstract_syntax' is an invalid UID") if uid and not uid.is_valid: LOGGER.warning( "The Abstract Syntax Name '{}' is non-conformant".format(uid) ) self._abstract_syntax = uid
def test_validate_uid_conformance_false(self, uid, is_valid): _config.ENFORCE_UID_CONFORMANCE = False assert validate_uid(UID(uid)) == is_valid[1]
def test_validate_uid_conformance_true(self, uid, is_valid): _config.ENFORCE_UID_CONFORMANCE = True assert validate_uid(UID(uid)) == is_valid[0]