
    qhhA                         S 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
JrJr  SSKJrJr  \R                   " \5      rSrSrSr\rS	rS
rSr\rSr\\\\\\\4rSrSrSrSr  " S S5      r!g)a  
oauthlib.oauth1.rfc5849
~~~~~~~~~~~~~~

This module is an implementation of various logic needed
for signing and checking OAuth 1.0 RFC 5849 requests.

It supports all three standard signature methods defined in RFC 5849:

- HMAC-SHA1
- RSA-SHA1
- PLAINTEXT

It also supports signature methods that are not defined in RFC 5849. These are
based on the standard ones but replace SHA-1 with the more secure SHA-256:

- HMAC-SHA256
- RSA-SHA256

    N)Requestgenerate_noncegenerate_timestamp
to_unicode	urlencode   )
parameters	signaturez	HMAC-SHA1zHMAC-SHA256zHMAC-SHA512zRSA-SHA1z
RSA-SHA256z
RSA-SHA512	PLAINTEXTAUTH_HEADERQUERYBODY!application/x-www-form-urlencodedc                      \ rS rSrSr\\R                  \\R                  \
\R                  \\R                  \\R                  \\R"                  \\R&                  0r\S 5       rSSSS\\SSSSSSS4S jrS rS rS	 rSS
 jrSS jrSrg)ClientJ   z2A client used to sign OAuth 1.0 RFC 5849 requests.c                      X R                   U'   g N)SIGNATURE_METHODS)clsmethod_namemethod_callbacks      R/var/www/html/env/lib/python3.13/site-packages/oauthlib/oauth1/rfc5849/__init__.pyregister_signature_method Client.register_signature_methodW   s    -<k*    Nutf-8c                 ~  ^ U4S jnU" U5      U l         U" U5      U l        U" U5      U l        U" U5      U l        U" U5      U l        U" U5      U l        U" U5      U l        U" U5      U l        U" U	5      U l        U" U
5      U l	        U" T5      U l
        U" U5      U l        U" U5      U l        U" U5      U l        g)a  Create an OAuth 1 client.

:param client_key: Client key (consumer key), mandatory.
:param resource_owner_key: Resource owner key (oauth token).
:param resource_owner_secret: Resource owner secret (oauth token secret).
:param callback_uri: Callback used when obtaining request token.
:param signature_method: SIGNATURE_HMAC, SIGNATURE_RSA or SIGNATURE_PLAINTEXT.
:param signature_type: SIGNATURE_TYPE_AUTH_HEADER (default),
                       SIGNATURE_TYPE_QUERY or SIGNATURE_TYPE_BODY
                       depending on where you want to embed the oauth
                       credentials.
:param rsa_key: RSA key used with SIGNATURE_RSA.
:param verifier: Verifier used when obtaining an access token.
:param realm: Realm (scope) to which access is being requested.
:param encoding: If you provide non-unicode input you may use this
                 to have oauthlib automatically convert.
:param decoding: If you wish that the returned uri, headers and body
                 from sign be encoded back from unicode, then set
                 decoding to your preferred encoding, i.e. utf-8.
