3
}:a @ s d Z ddlZdd Zdd ZdS )a `JOSE Base64`_ is defined as:
- URL-safe Base64
- padding stripped
.. _`JOSE Base64`:
https://tools.ietf.org/html/draft-ietf-jose-json-web-signature-37#appendix-C
.. Do NOT try to call this module "base64", as it will "shadow" the
standard library.
Nc C s" t | tstdtj| jdS )zJOSE Base64 encode.
:param data: Data to be encoded.
:type data: bytes
:returns: JOSE Base64 string.
:rtype: bytes
:raises TypeError: if ``data`` is of incorrect type
zargument should be bytes =)
isinstancebytes TypeErrorbase64Zurlsafe_b64encoderstrip)data r /usr/lib/python3.6/b64.py b64encode s
r c C sh t | tr8y| jd} W qJ tk
r4 tdY qJX nt | tsJtdtj| ddt | d S )a^ JOSE Base64 decode.
:param data: Base64 string to be decoded. If it's unicode, then
only ASCII characters are allowed.
:type data: bytes or unicode
:returns: Decoded data.
:rtype: bytes
:raises TypeError: if input is of incorrect type
:raises ValueError: if input is unicode with non-ASCII characters
asciiz5unicode argument should contain only ASCII charactersz#argument should be a str or unicoder )
r strencodeUnicodeEncodeError
ValueErrorr r r Zurlsafe_b64decodelen)r r r r
b64decode! s
r )__doc__r r r r r r r