@@ -51,7 +51,7 @@ The :rfc:`4648` encodings are suitable for encoding binary data so that it can b
5151safely sent by email, used as parts of URLs, or included as part of an HTTP
5252POST request.
5353
54- .. function :: b64encode(s, altchars=None, *, wrapcol=0)
54+ .. function :: b64encode(s, altchars=None, *, padded=True, wrapcol=0)
5555
5656 Encode the :term: `bytes-like object ` *s * using Base64 and return the encoded
5757 :class: `bytes `.
@@ -61,6 +61,10 @@ POST request.
6161 This allows an application to e.g. generate URL or filesystem safe Base64
6262 strings. The default is ``None ``, for which the standard Base64 alphabet is used.
6363
64+ If *padded * is true (default), pad the encoded data with the '='
65+ character to a size multiple of 4.
66+ If *padded * is false, do not add the pad characters.
67+
6468 If *wrapcol * is non-zero, insert a newline (``b'\n' ``) character
6569 after at most every *wrapcol * characters.
6670 If *wrapcol * is zero (default), do not insert any newlines.
@@ -69,11 +73,11 @@ POST request.
6973 :exc: `TypeError ` if *altchars * is not a :term: `bytes-like object `.
7074
7175 .. versionchanged :: 3.15
72- Added the *wrapcol * parameter .
76+ Added the *padded * and * wrapcol * parameters .
7377
7478
75- .. function :: b64decode(s, altchars=None, validate=False)
76- b64decode(s, altchars=None, validate=True, *, ignorechars)
79+ .. function :: b64decode(s, altchars=None, validate=False, *, padded=True )
80+ b64decode(s, altchars=None, validate=True, *, ignorechars, padded=True )
7781
7882 Decode the Base64 encoded :term: `bytes-like object ` or ASCII string
7983 *s * and return the decoded :class: `bytes `.
@@ -82,6 +86,11 @@ POST request.
8286 of length 2 which specifies the alternative alphabet used instead of the
8387 ``+ `` and ``/ `` characters.
8488
89+ If *padded * is true, the last group of 4 base 64 alphabet characters must
90+ be padded with the '=' character.
91+ If *padded * is false, the '=' character is treated as other non-alphabet
92+ characters (depending on the value of *validate * and *ignorechars *).
93+
8594 A :exc: `binascii.Error ` exception is raised
8695 if *s * is incorrectly padded.
8796
@@ -106,7 +115,7 @@ POST request.
106115 For more information about the strict base64 check, see :func: `binascii.a2b_base64 `
107116
108117 .. versionchanged :: 3.15
109- Added the *ignorechars * parameter .
118+ Added the *ignorechars * and * padded * parameters .
110119
111120 .. deprecated :: 3.15
112121 Accepting the ``+ `` and ``/ `` characters with an alternative alphabet
@@ -125,41 +134,52 @@ POST request.
125134 Base64 alphabet and return the decoded :class: `bytes `.
126135
127136
128- .. function :: urlsafe_b64encode(s)
137+ .. function :: urlsafe_b64encode(s, *, padded=True )
129138
130139 Encode :term: `bytes-like object ` *s * using the
131140 URL- and filesystem-safe alphabet, which
132141 substitutes ``- `` instead of ``+ `` and ``_ `` instead of ``/ `` in the
133142 standard Base64 alphabet, and return the encoded :class: `bytes `. The result
134- can still contain ``= ``.
143+ can still contain ``= `` if *padded * is true (default).
144+
145+ .. versionchanged :: next
146+ Added the *padded * parameter.
135147
136148
137- .. function :: urlsafe_b64decode(s)
149+ .. function :: urlsafe_b64decode(s, *, padded=False )
138150
139151 Decode :term: `bytes-like object ` or ASCII string *s *
140152 using the URL- and filesystem-safe
141153 alphabet, which substitutes ``- `` instead of ``+ `` and ``_ `` instead of
142154 ``/ `` in the standard Base64 alphabet, and return the decoded
143155 :class: `bytes `.
144156
157+ .. versionchanged :: next
158+ Added the *padded * parameter.
159+ Padding of input is no longer required by default.
160+
145161 .. deprecated :: 3.15
146162 Accepting the ``+ `` and ``/ `` characters is now deprecated.
147163
148164
149- .. function :: b32encode(s, *, wrapcol=0)
165+ .. function :: b32encode(s, *, padded=True, wrapcol=0)
150166
151167 Encode the :term: `bytes-like object ` *s * using Base32 and return the
152168 encoded :class: `bytes `.
153169
170+ If *padded * is true (default), pad the encoded data with the '='
171+ character to a size multiple of 8.
172+ If *padded * is false, do not add the pad characters.
173+
154174 If *wrapcol * is non-zero, insert a newline (``b'\n' ``) character
155175 after at most every *wrapcol * characters.
156176 If *wrapcol * is zero (default), do not add any newlines.
157177
158178 .. versionchanged :: next
159- Added the *wrapcol * parameter .
179+ Added the *padded * and * wrapcol * parameters .
160180
161181
162- .. function :: b32decode(s, casefold=False, map01=None, *, ignorechars=b'')
182+ .. function :: b32decode(s, casefold=False, map01=None, *, padded=True, ignorechars=b'')
163183
164184 Decode the Base32 encoded :term: `bytes-like object ` or ASCII string *s * and
165185 return the decoded :class: `bytes `.
@@ -175,6 +195,11 @@ POST request.
175195 digit 0 is always mapped to the letter O). For security purposes the default is
176196 ``None ``, so that 0 and 1 are not allowed in the input.
177197
198+ If *padded * is true, the last group of 8 base 32 alphabet characters must
199+ be padded with the '=' character.
200+ If *padded * is false, the '=' character is treated as other non-alphabet
201+ characters (depending on the value of *ignorechars *).
202+
178203 *ignorechars * should be a :term: `bytes-like object ` containing characters
179204 to ignore from the input.
180205
@@ -183,21 +208,21 @@ POST request.
183208 input.
184209
185210 .. versionchanged :: next
186- Added the *ignorechars * parameter .
211+ Added the *ignorechars * and * padded * parameters .
187212
188213
189- .. function :: b32hexencode(s, *, wrapcol=0)
214+ .. function :: b32hexencode(s, *, padded=True, wrapcol=0)
190215
191216 Similar to :func: `b32encode ` but uses the Extended Hex Alphabet, as defined in
192217 :rfc: `4648 `.
193218
194219 .. versionadded :: 3.10
195220
196221 .. versionchanged :: next
197- Added the *wrapcol * parameter .
222+ Added the *padded * and * wrapcol * parameters .
198223
199224
200- .. function :: b32hexdecode(s, casefold=False, *, ignorechars=b'')
225+ .. function :: b32hexdecode(s, casefold=False, *, padded=True, ignorechars=b'')
201226
202227 Similar to :func: `b32decode ` but uses the Extended Hex Alphabet, as defined in
203228 :rfc: `4648 `.
@@ -210,7 +235,7 @@ POST request.
210235 .. versionadded :: 3.10
211236
212237 .. versionchanged :: next
213- Added the *ignorechars * parameter .
238+ Added the *ignorechars * and * padded * parameters .
214239
215240
216241.. function :: b16encode(s, *, wrapcol=0)
0 commit comments