[Python-checkins] cpython (2.7): Issue #16012: Fix a regression in pyexpat. The parser's UseForeignDTD()
christian.heimes
python-checkins at python.org
Mon Sep 24 13:28:22 CEST 2012
http://hg.python.org/cpython/rev/3e0d632ce910
changeset: 79138:3e0d632ce910
branch: 2.7
parent: 79088:bfdf366a779a
user: Christian Heimes <christian at cheimes.de>
date: Mon Sep 24 13:17:08 2012 +0200
summary:
Issue #16012: Fix a regression in pyexpat. The parser's UseForeignDTD()
method doesn't require an argument again.
files:
Lib/test/test_pyexpat.py | 55 +++++++++++++++++++++++++++-
Misc/NEWS | 6 +++
Modules/pyexpat.c | 2 +-
3 files changed, 61 insertions(+), 2 deletions(-)
diff --git a/Lib/test/test_pyexpat.py b/Lib/test/test_pyexpat.py
--- a/Lib/test/test_pyexpat.py
+++ b/Lib/test/test_pyexpat.py
@@ -588,6 +588,58 @@
except expat.ExpatError as e:
self.assertEqual(str(e), 'XML declaration not well-formed: line 1, column 14')
+class ForeignDTDTests(unittest.TestCase):
+ """
+ Tests for the UseForeignDTD method of expat parser objects.
+ """
+ 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)])
+
+ 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")])
+
+
def test_main():
run_unittest(SetAttributeTest,
ParseTest,
@@ -598,7 +650,8 @@
PositionTest,
sf1296433Test,
ChardataBufferTest,
- MalformedInputText)
+ MalformedInputText,
+ ForeignDTDTests)
if __name__ == "__main__":
test_main()
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -379,6 +379,12 @@
- Issue #6884: Fix long-standing bugs with MANIFEST.in parsing in distutils
on Windows.
+Extension Modules
+-----------------
+
+- Issue #16012: Fix a regression in pyexpat. The parser's UseForeignDTD()
+ method doesn't require an argument again.
+
Tests
-----
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -1176,7 +1176,7 @@
PyObject *flagobj = NULL;
int flag = 1;
enum XML_Error rc;
- if (!PyArg_ParseTuple(args, "O:UseForeignDTD", &flagobj))
+ if (!PyArg_ParseTuple(args, "|O:UseForeignDTD", &flagobj))
return NULL;
if (flagobj != NULL) {
flag = PyObject_IsTrue(flagobj);
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list