:param nonce: Use this nonce instead of generating one. (Mainly for testing)
:param timestamp: Use this timestamp instead of using current. (Mainly for testing)
c                 .   > T(       a  [        U T5      $ U $ r   )r   )xencodings    r   <lambda>!Client.__init__.<locals>.<lambda>|   s    h:a2EAEr   N)
client_keyclient_secretresource_owner_keyresource_owner_secretsignature_methodsignature_typecallback_urirsa_keyverifierrealmr!   decodingnonce	timestamp)selfr$   r%   r&   r'   r*   r(   r)   r+   r,   r-   r!   r.   r/   r0   encodes              `    r   __init__Client.__init__[   s    B F ,#M2"();"<%+,A%B" &'7 8$^4"<0gx(E]
x(x(E]
	*r   c                 2   [        U 5      R                  5       nUS   (       a  SOS US'   US   (       a  SOS US'   US   (       a  SOS US'   SR                  S UR                  5        5       5      nSR	                  U R
                  R                  U5      $ )Nr%   z****r+   r'   z, c              3   H   #    U  H  u  pS R                  X5      v   M     g7f)z{}={}N)format).0kvs      r   	<genexpr>"Client.__repr__.<locals>.<genexpr>   s     !Q=41'.."6"6=s    "z<{} {}>)varscopyjoinitemsr7   	__class____name__)r1   attrsattribute_strs      r   __repr__Client.__repr__   s    T
!+0+Ato%*9%564i167N1OvUY 	#	%		!Q5;;=!QQ 7 7GGr   c                    U R                   [        :X  a+  [        R                  " U R                  U R
                  5      $ U R                  U5      u  p#n[        R                  " [        R                  " U5      R                  UUS9n[        R                  SR                  U5      5        [        R                  " U5      n[        R                  " X#R                  SS5      5      n[        R                  SR                  U5      5        [        R                  SR                  U5      5        [        R                   " UR"                  Xv5      n[        R                  SR                  U5      5        U R                   U R$                  ;  a  ['        S5      eU R$                  U R                      " X5      n	[        R                  S	R                  U	5      5        U	$ )
aG  Get an OAuth signature to be used in signing a request

To satisfy `section 3.4.1.2`_ item 2, if the request argument's
headers dict attribute contains a Host item, its value will
replace any netloc part of the request argument's uri attribute
value.

.. _`section 3.4.1.2`: https://tools.ietf.org/html/rfc5849#section-3.4.1.2
)	uri_querybodyheaderszCollected params: {}HostNzNormalized params: {}zNormalized URI: {}z"Signing: signature base string: {}zInvalid signature method.zSignature: {})r(   SIGNATURE_PLAINTEXTr
   sign_plaintextr%   r'   _rendercollect_parametersurlparsequerylogdebugr7   normalize_parametersbase_string_urigetsignature_base_stringhttp_methodr   
ValueError)
r1   requesturirJ   rI   collected_paramsnormalized_paramsnormalized_uribase_stringsigs
             r   get_oauth_signatureClient.get_oauth_signature   s      $77++D,>,>,0,F,FH H "\\'2d$77'',22 			(//0@AB%::;KL"223FD8QR		)001BCD		&--n=>55g6I6I6DY 			6==kJK  (>(>>899$$T%:%:;KN		/((-.
r   c           
      h   U R                   c
  [        5       OU R                   nU R                  c
  [        5       OU R                  nSU4SU4SSU R                  4SU R
                  4/nU R                  (       a  UR                  SU R                  45        U R                  (       a  UR                  SU R                  45        U R                  (       a  UR                  S	U R                  45        UR                  R                  S
S5      nU=(       a    UR                  S5      S:  nUR                  bx  U(       aq  UR                  S[        R                  " [         R"                  " UR                  R%                  S5      5      R'                  5       5      R)                  S5      45        U$ )zMGet the basic OAuth parameters to be used in generating a signature.
        Noauth_nonceoauth_timestamp)oauth_versionz1.0oauth_signature_methodoauth_consumer_keyoauth_tokenoauth_callbackoauth_verifierContent-Typer   r   oauth_body_hashr   )r/   r   r0   r   r(   r$   r&   appendr*   r,   rJ   rV   findrI   base64	b64encodehashlibsha1r2   digestdecode)r1   rZ   r/   r0   paramscontent_typecontent_type_eligibles          r   get_oauth_paramsClient.get_oauth_params   sw    JJ&  !,0JJ 	 . ()48NN 	 E"	*$%t'<'<=!4??3
 ""MM=$*A*ABCMM+T->->?@==MM+T]];< **>4@ , k1B1BCf1gjk1k<<#(=MM,f.>.>w||GLLL_L_`gLh?i?p?p?r.s.z.z  |C  /D  E  Fr   c                 ,   UR                   UR                  UR                  penU R                  [        :X  a+  [
        R                  " UR                  UR                  US9nOU R                  [        :X  aP  UR                  bC  [
        R                  " UR                  UR                  5      nU(       a  [        U5      nSUS'   OKU R                  [        :X  a,  [
        R                  " UR                  UR                   5      nO[        S5      eXEU4$ )zRender a signed request according to signature type

Returns a 3-tuple containing the request URI, headers, and body.

If the formencode argument is True and the body contains parameters, it
is escaped and returned as a valid formencoded string.
)r-   r   rl   z!Unknown signature type specified.)r[   rJ   rI   r)   SIGNATURE_TYPE_AUTH_HEADERr	   prepare_headersoauth_paramsSIGNATURE_TYPE_BODYdecoded_bodyprepare_form_encoded_bodyr   SIGNATURE_TYPE_QUERYprepare_request_uri_queryrY   )r1   rZ   
formencoder-   r[   rJ   rI   s          r   rN   Client._render   s     %[['//7<<d "<< 00$$gooUDG  $77G<P<P<\77$$g&:&:<D &IGN#  $8866$$gkk3C @AAT!!r   c                    [        XX4U R                  S9nUR                  R                  SS5      nU=(       a    UR	                  S5      nU[
        :H  n	UR                  SLn
U(       a  U
(       a  [        S5      eU	(       a  U
(       d  [        S5      eU	(       d/  U
(       a(  [        SR                  U=(       d    S[
        5      5      eU R                  [        :X  a   U	(       a  U
(       a  U(       a  [        S	5      eUR                  5       S
;   a  U
(       a  [        S5      eU R                  U5      Ul        UR                  R                  SU R                  U5      45        U R!                  USU=(       d    U R"                  S9u  pnU R$                  (       a  [&        R)                  SU R$                  5        UR+                  U R$                  5      nU(       a  UR+                  U R$                  5      OUn0 nUR-                  5        H;  u  pUR+                  U R$                  5      XR+                  U R$                  5      '   M=     UnXU4$ )a  Sign a request

Signs an HTTP request with the specified parts.

Returns a 3-tuple of the signed request's URI, headers, and body.
Note that http_method is not returned as it is unaffected by the OAuth
signing process. Also worth noting is that duplicate parameters
will be included in the signature, regardless of where they are
specified (query, body).

The body argument may be a dict, a list of 2-tuples, or a formencoded
string. The Content-Type header must be 'application/x-www-form-urlencoded'
if it is present.

If the body argument is not one of the above, it will be returned
verbatim as it is unaffected by the OAuth signing process. Attempting to
sign a request with non-formencoded data using the OAuth body signature
type is invalid and will raise an exception.

If the body does contain parameters, it will be returned as a properly-
formatted formencoded string.

Body may not be included if the http_method is either GET or HEAD as
this changes the semantic meaning of the request.

All string data MUST be unicode or be encoded with the same encoding
scheme supplied to the Client constructor, default utf-8. This includes
strings inside body dicts, for example.
)r!   rl   Nz
multipart/z?Headers indicate a multipart body but body contains parameters.z?Headers indicate a formencoded body but body was not decodable.zEBody contains parameters but Content-Type header was {} instead of {}znot setz=Body signatures may only be used with form-urlencoded content)GETHEADz*GET/HEAD requests should not include body.oauth_signatureT)r   r-   z%Encoding URI, headers and body to %s.)r   r!   rJ   rV   
startswithCONTENT_TYPE_FORM_URLENCODEDr   rY   r7   r)   r   upperry   r~   rn   ra   rN   r-   r.   rR   rS   r2   r@   )r1   r[   rX   rI   rJ   r-   rZ   rw   	multipartshould_have_params
has_paramsnew_headersr9   r:   s                 r   signClient.sign  s   > #D#'==2 **>4@ J\%<%<\%J	)-II))5

 QS S
  
QS S $
  &|'@y(D!FG G   $77"z)OQ Q  O3
IJJ  $44W= 	## 8 8 AB	D "\\'d161D$** * Gd ==II=t}}M**T]]+C154;;t}}-4DK78xx7NHHT]]34 (!GT!!r   )r*   r$   r%   r.   r!   r/   r-   r&   r'   r+   r(   r)   r0   r,   )FN)r   NNN)rB   
__module____qualname____firstlineno____doc__SIGNATURE_HMAC_SHA1r
   sign_hmac_sha1_with_clientSIGNATURE_HMAC_SHA256sign_hmac_sha256_with_clientSIGNATURE_HMAC_SHA512sign_hmac_sha512_with_clientSIGNATURE_RSA_SHA1sign_rsa_sha1_with_clientSIGNATURE_RSA_SHA256sign_rsa_sha256_with_clientSIGNATURE_RSA_SHA512sign_rsa_sha512_with_clientrL   sign_plaintext_with_clientr   classmethodr   r|   r3   rE   ra   ry   rN   r   __static_attributes__ r   r   r   r   J   s    <YAAyEEyEEI??iCCiCCYAA = =  $$('+""5 :D!Dt0+dH'R!F#"Jf"r   r   )"r   rp   rr   loggingurllib.parseparserP   oauthlib.commonr   r   r   r   r    r	   r
   	getLoggerrB   rR   r   r   r   SIGNATURE_HMACr   r   r   SIGNATURE_RSArL   r   r|   r   r   r   r   r   r   r   <module>r      s   (      $! " % % $ # # "!    +   B c" c"r   