3
e                 @   s   d dl Z d dlZd dlZd dlZddlmZ ejee	f Z
de
eee	dddZe
e	d	d
dZe
e	d	ddZej ej djdZejdZejZejdejZee	dddZe	edddZdS )    N   )BadDatautf-8strict)sencodingerrorsreturnc             C   s   t | tr| j||} | S )N)
isinstancestrencode)r   r   r    r   =/tmp/pip-build-3irwxpxt/itsdangerous/itsdangerous/encoding.py
want_bytes   s    
r   )stringr	   c             C   s   t | } tj| jdS )z^Base64 encode a string of bytes or text. The resulting bytes are
    safe to use in URLs.
       =)r   base64urlsafe_b64encoderstrip)r   r   r   r   base64_encode   s    r   c             C   sT   t | ddd} | dt|  d  7 } y
tj| S  ttfk
rN   tdY nX dS )zOBase64 decode a URL-safe string of bytes or text. The result is
    bytes.
    asciiignore)r   r   r      zInvalid base64-encoded dataN)r   lenr   urlsafe_b64decode	TypeError
ValueErrorr   )r   r   r   r   base64_decode   s    
r   z-_=r   z>Qz#_t.Callable[[bytes], _t.Tuple[int]])numr	   c             C   s   t | jdS )N    )_int_to_byteslstrip)r   r   r   r   int_to_bytes1   s    r"   )bytestrr	   c             C   s   t | jddd S )N   r   r   )_bytes_to_intrjust)r#   r   r   r   bytes_to_int5   s    r'   )r   r   )r   r   structtypingZ_texcr   Unionr   bytesZ_t_str_bytesr   r   r   ascii_lettersdigitsr   Z_base64_alphabetStructZ_int64_structpackr    castunpackr%   intr"   r'   r   r   r   r   <module>   s   
