本文整理汇总了Python中stix.core.STIXHeader.to_xml方法的典型用法代码示例。如果您正苦于以下问题:Python STIXHeader.to_xml方法的具体用法?Python STIXHeader.to_xml怎么用?Python STIXHeader.to_xml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stix.core.STIXHeader
的用法示例。
在下文中一共展示了STIXHeader.to_xml方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_to_xml_utf16_encoded
# 需要导入模块: from stix.core import STIXHeader [as 别名]
# 或者: from stix.core.STIXHeader import to_xml [as 别名]
def test_to_xml_utf16_encoded(self):
encoding = 'utf-16'
s = STIXHeader()
s.title = UNICODE_STR
xml = s.to_xml(encoding=encoding)
print(xml)
self.assertTrue(UNICODE_STR in xml.decode(encoding))
示例2: main
# 需要导入模块: from stix.core import STIXHeader [as 别名]
# 或者: from stix.core.STIXHeader import to_xml [as 别名]
def main():
# Create STIXHeader instance
header = STIXHeader()
header.package_intents.append(PackageIntent.TERM_INDICATORS)
# To add a Package_Intent value that exists outside of the
# PackageIntentVocab controlled vocabulary, we pass in an
# instance of VocabString.
#
# This will create a new Package_Intent field without an
# xsi:type and will not perform any validation of input terms.
#
# Passing in an instance of VocabString works for every
# ControlledVocabularyStringType field (or in python-stix,
# every VocabString field).
non_default_value = VocabString("NON STANDARD PACKAGE INTENT")
header.package_intents.append(non_default_value)
# Print XML!
print header.to_xml()
# NOTE: Passing in a str value that is not included in the list
# of default CV terms will raise a ValueError. This is why we pass
# in a VocabString instance.
#
# Example:
try:
msg = (
"[-] Attempting to add an str instance that does not exist "
"in the PackageIntent ALLOWED_VALUES list"
)
print(msg)
header.package_intents.append("THIS WILL THROW A VALUEERROR")
except Exception as ex:
print "[!] As expected, that failed. Here's the Exception message:"
print "[!]", str(ex)
示例3: test_to_xml_no_encoding
# 需要导入模块: from stix.core import STIXHeader [as 别名]
# 或者: from stix.core.STIXHeader import to_xml [as 别名]
def test_to_xml_no_encoding(self):
s = STIXHeader()
s.title = UNICODE_STR
xml = s.to_xml(encoding=None)
self.assertTrue(isinstance(xml, unicode))
self.assertTrue(UNICODE_STR in xml)
示例4: test_to_xml_default_encoded
# 需要导入模块: from stix.core import STIXHeader [as 别名]
# 或者: from stix.core.STIXHeader import to_xml [as 别名]
def test_to_xml_default_encoded(self):
s = STIXHeader()
s.title = UNICODE_STR
xml = s.to_xml()
self.assertTrue(UNICODE_STR in xml.decode("utf-8"))