
    Ii%                         % S r SSKJrJr  SSKJrJrJrJr  SSK	J
r
  SSKJrJrJr  SSKJr   " S S	\S
9r " S S\5      r " S S\5      r " S S\5      r\\\   \\   \\   4   r\\\S.r\\\4   \S'   g)z
Rate limiting strategies
    )ABCMetaabstractmethod)DictTypeUnioncast   )RateLimitItem)MovingWindowSupportStorageStorageTypes)WindowStatsc            
           \ rS rSrS\4S jr\SS.S\S\S\	S	\
4S
 jj5       r\SS.S\S\S\	S	\
4S jj5       r\S\S\S	\4S j5       rS\S\S	S4S jrSrg)RateLimiter   storagec                 >    [        U[        5      (       d   eXl        g N)
isinstancer   r   )selfr   s     7/venv/lib/python3.13/site-packages/limits/strategies.py__init__RateLimiter.__init__   s    '7++++ '    r	   costitemidentifiersr   returnc                    [         e)
Consume the rate limit

:param item: The rate limit item
:param identifiers: variable list of strings to uniquely identify this
 instance of the limit
:param cost: The cost of this hit, default 1
NotImplementedErrorr   r   r   r   s       r   hitRateLimiter.hit   
     "!r   c                    [         e)z
Check the rate limit without consuming from it.

:param item: The rate limit item
:param identifiers: variable list of strings to uniquely identify this
  instance of the limit
:param cost: The expected cost to be consumed, default 1
r"   r$   s       r   testRateLimiter.test   r'   r   c                     [         e)
Query the reset time and remaining amount for the limit

:param item: The rate limit item
:param identifiers: variable list of strings to uniquely identify this
 instance of the limit
:return: (reset time, remaining)
r"   r   r   r   s      r   get_window_statsRateLimiter.get_window_stats*   r'   r   Nc                 R    U R                   R                  UR                  " U6 5      $ r   )r   clearkey_forr-   s      r   r1   RateLimiter.clear6   s     ||!!$,,"<==r   )r   )__name__
__module____qualname____firstlineno__r   r   r   r
   strintboolr%   r)   r   r.   r1   __static_attributes__ r   r   r   r      s    ( ( FG 	" 	"S 	" 	"D 	" 	" GH 	" 	"c 	" 	"T 	" 	" 	"] 	"# 	"+ 	" 	">- >s >t >r   r   )	metaclassc            	          ^  \ rS rSrSrS\4U 4S jjrSS.S\S\S	\	S
\
4S jjrSS.S\S\S	\	S
\
4S jjrS\S\S
\4S jrSrU =r$ )MovingWindowRateLimiter:   z,
Reference: :ref:`strategies:moving window`
r   c                    > [        US5      (       d)  [        US5      (       d  [        SUR                  -  5      e[        TU ]  U5        g )Nacquire_entryget_moving_windowzBMovingWindowRateLimiting is not implemented for storage of type %s)hasattrr#   	__class__superr   )r   r   rE   s     r   r    MovingWindowRateLimiter.__init__?   sL    G_--BU1V1V%&001  	!r   r	   r   r   r   r   r   c                    [        [        U R                  5      R                  UR                  " U6 UR
                  UR                  5       US9$ )z
Consume the rate limit

:param item: The rate limit item
:param identifiers: variable list of strings to uniquely identify this
 instance of the limit
:param cost: The cost of this hit, default 1
:return: (reset time, remaining)
)amount)r   r   r   rB   r2   rI   
get_expiryr$   s       r   r%   MovingWindowRateLimiter.hitI   sF     '6DDLL+&T__5Ft E 
 	
r   c                    [        [        U R                  5      R                  UR                  " U6 UR
                  UR                  5       5      S   UR
                  U-
  :*  $ z
Check if the rate limit can be consumed

:param item: The rate limit item
:param identifiers: variable list of strings to uniquely identify this
 instance of the limit
:param cost: The expected cost to be consumed, default 1
r	   )r   r   r   rC   r2   rI   rJ   r$   s       r   r)   MovingWindowRateLimiter.testX   s]     $dll3EEk*! 	
 {{T!"	
r   c                     [        [        U R                  5      R                  UR                  " U6 UR
                  UR                  5       5      u  p4X1R                  5       -   n[        XQR
                  U-
  5      $ )z
returns the number of requests remaining within this limit.

:param item: The rate limit item
:param identifiers: variable list of strings to uniquely identify this
 instance of the limit
:return: tuple (reset time, remaining)
)r   r   r   rC   r2   rI   rJ   r   )r   r   r   window_startwindow_itemsresets         r   r.   (MovingWindowRateLimiter.get_window_statsk   sd     &*&


DLL+6T__EV
W 	# 005++"<==r   r<   )r4   r5   r6   r7   __doc__r   r   r
   r8   r9   r:   r%   r)   r   r.   r;   __classcell__)rE   s   @r   r?   r?   :   s    " " GH 
 
S 
 
D 
 HI 
 
c 
 
T 
&>] ># >+ > >r   r?   c            	       r    \ rS rSrSrSS.S\S\S\S\4S	 jjr	SS.S\S\S\S\4S
 jjr
S\S\S\4S jrSrg)FixedWindowRateLimiter|   z+
Reference: :ref:`strategies:fixed window`
r	   r   r   r   r   r   c                    U R                   R                  UR                  " U6 UR                  5       SUS9UR                  :*  $ )r!   Felastic_expiryrI   r   incrr2   rJ   rI   r$   s       r   r%   FixedWindowRateLimiter.hit   sJ     LLk*!$	   {{	
r   c                x    U R                   R                  UR                  " U6 5      UR                  U-
  S-   :  $ rM   )r   getr2   rI   r$   s       r   r)   FixedWindowRateLimiter.test   s6     ||k :;dkkD>PST>TTTr   c           	          [        SUR                  U R                  R                  UR                  " U6 5      -
  5      nU R                  R                  UR                  " U6 5      n[        XC5      $ )r,   r   )maxrI   r   r`   r2   rJ   r   )r   r   r   	remainingrR   s        r   r.   'FixedWindowRateLimiter.get_window_stats   sY     4;;)9)9$,,:T)UUV	''k(BC5,,r   r<   N)r4   r5   r6   r7   rT   r
   r8   r9   r:   r%   r)   r   r.   r;   r<   r   r   rW   rW   |   sv     GH 
 
S 
 
D 
( HI 
U 
Uc 
U 
UT 
U-] -# -+ -r   rW   c            	       :    \ rS rSrSrSS.S\S\S\S\4S	 jjr	S
r
g)#FixedWindowElasticExpiryRateLimiter   z?
Reference: :ref:`strategies:fixed window with elastic expiry`
r	   r   r   r   r   r   c                    U R                   R                  UR                  " U6 UR                  5       SUS9UR                  :*  $ )r!   TrZ   r\   r$   s       r   r%   'FixedWindowElasticExpiryRateLimiter.hit   sJ     LLk*!#	   {{	
r   r<   N)r4   r5   r6   r7   rT   r
   r8   r9   r:   r%   r;   r<   r   r   rg   rg      s4     GH 
 
S 
 
D 
 
r   rg   )zfixed-windowzfixed-window-elastic-expiryzmoving-window
STRATEGIESN)rT   abcr   r   typingr   r   r   r   limitsr
   r   r   r   r   utilr   r   r?   rW   rg   KnownStrategyrk   r8   __annotations__r<   r   r   <module>rr      s    ( * * ! ? ? *>G *>Z?>k ?>D1-[ 1-h
*@ 
4 	 	,-	 !# +#F,(
Dm#$ r   