ó
›t0^c           @   s4   d  Z  d d l Z d d l Z d „  Z d „  Z d S(   s  `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.

iÿÿÿÿNc         C   sC   t  |  t j ƒ s- t d j t j ƒ ƒ ‚ n  t j |  ƒ j d ƒ S(   sÃ   JOSE 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

    s   argument should be {0}t   =(   t
   isinstancet   sixt   binary_typet	   TypeErrort   formatt   base64t   urlsafe_b64encodet   rstrip(   t   data(    (    s.   /usr/lib/python2.7/site-packages/josepy/b64.pyt	   b64encode   s    c         C   sŒ   t  |  t j ƒ rH y |  j d ƒ }  Wqi t k
 rD t d ƒ ‚ qi Xn! t  |  t j ƒ si t d ƒ ‚ n  t j	 |  d d t
 |  ƒ d ƒ S(   s^  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

    t   asciis5   unicode argument should contain only ASCII characterss#   argument should be a str or unicodeR    i   (   R   R   t   string_typest   encodet   UnicodeEncodeErrort
   ValueErrorR   R   R   t   urlsafe_b64decodet   len(   R	   (    (    s.   /usr/lib/python2.7/site-packages/josepy/b64.pyt	   b64decode#   s    (   t   __doc__R   R   R
   R   (    (    (    s.   /usr/lib/python2.7/site-packages/josepy/b64.pyt   <module>   s   	