How to use the pynetdicom.utils.validate_uid function in pynetdicom

To help you get started, we’ve selected a few pynetdicom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pydicom / pynetdicom / pynetdicom / pdu_primitives.py View on Github external
The value for the Implementation Class UID
        """
        # pylint: disable=attribute-defined-outside-init
        if isinstance(value, UID):
            pass
        elif isinstance(value, str):
            value = UID(value)
        elif isinstance(value, bytes):
            value = UID(value.decode('ascii'))
        elif value is None:
            pass
        else:
            raise TypeError("Implementation Class UID must be a "
                            "pydicom.uid.UID, str or bytes")

        if value is not None and not validate_uid(value):
            msg = (
                "The Implementation Class UID Notification's 'Implementation "
                "Class UID' parameter value '{}' is not a valid UID"
                .format(value)
            )
            LOGGER.error(msg)
            raise ValueError(msg)

        if value and not value.is_valid:
            LOGGER.warning(
                "The Implementation Class UID '{}' is non-conformant"
                .format(value)
            )

        self._implementation_class_uid = value
github pydicom / pynetdicom / pynetdicom / pdu_primitives.py View on Github external
The value for the Application Context Name
        """
        # pylint: disable=attribute-defined-outside-init
        if isinstance(value, UID):
            pass
        elif isinstance(value, str):
            value = UID(value)
        elif isinstance(value, bytes):
            value = UID(value.decode('ascii'))
        elif value is None:
            pass
        else:
            raise TypeError("application_context_name must be a "
                            "pydicom.uid.UID, str or bytes")

        if value is not None and not validate_uid(value):
            LOGGER.error("application_context_name is an invalid UID")
            raise ValueError("application_context_name is an invalid UID")

        if value and not value.is_valid:
            LOGGER.warning(
                "The Application Context Name '{}' is non-conformant"
                .format(value)
            )

        self._application_context_name = value
github pydicom / pynetdicom / pynetdicom / presentation.py View on Github external
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:
            if syntax is not None:
                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' "
github pydicom / pynetdicom / pynetdicom / dimse_primitives.py View on Github external
value : pydicom.uid.UID, bytes or str
            The value for the Requested SOP Class UID
        """
        if isinstance(value, UID):
            pass
        elif isinstance(value, str):
            value = UID(value)
        elif isinstance(value, bytes):
            value = UID(value.decode('ascii'))
        elif value is None:
            pass
        else:
            raise TypeError("Requested SOP Class UID must be a "
                            "pydicom.uid.UID, str or bytes")

        if value and not validate_uid(value):
            LOGGER.error("Requested SOP Class UID is an invalid UID")
            raise ValueError("Requested SOP Class UID is an invalid UID")

        if value and not value.is_valid:
            LOGGER.warning(
                "The Requested SOP Class UID '{}' is non-conformant"
                .format(value)
            )

        if value:
            self._requested_sop_class_uid = value
        else:
            self._requested_sop_class_uid = None
github pydicom / pynetdicom / pynetdicom / pdu_primitives.py View on Github external
for uid in uid_list:
                if isinstance(uid, UID):
                    pass
                elif isinstance(uid, str):
                    uid = UID(uid)
                elif isinstance(uid, bytes):
                    uid = UID(uid.decode('ascii'))
                else:
                    msg = (
                        "Related General SOP Class Identification "
                        "must be a list of pydicom.uid.UID, str or bytes"
                    )
                    LOGGER.error(msg)
                    raise TypeError(msg)

                if uid is not None and not validate_uid(uid):
                    msg = (
                        "Related General SOP Class "
                        "Identification contains an invalid UID"
                    )
                    LOGGER.error(msg)
                    raise ValueError(msg)

                if uid and not uid.is_valid:
                    LOGGER.warning(
                        "The Related General SOP Class UID '{}' is "
                        "non-conformant".format(uid)
                    )

                valid_uid_list.append(uid)

            self._related_general_sop_class_identification = valid_uid_list
github pydicom / pynetdicom / pynetdicom / dimse_primitives.py View on Github external
value : pydicom.uid.UID, bytes or str
            The value for the Requested SOP Instance UID
        """
        if isinstance(value, UID):
            pass
        elif isinstance(value, str):
            value = UID(value)
        elif isinstance(value, bytes):
            value = UID(value.decode('ascii'))
        elif value is None:
            pass
        else:
            raise TypeError("Requested SOP Instance UID must be a "
                            "pydicom.uid.UID, str or bytes")

        if value and not validate_uid(value):
            LOGGER.error("Requested SOP Instance UID is an invalid UID")
            raise ValueError("Requested SOP Instance UID is an invalid UID")

        if value and not value.is_valid:
            LOGGER.warning(
                "The Requested SOP Instance UID '{}' is non-conformant"
                .format(value)
            )

        if value:
            self._requested_sop_instance_uid = value
        else:
            self._requested_sop_instance_uid = None
github pydicom / pynetdicom / pynetdicom / dimse_primitives.py View on Github external
value : pydicom.uid.UID, bytes or str
            The value to use for the *Affected SOP Class UID* parameter.
        """
        if isinstance(value, UID):
            pass
        elif isinstance(value, str):
            value = UID(value)
        elif isinstance(value, bytes):
            value = UID(value.decode('ascii'))
        elif value is None:
            pass
        else:
            raise TypeError("Affected SOP Class UID must be a "
                            "pydicom.uid.UID, str or bytes")

        if value and not validate_uid(value):
            LOGGER.error("Affected SOP Class UID is an invalid UID")
            raise ValueError("Affected SOP Class UID is an invalid UID")

        if value and not value.is_valid:
            LOGGER.warning(
                "The Affected SOP Class UID '{}' is non-conformant"
                .format(value)
            )

        if value:
            self._affected_sop_class_uid = value
        else:
            self._affected_sop_class_uid = None
github pydicom / pynetdicom / pynetdicom / pdu_primitives.py View on Github external
"""
        # pylint: disable=attribute-defined-outside-init
        if isinstance(value, UID):
            pass
        elif isinstance(value, str):
            value = UID(value)
        elif isinstance(value, bytes):
            value = UID(value.decode('ascii'))
        elif value is None:
            pass
        else:
            msg = "SOP Class UID must be a pydicom.uid.UID, str or bytes"
            LOGGER.error(msg)
            raise TypeError(msg)

        if value is not None and not validate_uid(value):
            LOGGER.error("SOP Class UID is an invalid UID")
            raise ValueError("SOP Class UID is an invalid UID")

        if value and not value.is_valid:
            LOGGER.warning(
                "The SOP Class UID '{}' is non-conformant"
                .format(value)
            )

        self._sop_class_uid = value
github pydicom / pynetdicom / pynetdicom / presentation.py View on Github external
def abstract_syntax(self, uid):
        """Set the context's *Abstract Syntax*.

        Parameters
        ----------
        uid : str or bytes or pydicom.uid.UID
            The abstract syntax UID.
        """
        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