Skip to content

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

Merged
serhiy-storchaka merged 5 commits into
python:mainfrom
serhiy-storchaka:pyexpat-multibyte-encodings2
May 26, 2026
Merged

gh-62259: Add support of multi-byte encodings in the XML parser#149860
serhiy-storchaka merged 5 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

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 Outdated
Comment thread Doc/library/pyexpat.rst Outdated
*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 Outdated
Comment thread Misc/NEWS.d/next/Library/2026-05-14-17-01-19.gh-issue-62259.ytlFD5.rst Outdated
@serhiy-storchaka serhiy-storchaka enabled auto-merge (squash) May 26, 2026 19:16
@serhiy-storchaka serhiy-storchaka merged commit 8ab7b43 into python:main May 26, 2026
56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants