Skip to content

Commit 81079d7

Browse files
[3.13] gh-136278: Document codecs.escape_encode() and codecs.escape_decode() (GH-136314) (#137150)
gh-136278: Document codecs.escape_encode() and codecs.escape_decode() (GH-136314) Closes GH-136278 (cherry picked from commit 6784ef7) Co-authored-by: Toshaksha <147024929+Toshaksha@users.noreply.github.com>
1 parent 4a37dd6 commit 81079d7

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Doc/library/codecs.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,36 @@ to :class:`bytes` mappings. They are not supported by :meth:`bytes.decode`
14721472
Restoration of the aliases for the binary transforms.
14731473

14741474

1475+
.. _standalone-codec-functions:
1476+
1477+
Standalone Codec Functions
1478+
^^^^^^^^^^^^^^^^^^^^^^^^^^
1479+
1480+
The following functions provide encoding and decoding functionality similar to codecs,
1481+
but are not available as named codecs through :func:`codecs.encode` or :func:`codecs.decode`.
1482+
They are used internally (for example, by :mod:`pickle`) and behave similarly to the
1483+
``string_escape`` codec that was removed in Python 3.
1484+
1485+
.. function:: codecs.escape_encode(input, errors=None)
1486+
1487+
Encode *input* using escape sequences. Similar to how :func:`repr` on bytes
1488+
produces escaped byte values.
1489+
1490+
*input* must be a :class:`bytes` object.
1491+
1492+
Returns a tuple ``(output, length)`` where *output* is a :class:`bytes`
1493+
object and *length* is the number of bytes consumed.
1494+
1495+
.. function:: codecs.escape_decode(input, errors=None)
1496+
1497+
Decode *input* from escape sequences back to the original bytes.
1498+
1499+
*input* must be a :term:`bytes-like object`.
1500+
1501+
Returns a tuple ``(output, length)`` where *output* is a :class:`bytes`
1502+
object and *length* is the number of bytes consumed.
1503+
1504+
14751505
.. _text-transforms:
14761506

14771507
Text Transforms

0 commit comments

Comments
 (0)