summaryrefslogtreecommitdiffstats
path: root/Modules/_elementtree.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-03-30 15:12:06 (GMT)
committerGitHub <noreply@github.com>2017-03-30 15:12:06 (GMT)
commit762ec97ea68a1126b8855996c61fa8239dc9fff7 (patch)
tree8addf50d8a5ed50492790532396b08d1d25737bd /Modules/_elementtree.c
parent722a3af092b94983aa26f5e591fb1b45e2c2a0ff (diff)
downloadcpython-762ec97ea68a1126b8855996c61fa8239dc9fff7.zip
cpython-762ec97ea68a1126b8855996c61fa8239dc9fff7.tar.gz
cpython-762ec97ea68a1126b8855996c61fa8239dc9fff7.tar.bz2
bpo-29204: Emit warnings for already deprecated ElementTree features. (#773)
Element.getiterator() and the html parameter of XMLParser() were deprecated only in the documentation (since Python 3.2 and 3.4 correspondintly). Now using them emits a deprecation warning. * Don’t need check_warnings any more.
Diffstat (limited to 'Modules/_elementtree.c')
-rw-r--r--Modules/_elementtree.c39
1 files changed, 37 insertions, 2 deletions
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index 36aa391..4e1750f 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -1366,7 +1366,12 @@ _elementtree_Element_getchildren_impl(ElementObject *self)
Py_ssize_t i;
PyObject* list;
- /* FIXME: report as deprecated? */
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "This method will be removed in future versions. "
+ "Use 'list(elem)' or iteration over elem instead.",
+ 1) < 0) {
+ return NULL;
+ }
if (!self->extra)
return PyList_New(0);
@@ -1416,6 +1421,28 @@ _elementtree_Element_iter_impl(ElementObject *self, PyObject *tag)
/*[clinic input]
+_elementtree.Element.getiterator
+
+ tag: object = None
+
+[clinic start generated code]*/
+
+static PyObject *
+_elementtree_Element_getiterator_impl(ElementObject *self, PyObject *tag)
+/*[clinic end generated code: output=cb69ff4a3742dfa1 input=500da1a03f7b9e28]*/
+{
+ /* Change for a DeprecationWarning in 1.4 */
+ if (PyErr_WarnEx(PyExc_PendingDeprecationWarning,
+ "This method will be removed in future versions. "
+ "Use 'tree.iter()' or 'list(tree.iter())' instead.",
+ 1) < 0) {
+ return NULL;
+ }
+ return _elementtree_Element_iter_impl(self, tag);
+}
+
+
+/*[clinic input]
_elementtree.Element.itertext
[clinic start generated code]*/
@@ -3244,6 +3271,14 @@ _elementtree_XMLParser___init___impl(XMLParserObject *self, PyObject *html,
PyObject *target, const char *encoding)
/*[clinic end generated code: output=d6a16c63dda54441 input=155bc5695baafffd]*/
{
+ if (html != NULL) {
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "The html argument of XMLParser() is deprecated",
+ 1) < 0) {
+ return -1;
+ }
+ }
+
self->entity = PyDict_New();
if (!self->entity)
return -1;
@@ -3716,7 +3751,7 @@ static PyMethodDef element_methods[] = {
_ELEMENTTREE_ELEMENT_ITERTEXT_METHODDEF
_ELEMENTTREE_ELEMENT_ITERFIND_METHODDEF
- {"getiterator", (PyCFunction)_elementtree_Element_iter, METH_FASTCALL, _elementtree_Element_iter__doc__},
+ _ELEMENTTREE_ELEMENT_GETITERATOR_METHODDEF
_ELEMENTTREE_ELEMENT_GETCHILDREN_METHODDEF
_ELEMENTTREE_ELEMENT_ITEMS_METHODDEF