Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _set_huge_tree_parser():
parser = lxml.etree.ETCompatXMLParser(
attribute_defaults=False,
load_dtd=False,
huge_tree=True,
no_network=True,
ns_clean=True,
recover=False,
remove_pis=False,
remove_blank_text=False,
remove_comments=False,
resolve_entities=False,
strip_cdata=True
)
utils.set_xml_parser(parser)
def check_root(doc):
if utils.is_cybox(doc):
return
error = "Input document does not contain a valid CybOX root element."
raise errors.ValidationError(error)
def inner(*args, **kwargs):
try:
doc = args[1]
except IndexError:
doc = kwargs['doc']
# Get the root element for the input doc
root = utils.get_etree_root(doc)
# Check that the root is a valid STIX root-level element
check_root(root)
return func(*args, **kwargs)
def _check_timestamp_usage(self, root, namespaces, selectors):
"""Inspects each node in `nodes` for correct timestamp use.
"""
results = BestPracticeWarningCollection("Timestamp Use")
xpath = " | ".join("//%s" % x for x in selectors)
nodes = root.xpath(xpath, namespaces=namespaces)
for node in nodes:
attrib = node.attrib.get
id_ = attrib('id')
idref = attrib('idref')
timestamp = attrib('timestamp')
if timestamp:
tz_set = utils.has_tzinfo(timestamp)
if not tz_set:
warning = BestPracticeWarning(
node = node,
message="Timestamp without timezone information."
)
warning['timestamp'] = timestamp
results.append(warning)
if id_ and not timestamp:
warning = BestPracticeWarning(
node=node,
message="ID present but missing timestamp"
)
elif idref and not timestamp:
warning = BestPracticeWarning(
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
it to be "http://icl.com/saxon". The freely distributed SaxonHE
library does not support Saxon extension functions at all.
Returns:
An ``etree._ElementTree`` XSLT document.
"""
if not self._schematron:
return None
s = etree.tostring(self._schematron.validator_xslt)
s = s.replace(' []', '')
s = s.replace('xmlns:saxon="http://icl.com/saxon"', '')
s = s.replace('', '')
parser = utils.get_xml_parser()
return etree.parse(StringIO(s), parser=parser)
def _equal_timestamps(nodeset):
return [x for x in nodeset if utils.is_equal_timestamp(node, x)]