Skip to content

Commit bac4fee

Browse files
authored
gh-73613: clarify padding= docs in for base64 & binascii modules (GH-148183)
Based on mayeut's comment in #147974 (comment).
1 parent ca960b6 commit bac4fee

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

Doc/library/base64.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,11 @@ POST request.
8585

8686
If *padded* is true, the last group of 4 base 64 alphabet characters must
8787
be padded with the '=' character.
88-
If *padded* is false, the '=' character is treated as other non-alphabet
89-
characters (depending on the value of *validate* and *ignorechars*).
88+
If *padded* is false, padding is neither required nor recognized:
89+
the '=' character is not treated as padding but as a non-alphabet
90+
character, which means it is silently discarded when *validate* is false,
91+
or causes an :exc:`~binascii.Error` when *validate* is true unless
92+
b'=' is included in *ignorechars*.
9093

9194
A :exc:`binascii.Error` exception is raised
9295
if *s* is incorrectly padded.
@@ -194,8 +197,10 @@ POST request.
194197

195198
If *padded* is true, the last group of 8 base 32 alphabet characters must
196199
be padded with the '=' character.
197-
If *padded* is false, the '=' character is treated as other non-alphabet
198-
characters (depending on the value of *ignorechars*).
200+
If *padded* is false, padding is neither required nor recognized:
201+
the '=' character is not treated as padding but as a non-alphabet
202+
character, which means it raises an :exc:`~binascii.Error` unless
203+
b'=' is included in *ignorechars*.
199204

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

Doc/library/binascii.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@ The :mod:`!binascii` module defines the following functions:
5959

6060
If *padded* is true, the last group of 4 base 64 alphabet characters must
6161
be padded with the '=' character.
62-
If *padded* is false, the '=' character is treated as other non-alphabet
63-
characters (depending on the value of *strict_mode* and *ignorechars*).
62+
If *padded* is false, padding is neither required nor recognized:
63+
the '=' character is not treated as padding but as a non-alphabet
64+
character, which means it is silently discarded when *strict_mode* is false,
65+
or causes an :exc:`~binascii.Error` when *strict_mode* is true unless
66+
b'=' is included in *ignorechars*.
6467

6568
If *ignorechars* is specified, it should be a :term:`bytes-like object`
6669
containing characters to ignore from the input when *strict_mode* is true.

0 commit comments

Comments
 (0)