Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0fe030b

Browse files
committed
Issue #16323: Fix wrong C API documentation for locale encoding.
Patch by Berker Peksag.
1 parent bb4e941 commit 0fe030b

1 file changed

Lines changed: 24 additions & 20 deletions

File tree

Doc/c-api/unicode.rst

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -735,15 +735,18 @@ Locale Encoding
735735
The current locale encoding can be used to decode text from the operating
736736
system.
737737
738-
.. c:function:: PyObject* PyUnicode_DecodeLocaleAndSize(const char *str, Py_ssize_t len, int surrogateescape)
739-
740-
Decode a string from the current locale encoding. The decoder is strict if
741-
*surrogateescape* is equal to zero, otherwise it uses the
742-
``'surrogateescape'`` error handler (:pep:`383`) to escape undecodable
743-
bytes. If a byte sequence can be decoded as a surrogate character and
744-
*surrogateescape* is not equal to zero, the byte sequence is escaped using
745-
the ``'surrogateescape'`` error handler instead of being decoded. *str*
746-
must end with a null character but cannot contain embedded null characters.
738+
.. c:function:: PyObject* PyUnicode_DecodeLocaleAndSize(const char *str, \
739+
Py_ssize_t len, \
740+
const char *errors)
741+
742+
Decode a string from the current locale encoding. The supported
743+
error handlers are ``"strict"`` and ``"surrogateescape"``
744+
(:pep:`383`). The decoder uses ``"strict"`` error handler if
745+
*errors* is ``NULL``. If a byte sequence can be decoded as a
746+
surrogate character and *errors* is not ``"strict"``, then the byte
747+
sequence is escaped using the ``"surrogateescape"`` error handler
748+
instead of being decoded. *str* must end with a null character but
749+
cannot contain embedded null characters.
747750
748751
.. seealso::
749752
@@ -754,20 +757,21 @@ system.
754757
.. versionadded:: 3.3
755758
756759
757-
.. c:function:: PyObject* PyUnicode_DecodeLocale(const char *str, int surrogateescape)
760+
.. c:function:: PyObject* PyUnicode_DecodeLocale(const char *str, const char *errors)
758761
759762
Similar to :c:func:`PyUnicode_DecodeLocaleAndSize`, but compute the string
760763
length using :c:func:`strlen`.
761764
762765
.. versionadded:: 3.3
763766
764767
765-
.. c:function:: PyObject* PyUnicode_EncodeLocale(PyObject *unicode, int surrogateescape)
768+
.. c:function:: PyObject* PyUnicode_EncodeLocale(PyObject *unicode, const char *errors)
766769
767-
Encode a Unicode object to the current locale encoding. The encoder is
768-
strict if *surrogateescape* is equal to zero, otherwise it uses the
769-
``'surrogateescape'`` error handler (:pep:`383`). Return a :class:`bytes`
770-
object. *str* cannot contain embedded null characters.
770+
Encode a Unicode object to the current locale encoding. The
771+
supported error handlers are ``"strict"`` and ``"surrogateescape"``
772+
(:pep:`383`). The encoder uses ``"strict"`` error handler if
773+
*errors* is ``NULL``. Return a :class:`bytes` object. *str* cannot
774+
contain embedded null characters.
771775
772776
.. seealso::
773777
@@ -813,7 +817,7 @@ used, passing :c:func:`PyUnicode_FSDecoder` as the conversion function:
813817
.. c:function:: PyObject* PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size)
814818
815819
Decode a string using :c:data:`Py_FileSystemDefaultEncoding` and the
816-
``'surrogateescape'`` error handler, or ``'strict'`` on Windows.
820+
``"surrogateescape"`` error handler, or ``"strict"`` on Windows.
817821
818822
If :c:data:`Py_FileSystemDefaultEncoding` is not set, fall back to the
819823
locale encoding.
@@ -826,27 +830,27 @@ used, passing :c:func:`PyUnicode_FSDecoder` as the conversion function:
826830
:c:func:`PyUnicode_DecodeLocaleAndSize`.
827831
828832
.. versionchanged:: 3.2
829-
Use ``'strict'`` error handler on Windows.
833+
Use ``"strict"`` error handler on Windows.
830834
831835
832836
.. c:function:: PyObject* PyUnicode_DecodeFSDefault(const char *s)
833837
834838
Decode a null-terminated string using :c:data:`Py_FileSystemDefaultEncoding`
835-
and the ``'surrogateescape'`` error handler, or ``'strict'`` on Windows.
839+
and the ``"surrogateescape"`` error handler, or ``"strict"`` on Windows.
836840
837841
If :c:data:`Py_FileSystemDefaultEncoding` is not set, fall back to the
838842
locale encoding.
839843
840844
Use :c:func:`PyUnicode_DecodeFSDefaultAndSize` if you know the string length.
841845
842846
.. versionchanged:: 3.2
843-
Use ``'strict'`` error handler on Windows.
847+
Use ``"strict"`` error handler on Windows.
844848
845849
846850
.. c:function:: PyObject* PyUnicode_EncodeFSDefault(PyObject *unicode)
847851
848852
Encode a Unicode object to :c:data:`Py_FileSystemDefaultEncoding` with the
849-
``'surrogateescape'`` error handler, or ``'strict'`` on Windows, and return
853+
``"surrogateescape"`` error handler, or ``"strict"`` on Windows, and return
850854
:class:`bytes`. Note that the resulting :class:`bytes` object may contain
851855
null bytes.
852856

0 commit comments

Comments
 (0)