Content-Length: 413350 | pFad | https://github.com/python/cpython/commit/#start-of-content

ion: iad gh-118318: Remove outdated c14n references from ElementTree (GH-118319) · python/cpython@87b120f · GitHub
Skip to content

Commit 87b120f

Browse files
authored
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.
1 parent 1286d43 commit 87b120f

3 files changed

Lines changed: 19 additions & 12 deletions

File tree

Doc/whatsnew/3.16.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,17 @@ tarfile
727727
* The undocumented and unused :attr:`!tarfile.TarFile.tarfile` attribute
728728
has been deprecated since Python 3.13.
729729

730+
xml.etree.ElementTree
731+
---------------------
732+
733+
* The undocumented :meth:`!xml.etree.ElementTree.ElementTree.write_c14n` method
734+
and the support of ``method="c14n"`` in
735+
:meth:`~xml.etree.ElementTree.ElementTree.write` and
736+
:func:`~xml.etree.ElementTree.tostring`.
737+
They never worked and always raised :exc:`ValueError`.
738+
Use :func:`xml.etree.ElementTree.canonicalize` instead.
739+
(Contributed by Daniel Hillier in :gh:`118318`.)
740+
730741
.. Add removals above alphabetically, not here at the end.
731742
732743

Lib/xml/etree/ElementTree.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ def write(self, file_or_filename,
714714
*default_namespace* -- sets the default XML namespace (for
715715
"xmlns")
716716
717-
*method* -- either "xml" (default), "html, "text", or "c14n"
717+
*method* -- either "xml" (default), "html" or "text"
718718
719719
*short_empty_elements* -- controls the formatting of elements
720720
that contain no content. If True
@@ -730,10 +730,7 @@ def write(self, file_or_filename,
730730
elif method not in _serialize:
731731
raise ValueError("unknown method %r" % method)
732732
if not encoding:
733-
if method == "c14n":
734-
encoding = "utf-8"
735-
else:
736-
encoding = "us-ascii"
733+
encoding = "us-ascii"
737734
with _get_writer(file_or_filename, encoding) as (write, declared_encoding):
738735
if method == "xml" and (xml_declaration or
739736
(xml_declaration is None and
@@ -749,10 +746,6 @@ def write(self, file_or_filename,
749746
serialize(write, self._root, qnames, namespaces,
750747
short_empty_elements=short_empty_elements)
751748

752-
def write_c14n(self, file):
753-
# lxml.etree compatibility. use output method instead
754-
return self.write(file, method="c14n")
755-
756749
# --------------------------------------------------------------------
757750
# serialization support
758751

@@ -987,8 +980,6 @@ def _serialize_text(write, elem):
987980
"xml": _serialize_xml,
988981
"html": _serialize_html,
989982
"text": _serialize_text,
990-
# this optional method is imported at the end of the module
991-
# "c14n": _serialize_c14n,
992983
}
993984

994985

@@ -1100,7 +1091,7 @@ def tostring(element, encoding=None, method=None, *,
11001091
11011092
*element* is an Element instance, *encoding* is an optional output
11021093
encoding defaulting to US-ASCII, *method* is an optional output which
1103-
can be one of "xml" (default), "html", "text" or "c14n",
1094+
can be one of "xml" (default), "html" or "text",
11041095
*default_namespace* sets the default XML namespace (for "xmlns").
11051096
11061097
Returns an (optionally) encoded string containing the XML data.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Remove the ``write_c14n()`` method of :class:`xml.etree.ElementTree.ElementTree`
2+
and the support of ``method="c14n"`` in :meth:`~xml.etree.ElementTree.ElementTree.write`
3+
and :func:`~xml.etree.ElementTree.tostring`. They never worked and always
4+
raised :exc:`ValueError`. Use :func:`xml.etree.ElementTree.canonicalize`
5+
instead.

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/python/cpython/commit/#start-of-content

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy