
    qh.B                         S SK Jr  S SKrS SKJr  S SKJr  S SKJrJ	r	J
r
  S SKrSSKJr  \R                  " \5      rS r " S	 S
\5      r " S S\5      r " S S\5      r " S S\R*                  5      rg)    )urlparseN)add_params_to_uri)	urldecode)SIGNATURE_HMACSIGNATURE_RSASIGNATURE_TYPE_AUTH_HEADER   )OAuth1c                 d     [        U 5      $ ! [         a    SSKnUR                  U 5      s $ f = f)z(Parse query or json to python dictionaryr   N)
_urldecode	Exceptionjsonloads)bodyr   s     R/var/www/html/env/lib/python3.13/site-packages/requests_oauthlib/oauth1_session.pyr   r      s3     $  zz$ s   
 //c                   8   ^  \ rS rSrU 4S jr\S 5       rSrU =r$ )TokenRequestDenied   c                 8   > [         [        U ]  U5        X l        g N)superr   __init__responseselfmessager   	__class__s      r   r   TokenRequestDenied.__init__   s     $09     c                 .    U R                   R                  $ )z$For backwards-compatibility purposes)r   status_coder   s    r   r!   TokenRequestDenied.status_code   s     }}(((r   r   )	__name__
__module____qualname____firstlineno__r   propertyr!   __static_attributes____classcell__r   s   @r   r   r      s    ! ) )r   r   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )TokenMissing%   c                 8   > [         [        U ]  U5        X l        g r   )r   r.   r   r   r   s      r   r   TokenMissing.__init__&   s    lD*73 r   r$   )r%   r&   r'   r(   r   r*   r+   r,   s   @r   r.   r.   %   s    ! !r   r.   c                       \ rS rSrSrg)VerifierMissing+    N)r%   r&   r'   r(   r*   r5   r   r   r3   r3   +   s    r   r3   c            
          ^  \ rS rSrSrSSSS\\SSSS4
U 4S jjr\S 5       r	\	R                  S 5       r	\S 5       rSS	 jrSS
 jrSS jrS rS rS rS rSrU =r$ )OAuth1Session/   a  Request signing and convenience methods for the oauth dance.

What is the difference between OAuth1Session and OAuth1?

OAuth1Session actually uses OAuth1 internally and its purpose is to assist
in the OAuth workflow through convenience methods to prepare authorization
URLs and parse the various token and redirection responses. It also provide
rudimentary validation of responses.

An example of the OAuth workflow using a basic CLI app and Twitter.

