()
| 12 | |
| 13 | |
| 14 | def 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 | |
| 53 | if __name__ == '__main__': |
| 54 | main() |
no test coverage detected