kmip/core/objects.py
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_2_0):
        """
        Read the data stream and decode the Attributes structure into its
        parts.

        Args:
            input_stream (stream): A data stream containing encoded object
                data, supporting a read method.
            kmip_version (enum): A KMIPVersion enumeration defining the KMIP
                version with which the object will be decoded. Optional,
                defaults to KMIP 2.0.

        Raises:
            AttributeNotSupported: Raised if an unsupported attribute is
                encountered while decoding.
            VersionNotSupported: Raised when a KMIP version is provided that
                does not support the Attributes object.
        """
        if kmip_version < enums.KMIPVersion.KMIP_2_0:
            raise exceptions.VersionNotSupported(
                "KMIP {} does not support the Attributes object.".format(
                    kmip_version.value
                )
            )

        super(Attributes, self).read(input_stream, kmip_version=kmip_version)
        local_stream = BytearrayStream(input_stream.read(self.length))

        while True:
            if len(local_stream) < 3:
                break
            tag = struct.unpack('!I', b'\x00' + local_stream.peek(3))[0]
            if enums.is_enum_value(enums.Tags, tag):
                tag = enums.Tags(tag)
                if not enums.is_attribute(tag, kmip_version=kmip_version):
                    raise exceptions.AttributeNotSupported(
                        "Attribute {} is not supported by KMIP {}.".format(
                            tag.name,
                            kmip_version.value
                        )
                    )
                value = self._factory.create_attribute_value_by_enum(tag, None)
                value.read(local_stream, kmip_version=kmip_version)
                self._attributes.append(value)
            else:
                break

        self.is_oversized(local_stream)
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_2_0):
        """
        Read the data stream and decode the Attributes structure into its
        parts.

        Args:
            input_stream (stream): A data stream containing encoded object
                data, supporting a read method.
            kmip_version (enum): A KMIPVersion enumeration defining the KMIP
                version with which the object will be decoded. Optional,
                defaults to KMIP 2.0.

        Raises:
            AttributeNotSupported: Raised if an unsupported attribute is
                encountered while decoding.
            VersionNotSupported: Raised when a KMIP version is provided that
                does not support the Attributes object.
        """
        if kmip_version < enums.KMIPVersion.KMIP_2_0:
            raise exceptions.VersionNotSupported(
                "KMIP {} does not support the Attributes object.".format(
                    kmip_version.value
                )
            )

        super(Attributes, self).read(input_stream, kmip_version=kmip_version)
        local_stream = BytearrayStream(input_stream.read(self.length))

        while True:
            if len(local_stream) < 3:
                break
            tag = struct.unpack('!I', b'\x00' + local_stream.peek(3))[0]
            if enums.is_enum_value(enums.Tags, tag):
                tag = enums.Tags(tag)
                if not enums.is_attribute(tag, kmip_version=kmip_version):
                    raise exceptions.AttributeNotSupported(
                        "Attribute {} is not supported by KMIP {}.".format(
                            tag.name,
                            kmip_version.value
                        )
                    )
                value = self._factory.create_attribute_value_by_enum(tag, None)
                value.read(local_stream, kmip_version=kmip_version)
                self._attributes.append(value)
            else:
                break

        self.is_oversized(local_stream)
Read the data stream and decode the Attributes structure into its
        parts.

        Args:
            input_stream (stream): A data stream containing encoded object
                data, supporting a read method.
            kmip_version (enum): A KMIPVersion enumeration defining the KMIP
                version with which the object will be decoded. Optional,
                defaults to KMIP 2.0.

        Raises:
            AttributeNotSupported: Raised if an unsupported attribute is
                encountered while decoding.
            VersionNotSupported: Raised when a KMIP version is provided that
                does not support the Attributes object.