Example #1
0
    def transfer_syntaxes(self, transfer_syntaxes):
        """Set the supported transfer syntaxes."""
        # pylint: disable=attribute-defined-outside-init
        self._transfer_syntaxes = []
        if not isinstance(transfer_syntaxes, list):
            raise ValueError("Transfer syntax must be a list of SOP classes.")

        for syntax in transfer_syntaxes:
            if isinstance(syntax, str):
                sop_uid = UID(syntax)
            elif isinstance(syntax, bytes):
                sop_uid = UID(syntax.decode('utf-8'))
            else:
                raise ValueError("Transfer syntax SOP class must be a "
                                 "UID str, UID bytes or UID.")
            try:
                sop_uid.is_valid()
            except InvalidUID:
                raise ValueError("Transfer syntax contained an "
                                 "invalid UID string")

            if sop_uid.is_transfer_syntax:
                self._transfer_syntaxes.append(sop_uid)
            else:
                LOGGER.warning(
                    "Attempted to add a non-transfer syntax "
                    "UID '%s'", syntax)

        if self._transfer_syntaxes == []:
            raise ValueError("Transfer syntax must be a list of SOP "
                             "Classes")
 def AffectedSOPClassUID(self, value):
     """
     Sets the Affected SOP Class UID parameter
     
     Parameters
     ----------
     value : pydicom.uid.UID, bytes or str
         The value for the Affected SOP Class UID
     """
     if isinstance(value, UID):
         pass
     elif isinstance(value, str):
         value = UID(value)
     elif isinstance(value, bytes):
         value = UID(value.decode('utf-8'))
     elif value is None:
         pass
     else:
         raise TypeError("Affected SOP Class UID must be a " \
                 "pydicom.uid.UID, str or bytes")
     
     if value is not None:
         try:
             value.is_valid()
         except:
             logger.error("Affected SOP Class UID is an invalid UID")
             raise ValueError("Affected SOP Class UID is an invalid UID")
     
     self._affected_sop_class_uid = value
Example #3
0
    def TransferSyntax(self, uid_list):
        """Set the Presentation Context's Transfer Syntax parameter.

        Parameters
        ----------
        uid_list : list of str or bytes or pydicom.uid.UID
            The transfer syntax UIDs
        """
        # pylint: disable=attribute-defined-outside-init
        self._transfer_syntax = []
        if not isinstance(uid_list, list):
            raise TypeError("transfer_syntaxes must be a list.")

        for uid in uid_list:
            if isinstance(uid, bytes):
                uid = UID(uid.decode('utf-8'))
            elif isinstance(uid, UID):
                pass
            elif isinstance(uid, str):
                uid = UID(uid)
            else:
                raise ValueError("PresentationContext(): Invalid transfer "
                                 "syntax item")

            try:
                uid.is_valid()
            except InvalidUID:
                LOGGER.info('Presentation Context attempted to set an invalid '
                            'transfer syntax UID')
                continue

            if uid.is_transfer_syntax:
                self._transfer_syntax.append(uid)
Example #4
0
    def AbstractSyntax(self, uid):
        """Set the Presentation Context's Abstract Syntax parameter.

        Parameters
        ----------
        uid : str or bytes or pydicom.uid.UID
            The abstract syntax UIDs
        """
        # pylint: disable=attribute-defined-outside-init
        if uid is None:
            self._abstract_syntax = None
            return

        if isinstance(uid, bytes):
            uid = UID(uid.decode('utf-8'))
        elif isinstance(uid, UID):
            pass
        elif isinstance(uid, str):
            uid = UID(uid)
        else:
            raise TypeError("Presentation Context invalid type for abstract "
                            "syntax")

        try:
            uid.is_valid()
            self._abstract_syntax = uid
        except InvalidUID:
            LOGGER.info('Presentation Context attempted to set an invalid '
                        'abstract syntax UID')
Example #5
0
    def add_transfer_syntax(self, transfer_syntax):
        """Append a transfer syntax to the Presentation Context.

        Parameters
        ----------
        transfer_syntax : pydicom.uid.UID, bytes or str
            The transfer syntax to add to the Presentation Context. For
            Presentation contexts that are rejected the `transfer_syntax` may
            be an empty UID.
        """
        # UID is a subclass of str
        if isinstance(transfer_syntax, str):
            transfer_syntax = UID(transfer_syntax)
        elif isinstance(transfer_syntax, bytes):
            transfer_syntax = UID(transfer_syntax.decode('utf-8'))
        else:
            raise TypeError('transfer_syntax must be a pydicom.uid.UID,' \
                             ' bytes or str')

        if transfer_syntax not in self.TransferSyntax and \
                                                    transfer_syntax != '':
            try:
                transfer_syntax.is_valid()
            except InvalidUID:
                raise ValueError('Presentation Context attempted to add a '
                                 'invalid UID')
            if not transfer_syntax.is_transfer_syntax:
                raise ValueError('Presentation Context attempted to add a '
                                 'non-transfer syntax UID')
            self.TransferSyntax.append(transfer_syntax)
