From 7493480e3bec2e02eecaa66782dc1f1ab9bd6690 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Fri, 9 May 2025 16:26:49 +0100 Subject: [PATCH 1/2] Backport --- Doc/c-api/unicode.rst | 9 +++++++++ Doc/data/refcounts.dat | 3 +++ 2 files changed, 12 insertions(+) diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst index 7baf8de10c8175..5653131f9806ee 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -621,6 +621,15 @@ APIs: decref'ing the returned objects. +.. c:function:: PyObject* PyUnicode_BuildEncodingMap(PyObject* string) + Return a mapping suitable for decoding a custom single-byte encoding. + Given a Unicode string *string* of up to 256 characters representing an encoding + table, returns either a compact internal mapping object or a dictionary + mapping character ordinals to byte values. Raises a :exc:`TypeError` and + return ``NULL`` on invalid input. + .. versionadded:: 3.2 + + .. c:function:: const char* PyUnicode_GetDefaultEncoding(void) Return the name of the default string encoding, ``"utf-8"``. diff --git a/Doc/data/refcounts.dat b/Doc/data/refcounts.dat index 964914aa714f09..042cae5f18ab1a 100644 --- a/Doc/data/refcounts.dat +++ b/Doc/data/refcounts.dat @@ -2759,6 +2759,9 @@ PyUnicode_FromFormatV:va_list:args:: PyUnicode_FromOrdinal:PyObject*::+1: PyUnicode_FromOrdinal:int:ordinal:: +PyUnicode_BuildEncodingMap:PyObject*::+1: +PyUnicode_BuildEncodingMap:PyObject*:string::: + PyUnicode_GetDefaultEncoding:const char*::: PyUnicode_GetDefaultEncoding::void:: From df057e47afce6e94b2871c13720480b8bbb46a43 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Fri, 9 May 2025 16:38:33 +0100 Subject: [PATCH 2/2] Blank line --- Doc/c-api/unicode.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst index 5653131f9806ee..9e679d080fb5f5 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -622,6 +622,7 @@ APIs: .. c:function:: PyObject* PyUnicode_BuildEncodingMap(PyObject* string) + Return a mapping suitable for decoding a custom single-byte encoding. Given a Unicode string *string* of up to 256 characters representing an encoding table, returns either a compact internal mapping object or a dictionary