From 3d03255c95a3e0473a8843947989e9e1233eeab4 Mon Sep 17 00:00:00 2001 From: Daniel Hillier Date: Fri, 26 Apr 2024 21:55:37 +1000 Subject: [PATCH 1/2] Remove outdated c14n references from ElementTree 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. --- Lib/xml/etree/ElementTree.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py index 9e15d34d22aa6c4..3f5ef4c63598a65 100644 --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -696,7 +696,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 (default) @@ -710,10 +710,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 @@ -729,10 +726,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 @@ -961,8 +954,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, } @@ -1074,8 +1065,8 @@ 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", *default_namespace* - sets the default XML namespace (for "xmlns"). + 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. From 95faf7febbcbc259146589a12e7f55f2bdcf4bc6 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 25 May 2026 12:56:04 +0300 Subject: [PATCH 2/2] Update Lib/xml/etree/ElementTree.py --- Lib/xml/etree/ElementTree.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py index d793193e6e82c23..26d6f2c84c89eed 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 or "text" + *method* -- either "xml" (default), "html" or "text" *short_empty_elements* -- controls the formatting of elements that contain no content. If True