Encode the bytes-like object s using Base64 and return a bytes object. Optional altchars should be a byte string of length 2 which specifies an alternative alphabet for the '+' and '/' characters. This allows an application to e.g. generate url or filesystem safe Base64 strings.
(s, altchars=None)
| 46 | # Base64 encoding/decoding uses binascii |
| 47 | |
| 48 | def b64encode(s, altchars=None): |
| 49 | """Encode the bytes-like object s using Base64 and return a bytes object. |
| 50 | |
| 51 | Optional altchars should be a byte string of length 2 which specifies an |
| 52 | alternative alphabet for the '+' and '/' characters. This allows an |
| 53 | application to e.g. generate url or filesystem safe Base64 strings. |
| 54 | """ |
| 55 | encoded = binascii.b2a_base64(s, newline=False) |
| 56 | if altchars is not None: |
| 57 | assert len(altchars) == 2, repr(altchars) |
| 58 | return encoded.translate(bytes.maketrans(b'+/', altchars)) |
| 59 | return encoded |
| 60 | |
| 61 | |
| 62 | def b64decode(s, altchars=None, validate=False): |