diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-06-29 20:08:52 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-06-29 20:08:52 (GMT) |
commit | 4a01cab89894b157f282b2032862a278c9edb842 (patch) | |
tree | cf4d7a979b071d6c99ac909a4d47dd9b60a15aea /Modules/_elementtree.c | |
parent | bc9e75ed023ff03f555682e57d25fee32e6548a0 (diff) | |
parent | 05744ac6e0948cbd6a50fc03a239a5402abceb14 (diff) | |
download | cpython-4a01cab89894b157f282b2032862a278c9edb842.zip cpython-4a01cab89894b157f282b2032862a278c9edb842.tar.gz cpython-4a01cab89894b157f282b2032862a278c9edb842.tar.bz2 |
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/_elementtree.c')
-rw-r--r-- | Modules/_elementtree.c | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index ea77051..911b5ac 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -2782,7 +2782,11 @@ typedef struct { } XMLParserObject; -#define XMLParser_CheckExact(op) (Py_TYPE(op) == &XMLParser_Type) +static PyObject* +_elementtree_XMLParser_doctype(XMLParserObject* self, PyObject* args); +static PyObject * +_elementtree_XMLParser_doctype_impl(XMLParserObject *self, PyObject *name, + PyObject *pubid, PyObject *system); /* helpers */ @@ -3182,20 +3186,22 @@ 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) _elementtree_XMLParser_doctype)) { + res = _elementtree_XMLParser_doctype_impl(self, doctype_name_obj, + pubid_obj, sysid_obj); + if (!res) goto clear; - } + Py_DECREF(res); res = PyObject_CallFunction(parser_doctype, "OOO", doctype_name_obj, pubid_obj, sysid_obj); Py_CLEAR(res); @@ -3572,12 +3578,24 @@ _elementtree_XMLParser__parse_whole(XMLParserObject *self, PyObject *file) /*[clinic input] _elementtree.XMLParser.doctype + name: object + pubid: object + system: object + / + [clinic start generated code]*/ static PyObject * -_elementtree_XMLParser_doctype_impl(XMLParserObject *self) -/*[clinic end generated code: output=d09fdb9c45f3a602 input=20d5e0febf902a2f]*/ -{ +_elementtree_XMLParser_doctype_impl(XMLParserObject *self, PyObject *name, + PyObject *pubid, PyObject *system) +/*[clinic end generated code: output=10fb50c2afded88d input=84050276cca045e1]*/ +{ + 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; } |