
    qhA4                        S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSKJ	r
JrJr  SSKJr   SSKJrJr  SrS	r\R2                  " S
\R4                  5      r\R2                  " S5      rSr\R<                  " S5      rS%S jr	S rS rS r S r!\"" \5      \"" S5      -  r#S r$S r%S r&S r'S\4S jr(S r)S r*S\4S jr+S r,S&S jr-S r.S'S  jr/ " S! S"\05      r1 " S# S$5      r2g! \ a    SSKJrJr   Nf = f)(z|
oauthlib.common
~~~~~~~~~~~~~~

This module provides data structures and utilities common
to all implementations of OAuth.
    N)quoteunquote	urlencode   )	get_debug)SystemRandomrandbits)r   getrandbits>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789z_ !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}z&([^&;]*(?:password|token)[^=]*=)[^&;]+z&%[^0-9A-Fa-f]|%[0-9A-Fa-f][^0-9A-Fa-f]zAABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-oauthlibc                     [        U [        5      (       a  U R                  S5      OU n [        X5      n [        U [        5      (       a  U R                  S5      n U $ Nutf-8)
isinstancestrencode_quotebytesdecode)ssafes     A/var/www/html/env/lib/python3.13/site-packages/oauthlib/common.pyr   r   +   sI    '3//QAqA !UHHWH    c                 h    [        U 5      n [        U [        5      (       a  U R                  S5      n U $ r   )_unquoter   r   r   )r   s    r   r   r   5   s-    A !UHHWHr   c                 ~    [        U 5      n[        U5      n[        U[        5      (       a  U$ UR	                  S5      $ r   )encode_params_utf8
_urlencoder   r   r   )paramsutf8_params
urlencodeds      r   r   r   ?   s:    $V,KK(J*c""  ))r   c                     / nU  Hd  u  p#UR                  [        U[        5      (       a  UR                  S5      OU[        U[        5      (       a  UR                  S5      OU45        Mf     U$ )zaEnsures that all parameters in a list of 2-element tuples are encoded to
bytestrings using UTF-8
r   )appendr   r   r   )r   encodedkvs       r   r   r   H   sa     G!+As!3!3AHHW!+As!3!3AHHW< 	=  Nr   c                     / nU  Hd  u  p#UR                  [        U[        5      (       a  UR                  S5      OU[        U[        5      (       a  UR                  S5      OU45        Mf     U$ )z^Ensures that all parameters in a list of 2-element tuples are decoded to
unicode using UTF-8.
r   )r#   r   r   r   )r   decodedr%   r&   s       r   decode_params_utf8r)   T   sa     G!+Au!5!5AHHW1!+Au!5!5AHHW1> 	?  Nr   z=&;:%+~,*@!()/?'$c                    U (       a5  [        U 5      [        ::  d"  Sn[        U[        U 5      [        -
  U 4-  5      e[        R	                  U 5      (       a  [        S5      e[
        R                  " U SS9n[        U5      $ )aj  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.
zError 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.Tkeep_blank_values)setr!   
ValueErrorINVALID_HEX_PATTERNsearchurlparse	parse_qslr)   )queryerrorr   s      r   	urldecoder5   c   sy     SZ:-*
 #e*z"95!AABB !!%((@AA >F f%%r   c                 x   [        U [        [        45      (       a   [        U 5      nU$ [        U S5      (       aI   [        U 5        [        [        U [        5      (       a  U R                  5       OU 5      n[        U5      nU$ SnU$ ! [         a    Sn U$ f = f! [         a    Sn U$ [         a    Sn U$ f = f)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   r5   r.   hasattrdictlistitemsr)   	TypeError)rawr   s     r   extract_paramsr>      s     #s|$$	s^F  M 
j	!	!	0I C)>)>#))+CHF'/F M M  	F M	
  	F M  	F M	s(   B B BBB9*B98B9c                  R    [        [        [        S5      5      [        5       -   5      $ )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`: https://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-01#section-3.2.1
.. _`section 3.3`: https://tools.ietf.org/html/rfc5849#section-3.3
@   )r   r	   generate_timestamp r   r   generate_noncerC      s!     s8B< #5#7788r   c                  P    [        [        [        R                  " 5       5      5      $ )a0  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`: https://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-01#section-3.2.1
.. _`section 3.3`: https://tools.ietf.org/html/rfc5849#section-3.3
)r   inttimerB   r   r   rA   rA      s     s499;  r      c                 d   ^^ [        5       mSR                  UU4S j[        U 5       5       5      $ )aD  Generates 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.
 c              3   F   >#    U  H  nTR                  T5      v   M     g 7fN)choice).0xcharsrands     r   	<genexpr>!generate_token.<locals>.<genexpr>   s     =}!4;;u%%}s   !)r   joinrange)lengthrO   rP   s    `@r   generate_tokenrV      s%     >D77=uV}===r   c                    SS K n[        R                  R                  5       nUR                  U[        R                  " UR
                  S9-   S.nUR                  UR                  5        UR                  X@S5      n[        US5      nU$ )Nr   )seconds)scopeexpRS256UTF-8)
jwtdatetimeutcnowrY   	timedelta
expires_inupdateclaimsr   
to_unicode)private_pemrequestr]   nowrc   tokens         r   generate_signed_tokenri      su    



