%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core/17212/usr/lib/python3/dist-packages/oauthlib/__pycache__/
Upload File :
Create Path :
Current File : //snap/core/17212/usr/lib/python3/dist-packages/oauthlib/__pycache__/common.cpython-35.pyc



}�U6�@s�dZddlmZmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
y4ddlmZ
ddlmZddlmZWnBek
r�ddlmZ
ddlmZddlmZYnXyddlZWn!ek
rddljZYnXdZdZejd	�Zejd
�ZdZejd�Ze	jdd
kZer�e Z!e"Z#ne$Z!e Z#ddd�Zdd�Zdd�Zdd�Z%dd�Z&e'e�e'd�BZ(dd�Z)dd�Z*dd�Z+d d!�Z,d"ed#d$�Z-d%d&�Z.d'd(�Z/d"ed)d*�Z0d+d,�Z1d-d.d/�Z2d0d1�Z3d2d3d4�Z4Gd5d6�d6e5�Z6Gd7d8�d8e7�Z8dS)9z|
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{|}zpassword=[^&]+z&%[^0-9A-Fa-f]|%[0-9A-Fa-f][^0-9A-Fa-f]zAABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-Zoauthlib��/cCsUt|t�r|jd�n|}t||�}t|t�rQ|jd�}|S)Nzutf-8)�
isinstance�unicode_type�encode�_quote�
bytes_type�decode)�sZsafe�r�1/usr/lib/python3/dist-packages/oauthlib/common.pyr;s
$rcCs.t|�}t|t�r*|jd�}|S)Nzutf-8)�_unquoter	r
r)rrrrrEsrcCs<t|�}t|�}t|t�r+|S|jd�SdS)Nzutf-8)�encode_params_utf8�
_urlencoder	r
r)�paramsZutf8_params�
urlencodedrrrrOs
rcCspg}xc|D][\}}|jt|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)rZencoded�k�vrrrrXs!,rcCspg}xc|D][\}}|jt|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)rr	r
r)rZdecodedrrrrr�decode_params_utf8ds!,rz
=&;%+~,*@!cCs�|r?t|�tkr?d}t|t|�t|f��tj|�rZtd��trt|t�r|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-8�keep_blank_valuesT)�setr�
ValueError�INVALID_HEX_PATTERN�search�PY3r	r
r�urlparse�	parse_qslr)�query�errorrrrr�	urldecodess
 +r%cCs�t|t�st|t�rLyt|�}Wq�tk
rHd}Yq�Xn�t|d�r�yt|�Wn/tk
r�d}Yq�tk
r�d}Yq�Xtt|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)�rawrrrr�extract_params�s 



'r-cCs tttjd��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_timestamprrrr�generate_nonce�sr1cCstttj���S)aBGet 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�timerrrrr0�s	r0�cs5tj��dj��fdd�t|�D��S)aXGenerates a non-guessable OAuth token

    OAuth (1 and 2) does not specify the format of tokens except that they
    should be strings of random characters. Tokens should not be guessable
    and entropy when generating the random characters is important. Which is
    why SystemRandom is used instead of the default random.choice method.
    �c3s|]}�j��VqdS)N)Zchoice)�.0�x)�chars�randrr�	<genexpr>�sz!generate_token.<locals>.<genexpr>)r/ZSystemRandom�join�range)�lengthr8r)r8r9r�generate_token�sr>cCs{ddl}tjj�}d|jd|tjd|j�i}|j|j�|j||d�}t	|d�}|S)Nr�scopeZexpZseconds�RS256zUTF-8)
�jwt�datetimeZutcnowr?Z	timedeltaZ
expires_in�update�claimsr�
to_unicode)Zprivate_pemZrequestrAZnowrD�tokenrrr�generate_signed_token�s	rGcCs%ddl}|j||ddg�S)NrZ
algorithmsr@)rAr)Z
public_pemrFrArrr�verify_signed_token�srHcCs
t||�S)z�Generates an OAuth client_id

    OAuth 2 specify the format of client_id in
    http://tools.ietf.org/html/rfc6749#appendix-A.
    )r>)r=r8rrr�generate_client_idsrIcCsGt|t�r|j�}tj|dd�}|j|�t|�S)z)Extend a query with a list of two-tuples.rT)r	r(r+r!r"�extendr)r#rZqueryparamsrrr�add_params_to_qs	s

rKFc	Csgtj|�\}}}}}}|r9t||�}nt||�}tj||||||f�S)z5Add a list of two-tuples to the uri query components.)r!rKZ
urlunparse)	�urirZfragmentZschZnet�pathZparr#Zfrarrr�add_params_to_uris
!rNcCsft|�t|�krdSd}x7t||�D]&\}}|t|�t|�AO}q2W|dkS)a Near-constant time string comparison.

    Used in order to avoid timing attacks on sensitive information such
    as secret keys during request verification (`rootLabs`_).

    .. _`rootLabs`: http://rdist.root.org/2010/01/07/timing-independent-array-comparison/

    Fr)�len�zip�ord)�a�b�resultr7�yrrr�safe_string_equalss	rVzUTF-8cs�t|t�r|St|t�r2t|d��St|d�r�yt|�Wn:tk
