Skip to content

Commit 6784ef7

Browse files
authored
pythongh-136278: Document codecs.escape_encode() and codecs.escape_decode() (python#136314)
Closes python#136278
1 parent 2bd4ff0 commit 6784ef7

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
@@ -1483,6 +1483,36 @@ to :class:`bytes` mappings. They are not supported by :meth:`bytes.decode`
14831483
Restoration of the aliases for the binary transforms.
14841484

14851485

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

14881518
Text Transforms

0 commit comments

Comments
 (0)