>>> # Credentials obtained during the registration.
>>> client_key = 'client key'
>>> client_secret = 'secret'
>>> callback_uri = 'https://127.0.0.1/callback'
>>>
>>> # Endpoints found in the OAuth provider API documentation
>>> request_token_url = 'https://api.twitter.com/oauth/request_token'
>>> authorization_url = 'https://api.twitter.com/oauth/authorize'
>>> access_token_url = 'https://api.twitter.com/oauth/access_token'
>>>
>>> oauth_session = OAuth1Session(client_key,client_secret=client_secret, callback_uri=callback_uri)
>>>
>>> # First step, fetch the request token.
>>> oauth_session.fetch_request_token(request_token_url)
{
    'oauth_token': 'kjerht2309u',
    'oauth_token_secret': 'lsdajfh923874',
}
>>>
>>> # Second step. Follow this link and authorize
>>> oauth_session.authorization_url(authorization_url)
'https://api.twitter.com/oauth/authorize?oauth_token=sdf0o9823sjdfsdf&oauth_callback=https%3A%2F%2F127.0.0.1%2Fcallback'
>>>
>>> # Third step. Fetch the access token
>>> redirect_response = input('Paste the full redirect URL here.')
>>> oauth_session.parse_authorization_response(redirect_response)
{
    'oauth_token: 'kjerht2309u',
    'oauth_token_secret: 'lsdajfh923874',
    'oauth_verifier: 'w34o8967345',
}
>>> oauth_session.fetch_access_token(access_token_url)
{
    'oauth_token': 'sdf0o9823sjdfsdf',
    'oauth_token_secret': '2kjshdfp92i34asdasd',
}
>>> # Done. You can now make OAuth requests.
>>> status_url = 'http://api.twitter.com/1/statuses/update.json'
>>> new_status = {'status':  'hello world!'}
>>> oauth_session.post(status_url, data=new_status)
<Response [200]>
NFc                    > [         [        U ]  5         [        U4UUUUUUUU	U
US.
UD6U l        U R                  U l        g)a  Construct the OAuth 1 session.

:param client_key: A client specific identifier.
:param client_secret: A client specific secret used to create HMAC and
                      plaintext signatures.
:param resource_owner_key: A resource owner key, also referred to as
                           request token or access token depending on
                           when in the workflow it is used.
:param resource_owner_secret: A resource owner secret obtained with
                              either a request or access token. Often
                              referred to as token secret.
:param callback_uri: The URL the user is redirect back to after
                     authorization.
:param signature_method: Signature methods determine how the OAuth
                         signature is created. The three options are
                         oauthlib.oauth1.SIGNATURE_HMAC (default),
                         oauthlib.oauth1.SIGNATURE_RSA and
                         oauthlib.oauth1.SIGNATURE_PLAIN.
:param signature_type: Signature type decides where the OAuth
                       parameters are added. Either in the
                       Authorization header (default) or to the URL
                       query parameters or the request body. Defined as
                       oauthlib.oauth1.SIGNATURE_TYPE_AUTH_HEADER,
                       oauthlib.oauth1.SIGNATURE_TYPE_QUERY and
                       oauthlib.oauth1.SIGNATURE_TYPE_BODY
                       respectively.
:param rsa_key: The private RSA key as a string. Can only be used with
                signature_method=oauthlib.oauth1.SIGNATURE_RSA.
:param verifier: A verifier string to prove authorization was granted.
:param client_class: A subclass of `oauthlib.oauth1.Client` to use with
                     `requests_oauthlib.OAuth1` instead of the default
:param force_include_body: Always include the request body in the
                           signature creation.
:param **kwargs: Additional keyword arguments passed to `OAuth1`
)
client_secretresource_owner_keyresource_owner_secretcallback_urisignature_methodsignature_typersa_keyverifierclient_classforce_include_bodyN)r   r7   r   r
   _clientauth)r   
