当前位置: 首页>>代码示例>>Python>>正文


Python STIXHeader.to_xml方法代码示例

本文整理汇总了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))
开发者ID:STIXProject,项目名称:python-stix,代码行数:9,代码来源:encoding_test.py

示例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)
开发者ID:STIXProject,项目名称:python-stix,代码行数:40,代码来源:vocabstrings.py

示例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)
开发者ID:dandye,项目名称:python-stix,代码行数:8,代码来源:encoding_test.py

示例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"))
开发者ID:dandye,项目名称:python-stix,代码行数:7,代码来源:encoding_test.py


注:本文中的stix.core.STIXHeader.to_xml方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。