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


Python expat.XML_PARAM_ENTITY_PARSING_ALWAYS属性代码示例

本文整理汇总了Python中xml.parsers.expat.XML_PARAM_ENTITY_PARSING_ALWAYS属性的典型用法代码示例。如果您正苦于以下问题:Python expat.XML_PARAM_ENTITY_PARSING_ALWAYS属性的具体用法?Python expat.XML_PARAM_ENTITY_PARSING_ALWAYS怎么用?Python expat.XML_PARAM_ENTITY_PARSING_ALWAYS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在xml.parsers.expat的用法示例。


在下文中一共展示了expat.XML_PARAM_ENTITY_PARSING_ALWAYS属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_ignore_use_foreign_dtd

# 需要导入模块: from xml.parsers import expat [as 别名]
# 或者: from xml.parsers.expat import XML_PARAM_ENTITY_PARSING_ALWAYS [as 别名]
def test_ignore_use_foreign_dtd(self):
        """
        If UseForeignDTD is passed True and a document with an external
        entity reference is parsed, ExternalEntityRefHandler is called with
        the public and system ids from the document.
        """
        handler_call_args = []
        def resolve_entity(context, base, system_id, public_id):
            handler_call_args.append((public_id, system_id))
            return 1

        parser = expat.ParserCreate()
        parser.UseForeignDTD(True)
        parser.SetParamEntityParsing(expat.XML_PARAM_ENTITY_PARSING_ALWAYS)
        parser.ExternalEntityRefHandler = resolve_entity
        parser.Parse(
            "<?xml version='1.0'?><!DOCTYPE foo PUBLIC 'bar' 'baz'><element/>")
        self.assertEqual(handler_call_args, [("bar", "baz")]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_pyexpat.py

示例2: test_ignore_use_foreign_dtd

# 需要导入模块: from xml.parsers import expat [as 别名]
# 或者: from xml.parsers.expat import XML_PARAM_ENTITY_PARSING_ALWAYS [as 别名]
def test_ignore_use_foreign_dtd(self):
        """
        If UseForeignDTD is passed True and a document with an external
        entity reference is parsed, ExternalEntityRefHandler is called with
        the public and system ids from the document.
        """
        handler_call_args = []
        def resolve_entity(context, base, system_id, public_id):
            handler_call_args.append((public_id, system_id))
            return 1

        parser = expat.ParserCreate()
        parser.UseForeignDTD(True)
        parser.SetParamEntityParsing(expat.XML_PARAM_ENTITY_PARSING_ALWAYS)
        parser.ExternalEntityRefHandler = resolve_entity
        parser.Parse(
            b"<?xml version='1.0'?><!DOCTYPE foo PUBLIC 'bar' 'baz'><element/>")
        self.assertEqual(handler_call_args, [("bar", "baz")]) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:20,代码来源:test_pyexpat.py

示例3: test_use_foreign_dtd

# 需要导入模块: from xml.parsers import expat [as 别名]
# 或者: from xml.parsers.expat import XML_PARAM_ENTITY_PARSING_ALWAYS [as 别名]
def test_use_foreign_dtd(self):
        """
        If UseForeignDTD is passed True and a document without an external
        entity reference is parsed, ExternalEntityRefHandler is first called
        with None for the public and system ids.
        """
        handler_call_args = []
        def resolve_entity(context, base, system_id, public_id):
            handler_call_args.append((public_id, system_id))
            return 1

        parser = expat.ParserCreate()
        parser.UseForeignDTD(True)
        parser.SetParamEntityParsing(expat.XML_PARAM_ENTITY_PARSING_ALWAYS)
        parser.ExternalEntityRefHandler = resolve_entity
        parser.Parse("<?xml version='1.0'?><element/>")
        self.assertEqual(handler_call_args, [(None, None)])

        # test UseForeignDTD() is equal to UseForeignDTD(True)
        handler_call_args[:] = []

        parser = expat.ParserCreate()
        parser.UseForeignDTD()
        parser.SetParamEntityParsing(expat.XML_PARAM_ENTITY_PARSING_ALWAYS)
        parser.ExternalEntityRefHandler = resolve_entity
        parser.Parse("<?xml version='1.0'?><element/>")
        self.assertEqual(handler_call_args, [(None, None)]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:29,代码来源:test_pyexpat.py

示例4: test_use_foreign_dtd

# 需要导入模块: from xml.parsers import expat [as 别名]
# 或者: from xml.parsers.expat import XML_PARAM_ENTITY_PARSING_ALWAYS [as 别名]
def test_use_foreign_dtd(self):
        """
        If UseForeignDTD is passed True and a document without an external
        entity reference is parsed, ExternalEntityRefHandler is first called
        with None for the public and system ids.
        """
        handler_call_args = []
        def resolve_entity(context, base, system_id, public_id):
            handler_call_args.append((public_id, system_id))
            return 1

        parser = expat.ParserCreate()
        parser.UseForeignDTD(True)
        parser.SetParamEntityParsing(expat.XML_PARAM_ENTITY_PARSING_ALWAYS)
        parser.ExternalEntityRefHandler = resolve_entity
        parser.Parse(b"<?xml version='1.0'?><element/>")
        self.assertEqual(handler_call_args, [(None, None)])

        # test UseForeignDTD() is equal to UseForeignDTD(True)
        handler_call_args[:] = []

        parser = expat.ParserCreate()
        parser.UseForeignDTD()
        parser.SetParamEntityParsing(expat.XML_PARAM_ENTITY_PARSING_ALWAYS)
        parser.ExternalEntityRefHandler = resolve_entity
        parser.Parse(b"<?xml version='1.0'?><element/>")
        self.assertEqual(handler_call_args, [(None, None)]) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:29,代码来源:test_pyexpat.py


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