MCPcopy Create free account
hub / github.com/STIXProject/python-stix / main

Function main

examples/vocabstrings.py:14–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12
13
14def main():
15 # Create STIXHeader instance
16 header = STIXHeader()
17 header.package_intents.append(PackageIntent.TERM_INDICATORS)
18
19 # To add a Package_Intent value that exists outside of the
20 # PackageIntentVocab controlled vocabulary, we pass in an
21 # instance of VocabString.
22 #
23 # This will create a new Package_Intent field without an
24 # xsi:type and will not perform any validation of input terms.
25 #
26 # Passing in an instance of VocabString works for every
27 # ControlledVocabularyStringType field (or in python-stix,
28 # every VocabString field).
29
30 non_default_value = VocabString("NON STANDARD PACKAGE INTENT")
31 header.package_intents.append(non_default_value)
32
33 # Print XML!
34 print header.to_xml()
35
36 # NOTE: Passing in a str value that is not included in the list
37 # of default CV terms will raise a ValueError. This is why we pass
38 # in a VocabString instance.
39 #
40 # Example:
41 try:
42 msg = (
43 "[-] Attempting to add an str instance that does not exist "
44 "in the PackageIntent ALLOWED_VALUES list"
45 )
46 print(msg)
47
48 header.package_intents.append("THIS WILL THROW A VALUEERROR")
49 except Exception as ex:
50 print "[!] As expected, that failed. Here's the Exception message:"
51 print "[!]", str(ex)
52
53if __name__ == '__main__':
54 main()

Callers 1

vocabstrings.pyFile · 0.70

Calls 3

STIXHeaderClass · 0.90
VocabStringClass · 0.90
to_xmlMethod · 0.45

Tested by

no test coverage detected