gh-146431: Add the wrapcol and ignorechars parameters for more Base XX codec by serhiy-storchaka · Pull Request #146434 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
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
79 changes: 69 additions & 10 deletions Doc/library/base64.rst
38 changes: 31 additions & 7 deletions Doc/library/binascii.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ The :mod:`!binascii` module defines the following functions:
Added the *alphabet* and *wrapcol* parameters.


.. function:: a2b_ascii85(string, /, *, foldspaces=False, adobe=False, ignorechars=b"")
.. function:: a2b_ascii85(string, /, *, foldspaces=False, adobe=False, ignorechars=b'')

Convert Ascii85 data back to binary and return the binary data.

Expand Down Expand Up @@ -151,7 +151,7 @@ The :mod:`!binascii` module defines the following functions:
.. versionadded:: 3.15


.. function:: a2b_base85(string, /, *, alphabet=BASE85_ALPHABET)
.. function:: a2b_base85(string, /, *, alphabet=BASE85_ALPHABET, ignorechars=b'')

Convert Base85 data back to binary and return the binary data.
More than one line may be passed at a time.
Expand All @@ -164,26 +164,33 @@ The :mod:`!binascii` module defines the following functions:
Optional *alphabet* must be a :class:`bytes` object of length 85 which
specifies an alternative alphabet.

*ignorechars* should be a :term:`bytes-like object` containing characters
to ignore from the input.

Invalid Base85 data will raise :exc:`binascii.Error`.

.. versionadded:: 3.15


.. function:: b2a_base85(data, /, *, alphabet=BASE85_ALPHABET, pad=False)
.. function:: b2a_base85(data, /, *, alphabet=BASE85_ALPHABET, wrapcol=0, pad=False)

Convert binary data to a line of ASCII characters in Base85 coding.
The return value is the converted line.

Optional *alphabet* must be a :term:`bytes-like object` of length 85 which
specifies an alternative alphabet.

If *wrapcol* is non-zero, insert a newline (``b'\n'``) character
after at most every *wrapcol* characters.
If *wrapcol* is zero (default), do not insert any newlines.

If *pad* is true, the input is padded with ``b'\0'`` so its length is a
multiple of 4 bytes before encoding.

.. versionadded:: 3.15


.. function:: a2b_base32(string, /, *, alphabet=BASE32_ALPHABET)
.. function:: a2b_base32(string, /, *, alphabet=BASE32_ALPHABET, ignorechars=b'')

Convert base32 data back to binary and return the binary data.

Expand All @@ -201,18 +208,28 @@ The :mod:`!binascii` module defines the following functions:
Optional *alphabet* must be a :class:`bytes` object of length 32 which
specifies an alternative alphabet.

*ignorechars* should be a :term:`bytes-like object` containing characters
to ignore from the input.
If *ignorechars* contains the pad character ``'='``, the pad characters
presented before the end of the encoded data and the excess pad characters
will be ignored.

Invalid base32 data will raise :exc:`binascii.Error`.

.. versionadded:: next

.. function:: b2a_base32(data, /, *, alphabet=BASE32_ALPHABET)
.. function:: b2a_base32(data, /, *, alphabet=BASE32_ALPHABET, wrapcol=0)

Convert binary data to a line of ASCII characters in base32 coding,
as specified in :rfc:`4648`. The return value is the converted line.

Optional *alphabet* must be a :term:`bytes-like object` of length 32 which
specifies an alternative alphabet.

If *wrapcol* is non-zero, insert a newline (``b'\n'``) character
after at most every *wrapcol* characters.
If *wrapcol* is zero (default), do not insert any newlines.

.. versionadded:: next

.. function:: a2b_qp(data, header=False)
Expand Down Expand Up @@ -288,18 +305,25 @@ The :mod:`!binascii` module defines the following functions:
.. versionchanged:: 3.8
The *sep* and *bytes_per_sep* parameters were added.

.. function:: a2b_hex(hexstr)
unhexlify(hexstr)
.. function:: a2b_hex(hexstr, *, ignorechars=b'')
unhexlify(hexstr, *, ignorechars=b'')

Return the binary data represented by the hexadecimal string *hexstr*. This
function is the inverse of :func:`b2a_hex`. *hexstr* must contain an even number
of hexadecimal digits (which can be upper or lower case), otherwise an
:exc:`Error` exception is raised.

*ignorechars* should be a :term:`bytes-like object` containing characters
to ignore from the input.

Similar functionality (accepting only text string arguments, but more
liberal towards whitespace) is also accessible using the
:meth:`bytes.fromhex` class method.

.. versionchanged:: next
Added the *ignorechars* parameter.


.. exception:: Error

Exception raised on errors. These are usually programming errors.
Expand Down
31 changes: 19 additions & 12 deletions Doc/whatsnew/3.15.rst
Loading
Loading