Version: 2.5.0
sdv.validators.stix.best_practice Module¶
-
class
sdv.validators.stix.best_practice.STIXBestPracticeValidator[source]¶ Bases:
objectPerforms STIX Best Practice validation.
-
validate(doc, version=None)[source]¶ Checks that a STIX document aligns with suggested authoring practices.
Parameters: - doc – The STIX document. Can be a filename, file-like object, lxml._Element, or lxml._ElementTree instance.
- version – The version of the STIX document. This will determine the
set of best practice rules to check. If
Nonean attempt will be made to extract the version from doc.
Returns: An instance of
BestPracticeValidationResults.Raises: UnknownSTIXVersionError– If version wasNoneand doc did not contain any version information.InvalidSTIXVersionError– If discovered version or version argument contains an invalid STIX version number.ValidationError– If there are any issues parsing doc.
-
-
class
sdv.validators.stix.best_practice.BestPracticeWarning(node, message=None)[source]¶ Represents a best practice warning. These are built within best practice rule checking methods and attached to
BestPracticeWarningCollectioninstances.Note
This class acts like a dictionary and contains the following keys at a minimum:
'id': The id of a node associated with the warning.'idref': The idref of a node associated with the warning.'line': The line number of the offending node.'message': A message associated with the warning.'tag': The lxml tag for the offending node.
These keys can be retrieved via the
core_keysproperty.Instances of this class may attach additional keys. These other keys can be obtained via the
other_keysproperty.Parameters: - node – The
lxml._Elementnode associated with this warning. - message – A message for this warning.
-
as_dict()[source]¶ Returns a dictionary representation of this class instance. This is implemented for consistency across other validation error types.
The
BestPracticeWarningclass extendscollections.MutableMapping, so this method isn’t really necessary.
-
as_json()¶ Returns a JSON representation of this class instance.
-
core_keys¶ Returns a
tupleof the keys that can always be found on instance of this class.Returns: A tuple including the following keys. 'id': The id of the warning node. The associated value may beNone.'idref': The idref of the warning node. The associated value may beNone.'line': The line number of the warning node in the input document. The associated value may beNone.'tag': The{namespace}localnamevalue of the warning node.'message': An optional message that can be attached to the warning. The associated value may beNone.
-
line¶ Returns the line number of the warning node in the input document.
-
class
sdv.validators.stix.best_practice.BestPracticeWarningCollection(name)[source]¶ Bases:
_abcoll.MutableSequenceA collection of
BestPracticeWarninginstances for a given type of STIX Best Practice.For example, all warnings about STIX constructs missing titles would go within an instance of this class.
Note
This class behaves like a mutable sequence, such as a
list.Parameters: name – The name of the STIX best practice for this collection (e.g., ‘Missing Titles’). -
name¶ The name of the STIX best practice for this collection (e.g., ‘Missing Titles’).
-
as_dict()[source]¶ Returns a dictionary representation.
The key of the dictionary is the
nameof this collection. The associated value is alistofBestPracticeWarningdictionaries.
-
insert(idx, value)[source]¶ Inserts value at idx into this
BestPracticeWarningCollectioninstance.Note
Values that evaluate to
Falsewill not be inserted.
-
-
class
sdv.validators.stix.best_practice.BestPracticeValidationResults[source]¶ Bases:
sdv.validators.base.ValidationResults,_abcoll.MutableSequenceRepresents STIX best practice validation results. This class behaves like a
listand accepts instances ofBestPracticeWarningCollection.-
as_dict()[source]¶ Returns a dictionary representation.
- Keys:
'result': The result of the validation. Values can beTrueorFalse.'errors': A list ofBestPracticeWarningCollectiondictionaries.
-
as_json()¶ Returns a JSON representation of this class instance.
-
errors¶ Returns a
listofBestPracticeWarningCollectioninstances.
-
is_valid¶ Returns
Trueif an instance of this class contains no warning collections or only contains only warning collections.
-