"
"
$C X''0B0BCCF
 MM'..!JJvG4Eug&ELr   c                 ,    SS K nUR                  XS/S9$ )Nr   r[   )
algorithms)r]   r   )
public_pemrh   r]   s      r   verify_signed_tokenrm      s    ::eWI:>>r   c                     [        X5      $ )zyGenerates an OAuth client_id

OAuth 2 specify the format of client_id in
https://tools.ietf.org/html/rfc6749#appendix-A.
)rV   )rU   rO   s     r   generate_client_idro      s     &((r   c                     [        U[        5      (       a  UR                  5       n[        R                  " U SS9nUR                  U5        [        U5      $ )z)Extend a query with a list of two-tuples.Tr+   )r   r9   r;   r1   r2   extendr   )r3   r   queryparamss      r   add_params_to_qsrs      sE    &$$$UdCKv[!!r   c                     [         R                   " U 5      u  p4pVpxU(       a  [        X5      nO[        Xq5      n[         R                  " X4XVXx45      $ )z5Add a list of two-tuples to the uri query components.)r1   rs   
urlunparse)	urir   fragmentschnetpathparr3   fras	            r   add_params_to_urir}      sH    &.&7&7&<#Cds+ /$U@AAr   c                     [        U 5      [        U5      :w  a  gSn[        X5       H  u  p4U[        U5      [        U5      -  -  nM!     US:H  $ )zNear-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resultrN   ys        r   safe_string_equalsr      sL     1vQFA	#a&3q6/! Q;r   c           	        ^ [        U [        5      (       a  U $ [        U [        5      (       a
  [        U TS9$ [        U S5      (       aY   [	        U 5        [        U S5      (       a  U R                  5       n U  VVs0 s H  u  p#[        UT5      [        UT5      _M     snn$ U $ s  snnf ! [         a     U $ [         a    U4S jU  5       s $ f = f)z:Convert a number of different types of objects to unicode.)encodingr7   r;   c              3   <   >#    U  H  n[        UT5      v   M     g 7frK   rd   )rM   ir   s     r   rQ   to_unicode.<locals>.<genexpr>  s     :TJq(++Ts   )	r   r   r   r8   r9   r;   rd   r<   r.   )datar   r%   r&   s    `  r   rd   rd     s    $$4(++tZ  	WJ tW%%zz|QUVQUJq(+Z8-DDQUVVK W  	 K  	;:T::	;s   
B* ;#B$*
C7CCc                   j   ^  \ rS rSrSr0 rS rS rU 4S jrU 4S jr	SS jr
U 4S jrU 4S	 jrS
rU =r$ )CaseInsensitiveDicti'  z3Basic case insensitive dict with strings only keys.c                 x    U Vs0 s H  o"R                  5       U_M     snU l        U H	  nX   X'   M     g s  snf rK   lowerproxy)selfr   r%   s      r   __init__CaseInsensitiveDict.__init__-  s8    ,01DqggilD1
AgDG  2s   7c                 <    UR                  5       U R                  ;   $ rK   r   )r   r%   s     r   __contains__ CaseInsensitiveDict.__contains__2  s    wwyDJJ&&r   c                    > U R                   UR                  5          n[        TU ]  U5        U R                   UR                  5       	 g rK   )r   r   super__delitem__r   r%   key	__class__s      r   r   CaseInsensitiveDict.__delitem__5  s6    jj#C JJqwwy!r   c                 \   > U R                   UR                  5          n[        TU ]  U5      $ rK   )r   r   r   __getitem__r   s      r   r   CaseInsensitiveDict.__getitem__:  s'    jj#w"3''r   c                     X;   a  X   $ U$ rK   rB   )r   r%   defaults      r   getCaseInsensitiveDict.get>  s    )tw00r   c                 \   > [         TU ]  X5        XR                  UR                  5       '   g rK   )r   __setitem__r   r   )r   r%   r&   r   s      r   r   CaseInsensitiveDict.__setitem__A  s"    A! !

1779r   c                    > [         TU ]  " U0 UD6  [        U0 UD6 H  nX0R                  UR	                  5       '   M!     g rK   )r   rb   r9   r   r   )r   argskwargsr%   r   s       r   rb   CaseInsensitiveDict.updateE  s:    ''t&v&A$%JJqwwy! 'r   )r   rK   )__name__
__module____qualname____firstlineno____doc__r   r   r   r   r   r   r   rb   __static_attributes____classcell__)r   s   @r   r   r   '  s3    =E
'"
(1"& &r   r   c                   b    \ rS rSrSr  SS jrS rS r\S 5       r	\S 5       r
\S	 5       rS
rg)RequestiK  a  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.
Nc                 ^  ^ U4S jnU" U5      U l         U" U5      U l        [        U" U=(       d    0 5      5      U l        U" U5      U l        [        U R                  5      U l        / U l        0 U l        0 SS _SS _SS _SS _SS _SS _SS _S	S _S
S _SS _SS _SS _SS _SS _SS _SS _SS _S S S S S S S S S S S S S S.EU l	        U R                  R                  [        [        U R                  5      5      5        U R                  R                  [        U R                  =(       d    / 5      5        g )Nc                 .   > T(       a  [        U T5      $ U $ rK   r   )rN   r   s    r   <lambda>"Request.__init__.<locals>.<lambda>]  s    h:a2EAEr   access_tokenclient	client_idclient_secretcodecode_challengecode_challenge_methodcode_verifierextra_credentials
grant_typeredirect_urirefresh_tokenrequest_tokenresponse_typerY   scopesstate)rh   usertoken_type_hintresponse_modenoncedisplaypromptrc   max_age
ui_localesid_token_hint
login_hint
acr_values)rv   http_methodr   headersbodyr>   decoded_bodyoauth_paramsvalidator_log_paramsrb   r9   r5   	uri_query)r   rv   r   r   r   r   r   s        ` r   r   Request.__init__Z  s    F#;!+.*6'-R+@A4L	*4995!
D!
d!
 !
 T	!

 D!
 d!
 $T!
 T!
  !
 $!
 D!
 T!
 T!
 T!
 T!
  d!!
" T#!
$ # "!A!
D 	D4>>!:;<D!2!2!8b9:r   c                 T    XR                   ;   a  U R                   U   $ [        U5      erK   )r   AttributeError)r   names     r   __getattr__Request.__getattr__  s&    <<<<%% &&r   c                    [        5       (       d  gU R                  nU R                  R                  5       nU(       a  [        R                  S[        U5      5      nSU;   a  SUS'   SR                  U R                  U R                  X!5      $ )Nz<oauthlib.Request SANITIZED>z<SANITIZED>Authorizationz<SANITIZED>zF<oauthlib.Request url="{}", http_method="{}", headers="{}", body="{}">)
r   r   r   copySANITIZE_PATTERNsubr   formatrv   r   )r   r   r   s      r   __repr__Request.__repr__  sv    {{1yy,,##%#''TCDg%'4GO$W^^HHd&&7 	7r   c                 V    [         R                   " U R                  5      R                  $ rK   )r1   rv   r3   r   s    r   r   Request.uri_query  s      *000r   c                 h    U R                   (       d  / $ [        R                  " U R                   SSS9$ )NT)r,   strict_parsing)r   r1   r2   r   s    r   uri_query_paramsRequest.uri_query_params  s,    ~~I!!$..D157 	7r   c                    [         R                  " [        5      nS U R                  =(       d    / U R                  -    5       nU H  nX==   S-  ss'   M     UR                  5        VVs/ s H  u  p4US:  d  M  UPM     snn$ s  snnf )Nc              3   ,   #    U  H
  nUS    v   M     g7f)r   NrB   )rM   ps     r   rQ   +Request.duplicate_params.<locals>.<genexpr>  s      PN aDNs   r   )collectionsdefaultdictrE   r   r   r;   )r   	seen_keysall_keysr%   cs        r   duplicate_paramsRequest.duplicate_params  sx    ++C0	P"//529N9NNPALAL 'oo/9/da1q5/999s   ,B<B)r   r   r   r   r   r   rv   r   )GETNNr   )r   r   r   r   r   r   r   r   propertyr   r   r   r   rB   r   r   r   r   K  s]     CG!0;d'
7 1 1 7 7 : :r   r   )   /)F)r\   )3r   r   r^   loggingrerF   urllib.parseparser1   r   r   r   r   r   r   rI   r   secretsr   r	   ImportErrorrandomr
   UNICODE_ASCII_CHARACTER_SETCLIENT_ID_CHARACTER_SETcompile
IGNORECASEr   r/   always_safe	getLoggerlogr   r)   r-   r!   r5   r>   rC   rA   rV   ri   rm   ro   rs   r}   r   rd   r9   r   r   rB   r   r   <module>r     s6      	    =. , N  ::GW jj!JK " 
#*		 $8 99
&B:9	! $? 	>$? !(? )"B$2!&$ !&He: e:k	  =<<=s   C% %C65C6