
    Ti)                    ,   % S r SSKJr  SSKrSSKJrJ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JrJr  SSKJr  SSKJr   " S S\S9r " S S\5      r " S S\5      r\" SS9 " S S\5      5       r\\   \\   -  \\   -  r\\\S.rS\S'   g)z
Rate limiting strategies
    )annotationsN)ABCMetaabstractmethod)floorinf)versionadded)SlidingWindowCounterSupport   )RateLimitItem)MovingWindowSupportStorageStorageTypes)cast)WindowStatsc                  t    \ rS rSrSS jr\SS.SS jj5       r\SS.SS jj5       r\SS j5       rSS jr	S	r
g
)RateLimiter   c                >    [        U[        5      (       d   eXl        g N)
isinstancer   storage)selfr   s     c/var/www/html/backend/Backoffice_Marketplace/venv/lib/python3.13/site-packages/limits/strategies.py__init__RateLimiter.__init__   s    '7++++ '    r
   costc                   [         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

:return: True if ``cost`` could be deducted from the rate limit without exceeding it
NotImplementedErrorr   itemr   identifierss       r   hitRateLimiter.hit   
     "!r   c                   [         e)a  
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

:return: True if the rate limit is not depleted
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_stats6   s
     "!r   c                R    U R                   R                  UR                  " U6 5      $ r   )r   clearkey_forr/   s      r   r3   RateLimiter.clearB   s     ||!!$,,"<==r   )r   Nr   r   r%   r   r&   strr   intreturnboolr%   r   r&   r8   r:   r   r%   r   r&   r8   r:   None)__name__
__module____qualname____firstlineno__r   r   r'   r+   r0   r3   __static_attributes__ r   r   r   r      sN    ( FG " " GH " " 	" 	">r   r   )	metaclassc                  ^   ^  \ rS rSrSrS
U 4S jjrSS.SS jjrSS.SS jjrSS jrS	r	U =r
$ )MovingWindowRateLimiterF   z,
Reference: :ref:`strategies:moving window`
c                   > [        US5      (       d)  [        US5      (       d  [        SUR                   35      e[        TU ]  U5        g )Nacquire_entryget_moving_windowz@MovingWindowRateLimiting is not implemented for storage of type hasattrr#   	__class__superr   r   r   rN   s     r   r    MovingWindowRateLimiter.__init__K   sO    G_--BU1V1V%",,-/  	!r   r
   r   c                   [        [        U R                  5      R                  UR                  " U6 UR
                  UR                  5       US9$ r!   )amount)r   r   r   rJ   r4   rT   
get_expiryr$   s       r   r'   MovingWindowRateLimiter.hitU   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-
  :*  $ a  
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

:return: True if the rate limit is not depleted
r
   )r   r   r   rK   r4   rT   rU   r$   s       r   r+   MovingWindowRateLimiter.teste   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   rK   r4   rT   rU   r   )r   r%   r&   window_startwindow_itemsresets         r   r0   (MovingWindowRateLimiter.get_window_statsz   sd     &*&


DLL+6T__EV
W 	# 005++"<==r   rD   r6   r7   r<   )r?   r@   rA   rB   __doc__r   r'   r+   r0   rC   __classcell__rN   s   @r   rG   rG   F   s/    " GH 
  HI 
*> >r   rG   c                  F    \ rS rSrSrSS.S
S jjrSS.S
S jjrSS jrSrg	)FixedWindowRateLimiter   z+
Reference: :ref:`strategies:fixed window`
r
   r   c                   U R                   R                  UR                  " U6 UR                  5       US9UR                  :*  $ rS   )r   incrr4   rU   rT   r$   s       r   r'   FixedWindowRateLimiter.hit   sG     LLk*!  
 {{	
r   c               x    U R                   R                  UR                  " U6 5      UR                  U-
  S-   :  $ rX   )r   getr4   rT   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   )maxrT   r   ri   r4   rU   r   )r   r%   r&   	remainingr]   s        r   r0   'FixedWindowRateLimiter.get_window_stats   sY     4;;)9)9$,,:T)UUV	''k(BC5,,r   rD   Nr7   r<   )	r?   r@   rA   rB   r_   r'   r+   r0   rC   rD   r   r   rc   rc      s%     GH 
