def _get_1_2_header_warnings(self, root, namespaces): """Checks for deprecated fields on STIX Header instances. """ to_check = ( "{0}:Title".format(common.PREFIX_STIX_CORE), "{0}:Description".format(common.PREFIX_STIX_CORE), "{0}:Short_Description".format(common.PREFIX_STIX_CORE), "{0}:Package_Intent".format(common.PREFIX_STIX_CORE), ) header = "//{0}:STIX_Header".format(common.PREFIX_STIX_CORE) xpath = " | ".join("%s/%s" % (header, x) for x in to_check) nodes = root.xpath(xpath, namespaces=namespaces) fmt = "%s is deprecated in STIX Header." warns = [] for node in nodes: localname = utils.localname(node) msg = fmt % localname warn = BestPracticeWarning(node=node, message=msg) warns.append(warn) return warns
def _check_titles(self, root, namespaces, selectors): """Checks that each node in `nodes` has a ``Title`` element unless there is an ``@idref`` attribute set. """ results = BestPracticeWarningCollection("Missing Titles") xpath = " | ".join("//%s" % x for x in selectors) nodes = root.xpath(xpath, namespaces=namespaces) for node in nodes: if 'idref' in node.attrib: continue if not any(utils.localname(x) == 'Title' for x in utils.iterchildren(node)): warning = BestPracticeWarning(node=node) results.append(warning) return results
def _check_titles(self, root, namespaces, selectors): """Checks that each node in `nodes` has a ``Title`` element unless there is an ``@idref`` attribute set. """ results = BestPracticeWarningCollection("Missing Titles") xpath = " | ".join("//%s" % x for x in selectors) nodes = root.xpath(xpath, namespaces=namespaces) for node in nodes: if 'idref' in node.attrib: continue if not any( utils.localname(x) == 'Title' for x in utils.iterchildren(node)): warning = BestPracticeWarning(node=node) results.append(warning) return results