Decode bytes using the URL- and filesystem-safe Base64 alphabet. Argument s is a bytes-like object or ASCII string to decode. The result is returned as a bytes object. A binascii.Error is raised if the input is incorrectly padded. Characters that are not in the URL-safe base-64 a
(s, *, padded=False)
| 163 | alphabet=binascii.URLSAFE_BASE64_ALPHABET) |
| 164 | |
| 165 | def urlsafe_b64decode(s, *, padded=False): |
| 166 | """Decode bytes using the URL- and filesystem-safe Base64 alphabet. |
| 167 | |
| 168 | Argument s is a bytes-like object or ASCII string to decode. The result |
| 169 | is returned as a bytes object. A binascii.Error is raised if the input |
| 170 | is incorrectly padded. Characters that are not in the URL-safe base-64 |
| 171 | alphabet, and are not a plus '+' or slash '/', are discarded prior to the |
| 172 | padding check. |
| 173 | |
| 174 | If padded is false, padding in input is not required. |
| 175 | |
| 176 | The alphabet uses '-' instead of '+' and '_' instead of '/'. |
| 177 | """ |
| 178 | s = _bytes_from_decode_data(s) |
| 179 | badchar = None |
| 180 | for b in b'+/': |
| 181 | if b in s: |
| 182 | badchar = b |
| 183 | break |
| 184 | s = s.translate(_urlsafe_decode_translation) |
| 185 | result = binascii.a2b_base64(s, strict_mode=False, padded=padded) |
| 186 | if badchar is not None: |
| 187 | import warnings |
| 188 | warnings.warn(f'invalid character {chr(badchar)!a} in URL-safe Base64 data ' |
| 189 | f'will be discarded in future Python versions', |
| 190 | FutureWarning, stacklevel=2) |
| 191 | return result |
| 192 | |
| 193 | |
| 194 |
searching dependent graphs…