Decode the Base64 encoded bytes-like object or ASCII string s. Optional altchars must be a bytes-like object or ASCII string of length 2 which specifies the alternative alphabet used instead of the '+' and '/' characters. The result is returned as a bytes object. A binascii.Error
(s, altchars=None, validate=False)
| 60 | |
| 61 | |
| 62 | def b64decode(s, altchars=None, validate=False): |
| 63 | """Decode the Base64 encoded bytes-like object or ASCII string s. |
| 64 | |
| 65 | Optional altchars must be a bytes-like object or ASCII string of length 2 |
| 66 | which specifies the alternative alphabet used instead of the '+' and '/' |
| 67 | characters. |
| 68 | |
| 69 | The result is returned as a bytes object. A binascii.Error is raised if |
| 70 | s is incorrectly padded. |
| 71 | |
| 72 | If validate is False (the default), characters that are neither in the |
| 73 | normal base-64 alphabet nor the alternative alphabet are discarded prior |
| 74 | to the padding check. If validate is True, these non-alphabet characters |
| 75 | in the input result in a binascii.Error. |
| 76 | For more information about the strict base64 check, see: |
| 77 | |
| 78 | https://docs.python.org/3.11/library/binascii.html#binascii.a2b_base64 |
| 79 | """ |
| 80 | s = _bytes_from_decode_data(s) |
| 81 | if altchars is not None: |
| 82 | altchars = _bytes_from_decode_data(altchars) |
| 83 | assert len(altchars) == 2, repr(altchars) |
| 84 | s = s.translate(bytes.maketrans(altchars, b'+/')) |
| 85 | return binascii.a2b_base64(s, strict_mode=validate) |
| 86 | |
| 87 | |
| 88 | def standard_b64encode(s): |
no test coverage detected