| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c5b242f commit f02ea62
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -873,18 +873,6 @@ Element Objects | |||
| 873 | 873 | in the expression into the given namespace. | |
| 874 | 874 | ||
| 875 | 875 | ||
| 876 | - .. method:: getchildren() | ||
| 877 | - | ||
| 878 | - .. deprecated-removed:: 3.2 3.9 | ||
| 879 | - Use ``list(elem)`` or iteration. | ||
| 880 | - | ||
| 881 | - | ||
| 882 | - .. method:: getiterator(tag=None) | ||
| 883 | - | ||
| 884 | - .. deprecated-removed:: 3.2 3.9 | ||
| 885 | - Use method :meth:`Element.iter` instead. | ||
| 886 | - | ||
| 887 | - | ||
| 888 | 876 | .. method:: insert(index, subelement) | |
| 889 | 877 | ||
| 890 | 878 | Inserts *subelement* at the given position in this element. Raises | |
@@ -1019,12 +1007,6 @@ ElementTree Objects | |||
| 1019 | 1007 | Same as :meth:`Element.findtext`, starting at the root of the tree. | |
| 1020 | 1008 | ||
| 1021 | 1009 | ||
| 1022 | - .. method:: getiterator(tag=None) | ||
| 1023 | - | ||
| 1024 | - .. deprecated-removed:: 3.2 3.9 | ||
| 1025 | - Use method :meth:`ElementTree.iter` instead. | ||
| 1026 | - | ||
| 1027 | - | ||
| 1028 | 1010 | .. method:: getroot() | |
| 1029 | 1011 | ||
| 1030 | 1012 | Returns the root element for this tree. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -207,6 +207,12 @@ Removed | |||
| 207 | 207 | Use :meth:`~threading.Thread.is_alive()` instead. | |
| 208 | 208 | (Contributed by Dong-hee Na in :issue:`37804`.) | |
| 209 | 209 | ||
| 210 | + * Methods ``getchildren()`` and ``getiterator()`` in the | ||
| 211 | + :mod:`~xml.etree.ElementTree` module have been removed. They were | ||
| 212 | + deprecated in Python 3.2. Use functions :func:`list` and :func:`iter` | ||
| 213 | + instead. The ``xml.etree.cElementTree`` module has been removed. | ||
| 214 | + (Contributed by Serhiy Storchaka in :issue:`36543`.) | ||
| 215 | + | ||
| 210 | 216 | ||
| 211 | 217 | Porting to Python 3.9 | |
| 212 | 218 | ===================== | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -242,7 +242,6 @@ def check_method(method): | |||
| 242 | 242 | check_method(element.extend) | |
| 243 | 243 | check_method(element.insert) | |
| 244 | 244 | check_method(element.remove) | |
| 245 | - check_method(element.getchildren) | ||
| 246 | 245 | check_method(element.find) | |
| 247 | 246 | check_method(element.iterfind) | |
| 248 | 247 | check_method(element.findall) | |
@@ -254,7 +253,6 @@ def check_method(method): | |||
| 254 | 253 | check_method(element.items) | |
| 255 | 254 | check_method(element.iter) | |
| 256 | 255 | check_method(element.itertext) | |
| 257 | - check_method(element.getiterator) | ||
| 258 | 256 | ||
| 259 | 257 | # These methods return an iterable. See bug 6472. | |
| 260 | 258 | ||
@@ -741,46 +739,42 @@ def end_ns(self, prefix): | |||
| 741 | 739 | ('end-ns', ''), | |
| 742 | 740 | ]) | |
| 743 | 741 | ||
| 744 | - # Element.getchildren() and ElementTree.getiterator() are deprecated. | ||
| 745 | - @checkwarnings(("This method will be removed in future versions. " | ||
| 746 | - "Use .+ instead.", | ||
| 747 | - DeprecationWarning)) | ||
| 748 | - def test_getchildren(self): | ||
| 749 | - # Test Element.getchildren() | ||
| 742 | + def test_children(self): | ||
| 743 | + # Test Element children iteration | ||
| 750 | 744 | ||
| 751 | 745 | with open(SIMPLE_XMLFILE, "rb") as f: | |
| 752 | 746 | tree = ET.parse(f) | |
| 753 | - self.assertEqual([summarize_list(elem.getchildren()) | ||
| 747 | + self.assertEqual([summarize_list(elem) | ||
| 754 | 748 | for elem in tree.getroot().iter()], [ | |
| 755 | 749 | ['element', 'element', 'empty-element'], | |
| 756 | 750 | [], | |
| 757 | 751 | [], | |
| 758 | 752 | [], | |
| 759 | 753 | ]) | |
| 760 | - self.assertEqual([summarize_list(elem.getchildren()) | ||
| 761 | - for elem in tree.getiterator()], [ | ||
| 754 | + self.assertEqual([summarize_list(elem) | ||
| 755 | + for elem in tree.iter()], [ | ||
| 762 | 756 | ['element', 'element', 'empty-element'], | |
| 763 | 757 | [], | |
| 764 | 758 | [], | |
| 765 | 759 | [], | |
| 766 | 760 | ]) | |
| 767 | 761 | ||
| 768 | 762 | elem = ET.XML(SAMPLE_XML) | |
| 769 | - self.assertEqual(len(elem.getchildren()), 3) | ||
| 770 | - self.assertEqual(len(elem[2].getchildren()), 1) | ||
| 771 | - self.assertEqual(elem[:], elem.getchildren()) | ||
| 763 | + self.assertEqual(len(list(elem)), 3) | ||
| 764 | + self.assertEqual(len(list(elem[2])), 1) | ||
| 765 | + self.assertEqual(elem[:], list(elem)) | ||
| 772 | 766 | child1 = elem[0] | |
| 773 | 767 | child2 = elem[2] | |
| 774 | 768 | del elem[1:2] | |
| 775 | - self.assertEqual(len(elem.getchildren()), 2) | ||
| 769 | + self.assertEqual(len(list(elem)), 2) | ||
| 776 | 770 | self.assertEqual(child1, elem[0]) | |
| 777 | 771 | self.assertEqual(child2, elem[1]) | |
| 778 | 772 | elem[0:2] = [child2, child1] | |
| 779 | 773 | self.assertEqual(child2, elem[0]) | |
| 780 | 774 | self.assertEqual(child1, elem[1]) | |
| 781 | 775 | self.assertNotEqual(child1, elem[0]) | |
| 782 | 776 | elem.clear() | |
| 783 | - self.assertEqual(elem.getchildren(), []) | ||
| 777 | + self.assertEqual(list(elem), []) | ||
| 784 | 778 | ||
| 785 | 779 | def test_writestring(self): | |
| 786 | 780 | elem = ET.XML("<html><body>text</body></html>") | |
@@ -2955,40 +2949,6 @@ def test_iter_by_tag(self): | |||
| 2955 | 2949 | self.assertEqual(self._ilist(doc), all_tags) | |
| 2956 | 2950 | self.assertEqual(self._ilist(doc, '*'), all_tags) | |
| 2957 | 2951 | ||
| 2958 | - # Element.getiterator() is deprecated. | ||
| 2959 | - @checkwarnings(("This method will be removed in future versions. " | ||
| 2960 | - "Use .+ instead.", DeprecationWarning)) | ||
| 2961 | - def test_getiterator(self): | ||
| 2962 | - doc = ET.XML(''' | ||
| 2963 | - <document> | ||
| 2964 | - <house> | ||
| 2965 | - <room>bedroom1</room> | ||
| 2966 | - <room>bedroom2</room> | ||
| 2967 | - </house> | ||
| 2968 | - <shed>nothing here | ||
| 2969 | - </shed> | ||
| 2970 | - <house> | ||
| 2971 | - <room>bedroom8</room> | ||
| 2972 | - </house> | ||
| 2973 | - </document>''') | ||
| 2974 | - | ||
| 2975 | - self.assertEqual(summarize_list(doc.getiterator('room')), | ||
| 2976 | - ['room'] * 3) | ||
| 2977 | - self.assertEqual(summarize_list(doc.getiterator('house')), | ||
| 2978 | - ['house'] * 2) | ||
| 2979 | - | ||
| 2980 | - # test that getiterator also accepts 'tag' as a keyword arg | ||
| 2981 | - self.assertEqual( | ||
| 2982 | - summarize_list(doc.getiterator(tag='room')), | ||
| 2983 | - ['room'] * 3) | ||
| 2984 | - | ||
| 2985 | - # make sure both tag=None and tag='*' return all tags | ||
| 2986 | - all_tags = ['document', 'house', 'room', 'room', | ||
| 2987 | - 'shed', 'house', 'room'] | ||
| 2988 | - self.assertEqual(summarize_list(doc.getiterator()), all_tags) | ||
| 2989 | - self.assertEqual(summarize_list(doc.getiterator(None)), all_tags) | ||
| 2990 | - self.assertEqual(summarize_list(doc.getiterator('*')), all_tags) | ||
| 2991 | - | ||
| 2992 | 2952 | def test_copy(self): | |
| 2993 | 2953 | a = ET.Element('a') | |
| 2994 | 2954 | it = a.iter() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -273,19 +273,6 @@ def remove(self, subelement): | |||
| 273 | 273 | # assert iselement(element) | |
| 274 | 274 | self._children.remove(subelement) | |
| 275 | 275 | ||
| 276 | - def getchildren(self): | ||
| 277 | - """(Deprecated) Return all subelements. | ||
| 278 | - | ||
| 279 | - Elements are returned in document order. | ||
| 280 | - | ||
| 281 | - """ | ||
| 282 | - warnings.warn( | ||
| 283 | - "This method will be removed in future versions. " | ||
| 284 | - "Use 'list(elem)' or iteration over elem instead.", | ||
| 285 | - DeprecationWarning, stacklevel=2 | ||
| 286 | - ) | ||
| 287 | - return self._children | ||
| 288 | - | ||
| 289 | 276 | def find(self, path, namespaces=None): | |
| 290 | 277 | """Find first matching element by tag name or path. | |
| 291 | 278 | ||
@@ -409,15 +396,6 @@ def iter(self, tag=None): | |||
| 409 | 396 | for e in self._children: | |
| 410 | 397 | yield from e.iter(tag) | |
| 411 | 398 | ||
| 412 | - # compatibility | ||
| 413 | - def getiterator(self, tag=None): | ||
| 414 | - warnings.warn( | ||
| 415 | - "This method will be removed in future versions. " | ||
| 416 | - "Use 'elem.iter()' or 'list(elem.iter())' instead.", | ||
| 417 | - DeprecationWarning, stacklevel=2 | ||
| 418 | - ) | ||
| 419 | - return list(self.iter(tag)) | ||
| 420 | - | ||
| 421 | 399 | def itertext(self): | |
| 422 | 400 | """Create text iterator. | |
| 423 | 401 | ||
@@ -617,15 +595,6 @@ def iter(self, tag=None): | |||
| 617 | 595 | # assert self._root is not None | |
| 618 | 596 | return self._root.iter(tag) | |
| 619 | 597 | ||
| 620 | - # compatibility | ||
| 621 | - def getiterator(self, tag=None): | ||
| 622 | - warnings.warn( | ||
| 623 | - "This method will be removed in future versions. " | ||
| 624 | - "Use 'tree.iter()' or 'list(tree.iter())' instead.", | ||
| 625 | - DeprecationWarning, stacklevel=2 | ||
| 626 | - ) | ||
| 627 | - return list(self.iter(tag)) | ||
| 628 | - | ||
| 629 | 598 | def find(self, path, namespaces=None): | |
| 630 | 599 | """Find first matching element by tag name or path. | |
| 631 | 600 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Removed methods Element.getchildren(), Element.getiterator() and | ||
| 2 | + ElementTree.getiterator() and the xml.etree.cElementTree module. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1426,42 +1426,6 @@ _elementtree_Element_get_impl(ElementObject *self, PyObject *key, | |||
| 1426 | 1426 | return value; | |
| 1427 | 1427 | } | |
| 1428 | 1428 | ||
| 1429 | - /*[clinic input] | ||
| 1430 | - _elementtree.Element.getchildren | ||
| 1431 | - | ||
| 1432 | - [clinic start generated code]*/ | ||
| 1433 | - | ||
| 1434 | - static PyObject * | ||
| 1435 | - _elementtree_Element_getchildren_impl(ElementObject *self) | ||
| 1436 | - /*[clinic end generated code: output=e50ffe118637b14f input=0f754dfded150d5f]*/ | ||
| 1437 | - { | ||
| 1438 | - Py_ssize_t i; | ||
| 1439 | - PyObject* list; | ||
| 1440 | - | ||
| 1441 | - if (PyErr_WarnEx(PyExc_DeprecationWarning, | ||
| 1442 | - "This method will be removed in future versions. " | ||
| 1443 | - "Use 'list(elem)' or iteration over elem instead.", | ||
| 1444 | - 1) < 0) { | ||
| 1445 | - return NULL; | ||
| 1446 | - } | ||
| 1447 | - | ||
| 1448 | - if (!self->extra) | ||
| 1449 | - return PyList_New(0); | ||
| 1450 | - | ||
| 1451 | - list = PyList_New(self->extra->length); | ||
| 1452 | - if (!list) | ||
| 1453 | - return NULL; | ||
| 1454 | - | ||
| 1455 | - for (i = 0; i < self->extra->length; i++) { | ||
| 1456 | - PyObject* item = self->extra->children[i]; | ||
| 1457 | - Py_INCREF(item); | ||
| 1458 | - PyList_SET_ITEM(list, i, item); | ||
| 1459 | - } | ||
| 1460 | - | ||
| 1461 | - return list; | ||
| 1462 | - } | ||
| 1463 | - | ||
| 1464 | - | ||
| 1465 | 1429 | static PyObject * | |
| 1466 | 1430 | create_elementiter(ElementObject *self, PyObject *tag, int gettext); | |
| 1467 | 1431 | ||
@@ -1492,27 +1456,6 @@ _elementtree_Element_iter_impl(ElementObject *self, PyObject *tag) | |||
| 1492 | 1456 | } | |
| 1493 | 1457 | ||
| 1494 | 1458 | ||
| 1495 | - /*[clinic input] | ||
| 1496 | - _elementtree.Element.getiterator | ||
| 1497 | - | ||
| 1498 | - tag: object = None | ||
| 1499 | - | ||
| 1500 | - [clinic start generated code]*/ | ||
| 1501 | - | ||
| 1502 | - static PyObject * | ||
| 1503 | - _elementtree_Element_getiterator_impl(ElementObject *self, PyObject *tag) | ||
| 1504 | - /*[clinic end generated code: output=cb69ff4a3742dfa1 input=500da1a03f7b9e28]*/ | ||
| 1505 | - { | ||
| 1506 | - if (PyErr_WarnEx(PyExc_DeprecationWarning, | ||
| 1507 | - "This method will be removed in future versions. " | ||
| 1508 | - "Use 'tree.iter()' or 'list(tree.iter())' instead.", | ||
| 1509 | - 1) < 0) { | ||
| 1510 | - return NULL; | ||
| 1511 | - } | ||
| 1512 | - return _elementtree_Element_iter_impl(self, tag); | ||
| 1513 | - } | ||
| 1514 | - | ||
| 1515 | - | ||
| 1516 | 1459 | /*[clinic input] | |
| 1517 | 1460 | _elementtree.Element.itertext | |
| 1518 | 1461 | ||
@@ -4220,9 +4163,6 @@ static PyMethodDef element_methods[] = { | |||
| 4220 | 4163 | _ELEMENTTREE_ELEMENT_ITERTEXT_METHODDEF | |
| 4221 | 4164 | _ELEMENTTREE_ELEMENT_ITERFIND_METHODDEF | |
| 4222 | 4165 | ||
| 4223 | - _ELEMENTTREE_ELEMENT_GETITERATOR_METHODDEF | ||
| 4224 | - _ELEMENTTREE_ELEMENT_GETCHILDREN_METHODDEF | ||
| 4225 | - | ||
| 4226 | 4166 | _ELEMENTTREE_ELEMENT_ITEMS_METHODDEF | |
| 4227 | 4167 | _ELEMENTTREE_ELEMENT_KEYS_METHODDEF | |
| 4228 | 4168 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments