
    ZeIi)                    p   U d Z ddlmZ ddlZddlmZmZ ddlmZm	Z	 ddl
mZ ddlmZ dd	lmZ dd
lmZmZmZ ddlmZ ddlmZ  G d de          Z G d de          Z G d de          Z ed           G d de                      Zee         ee         z  ee         z  ZeeedZded<   dS )z
Rate limiting strategies
    )annotationsN)ABCMetaabstractmethod)floorinf)versionadded)SlidingWindowCounterSupport   )RateLimitItem)MovingWindowSupportStorageStorageTypes)cast)WindowStatsc                  r    e Zd ZddZedddd            Zedddd            Zedd            ZddZdS )RateLimiterstorager   c                B    t          |t                    sJ || _        d S N)
isinstancer   r   )selfr   s     V/var/www/html/MCyber-Diagnostic/venv/lib/python3.11/site-packages/limits/strategies.py__init__zRateLimiter.__init__   s#    '7+++++ '    r
   costitemr   identifiersstrr   intreturnboolc                   t           S  
        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   r   r   r   s       r   hitzRateLimiter.hit   
     "!r   c                   t           )aT  
        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   testzRateLimiter.test(   r*   r   r   c                    t           )
  
        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_statszRateLimiter.get_window_stats6   s
     "!r   Nonec                F    | j                              |j        |           S r   )r   clearkey_forr/   s      r   r3   zRateLimiter.clearB   s!    |!!,$,"<===r   Nr   r   r   r   r   r   r   r    r!   r"   r   r   r   r   r!   r   r   r   r   r   r!   r1   )	__name__
__module____qualname__r   r   r)   r,   r0   r3    r   r   r   r      s        ( ( ( ( FG " " " " " ^" GH " " " " " ^" 	" 	" 	" ^	"> > > > > >r   r   )	metaclassc                  H     e Zd ZdZd fdZddddZddddZddZ xZS )MovingWindowRateLimiterz4
    Reference: :ref:`strategies:moving window`
    r   r   c                    t          |d          s't          |d          st          d|j                   t                                          |           d S )Nacquire_entryget_moving_windowz@MovingWindowRateLimiting is not implemented for storage of type hasattrr'   	__class__superr   r   r   rE   s     r   r   z MovingWindowRateLimiter.__init__K   sq    G_--	18BU1V1V	 &/",/ /   	!!!!!r   r
   r   r   r   r   r   r   r    r!   r"   c                   t          t          | j                                       |j        | |j        |                                |          S r%   )amount)r   r   r   rA   r4   rJ   
get_expiryr(   s       r   r)   zMovingWindowRateLimiter.hitU   sM     '66DDDL+&T__5F5Ft E 
 
 	
r   c                   t          t          | j                                       |j        | |j        |                                          d         |j        |z
  k    S aK  
        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   rB   r4   rJ   rK   r(   s       r   r,   zMovingWindowRateLimiter.teste   sb     $dl33EEk*!!  	
 {T!"	
r   r   c                   t          t          | j                                       |j        | |j        |                                          \  }}||                                z   }t          ||j        |z
            S )a  
        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   rB   r4   rJ   rK   r   )r   r   r   window_startwindow_itemsresets         r   r0   z(MovingWindowRateLimiter.get_window_statsz   su     &*&
 &


LDL+6T__EVEV
W
W 	#l t0005$+"<===r   r5   r6   r7   )	r9   r:   r;   __doc__r   r)   r,   r0   __classcell__rE   s   @r   r?   r?   F   s         " " " " " " GH 
 
 
 
 
 
  HI 
 
 
 
 
 
*> > > > > > > >r   r?   c                  6    e Zd ZdZddddZddddZddZdS )FixedWindowRateLimiterz3
    Reference: :ref:`strategies:fixed window`
    r
   r   r   r   r   r   r   r    r!   r"   c                   | j                              |j        | |                                |          |j        k    S rI   )r   incrr4   rK   rJ   r(   s       r   r)   zFixedWindowRateLimiter.hit   sK     Lk*!!   
 {	
r   c               d    | j                              |j        |           |j        |z
  dz   k     S rM   )r   getr4   rJ   r(   s       r   r,   zFixedWindowRateLimiter.test   s5     |k :;;dkD>PST>TTTr   r   c           	         t          d|j        | j                             |j        |           z
            }| j                             |j        |           }t          ||          S )r.   r   )maxrJ   r   rZ   r4   rK   r   )r   r   r   	remainingrQ   s        r   r0   z'FixedWindowRateLimiter.get_window_stats   sa     4;)9)9,$,:T)U)UUVV	''k(BCC5),,,r   Nr6   r7   )r9   r:   r;   rR   r)   r,   r0   r<   r   r   rV   rV      s          GH 
 
 
 
 
 
