Back to index

python3.2  3.2.2
Public Member Functions
test.test_pyexpat.ForeignDTDTests Class Reference

List of all members.

Public Member Functions

def test_use_foreign_dtd
def test_ignore_use_foreign_dtd

Detailed Description

Tests for the UseForeignDTD method of expat parser objects.

Definition at line 622 of file test_pyexpat.py.


Member Function Documentation

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.

Definition at line 644 of file test_pyexpat.py.

00644 
00645     def test_ignore_use_foreign_dtd(self):
00646         """
00647         If UseForeignDTD is passed True and a document with an external
00648         entity reference is parsed, ExternalEntityRefHandler is called with
00649         the public and system ids from the document.
00650         """
00651         handler_call_args = []
00652         def resolve_entity(context, base, system_id, public_id):
00653             handler_call_args.append((public_id, system_id))
00654             return 1
00655 
00656         parser = expat.ParserCreate()
00657         parser.UseForeignDTD(True)
00658         parser.SetParamEntityParsing(expat.XML_PARAM_ENTITY_PARSING_ALWAYS)
00659         parser.ExternalEntityRefHandler = resolve_entity
00660         parser.Parse(
00661             "<?xml version='1.0'?><!DOCTYPE foo PUBLIC 'bar' 'baz'><element/>")
00662         self.assertEqual(handler_call_args, [("bar", "baz")])
00663 

Here is the call graph for this function:

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.

Definition at line 626 of file test_pyexpat.py.

00626 
00627     def test_use_foreign_dtd(self):
00628         """
00629         If UseForeignDTD is passed True and a document without an external
00630         entity reference is parsed, ExternalEntityRefHandler is first called
00631         with None for the public and system ids.
00632         """
00633         handler_call_args = []
00634         def resolve_entity(context, base, system_id, public_id):
00635             handler_call_args.append((public_id, system_id))
00636             return 1
00637 
00638         parser = expat.ParserCreate()
00639         parser.UseForeignDTD(True)
00640         parser.SetParamEntityParsing(expat.XML_PARAM_ENTITY_PARSING_ALWAYS)
00641         parser.ExternalEntityRefHandler = resolve_entity
00642         parser.Parse("<?xml version='1.0'?><element/>")
00643         self.assertEqual(handler_call_args, [(None, None)])

Here is the call graph for this function:


The documentation for this class was generated from the following file: