File: //snap/core18/current/usr/lib/python3/dist-packages/oauthlib/__pycache__/common.cpython-36.pyc
3
%��Y�8 � @ s� d Z ddlmZmZ ddlZddlZddlZddlZddlZddl Z ddl
Z
y(ddlmZ
ddlmZ ddlmZ W n8 ek
r� ddlmZ
ddlmZ ddlmZ Y nX yddlZW n ek
r� ddljZY nX dZdZejd ej�Zejd
�ZdZejd�Ze jd d
kZ e �r&e!Z"e#Z$ne%Z"e!Z$d9dd�Zdd� Zdd� Zdd� Z&dd� Z'e(e�e(d�B Z)dd� Z*dd� Z+dd� Z,d d!� Z-d"efd#d$�Z.d%d&� Z/d'd(� Z0d"efd)d*�Z1d+d,� Z2d:d.d/�Z3d0d1� Z4d;d3d4�Z5G d5d6� d6e6�Z7G d7d8� d8e8�Z9dS )<z|
oauthlib.common
~~~~~~~~~~~~~~
This module provides data structures and utilities common
to all implementations of OAuth.
� )�absolute_import�unicode_literalsN)�quote)�unquote)� urlencodeZ>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789z_ !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}z&([^&;]*(?:password|token)[^=]*=)[^&;]+z&%[^0-9A-Fa-f]|%[0-9A-Fa-f][^0-9A-Fa-f]zAABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-Zoauthlib� � /c C s: t | t�r| jd�n| } t| |�} t | t�r6| jd�} | S )Nzutf-8)�
isinstance�unicode_type�encode�_quote�
bytes_type�decode)�sZsafe� r �1/usr/lib/python3/dist-packages/oauthlib/common.pyr ; s
r c C s t | �} t| t�r| jd�} | S )Nzutf-8)�_unquoter r
r )r r r r r E s
r c C s, t | �}t|�}t|t�r|S |jd�S d S )Nzutf-8)�encode_params_utf8�
_urlencoder r
r )�paramsZutf8_params�
urlencodedr r r r O s
r c C sP g }xF| D ]>\}}|j t|t�r*|jd�n|t|t�r@|jd�n|f� q
W |S )ziEnsures that all parameters in a list of 2-element tuples are encoded to
bytestrings using UTF-8
zutf-8)�appendr r
r )r Zencoded�k�vr r r r X s r c C sP g }xF| D ]>\}}|j t|t�r*|jd�n|t|t�r@|jd�n|f� q
W |S )zfEnsures that all parameters in a list of 2-element tuples are decoded to
unicode using UTF-8.
zutf-8)r r r
r )r Zdecodedr r r r r �decode_params_utf8d s r z=&;:%+~,*@!()/?c C st | r.t | �tk r.d}t|t | �t | f ��tj| �r@td��t rZt| t�rZ| jd�n| } t j
| dd�}t|�S )a� Decode a query string in x-www-form-urlencoded format into a sequence
of two-element tuples.
Unlike urlparse.parse_qsl(..., strict_parsing=True) urldecode will enforce
correct formatting of the query string by validation. If validation fails
a ValueError will be raised. urllib.parse_qsl will only raise errors if
any of name-value pairs omits the equals sign.
z�Error trying to decode a non urlencoded string. Found invalid characters: %s in the string: '%s'. Please ensure the request/response body is x-www-form-urlencoded.z%Invalid hex encoding in query string.zutf-8T)�keep_blank_values)�setr �
ValueError�INVALID_HEX_PATTERN�search�PY3r r
r �urlparse� parse_qslr )�query�errorr r r r � urldecodes s
r% c C s� t | t�st | t�r<yt| �}W q� tk
r8 d}Y q�X nnt| d�r�yt| � W n. tk
rj d}Y q� tk
r� d}Y q�X tt | t�r�| j � n| �}t
|�}nd}|S )a* Extract parameters and return them as a list of 2-tuples.
Will successfully extract parameters from urlencoded query strings,
dicts, or lists of 2-tuples. Empty strings/dicts/lists will return an
empty list of parameters. Any other input will result in a return
value of None.
N�__iter__)r r
r
r% r �hasattr�dict� TypeError�list�itemsr )�rawr r r r �extract_params� s
r- c C s t t tjd��t� �S )a� Generate pseudorandom nonce that is unlikely to repeat.
Per `section 3.3`_ of the OAuth 1 RFC 5849 spec.
Per `section 3.2.1`_ of the MAC Access Authentication spec.
A random 64-bit number is appended to the epoch timestamp for both
randomness and to decrease the likelihood of collisions.
.. _`section 3.2.1`: http://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-01#section-3.2.1
.. _`section 3.3`: http://tools.ietf.org/html/rfc5849#section-3.3
�@ )r
�randomZgetrandbits�generate_timestampr r r r �generate_nonce� s r1 c C s t ttj� ��S )aB Get seconds since epoch (UTC).
Per `section 3.3`_ of the OAuth 1 RFC 5849 spec.
Per `section 3.2.1`_ of the MAC Access Authentication spec.
.. _`section 3.2.1`: http://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-01#section-3.2.1
.. _`section 3.3`: http://tools.ietf.org/html/rfc5849#section-3.3
)r
�int�timer r r r r0 � s r0 � c s&