client_keyr:   r;   r<   r=   r>   r?   r@   rA   rB   rC   kwargsr   s                r   r   OAuth1Session.__init__f   s\    d 	mT+-
'1"7%-)%1
 
 LL	r   c                    U R                   R                  R                  nU R                   R                  R                  nU R                   R                  R                  n0 nU(       a  XS'   U(       a  X$S'   U(       a  X4S'   U$ )Noauth_tokenoauth_token_secretoauth_verifier)rD   clientr;   r<   rA   )r   rJ   rK   rL   
token_dicts        r   tokenOAuth1Session.token   sp    ll))<<!\\00FF,,55
(3}%/A+,+9'(r   c                 &    U R                  U5        g r   )_populate_attributes)r   values     r   rO   rP      s    !!%(r   c                    U R                   R                  R                  [        :X  a)  [	        U R                   R                  R
                  5      $ [	        U R                   R                  R                  5      =(       aY    [	        U R                   R                  R
                  5      =(       a)    [	        U R                   R                  R                  5      $ )aP  Boolean that indicates whether this session has an OAuth token
or not. If `self.authorized` is True, you can reasonably expect
OAuth-protected requests to the resource to succeed. If
`self.authorized` is False, you need the user to go through the OAuth
authentication dance before OAuth-protected requests to the resource
will succeed.
)rD   rM   r>   r   boolr;   r:   r<   r"   s    r   
authorizedOAuth1Session.authorized   s     <<//=@++>>?? T\\((667 D,,??@D,,BBCr   c                     U=(       d     U R                   R                  R                  US'   [        R	                  SX15        [        XR                  5       5      $ )ac  Create an authorization URL by appending request_token and optional
kwargs to url.

This is the second step in the OAuth 1 workflow. The user should be
redirected to this authorization URL, grant access to you, and then
be redirected back to you. The redirection back can either be specified
during client registration or by supplying a callback URI per request.

:param url: The authorization endpoint URL.
:param request_token: The previously obtained request token.
:param kwargs: Optional parameters to append to the URL.
:returns: The authorization URL with new parameters embedded.

An example using a registered default callback URI.

>>> request_token_url = 'https://api.twitter.com/oauth/request_token'
>>> authorization_url = 'https://api.twitter.com/oauth/authorize'
>>> oauth_session = OAuth1Session('client-key', client_secret='secret')
>>> oauth_session.fetch_request_token(request_token_url)
{
    'oauth_token': 'sdf0o9823sjdfsdf',
    'oauth_token_secret': '2kjshdfp92i34asdasd',
}
>>> oauth_session.authorization_url(authorization_url)
'https://api.twitter.com/oauth/authorize?oauth_token=sdf0o9823sjdfsdf'
>>> oauth_session.authorization_url(authorization_url, foo='bar')
'https://api.twitter.com/oauth/authorize?oauth_token=sdf0o9823sjdfsdf&foo=bar'

An example using an explicit callback URI.

>>> request_token_url = 'https://api.twitter.com/oauth/request_token'
>>> authorization_url = 'https://api.twitter.com/oauth/authorize'
>>> oauth_session = OAuth1Session('client-key', client_secret='secret', callback_uri='https://127.0.0.1/callback')
>>> oauth_session.fetch_request_token(request_token_url)
{
    'oauth_token': 'sdf0o9823sjdfsdf',
    'oauth_token_secret': '2kjshdfp92i34asdasd',
}
>>> oauth_session.authorization_url(authorization_url)
'https://api.twitter.com/oauth/authorize?oauth_token=sdf0o9823sjdfsdf&oauth_callback=https%3A%2F%2F127.0.0.1%2Fcallback'
rJ   zAdding parameters %s to url %s)rD   rM   r;   logdebugr   items)r   urlrequest_tokenrG   s       r   authorization_urlOAuth1Session.authorization_url   sD    T !. W1D1D1W1W}		2F@ lln55r   c                 (   U(       a  SR                  U5      OSU R                  R                  l        U R                  " U40 UD6n[
        R                  S5        SU R                  R                  l        SU R                  R                  l        U$ )a  Fetch a request token.

This is the first step in the OAuth 1 workflow. A request token is
obtained by making a signed post request to url. The token is then
parsed from the application/x-www-form-urlencoded response and ready
to be used to construct an authorization url.

:param url: The request token endpoint URL.
:param realm: A list of realms to request access to.
:param request_kwargs: Optional arguments passed to ''post''
    function in ''requests.Session''
:returns: The response in dict format.

Note that a previously set callback_uri will be reset for your
convenience, or else signature creation will be incorrect on
consecutive requests.

>>> request_token_url = 'https://api.twitter.com/oauth/request_token'
>>> oauth_session = OAuth1Session('client-key', client_secret='secret')
>>> oauth_session.fetch_request_token(request_token_url)
{
    'oauth_token': 'sdf0o9823sjdfsdf',
    'oauth_token_secret': '2kjshdfp92i34asdasd',
}
 Nz<Resetting callback_uri and realm (not needed in next phase).)joinrD   rM   realm_fetch_tokenrY   rZ   r=   )r   r\   rc   request_kwargsrO   s        r   fetch_request_token!OAuth1Session.fetch_request_token   sm    4 8=CHHUO$!!!#88		PQ+/($(!r   c                 0   U(       a  X R                   R                  l        [        U R                   R                  SS5      (       d  [	        S5      eU R
                  " U40 UD6n[        R                  S5        SU R                   R                  l        U$ )a  Fetch an access token.

This is the final step in the OAuth 1 workflow. An access token is
obtained using all previously obtained credentials, including the
verifier from the authorization step.

Note that a previously set verifier will be reset for your
convenience, or else signature creation will be incorrect on
consecutive requests.

