示例#1
0
    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)
示例#2
0
    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
示例#3
0
 def test_validate_uid_conformance_false(self, uid, is_valid):
     _config.ENFORCE_UID_CONFORMANCE = False
     assert validate_uid(UID(uid)) == is_valid[1]
示例#4
0
 def test_validate_uid_conformance_true(self, uid, is_valid):
     _config.ENFORCE_UID_CONFORMANCE = True
     assert validate_uid(UID(uid)) == is_valid[0]