Skip to content

gh-62259: Add support of multi-byte encodings in the XML parser#149860

Open
serhiy-storchaka wants to merge 2 commits into
python:mainfrom
serhiy-storchaka:pyexpat-multibyte-encodings2
Open

gh-62259: Add support of multi-byte encodings in the XML parser#149860
serhiy-storchaka wants to merge 2 commits into
python:mainfrom
serhiy-storchaka:pyexpat-multibyte-encodings2

Conversation

@serhiy-storchaka
Copy link
Copy Markdown
Member

@serhiy-storchaka serhiy-storchaka commented May 15, 2026

Supported encodings: "cp932", "cp949", "cp950", "Big5","EUC-JP", "GB2312", "GBK", "johab", and "Shift_JIS".

Partially supported encodings (only BMP characters): "Big5-HKSCS", "EUC_JIS-2004", "EUC_JISX0213", "Shift_JIS-2004", "Shift_JISX0213", "utf-8-sig" and non-standard aliases like "UTF8" (without hyphen).

The parser now raises ValueError for known unsupported multi-byte encodings such us "ISO-2022-JP" or "raw-unicode-escape" instead of failing later, when encounter non-ASCII data.

Supported encodings: "cp932", "cp949", "cp950", "Big5","EUC-JP",
"GB2312", "GBK", "johab", and "Shift_JIS".

Partially supported encodings (only BMP characters): "Big5-HKSCS",
"EUC_JIS-2004", "EUC_JISX0213", "Shift_JIS-2004", "Shift_JISX0213",
"utf-8-sig" and non-standard aliases like "UTF8" (without hyphen).

The parser now raises ValueError for known unsupported
multi-byte encodings such us "ISO-2022-JP" or "raw-unicode-escape"
instead of failing later, when encounter non-ASCII data.
@read-the-docs-community
Copy link
Copy Markdown

read-the-docs-community Bot commented May 15, 2026

Documentation build overview

📚 cpython-previews | 🛠️ Build #32704028 | 📁 Comparing 25c8b75 against main (7e98deb)

  🔍 Preview build  

3 files changed
± library/pyexpat.html
± whatsnew/3.16.html
± whatsnew/changelog.html

Copy link
Copy Markdown
Member

@malemburg malemburg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

The only detail that is missing is the documentation update. This still reads "UTF-8, UTF-16, ISO-8859-1 (Latin1), and ASCII" which already appears to be out of date.

Comment thread Doc/library/pyexpat.rst
be extended; it supports UTF-8, UTF-16, ISO-8859-1 (Latin1), and ASCII. If
*encoding* [1]_ is given it will override the implicit or explicit encoding of the
document.
must be a string naming the encoding used by the XML data.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
must be a string naming the encoding used by the XML data.
must be a string naming the encoding used by the XML data.

Comment thread Doc/library/pyexpat.rst
*encoding* [1]_ is given it will override the implicit or explicit encoding of the
document.
must be a string naming the encoding used by the XML data.
Expat natively understands and processes UTF-8, UTF-16, UTF-16BE, UTF-16LE,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be an .. impl-detail (I don't remember the exact name)?

Comment thread Doc/whatsnew/3.16.rst
---

* TODO
* Add support of multiple multi-byte encodings in the :mod:`XML parser
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Add support of multiple multi-byte encodings in the :mod:`XML parser
* Add support for multiple multi-byte encodings in the :mod:`XML parser

@@ -0,0 +1,9 @@
Add support of multiple multi-byte encodings in the :mod:`XML parser
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Add support of multiple multi-byte encodings in the :mod:`XML parser
Add support for multiple multi-byte encodings in the :mod:`XML parser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants