Skip to content

gh-136278: Document codecs.escape_encode() and codecs.escape_decode() #136314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Doc/library/codecs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,36 @@ to :class:`bytes` mappings. They are not supported by :meth:`bytes.decode`
Restoration of the aliases for the binary transforms.


.. _standalone-codec-functions:

Standalone Codec Functions
^^^^^^^^^^^^^^^^^^^^^^^^^^

The following functions provide encoding and decoding functionality similar to codecs,
but are not available as named codecs through :func:`codecs.encode` or :func:`codecs.decode`.
They are used internally (for example, by :mod:`pickle`) and behave similarly to the
``string_escape`` codec that was removed in Python 3.

.. function:: codecs.escape_encode(input, errors=None)

Encode *input* using escape sequences. Similar to how :func:`repr` on bytes
produces escaped byte values.

*input* must be a :class:`bytes` object.

Returns a tuple ``(output, length)`` where *output* is a :class:`bytes`
object and *length* is the number of bytes consumed.

.. function:: codecs.escape_decode(input, errors=None)

Decode *input* from escape sequences back to the original bytes.

*input* must be a :term:`bytes-like object`.

Returns a tuple ``(output, length)`` where *output* is a :class:`bytes`
object and *length* is the number of bytes consumed.


.. _text-transforms:

Text Transforms
Expand Down
Loading