HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib64/python3.10/site-packages/tweepy/__pycache__/auth.cpython-310.pyc
o

+we�@s�ddlZddlZddlZddlmZmZddlmZmZm	Z	ddl
mZdZe�
e�ZGdd�d�ZGdd	�d	e�ZGd
d�d�ZGdd
�d
e�ZGdd�de�ZGdd�de	�ZdS)�N)�AuthBase�
HTTPBasicAuth)�OAuth1�
OAuth1Session�
OAuth2Session)�TweepyExceptionz�Warning! Due to a Twitter API bug, signin_with_twitter
and access_type don't always play nice together. Details
https://dev.twitter.com/discussions/21281c@sXeZdZdZ		ddd�Zdd�Zdd�Zdd	d
�Z		ddd
�Zddd�Z	dd�Z
dS)�OAuth1UserHandlerz{OAuth 1.0a User Context authentication handler

    .. versionchanged:: 4.5
        Renamed from :class:`OAuthHandler`
    NcCs�t|ttf�stdt|�j��t|ttf�s tdt|�j��||_||_||_||_	||_
d|_i|_t
|||j
d�|_dS)Nz*Consumer key must be string or bytes, not z-Consumer secret must be string or bytes, not )�
client_secret�callback_uri)�
isinstance�str�bytes�	TypeError�type�__name__�consumer_key�consumer_secret�access_token�access_token_secret�callback�username�
request_tokenr�oauth��selfrrrrr�r�D/home/arjun/projects/env/lib/python3.10/site-packages/tweepy/auth.py�__init__s$���zOAuth1UserHandler.__init__cCst|j|j|j|jdd�S)N)r	�resource_owner_key�resource_owner_secret�decoding)rrrrr�rrrr�
apply_auth/s
�zOAuth1UserHandler.apply_authcCsd|S)Nzhttps://api.twitter.com/oauth/r)r�endpointrrr�_get_oauth_url6sz OAuth1UserHandler._get_oauth_urlc
CsLz|�d�}|r|d|��7}|j�|�WSty%}zt|��d}~ww)Nrz?x_auth_access_type=)r$r�fetch_request_token�	Exceptionr)r�access_type�url�errr�_get_request_token9s
��z$OAuth1UserHandler._get_request_tokenFc
Csfz"|r|�d�}|rt�t�n|�d�}|j|d�|_|j�|�WSty2}zt	|��d}~ww)�1Get the authorization URL to redirect the user to�authenticate�	authorize)r'N)
r$�log�warning�WARNING_MESSAGEr*rr�authorization_urlr&r)r�signin_with_twitterr'r(r)rrr�get_authorization_urlBs

�
���z'OAuth1UserHandler.get_authorization_urlc
Cs�z0|�d�}t|j|j|jd|jd||jd�|_|j�|�}|d|_|d|_	|j|j	fWSt
y@}zt|��d}~ww)z]After user has authorized the app, get access token and secret with
        verifier
        r�oauth_token�oauth_token_secret)r	rr�verifierr
N)r$rrrrrr�fetch_access_tokenrrr&r)rr6r(�respr)rrr�get_access_tokenSs 
�

��z"OAuth1UserHandler.get_access_tokencCs||_||_dS)zU
        .. deprecated:: 4.5
            Set through initialization instead.
        N)rr)r�key�secretrrr�set_access_tokenfs
z"OAuth1UserHandler.set_access_token�NNN�N)FN)r�
__module__�__qualname__�__doc__rr"r$r*r3r9r<rrrrrs
�
	
�
rcs&eZdZdZ		d�fdd�	Z�ZS)�OAuthHandlerzrAlias for :class:`OAuth1UserHandler`

    .. deprecated:: 4.5
        Use :class:`OAuth1UserHandler` instead.
    Ncs$t�dt�t��|||||�dS)Nz:OAuthHandler is deprecated; use OAuth1UserHandler instead.��warnings�warn�DeprecationWarning�superrr��	__class__rrrvs��zOAuthHandler.__init__r=�rr?r@rAr�
__classcell__rrrHrrBos
�rBc@s eZdZdZdd�Zdd�ZdS)�OAuth2AppHandlerz�OAuth 2.0 Bearer Token (App-Only) using API / Consumer key and secret
    authentication handler

    .. versionchanged:: 4.5
        Renamed from :class:`AppAuthHandler`
    cCsh||_||_d|_tjd|j|jfddid�}|��}|�d�dkr-td|�d��d	���|d
|_dS)N�z$https://api.twitter.com/oauth2/token�
grant_type�client_credentials)�auth�data�
token_type�bearerz/Expected token_type to equal "bearer", but got z insteadr)rr�
_bearer_token�requests�post�json�getr)rrrr8rQrrrr�s
�
�zOAuth2AppHandler.__init__cCs
t|j�Sr>)�OAuth2BearerHandlerrTr!rrrr"��
zOAuth2AppHandler.apply_authN)rr?r@rArr"rrrrrL�srLcs eZdZdZ�fdd�Z�ZS)�AppAuthHandlerzpAlias for :class:`OAuth2AppHandler`

    .. deprecated:: 4.5
        Use :class:`OAuth2AppHandler` instead.
    cst�dt�t��||�dS)Nz;AppAuthHandler is deprecated; use OAuth2AppHandler instead.rC)rrrrHrrr�s
�zAppAuthHandler.__init__rJrrrHrr[�sr[c@s(eZdZdZdd�Zdd�Zdd�ZdS)	rYzXOAuth 2.0 Bearer Token (App-Only) authentication handler

    .. versionadded:: 4.5
    cCs
||_dSr>)�bearer_token)rr\rrrr�rZzOAuth2BearerHandler.__init__cCsd|j|jd<|S)NzBearer �
Authorization)r\�headers)r�requestrrr�__call__�szOAuth2BearerHandler.__call__cCs|Sr>rr!rrrr"�szOAuth2BearerHandler.apply_authN)rr?r@rArr`r"rrrrrY�s
rYcs:eZdZdZdd��fdd�
Zdd�Z�fdd	�Z�ZS)
�OAuth2UserHandlerzuOAuth 2.0 Authorization Code Flow with PKCE (User Context)
    authentication handler

    .. versionadded:: 4.5
    N)r	cs4t�j|||d�|durt||�|_dSd|_dS)N)�redirect_uri�scope)rGrrrP)r�	client_idrbrcr	rHrrr�s
zOAuth2UserHandler.__init__cCs*|jd|j�|j�d�d�dd�\}}|S)r+z&https://twitter.com/i/oauth2/authorize��S256)�code_challenge�code_challenge_method)r1�_client�create_code_challenge�create_code_verifier)rr1�staterrrr3�s�
�z'OAuth2UserHandler.get_authorization_urlcst�jd||jd|jjd�S)zfAfter user has authorized the app, fetch access token with
        authorization response URL
        z&https://api.twitter.com/2/oauth2/tokenT)�authorization_responserP�include_client_id�
code_verifier)rG�fetch_tokenrPriro)rrmrHrrrp�s�zOAuth2UserHandler.fetch_token)rr?r@rArr3rprKrrrHrra�s

ra)�loggingrDrU�
requests.authrr�requests_oauthlibrrr�
tweepy.errorsrr0�	getLoggerrr.rrBrLr[rYrarrrr�<module>s
Z