# HG changeset patch # Parent 2ffaac4c8e531de022390e120d5ab35108ed7697 Issue 19176: Remove deprecated xml.etree.XMLParser.doctype() method diff -r 2ffaac4c8e53 Doc/library/xml.etree.elementtree.rst --- a/Doc/library/xml.etree.elementtree.rst Tue Dec 16 19:43:46 2014 +0200 +++ b/Doc/library/xml.etree.elementtree.rst Tue Mar 31 07:00:37 2015 +0000 @@ -984,13 +984,6 @@ this is the toplevel document element. - .. method:: doctype(name, pubid, system) - - .. deprecated:: 3.2 - Define the :meth:`TreeBuilder.doctype` method on a custom TreeBuilder - target. - - .. method:: feed(data) Feeds data to the parser. *data* is encoded data. diff -r 2ffaac4c8e53 Doc/whatsnew/3.5.rst --- a/Doc/whatsnew/3.5.rst Tue Dec 16 19:43:46 2014 +0200 +++ b/Doc/whatsnew/3.5.rst Tue Mar 31 07:00:37 2015 +0000 @@ -409,6 +409,11 @@ 3.4, and has now been removed. (Contributed by Matt Chaput in :issue:`6623`.) +* The :meth:`~xml.etree.ElementTree.XMLParser.doctype` method of + :class:`xml.etree.ElementTree.XMLParser` has been removed (:issue:`19176`). + It has been deprecated in favour of :meth:`TreeBuilder.doctype() + ` since Python 3.2. + Porting to Python 3.5 ===================== diff -r 2ffaac4c8e53 Lib/test/test_xml_etree.py --- a/Lib/test/test_xml_etree.py Tue Dec 16 19:43:46 2014 +0200 +++ b/Lib/test/test_xml_etree.py Tue Mar 31 07:00:37 2015 +0000 @@ -12,6 +12,7 @@ import sys import types import unittest +import warnings import weakref from itertools import product @@ -2117,20 +2118,16 @@ parser.feed(self.sample1) self._check_sample_element(parser.close()) - def test_subclass_doctype(self): - _doctype = None - class MyParserWithDoctype(ET.XMLParser): - def doctype(self, name, pubid, system): - nonlocal _doctype - _doctype = (name, pubid, system) - - parser = MyParserWithDoctype() - with self.assertWarns(DeprecationWarning): + def test_inherited_deprecation(self): + # Ensure that subclass usage is not deprecated. In Issue 19176, + # there was trouble detecting use of inherited deprecated methods. + with warnings.catch_warnings(): + warnings.simplefilter('error', DeprecationWarning) + class MyParser(ET.XMLParser): + pass + parser = MyParser() parser.feed(self.sample2) - parser.close() - self.assertEqual(_doctype, - ('html', '-//W3C//DTD XHTML 1.0 Transitional//EN', - 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd')) + parser.close() def test_parse_string(self): parser = ET.XMLParser(target=ET.TreeBuilder()) diff -r 2ffaac4c8e53 Lib/xml/etree/ElementTree.py --- a/Lib/xml/etree/ElementTree.py Tue Dec 16 19:43:46 2014 +0200 +++ b/Lib/xml/etree/ElementTree.py Tue Mar 31 07:00:37 2015 +0000 @@ -1607,28 +1607,8 @@ return if hasattr(self.target, "doctype"): self.target.doctype(name, pubid, system[1:-1]) - elif self.doctype != self._XMLParser__doctype: - # warn about deprecated call - self._XMLParser__doctype(name, pubid, system[1:-1]) - self.doctype(name, pubid, system[1:-1]) self._doctype = None - def doctype(self, name, pubid, system): - """(Deprecated) Handle doctype declaration - - *name* is the Doctype name, *pubid* is the public identifier, - and *system* is the system identifier. - - """ - warnings.warn( - "This method of XMLParser is deprecated. Define doctype() " - "method on the TreeBuilder target.", - DeprecationWarning, - ) - - # sentinel, if doctype is redefined in a subclass - __doctype = doctype - def feed(self, data): """Feed encoded data to parser.""" try: diff -r 2ffaac4c8e53 Modules/_elementtree.c --- a/Modules/_elementtree.c Tue Dec 16 19:43:46 2014 +0200 +++ b/Modules/_elementtree.c Tue Mar 31 07:00:37 2015 +0000 @@ -2741,8 +2741,6 @@ } XMLParserObject; -#define XMLParser_CheckExact(op) (Py_TYPE(op) == &XMLParser_Type) - /* helpers */ LOCAL(PyObject*) @@ -3099,9 +3097,7 @@ const XML_Char *pubid, int has_internal_subset) { - PyObject *self_pyobj = (PyObject *)self; PyObject *doctype_name_obj, *sysid_obj, *pubid_obj; - PyObject *parser_doctype = NULL; PyObject *res = NULL; if (PyErr_Occurred()) @@ -3141,27 +3137,6 @@ 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) { - goto clear; - } - res = PyObject_CallFunction(parser_doctype, "OOO", - doctype_name_obj, pubid_obj, sysid_obj); - Py_CLEAR(res); - } - } - -clear: - Py_XDECREF(parser_doctype); Py_DECREF(doctype_name_obj); Py_DECREF(pubid_obj); Py_DECREF(sysid_obj); @@ -3504,12 +3479,6 @@ } static PyObject* -xmlparser_doctype(XMLParserObject *self, PyObject *args) -{ - Py_RETURN_NONE; -} - -static PyObject* xmlparser_setevents(XMLParserObject *self, PyObject* args) { /* activate element event reporting */ @@ -3610,7 +3579,6 @@ {"close", (PyCFunction) xmlparser_close, METH_VARARGS}, {"_parse_whole", (PyCFunction) xmlparser_parse_whole, METH_VARARGS}, {"_setevents", (PyCFunction) xmlparser_setevents, METH_VARARGS}, - {"doctype", (PyCFunction) xmlparser_doctype, METH_VARARGS}, {NULL, NULL} };