rcYnatk
r��fdd�|D�SYn9Xt|d�r�|j�}t�fdd�|D��S|S)z:Convert a number of different types of objects to unicode.�encodingr&c3s|]}t|��VqdS)N)rE)r6�i)rWrrr:=szto_unicode.<locals>.<genexpr>r+c3s3|])\}}t|��t|��fVqdS)N)rE)r6rr)rWrrr:Bs)r	r
r
r'r(r)rr+)�datarWr)rWrrE.s

rEcsyeZdZdZiZdd�Zdd�Z�fdd�Z�fdd	�Zd
dd�Z	�fd
d�Z
�S)�CaseInsensitiveDictz3Basic case insensitive dict with strings only keys.cCs?tdd�|D��|_x|D]}||||<q#WdS)Ncss!|]}|j�|fVqdS)N)�lower)r6rrrrr:Nsz/CaseInsensitiveDict.__init__.<locals>.<genexpr>)r(�proxy)�selfrYrrrr�__init__Ms
zCaseInsensitiveDict.__init__cCs|j�|jkS)N)r[r\)r]rrrr�__contains__Rsz CaseInsensitiveDict.__contains__cs=|j|j�}tt|�j|�|j|j�=dS)N)r\r[�superrZ�__delitem__)r]r�key)�	__class__rrraUszCaseInsensitiveDict.__delitem__cs)|j|j�}tt|�j|�S)N)r\r[r`rZ�__getitem__)r]rrb)rcrrrdZszCaseInsensitiveDict.__getitem__NcCs||kr||S|S)Nr)r]r�defaultrrr�get^szCaseInsensitiveDict.getcs0tt|�j||�||j|j�<dS)N)r`rZ�__setitem__r\r[)r]rr)rcrrrgaszCaseInsensitiveDict.__setitem__)�__name__�
__module__�__qualname__�__doc__r\r^r_rardrfrgrr)rcrrZGsrZc@s|eZdZdZdddddd�Zdd�Zd	d
�Zedd��Zed
d��Z	edd��Z
dS)�Requesta:A malleable representation of a signable HTTP request.

    Body argument may contain any data, but parameters will only be decoded if
    they are one of:

    * urlencoded query string
    * dict
    * list of 2-tuples

    Anything else will be treated as raw body data to be passed through
    unmolested.
    ZGETNzutf-8c s<�fdd�}||�|_||�|_t||p?i��|_||�|_t|j�|_g|_i|_ddddddddddddd	dd
dddddd
dddddddddddi|_	|j	j
tt|j
���|j	j
t|jpg��|j	j
|j�dS)Ncs�rt|��S|S)N)rE)r7)rWrr�<lambda>xsz"Request.__init__.<locals>.<lambda>Zaccess_tokenZclientZ	client_idZ
client_secret�codeZextra_credentialsZ
grant_typeZredirect_uriZ
refresh_tokenZ
response_typer?Zscopes�staterF�userZtoken_type_hint)rL�http_methodrZ�headers�bodyr-�decoded_bodyZoauth_paramsZ
validator_log�_paramsrCr(r%�	uri_query)r]rLrqrsrrrWrr)rWrr^us6		zRequest.__init__cCs*||jkr|j|St|��dS)N)ru�AttributeError)r]�namerrr�__getattr__�szRequest.__getattr__cCsJ|j}|r-d|kr-tjd|�}d|j|j|j|fS)Nz	password=zpassword=***zF<oauthlib.Request url="%s", http_method="%s", headers="%s", body="%s">)rs�PASSWORD_PATTERN�subrLrqrr)r]rsrrr�__repr__�s
	zRequest.__repr__cCstj|j�jS)N)r!rLr#)r]rrrrv�szRequest.uri_querycCs)|js
gStj|jdddd�S)NrTZstrict_parsing)rvr!r")r]rrr�uri_query_params�s	zRequest.uri_query_paramscCshtjt�}dd�|jp$g|jD�}x|D]}||d7<q9Wdd�|j�D�S)Ncss|]}|dVqdS)rNr)r6�prrrr:�sz+Request.duplicate_params.<locals>.<genexpr>�cSs(g|]\}}|dkr|�qS)rr)r6r�crrr�
<listcomp>�s	z,Request.duplicate_params.<locals>.<listcomp>)�collections�defaultdictr2rtr}r+)r]Z	seen_keysZall_keysrrrr�duplicate_params�s	
zRequest.duplicate_params)rhrirjrkr^ryr|�propertyrvr}r�rrrrrlfs
	"rl)9rkZ
__future__rrr�rBZloggingr/�re�sysr3Zurllibrrrrrr�ImportErrorZurllib.parser!�parseZUNICODE_ASCII_CHARACTER_SETZCLIENT_ID_CHARACTER_SET�compilerzrZalways_safeZ	getLogger�log�version_infor �strr
�bytesr
Zunicoderrrrr%r-r1r0r>rGrHrIrKrNrVrEr(rZ�objectrlrrrr�<module>sh

	

	1		


Zerion Mini Shell 1.0