diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-06-29 22:35:58 +0300 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-06-29 22:35:58 +0300 |
commit | 68a5211f9504cd9478cfafad81d7a959d8cffe05 (patch) | |
tree | 038d0d43d10912a10964214285bab3243a03970c /Modules | |
parent | 3a6c91add7604a77a27c51165dacf7d114200bda (diff) | |
download | cpython-68a5211f9504cd9478cfafad81d7a959d8cffe05.tar.gz |
Issue #19176: Fixed doctype() related bugs in C implementation of ElementTree.
A deprecation warning no longer issued by XMLParser subclass with default
doctype() method. Direct call of doctype() now issues a warning. Parser's
doctype() now is not called if target's doctype() is called. Based on patch
by Martin Panter.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_elementtree.c | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 136f19cae6..826342aa91 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -2791,7 +2791,7 @@ typedef struct { } XMLParserObject; -#define XMLParser_CheckExact(op) (Py_TYPE(op) == &XMLParser_Type) +static PyObject* xmlparser_doctype(XMLParserObject* self, PyObject* args); /* helpers */ @@ -3190,20 +3190,21 @@ expat_start_doctype_handler(XMLParserObject *self, doctype_name_obj, pubid_obj, sysid_obj); Py_CLEAR(res); } - - /* Now see if the parser itself has a doctype method. If yes and it's - * a subclass, call it but warn about deprecation. If it's not a subclass - * (i.e. vanilla XMLParser), do nothing. - */ - parser_doctype = PyObject_GetAttrString(self_pyobj, "doctype"); - if (parser_doctype) { - if (!XMLParser_CheckExact(self_pyobj)) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, - "This method of XMLParser is deprecated. Define" - " doctype() method on the TreeBuilder target.", - 1) < 0) { + else { + /* Now see if the parser itself has a doctype method. If yes and it's + * a custom method, call it but warn about deprecation. If it's only + * the vanilla XMLParser method, do nothing. + */ + parser_doctype = PyObject_GetAttrString(self_pyobj, "doctype"); + if (parser_doctype && + !(PyCFunction_Check(parser_doctype) && + PyCFunction_GET_SELF(parser_doctype) == self_pyobj && + PyCFunction_GET_FUNCTION(parser_doctype) == + (PyCFunction) xmlparser_doctype)) { + res = xmlparser_doctype(self, NULL); + if (!res) goto clear; - } + Py_DECREF(res); res = PyObject_CallFunction(parser_doctype, "OOO", doctype_name_obj, pubid_obj, sysid_obj); Py_CLEAR(res); @@ -3556,6 +3557,12 @@ xmlparser_parse_whole(XMLParserObject* self, PyObject* args) static PyObject* xmlparser_doctype(XMLParserObject *self, PyObject *args) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "This method of XMLParser is deprecated. Define" + " doctype() method on the TreeBuilder target.", + 1) < 0) { + return NULL; + } Py_RETURN_NONE; } |