* HI U U U U U U- - - - - -r   rV   z4.1)versionc                  X     e Zd ZdZd fdZddZddddZddddZddZddZ	 xZ
S )SlidingWindowCounterRateLimiterz=
    Reference: :ref:`strategies:sliding window counter`
    r   r   c                    t          |d          rt          |d          st          d|j                   t                                          |           d S )Nget_sliding_windowacquire_sliding_window_entryzHSlidingWindowCounterRateLimiting is not implemented for storage of type rC   rG   s     r   r   z(SlidingWindowCounterRateLimiter.__init__   sv    w 455 	W3>
 >
 	 &/",/ /   	!!!!!r   r   r   previous_countr    previous_expires_infloatcurrent_countr!   c                <    ||z  |                                 z  |z   S )zu
        Return the approximated by weighting the previous window count and adding the current window count.
        )rK   )r   r   rd   re   rg   s        r   _weighted_countz/SlidingWindowCounterRateLimiter._weighted_count   s$      33doo6G6GG-WWr   r
   r   r   r   r   r"   c                   t          t          | j                                       |j        | |j        |                                |          S r$   )r   r	   r   rc   r4   rJ   rK   r(   s       r   r)   z#SlidingWindowCounterRateLimiter.hit   sN     '
 

&
&DL+&KOO	
 
	
r   c                   t          t          | j                                       |j        | |                                          \  }}}}|                     ||||          |j        |z
  dz   k     S rM   )r   r	   r   rb   r4   rK   ri   rJ   )r   r   r   r   rd   re   rg   _s           r   r,   z$SlidingWindowCounterRateLimiter.test   s     AE'A
 A


\T\;79J9J
K
K 	>+]A
   n&9=  kD 1$%	
r   r   c                   t          t          | j                                       |j        | |                                          \  }}}}t          d|j        t          | 	                    ||||                    z
            }t          j
                    }|s|st          ||          S |                                }	t          t          }}
|r||	|z  z  }
|r||	z  }t          |t          |
|          z   |          S )a  
        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   rb   r4   rK   r\   rJ   r   ri   timer   r   min)r   r   r   rd   re   rg   current_expires_inr]   nowexpiryprevious_reset_incurrent_reset_ins               r   r0   z0SlidingWindowCounterRateLimiter.get_window_stats  s*    RV'R
 R


\T\;79J9J
K
K 	O+]<N K$$.*=}  
 
	 ikk 	/- 	/sI..."".13+ 	P 3v7N O 	;1F:3%68H!I!II9UUUr   r1   c                    t          t          | j                                       |j        | |                                          S r   )r   r	   r   clear_sliding_windowr4   rK   r/   s      r   r3   z%SlidingWindowCounterRateLimiter.clear.  s?    />>SSDL+&(9(9
 
 	
r   r5   )
r   r   rd   r    re   rf   rg   r    r!   rf   r6   r7   r8   )r9   r:   r;   rR   r   ri   r)   r,   r0   r3   rS   rT   s   @r   r`   r`      s         " " " " " "
X 
X 
X 
X GH 
 
 
 
 
 
( HI 
 
 
 
 
 
,$V $V $V $VL
 
 
 
 
 
 
 
r   r`   )zsliding-window-counterzfixed-windowzmoving-windowzdict[str, KnownStrategy]
STRATEGIES) rR   
__future__r   rn   abcr   r   mathr   r   deprecated.sphinxr   limits.storage.baser	   limitsr   r   r   r   r   typingr   utilr   r   r?   rV   r`   typeKnownStrategyrw   __annotations__r<   r   r   <module>r      s     # " " " " "  ' ' ' ' ' ' ' '         * * * * * * ; ; ; ; ; ; ! ! ! ! ! ! ? ? ? ? ? ? ? ? ? ?            .> .> .> .> .>G .> .> .> .>bB> B> B> B> B>k B> B> B>J4- 4- 4- 4- 4-[ 4- 4- 4-n en
 n
 n
 n
 n
k n
 n
 n
d 		()
!"#
"#$  >*,( (
      r   