# 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 Thu Dec 18 06:41:43 2014 +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 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 Thu Dec 18 06:41:43 2014 +0000
@@ -2084,10 +2084,6 @@
class XMLParserTest(unittest.TestCase):
sample1 = b'22'
- sample2 = (b''
- b'text')
sample3 = ('\n'
'$\xa3\u20ac\U0001017b')
@@ -2117,21 +2113,6 @@
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):
- 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'))
-
def test_parse_string(self):
parser = ET.XMLParser(target=ET.TreeBuilder())
parser.feed(self.sample3)
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 Thu Dec 18 06:41:43 2014 +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 Thu Dec 18 06:41:43 2014 +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}
};