[New-bugs-announce] [issue27940] xml.etree: Avoid XML declaration for the "ascii" encoding

STINNER Victor report at bugs.python.org
Fri Sep 2 06:57:59 EDT 2016

New submission from STINNER Victor:

The ElementTree module (xml.etree) avoids the XML declaration for "utf-8" and "us-ascii" codecs, but not for the "ascii" encoding.

Attached patch avoids the XML declaration for the "ascii" codec since it's a subset of UTF-8 and UTF-8 is the default encoding of XML.

The patch also normalizes the encoding name to handle aliases like "utf8" (UTF-8) or "us_ascii" (ASCII).

The patch adds unit tests.


By the way, I'm surprised that the special encoding "unicode" relies on the *current* locale encoding when the XML declaration is requested. Why not alway susing UTF-8 for *unicode* instead of the locale encoding?

My unit test tests different locale encodings.

components: XML
files: etree_xml_declaration.patch
keywords: patch
messages: 274227
nosy: haypo
priority: normal
severity: normal
status: open
title: xml.etree: Avoid XML declaration for the "ascii" encoding
type: enhancement
versions: Python 3.6
Added file: http://bugs.python.org/file44346/etree_xml_declaration.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list