o
    ;hY                     @  s   d dl mZ d dlZd dlZd dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZmZ d dlmZ d dlmZ d	d
lmZ ejrGd	dlmZ G dd dZejdddG dd dZejdddG dd dZdS )    )annotationsN)Iterator)request)Response)RateLimitItem
parse_many)RateLimiter)WindowStats   )Callable)Limiterc                   @  st   e Zd ZU dZded< ded< ded< ded< dddZedddZedddZed ddZ	ed ddZ
dS )!RequestLimitzJ
    Provides details of a rate limit within the context of a request
    r   limitstrkeyboolbreachedshared	extensionr   request_args	list[str]returnNonec                 C  s:   t || _|| _|| _|j| | _|| _|| _d | _	d S N)
weakrefproxyr   r   r   Zkey_forr   r   r   _window)selfr   r   r   r   r    r   I/var/www/html/venv/lib/python3.10/site-packages/flask_limiter/wrappers.py__init__%   s   
zRequestLimit.__init__r   c                 C  s   t t| jjS r   )typingcastr   r   limiterr   r   r   r   r#   5   s   zRequestLimit.limiterr	   c                 C  s&   | j s| jj| jg| jR  | _ | j S r   )r   r#   Zget_window_statsr   r   r$   r   r   r   window9   s   zRequestLimit.windowintc                 C  s   t | jd d S )z/Timestamp at which the rate limit will be resetr   r
   )r&   r%   r$   r   r   r   reset_at@   s   zRequestLimit.reset_atc                 C  s
   | j d S )z&Quantity remaining for this rate limitr
   )r%   r$   r   r   r   	remainingF   s   
zRequestLimit.remainingN)r   r   r   r   r   r   r   r   r   r   r   r   )r   r   )r   r	   r   r&   )__name__
__module____qualname____doc____annotations__r    propertyr#   r%   r'   r(   r   r   r   r   r      s   
 
r   T)equnsafe_hashc                   @  s   e Zd ZU dZded< ded< ded< dZd	ed
< dZded< dZded< dZded< dZ	ded< dZ
ded< dZded< dZded< dZd	ed< d.ddZed/d d!Zed0d"d#Zed1d%d&Zed/d'd(Zd2d,d-ZdS )3Limitz@
    simple wrapper to encapsulate limits and their context
    r   r   Callable[[], str]Zkey_func!str | Callable[[str], str] | None_scopeFr   
per_methodNtuple[str, ...] | Nonemethods
str | Noneerror_messageCallable[[], bool] | Noneexempt_whenbool | Noneoverride_defaults!Callable[[Response], bool] | Nonededuct_when0Callable[[RequestLimit], Response | None] | None	on_breachr
   zCallable[[], int] | int_costr   r   r   c                 C  s$   | j rtdd | j D | _ d S d S )Nc                 S  s   g | ]}|  qS r   )lower).0kr   r   r   
<listcomp>b   s    z'Limit.__post_init__.<locals>.<listcomp>)r8   tupler$   r   r   r   __post_init__`   s   zLimit.__post_init__c                 C  s   | j r|   S dS )zCheck if the limit is exempt.F)r<   r$   r   r   r   	is_exemptd   s   zLimit.is_exemptc                 C  s    t | jr| tjpdS | jS )N )callabler5   r   endpointr$   r   r   r   scopem   s
   zLimit.scoper&   c                 C  s   t | jtr	| jS |  S r   )
isinstancerC   r&   r$   r   r   r   costu   s   z
Limit.costc                 C  s   | j duotj | j vS )z4Check if the limit is not applicable for this methodN)r8   r   methodrD   r$   r   r   r   method_exempt|   s   zLimit.method_exemptrM   r   rQ   c                 C  sN   | j }|r| jr|}n
| d| }n|}| jr%|sJ |d|  7 }|S )z
        Derive final bucket (scope) for this limit given the endpoint
        and request method. If the limit is shared between multiple
        routes, the scope does not include the endpoint.
        :)rN   r   r6   upper)r   rM   rQ   Zlimit_scoperN   r   r   r   	scope_for   s   zLimit.scope_for)r   r   )r   r   )r   r9   r)   )rM   r   rQ   r9   r   r   )r*   r+   r,   r-   r.   r6   r8   r:   r<   r>   r@   rB   rC   r   rI   r/   rJ   rN   rP   rR   rU   r   r   r   r   r2   M   s0   
 
r2   c                   @  s   e Zd ZU dZded< ded< dZded< dZd	ed
< dZded< dZded< dZ	ded< dZ
ded< dZded< dZded< dZded< dZded< dddZdS ) 
LimitGroupzf
    represents a group of related limits either from a string or a callable
    that returns one
    zCallable[[], str] | strlimit_providerr3   key_functionNr4   rN   r7   r8   r9   r:   r;   r<   Fr=   r>   r?   r@   rA   rB   r   r6   zCallable[[], int] | int | NonerP   r   r   Iterator[Limit]c                 c  sr    t | jr
|  n| j}|rt|ng }|D ]}t|| j| j| j| j| j| j	| j
| j| j| jp1d| jV  qd S )Nr
   )rL   rW   r   r2   rX   rN   r6   r8   r:   r<   r>   r@   rB   rP   r   )r   Z	limit_strZlimit_itemsr   r   r   r   __iter__   s,   
zLimitGroup.__iter__)r   rY   )r*   r+   r,   r-   r.   rN   r8   r:   r<   r>   r@   rB   r6   rP   r   rZ   r   r   r   r   rV      s   
 rV   )
__future__r   dataclassesr!   r   collections.abcr   Zflaskr   Zflask.wrappersr   Zlimitsr   r   Zlimits.strategiesr   Zlimits.utilr	   r   TYPE_CHECKINGr   r   r   	dataclassr2   rV   r   r   r   r   <module>   s$    9K