o
    PDiY                     @  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   key_forr   r   r   _window)selfr   r   r   r   r    r   O/var/www/Datamplify/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$   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]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>)r;   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 )callabler8   r   endpointr%   r   r   r    scopem   s
   zLimit.scoper(   c                 C  s   t | jtr	| jS |  S r   )
isinstancerF   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)r;   r   methodrG   r%   r   r   r    method_exempt|   s   zLimit.method_exemptrP   r   rT   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.
        :)rQ   r   r9   upper)r   rP   rT   limit_scoperQ   r   r   r    	scope_for   s   zLimit.scope_for)r   r   )r   r   )r   r<   r+   )rP   r   rT   r<   r   r   )r,   r-   r.   r/   r0   r9   r;   r=   r?   rA   rC   rE   rF   r   rL   r1   rM   rQ   rS   rU   rY   r   r   r   r    r4   M   s0   
 
r4   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_providerr5   key_functionNr7   rQ   r:   r;   r<   r=   r>   r?   Fr@   rA   rB   rC   rD   rE   r   r9   zCallable[[], int] | int | NonerS   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
   )rO   r[   r   r4   r\   rQ   r9   r;   r=   r?   rA   rC   rE   rS   r   )r   	limit_strlimit_itemsr   r   r   r    __iter__   s,   
zLimitGroup.__iter__)r   r]   )r,   r-   r.   r/   r0   rQ   r;   r=   r?   rA   rC   rE   r9   rS   r   r`   r   r   r   r    rZ      s   
 rZ   )
__future__r   dataclassesr"   r   collections.abcr   flaskr   flask.wrappersr   limitsr   r   limits.strategiesr   limits.utilr	   r   TYPE_CHECKINGr   r   r   	dataclassr4   rZ   r   r   r   r    <module>   s$    9K