gh-118318: Remove outdated c14n references from ElementTree (GH-118319)
serhiy-storchaka <[email protected]> Sun, 09 Aug 2026 17:12:09 -0400 (EDT)
| Newsgroups | gmane.comp.python.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://github.com/python/cpython/commit/87b120fdb58afd8f7cb79daa87122334e295b70c commit: 87b120fdb58afd8f7cb79daa87122334e295b70c branch: main author: Daniel Hillier <[email protected]> committer: serhiy-storchaka <[email protected]> date: 2026-08-09T21:06:42Z summary: gh-118318: Remove outdated c14n references from ElementTree (GH-118319) Some references to a removed `c14n` serialization method remained in ElementTree.py. Attempting to use `method='c14n'` in the `write()` method would result in `ValueError: unknown method 'c14n'`. Removes the `write_c14n()` method that uses `method='c14n'` and also raises the same error. files: A Misc/NEWS.d/next/Library/2026-08-09-21-30-00.gh-issue-118318.Xr4Kd8.rst M Doc/whatsnew/3.16.rst M Lib/xml/etree/ElementTree.py diff --git a/Doc/whatsnew/3.16.rst b/Doc/whatsnew/3.16.rst index 210bcafe65f5e9c..9edbccf3adef9e5 100644 --- a/Doc/whatsnew/3.16.rst +++ b/Doc/whatsnew/3.16.rst @@ -727,6 +727,17 @@ tarfile * The undocumented and unused :attr:`!tarfile.TarFile.tarfile` attribute has been deprecated since Python 3.13. +xml.etree.ElementTree +--------------------- + +* The undocumented :meth:`!xml.etree.ElementTree.ElementTree.write_c14n` method + and the support of ``method="c14n"`` in + :meth:`~xml.etree.ElementTree.ElementTree.write` and + :func:`~xml.etree.ElementTree.tostring`. + They never worked and always raised :exc:`ValueError`. + Use :func:`xml.etree.ElementTree.canonicalize` instead. + (Contributed by Daniel Hillier in :gh:`118318`.) + .. Add removals above alphabetically, not here at the end. diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py index 53727d7940b3f2a..7708d38b7759cb1 100644 --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -714,7 +714,7 @@ def write(self, file_or_filename, *default_namespace* -- sets the default XML namespace (for "xmlns") - *method* -- either "xml" (default), "html, "text", or "c14n" + *method* -- either "xml" (default), "html" or "text" *short_empty_elements* -- controls the formatting of elements that contain no content. If True @@ -730,10 +730,7 @@ def write(self, file_or_filename, elif method not in _serialize: raise ValueError("unknown method %r" % method) if not encoding: - if method == "c14n": - encoding = "utf-8" - else: - encoding = "us-ascii" + encoding = "us-ascii" with _get_writer(file_or_filename, encoding) as (write, declared_encoding): if method == "xml" and (xml_declaration or (xml_declaration is None and @@ -749,10 +746,6 @@ def write(self, file_or_filename, serialize(write, self._root, qnames, namespaces, short_empty_elements=short_empty_elements) - def write_c14n(self, file): - # lxml.etree compatibility. use output method instead - return self.write(file, method="c14n") - # -------------------------------------------------------------------- # serialization support @@ -987,8 +980,6 @@ def _serialize_text(write, elem): "xml": _serialize_xml, "html": _serialize_html, "text": _serialize_text, -# this optional method is imported at the end of the module -# "c14n": _serialize_c14n, } @@ -1100,7 +1091,7 @@ def tostring(element, encoding=None, method=None, *, *element* is an Element instance, *encoding* is an optional output encoding defaulting to US-ASCII, *method* is an optional output which - can be one of "xml" (default), "html", "text" or "c14n", + can be one of "xml" (default), "html" or "text", *default_namespace* sets the default XML namespace (for "xmlns"). Returns an (optionally) encoded string containing the XML data. diff --git a/Misc/NEWS.d/next/Library/2026-08-09-21-30-00.gh-issue-118318.Xr4Kd8.rst b/Misc/NEWS.d/next/Library/2026-08-09-21-30-00.gh-issue-118318.Xr4Kd8.rst new file mode 100644 index 000000000000000..31a39e50c72dd5f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-08-09-21-30-00.gh-issue-118318.Xr4Kd8.rst @@ -0,0 +1,5 @@ +Remove the ``write_c14n()`` method of :class:`xml.etree.ElementTree.ElementTree` +and the support of ``method="c14n"`` in :meth:`~xml.etree.ElementTree.ElementTree.write` +and :func:`~xml.etree.ElementTree.tostring`. They never worked and always +raised :exc:`ValueError`. Use :func:`xml.etree.ElementTree.canonicalize` +instead. _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]