>>> access_token_url = 'https://api.twitter.com/oauth/access_token'
>>> redirect_response = 'https://127.0.0.1/callback?oauth_token=kjerht2309uf&oauth_token_secret=lsdajfh923874&oauth_verifier=w34o8967345'
>>> oauth_session = OAuth1Session('client-key', client_secret='secret')
>>> oauth_session.parse_authorization_response(redirect_response)
{
    'oauth_token: 'kjerht2309u',
    'oauth_token_secret: 'lsdajfh923874',
    'oauth_verifier: 'w34o8967345',
}
>>> oauth_session.fetch_access_token(access_token_url)
{
    'oauth_token': 'sdf0o9823sjdfsdf',
    'oauth_token_secret': '2kjshdfp92i34asdasd',
}
rA   Nz No client verifier has been set.z9Resetting verifier attribute, should not be used anymore.)rD   rM   rA   getattrr3   rd   rY   rZ   )r   r\   rA   re   rO   s        r   fetch_access_token OAuth1Session.fetch_access_token   su    4 +3LL(t||**J==!"DEE!!#88		MN'+$r   c                     [         R                  SU5        [        [        [	        U5      R
                  5      5      n[         R                  S5        U R                  U5        X l        U$ )a  Extract parameters from the post authorization redirect response URL.

:param url: The full URL that resulted from the user being redirected
            back from the OAuth provider to you, the client.
:returns: A dict of parameters extracted from the URL.

>>> redirect_response = 'https://127.0.0.1/callback?oauth_token=kjerht2309uf&oauth_token_secret=lsdajfh923874&oauth_verifier=w34o8967345'
>>> oauth_session = OAuth1Session('client-key', client_secret='secret')
>>> oauth_session.parse_authorization_response(redirect_response)
{
    'oauth_token: 'kjerht2309u',
    'oauth_token_secret: 'lsdajfh923874',
    'oauth_verifier: 'w34o8967345',
}
z'Parsing token from query part of url %sz)Updating internal client token attribute.)rY   rZ   dictr   r   queryrR   rO   )r   r\   rO   s      r   parse_authorization_response*OAuth1Session.parse_authorization_responseC  sQ      			;SAYx}2234		=>!!%(
r   c                    SU;   a  US   U R                   R                  l        O[        SR	                  US9U5      eSU;   a  US   U R                   R                  l        SU;   a  US   U R                   R                  l        g g )NrJ   z)Response does not contain a token: {resp})resprK   rL   )rD   rM   r;   r.   formatr<   rA   )r   rO   s     r   rR   "OAuth1Session._populate_attributesZ  s    E!5:=5IDLL2;BBBNPU   5(8=>R8SDLL5u$+01A+BDLL( %r   c                 N   [         R                  SXR                  R                  5        U R                  " U40 UD6nUR
                  S:  a&  Sn[        XCR
                  UR                  4-  U5      e[         R                  SUR                  5         [        [        UR                  R                  5       5      5      n[         R                  SU5        [         R                  S5        U R                  U5        XPl        U$ ! [         a  nSU-  n[        U5      eS nAff = f)Nz&Fetching token from %s using client %si  z5Token request failed with code %s, response was '%s'.z!Decoding token from response "%s"zUnable to decode token from token response. This is commonly caused by an unsuccessful request where a non urlencoded error message is returned. The decoding error was %szObtained token %sz4Updating internal client attributes from token data.)rY   rZ   rD   rM   postr!   r   textrm   r   strip
ValueErrorrR   rO   )r   r\   re   rerrorrO   es          r   rd   OAuth1Session._fetch_tokenf  s    		:CATATUIIc,^,==CKE$UmmQVV-D%DaHH		5qvv>
	$166<<>23E 			%u-		HI!!%(
  	$ 	  U##	$s   ,D 
D$DD$c                     SUR                   ;   a7  UR                   R                  SS5        UR                  U R                  5        g)zu
When being redirected we should always strip Authorization
header, since nonce may not be reused as per OAuth spec.
AuthorizationTN)headerspopprepare_authrE   )r   prepared_requestr   s      r   rebuild_authOAuth1Session.rebuild_auth  s@    
 .666 $$(($?))$))4r   )rD   rE   rO   r   )r%   r&   r'   r(   __doc__r   r   r   r)   rO   setterrV   r^   rf   rj   ro   rR   rd   r   r*   r+   r,   s   @r   r7   r7   /   s    4r "'1 A!F   \\) )  &,6\B!F.
C6
 
r   r7   )urllib.parser   loggingoauthlib.commonr   r   r   oauthlib.oauth1r   r   r   requests r
   	getLoggerr%   rY   ry   r   r.   r3   Sessionr7   r5   r   r   <module>r      sl    !  - 3 U U   ! ) )!: !	j 	\H$$ \r   