o
    2gA                     @  sd   d Z ddlmZ ddlmZmZmZmZ ddlm	Z	m
Z
 ddlmZ ddlmZ G d	d
 d
eZdS )zProvide the Auth class.    )annotations)
AuthorizerImplicitAuthorizerUntrustedAuthenticatorsession   )InvalidImplicitAuth!MissingRequiredAttributeException)_deprecate_args   )PRAWBasec                   @  sh   e Zd ZdZed ddZd!d	d
Zedddd"ddZd#ddZ	edddddddd$ddZ
dS )%Authz5Auth provides an interface to Reddit's authorization.returndict[str, str | int | None]c                 C  s   | j jj}|j|j|jdS )a  Return a dictionary containing the rate limit info.

        The keys are:

        :remaining: The number of requests remaining to be made in the current rate
            limit window.
        :reset_timestamp: A unix timestamp providing an upper bound on when the rate
            limit counters will reset.
        :used: The number of requests made in the current rate limit window.

        All values are initially ``None`` as these values are set in response to issued
        requests.

        The ``reset_timestamp`` value is an upper bound as the real timestamp is
        computed on Reddit's end in preparation for sending the response. This value may
        change slightly within a given window due to slight changes in response times
        and rounding.

        )	remainingreset_timestampused)_reddit_core_rate_limiterr   r   r   )selfdata r   H/home/garg/my-data/venv/lib/python3.10/site-packages/praw/models/auth.pylimits   s
   
zAuth.limitscodestr
str | Nonec                 C  sF   | j jjj}t|}|| t|| j jjd}| | j _	| j _
|jS )a7  Complete the web authorization flow and return the refresh token.

        :param code: The code obtained through the request to the redirect uri.

        :returns: The obtained refresh token, if available, otherwise ``None``.

        The session's active authorization will be updated upon success.

        
authorizerwindow_size)r   _read_only_core_authorizer_authenticatorr   	authorizer   configr    r   _authorized_corerefresh_token)r   r   authenticatorr   authorized_sessionr   r   r   r$   +   s   


zAuth.authorizeaccess_token
expires_inscopeintc                C  sJ   | j jjj}t|tsttt||||| j j	j
d}| | j _| j _dS )a  Set the active authorization to be an implicit authorization.

        :param access_token: The access_token obtained from Reddit's callback.
        :param expires_in: The number of seconds the ``access_token`` is valid for. The
            origin of this value was returned from Reddit's callback. You may need to
            subtract an offset before passing in this number to account for a delay
            between when Reddit prepared the response, and when you make this function
            call.
        :param scope: A space-delimited string of Reddit OAuth2 scope names as returned
            from Reddit's callback.

        :raises: :class:`.InvalidImplicitAuth` if :class:`.Reddit` was initialized for a
            non-installed application type.

        r   N)r   r!   r"   r#   
isinstancer   r   r   r   r%   r    r   r&   )r   r*   r+   r,   r(   implicit_sessionr   r   r   implicit>   s   
zAuth.implicitset[str]c                 C  s    | j jj}| s|  |jS )zReturn a set of scopes included in the current authorization.

        For read-only authorizations this should return ``{"*"}``.

        )r   r   r"   is_validrefreshscopes)r   r   r   r   r   r4   Z   s   
zAuth.scopesr4   statedurationr0   	permanentF)r6   r0   bool	list[str]c                C  sb   | j jjj}|j| j jju rd}t|t|t	r&|j
|rdn||||dS |r*t|
|||S )a)  Return the URL used out-of-band to grant access to your application.

        :param duration: Either ``"permanent"`` or ``"temporary"`` (default:
            ``"permanent"``). ``"temporary"`` authorizations generate access tokens that
            last only 1 hour. ``"permanent"`` authorizations additionally generate a
            refresh token that expires 1 year after the last use and can be used
            indefinitely to generate new hour-long access tokens. This value is ignored
            when ``implicit=True``.
        :param implicit: For **installed** applications, this value can be set to use
            the implicit, rather than the code flow. When ``True``, the ``duration``
            argument has no effect as only temporary tokens can be retrieved.
        :param scopes: A list of OAuth scopes to request authorization for.
        :param state: A string that will be reflected in the callback to
            ``redirect_uri``. This value should be temporarily unique to the client for
            whom the URL was generated for.

        zredirect_uri must be provided	temporary)r0   )r   r!   r"   r#   redirect_urir%   CONFIG_NOT_SETr	   r.   r   authorize_urlr   )r   r6   r0   r4   r5   r(   msgr   r   r   urle   s   

zAuth.urlN)r   r   )r   r   r   r   )r*   r   r+   r-   r,   r   )r   r1   )
r6   r   r0   r8   r4   r9   r5   r   r   r   )__name__
__module____qualname____doc__propertyr   r$   r
   r0   r4   r?   r   r   r   r   r      s    


r   N)rC   
__future__r   prawcorer   r   r   r   
exceptionsr   r	   utilr
   baser   r   r   r   r   r   <module>   s    