@@ -239,8 +239,8 @@ wider range of codecs when working with binary files:
239239.. function :: iterencode(iterator, encoding, errors='strict', **kwargs)
240240
241241 Uses an incremental encoder to iteratively encode the input provided by
242- *iterator *. This function is a :term: ` generator ` .
243- The *errors * argument (as well as any
242+ *iterator *. * iterator * must yield :class: ` str ` objects .
243+ This function is a :term: ` generator `. The *errors * argument (as well as any
244244 other keyword argument) is passed through to the incremental encoder.
245245
246246 This function requires that the codec accept text :class: `str ` objects
@@ -251,8 +251,8 @@ wider range of codecs when working with binary files:
251251.. function :: iterdecode(iterator, encoding, errors='strict', **kwargs)
252252
253253 Uses an incremental decoder to iteratively decode the input provided by
254- *iterator *. This function is a :term: ` generator ` .
255- The *errors * argument (as well as any
254+ *iterator *. * iterator * must yield :class: ` bytes ` objects .
255+ This function is a :term: ` generator `. The *errors * argument (as well as any
256256 other keyword argument) is passed through to the incremental decoder.
257257
258258 This function requires that the codec accept :class: `bytes ` objects
@@ -261,6 +261,20 @@ wider range of codecs when working with binary files:
261261 :func: `iterencode `.
262262
263263
264+ .. function :: readbuffer_encode(buffer, errors=None, /)
265+
266+ Return a :class: `tuple ` containing the raw bytes of *buffer *, a
267+ :ref: `buffer-compatible object <bufferobjects >` or :class: `str `
268+ (encoded to UTF-8 before processing), and their length in bytes.
269+
270+ The *errors * argument is ignored.
271+
272+ .. code-block :: pycon
273+
274+ >>> codecs.readbuffer_encode(b"Zito")
275+ (b'Zito', 4)
276+
277+
264278 The module also provides the following constants which are useful for reading
265279and writing to platform dependent files:
266280
@@ -1473,6 +1487,54 @@ mapping. It is not supported by :meth:`str.encode` (which only produces
14731487 Restoration of the ``rot13 `` alias.
14741488
14751489
1490+ :mod: `encodings ` --- Encodings package
1491+ --------------------------------------
1492+
1493+ .. module :: encodings
1494+ :synopsis: Encodings package
1495+
1496+ This module implements the following functions:
1497+
1498+ .. function :: normalize_encoding(encoding)
1499+
1500+ Normalize encoding name *encoding *.
1501+
1502+ Normalization works as follows: all non-alphanumeric characters except the
1503+ dot used for Python package names are collapsed and replaced with a single
1504+ underscore, leading and trailing underscores are removed.
1505+ For example, ``' -;#' `` becomes ``'_' ``.
1506+
1507+ Note that *encoding * should be ASCII only.
1508+
1509+
1510+ .. note ::
1511+ The following function should not be used directly, except for testing
1512+ purposes; :func: `codecs.lookup ` should be used instead.
1513+
1514+
1515+ .. function :: search_function(encoding)
1516+
1517+ Search for the codec module corresponding to the given encoding name
1518+ *encoding *.
1519+
1520+ This function first normalizes the *encoding * using
1521+ :func: `normalize_encoding `, then looks for a corresponding alias.
1522+ It attempts to import a codec module from the encodings package using either
1523+ the alias or the normalized name. If the module is found and defines a valid
1524+ ``getregentry() `` function that returns a :class: `codecs.CodecInfo ` object,
1525+ the codec is cached and returned.
1526+
1527+ If the codec module defines a ``getaliases() `` function any returned aliases
1528+ are registered for future use.
1529+
1530+
1531+ This module implements the following exception:
1532+
1533+ .. exception :: CodecRegistryError
1534+
1535+ Raised when a codec is invalid or incompatible.
1536+
1537+
14761538:mod: `encodings.idna ` --- Internationalized Domain Names in Applications
14771539------------------------------------------------------------------------
14781540
0 commit comments