* HI U-r   rc   z4.1)versionc                     ^  \ rS rSrSrSU 4S jjr          SS jrSS.SS jjrSS.SS jjrSS	 jr	SS
 jr
SrU =r$ )SlidingWindowCounterRateLimiter   z5
Reference: :ref:`strategies:sliding window counter`
c                   > [        US5      (       a  [        US5      (       d  [        SUR                   35      e[        TU ]  U5        g )Nget_sliding_windowacquire_sliding_window_entryzHSlidingWindowCounterRateLimiting is not implemented for storage of type rL   rP   s     r   r   (SlidingWindowCounterRateLimiter.__init__   sW    w 455W3>
 >
 &",,-/  	!r   c                2    X#-  UR                  5       -  U-   $ )ze
Return the approximated by weighting the previous window count and adding the current window count.
)rU   )r   r%   previous_countprevious_expires_incurrent_counts        r   _weighted_count/SlidingWindowCounterRateLimiter._weighted_count   s     3doo6GG-WWr   r
   r   c                   [        [        U R                  5      R                  UR                  " U6 UR
                  UR                  5       U5      $ r    )r   r	   r   ru   r4   rT   rU   r$   s       r   r'   #SlidingWindowCounterRateLimiter.hit   sE     '

&
&LL+&KKOO	
	
r   c                   [        [        U R                  5      R                  UR                  " U6 UR                  5       5      u  pEpgU R                  XXV5      UR                  U-
  S-   :  $ rX   )r   r	   r   rt   r4   rU   r{   rT   )r   r%   r   r&   rx   ry   rz   _s           r   r+   $SlidingWindowCounterRateLimiter.test   sq     AE'A


T\\;79J
K 	>]
   &9 kkD 1$%	
r   c                   [        [        U R                  5      R                  UR                  " U6 UR                  5       5      u  p4pV[        SUR                  [        U R                  XXE5      5      -
  5      n[        R                  " 5       nU(       d  U(       d  [        X5      $ UR                  5       n	[        [        pU(       a  XIU-  -  n
U(       a  Xi-  n[        U[        X5      -   U5      $ )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 this
 instance of the limit
:return: WindowStats(reset time, remaining)
r   )r   r	   r   rt   r4   rU   rl   rT   r   r{   timer   r   min)r   r%   r&   rx   ry   rz   current_expires_inrm   nowexpiryprevious_reset_incurrent_reset_ins               r   r0   0SlidingWindowCounterRateLimiter.get_window_stats  s     RV'R


T\\;79J
K 	O] KK$$*=
	 iik-s..".13+ 37N O1:3%6!II9UUr   c                    [        [        U R                  5      R                  UR                  " U6 UR                  5       5      $ r   )r   r	   r   clear_sliding_windowr4   rU   r/   s      r   r3   %SlidingWindowCounterRateLimiter.clear.  s6    />SSLL+&(9
 	
r   rD   r6   )
r%   r   rx   r9   ry   floatrz   r9   r:   r   r7   r<   r=   )r?   r@   rA   rB   r_   r   r{   r'   r+   r0   r3   rC   r`   ra   s   @r   rq   rq      sq    "
X
X 
X #	
X
 
X 

X GH 
( HI 
,$VL
 
r   rq   )zsliding-window-counterzfixed-windowzmoving-windowzdict[str, KnownStrategy]
STRATEGIES) r_   
__future__r   r   abcr   r   mathr   r   deprecated.sphinxr   limits.storage.baser	   limitsr   r   r   r   r   typingr   utilr   r   rG   rc   rq   typeKnownStrategyr   __annotations__rD   r   r   <module>r      s    #  '  * ; ! ? ?  .>G .>bB>k B>J4-[ 4-n en
k n
 n
d 		()
!"#
"#$  >*,(
$ r   