def _check_version(self, root): """Checks that the version of the document `root` is valid for an implementation of ``_BaseUpdater``. Note: The ``version`` attribute of `root` is compared against the ``VERSION`` class-level attribute. Raises: .UnknownVersionError: If `root` does not contain a ``version`` attribute. .InvalidVersionError: If the ``version`` attribute value for `root` does not match the value of ``VERSION``. """ roots = self._get_root_nodes(root) expected = self.VERSION for node in roots: found = self.get_version(node) if not found: error = "Unable to determine the version of the STIX document." raise errors.UnknownVersionError(error) if utils.is_version_equal(found, expected): return error = "Document version does not match the expected version." raise errors.InvalidVersionError( message=error, node=node, expected=expected, found=found )
def _check_version(self, root): """Checks the versions of the Observables instances found in the `root` document. This overrides the ``_BaseUpdater._check_version()`` method. Note: The ``version`` attribute of `root` is compared against the ``VERSION`` class-level attribute. Args: root: The root node for the document. Raises: .UnknownVersionError: If `root` does not contain a ``version`` attribute. .InvalidVersionError: If the ``version`` attribute value for `root` does not match the value of ``VERSION``. """ roots = self._get_root_nodes(root) expected = self.VERSION for node in roots: found = self.get_version(node) if utils.is_version_equal(expected, found): continue error = "Document version '{0}' does not match the expected version '{1}'." error = error.format(found, expected) raise errors.InvalidVersionError(message=error, node=node, expected=expected, found=found)
def _check_version(self, root): """Checks that the version of the document `root` is valid for an implementation of ``_BaseUpdater``. Note: The ``version`` attribute of `root` is compared against the ``VERSION`` class-level attribute. Raises: .UnknownVersionError: If `root` does not contain a ``version`` attribute. .InvalidVersionError: If the ``version`` attribute value for `root` does not match the value of ``VERSION``. """ roots = self._get_root_nodes(root) expected = self.VERSION for node in roots: found = self.get_version(node) if not found: error = "Unable to determine the version of the STIX document." raise errors.UnknownVersionError(error) if utils.is_version_equal(found, expected): return error = "Document version does not match the expected version." raise errors.InvalidVersionError(message=error, node=node, expected=expected, found=found)
def _check_version(self, root): """Checks the versions of the Observables instances found in the `root` document. This overrides the ``_BaseUpdater._check_version()`` method. Note: The ``version`` attribute of `root` is compared against the ``VERSION`` class-level attribute. Args: root: The root node for the document. Raises: .UnknownVersionError: If `root` does not contain a ``version`` attribute. .InvalidVersionError: If the ``version`` attribute value for `root` does not match the value of ``VERSION``. """ roots = self._get_root_nodes(root) expected = self.VERSION for node in roots: found = self.get_version(node) if utils.is_version_equal(expected, found): continue error = "Document version '{0}' does not match the expected version '{1}'." error = error.format(found, expected) raise errors.InvalidVersionError( message=error, node=node, expected=expected, found=found )