
    Iip                         S r SSKJrJr  SSKJr  SSKJr  SSKJ	r	  SSK
Jr  SS	KJrJr   " S
 S\5      r " S S\5      r " S S\5      r " S S\5      r\\\S.rg)z'
Asynchronous rate limiting strategies
    )ABCabstractmethod)cast   )RateLimitItem)StorageTypes)WindowStats   )MovingWindowSupportStoragec            
           \ 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     ;/venv/lib/python3.13/site-packages/limits/aio/strategies.py__init__RateLimiter.__init__   s    '7++++ '    r
   costitemidentifiersr   returnc                   #    [         e7f)
Consume the rate limit

:param item: the rate limit item
:param identifiers: variable list of strings to uniquely identify the
 limit
:param cost: The cost of this hit, default 1
NotImplementedErrorr   r   r   r   s       r   hitRateLimiter.hit         "!   	c                   #    [         e7f)
Check if the rate limit can be consumed

:param item: the rate limit item
:param identifiers: variable list of strings to uniquely identify the
 limit
:param cost: The expected cost to be consumed, default 1
r    r"   s       r   testRateLimiter.test   r%   r&   c                    #    [         e7f)z
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 the
 limit
:return: (reset time, remaining))
r    r   r   r   s      r   get_window_statsRateLimiter.get_window_stats+   s      "!r&   Nc                 n   #    U R                   R                  UR                  " U6 5      I S h  vN $  N7fr   )r   clearkey_forr,   s      r   r0   RateLimiter.clear9   s)     \\''k(BCCCCs   ,535)r   )__name__
__module____qualname____firstlineno__r   r   r   r   strintboolr#   r)   r	   r-   r0   __static_attributes__ r   r   r   r      s    ( ( LM 	"m 	"3 	"c 	"RV 	" 	" MN 	"} 	"C 	"s 	"SW 	" 	" "!"14"	" "D DS DT Dr   r   c            	          ^  \ rS rSrSrS\S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   r   Nc                    > [        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   rC   s     r   r    MovingWindowRateLimiter.__init__B   sL    G_--BU1V1V%&001  	!r   r
   r   r   r   r   c                   #    [        [        U R                  5      R                  UR                  " U6 UR
                  UR                  5       US9I Sh  vN $  N7f)r   )amountN)r   r   r   r@   r1   rG   
get_expiryr"   s       r   r#   MovingWindowRateLimiter.hitL   sS      -t||<JJLL+&T__5Ft K 
 
 	
 
s   AAAAc                   #    [        [        U R                  5      R                  UR                  " U6 UR
                  UR                  5       5      I Sh  vN nUS   nXQR
                  U-
  :*  $  N7fr(   Nr
   )r   r   r   rA   r1   rG   rH   )r   r   r   r   resrG   s         r   r)   MovingWindowRateLimiter.testZ   sg      ,dll;MMLL+&KKOO
 

 Qt+++
s   AA3A1A3c                   #    [        [        U R                  5      R                  UR                  " U6 UR
                  UR                  5       5      I Sh  vN u  p4X1R                  5       -   n[        XQR
                  U-
  5      $  N07f)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 the
 limit
:return: (reset time, remaining)
N)r   r   r   rA   r1   rG   rH   r	   )r   r   r   window_startwindow_itemsresets         r   r-   (MovingWindowRateLimiter.get_window_statsl   sq      ,0,


DLL+6T__EV
W&X" 005++"<==&Xs   AB	B1B	r;   )r3   r4   r5   r6   __doc__r   r   r   r7   r8   r9   r#   r)   r	   r-   r:   __classcell__)rC   s   @r   r=   r=   =   s    " " " MN 
m 
3 
c 
RV 
 NO ,} ,C ,s ,SW ,$>!>14>	> >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I Sh  vN UR                  :*  $  N7f)r   Felastic_expiryrG   Nr   incrr1   rH   rG   r"   s       r   r#   FixedWindowRateLimiter.hit   sW      ,,##k*!$	 $   {{	
s   ;AAAc                   #    U R                   R                  UR                  " U6 5      I Sh  vN UR                  U-
  S-   :  $  N7frK   )r   getr1   rG   r"   s       r   r)   FixedWindowRateLimiter.test   sA      ,,""4<<#=>>tASVWAWW	
>s   ,AAAc           	        #    [        SUR                  U R                  R                  UR                  " U6 5      I Sh  vN -
  5      nU R                  R                  UR                  " U6 5      I Sh  vN n[        XC5      $  NE N7f)z
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 the
 limit
:return: reset time, remaining
r   N)maxrG   r   r_   r1   rH   r	   )r   r   r   	remainingrQ   s        r   r-   'FixedWindowRateLimiter.get_window_stats   sq      KK 0 0{1K LLL
	 ll--dllK.HII5,,	 MIs"   =B	B 5B	5B6B	B	r;   N)r3   r4   r5   r6   rS   r   r7   r8   r9   r#   r)   r	   r-   r:   r;   r   r   rV   rV      sv     MN 
m 
3 
c 
RV 
( NO 
} 
C 
s 
SW 
-!-14-	-r   rV   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I Sh  vN nXAR                  :*  $  N7f)z
Consume the rate limit

:param item: a :class:`limits.limits.RateLimitItem` instance
:param identifiers: variable list of strings to uniquely identify the
 limit
:param cost: The cost of this hit, default 1
TrY   Nr[   )r   r   r   r   rG   s        r   r#   'FixedWindowElasticExpiryRateLimiter.hit   sU      ||((LL+&OO	 ) 
 
 $$
s   ;AAAr;   N)r3   r4   r5   r6   rS   r   r7   r8   r9   r#   r:   r;   r   r   rf   rf      s5     MN %m %3 %c %RV % %r   rf   )zfixed-windowzfixed-window-elastic-expiryzmoving-windowN)rS   abcr   r   typingr   limitsr   r   r   utilr	   r   r   r   r=   rV   rf   
STRATEGIESr;   r   r   <module>ro      sf    $  " "  1,D# ,D^?>k ?>D8-[ 8-v%*@ %2 +#F,
r   