Example #6
0
    def scp_supported_sop(self, sop_list):
        """Set the AE's supported SCP SOP classes.

        Examples of the `sop_list` items:
        - '1.2.3.4'
        - b'1.2.3.4.5'
        - pydicom.uid.UID('1.2.3')
        - pynetdicom3.sop_class.VerificationSOPClass

        Parameters
        ----------
        sop_list : list of str, bytes, UID, pynetdicom3.sop_class.ServiceClass
            The supported SCP SOP classes.
        """
        # pylint: disable=attribute-defined-outside-init
        self._scp_supported_sop = []
        if not isinstance(sop_list, list):
            raise TypeError("scp_supported_sop must be a list of SOP " \
                               "classes.")

        for sop_class in sop_list:
            if isinstance(sop_class, str):
                sop_uid = UID(sop_class)
            elif isinstance(sop_class, bytes):
                sop_uid = UID(sop_class.decode('utf-8'))
            elif isclass(sop_class):
                if 'UID' in sop_class.__dict__:
                    sop_uid = sop_class.UID
                else:
                    continue
            else:
                continue

            try:
                sop_uid.is_valid()
            except InvalidUID:
                continue

            self._scp_supported_sop.append(sop_uid)

        if sop_list != [] and self._scp_supported_sop == []:
            raise TypeError("No valid SCP SOP classes were supplied")
 def transfer_syntaxes(self, transfer_syntaxes):
     
     self._transfer_syntaxes = []
     
     try:
         for syntax in transfer_syntaxes:
             try:
                 if isinstance(syntax, str):
                     sop_uid = UID(syntax)
                     sop_uid.is_valid()
                 elif isinstance(syntax, UID):
                     sop_uid = syntax
                     sop_uid.is_valid()
                 elif 'UID' in sop_class.__dict__.keys():
                     sop_uid = UID(syntax.UID)
                     sop_uid.is_valid()
                 else:
                     raise ValueError("Transfer syntax SOP class must be "
                                 "a UID str, UID or ServiceClass subclass")
                 
                 if sop_uid.is_transfer_syntax:
                     self._transfer_syntaxes.append(sop_uid)
                 else:
                     logger.warning("Attempted to add a non-transfer syntax "
                         "UID '%s'" %syntax)
             
             except InvalidUID:
                 raise ValueError("Transfer syntax contained an invalid "
                         "UID string")
         if self._transfer_syntaxes == []:
             raise ValueError("Transfer syntax must be a list of SOP Classes")
     except:
         raise ValueError("Transfer syntax SOP class must be a "
                             "UID str, UID or ServiceClass subclass")
    def scp_supported_sop(self, sop_list):
        """
        A valid SOP is either a str UID (ie '1.2.840.10008.1.1') or a
        valid pydicom.uid.UID object (UID.is_valid() shouldn't cause an 
        exception) or a pynetdicom.SOPclass.ServiceClass subclass with a UID 
        attribute(ie VerificationSOPClass)
        """
        self._scp_supported_sop = []

        try:
            for sop_class in sop_list:
                try:
                    
                    if isinstance(sop_class, str):
                        sop_uid = UID(sop_class)
                    elif isinstance(sop_class, UID):
                        sop_uid = sop_class
                    elif isinstance(sop_class, bytes):
                        sop_uid = UID(sop_uid.decode('utf-8'))
                    elif 'UID' in sop_class.__dict__.keys():
                        sop_uid = UID(sop_class.UID)
                    else:
                        raise ValueError("SCU SOP class must be a UID str, "
                                "UID or ServiceClass subclass")
                    
                    sop_uid.is_valid()
                    self._scp_supported_sop.append(sop_uid)

                except InvalidUID:
                    raise ValueError("scp_sop_class must be a list of "
                            "SOP Classes")
                except Exception as e:
                    logger.warning("Invalid SCP SOP class '%s'" %sop_class)

            if sop_list != [] and self._scp_supported_sop == []:
                raise ValueError("No valid SCP SOP classes were supplied")
        except TypeError:
            raise ValueError("scp_sop_class must be a list")
        except:
            raise ValueError("scp_sop_class must be a list of SOP Classes")