
    ZeIi`                        d dl mZ d dlZd dlmZmZ d dlmZ d dlm	Z	 d dl
mZmZmZmZmZ d dlmZ ddZ G d dee	          Z G d de          Z G d de          Z G d d          ZdS )    )annotationsN)ABCabstractmethod)errors)StorageRegistry)AnyCallablePRcast)LazyDependencyfnCallable[P, R]returnc                H     t          j                   d fd            }|S )	NargsP.argskwargsP.kwargsr   r   c                     t          t          | d                   }	  | i |S # |j        $ r"}|j        rt	          j        |          | d }~ww xY w)Nr   )r   Storagebase_exceptionswrap_exceptionsr   StorageError)r   r   instanceexcr   s       X/var/www/html/MCyber-Diagnostic/venv/lib/python3.11/site-packages/limits/storage/base.pyinnerz_wrap_errors.<locals>.inner   ss    a))	2t&v&&&' 	 	 	' 8)#..C7	s   & 
AAA)r   r   r   r   r   r   )	functoolswraps)r   r   s   ` r   _wrap_errorsr!      s?     _R      L    c                       e Zd ZU dZded<   	 d" fdZ	 	 d#d$ fdZeed%d                        Z	ed&d'd            Z
ed(d            Zed)d            Zed*d            Zed+d             Zed,d!            Z xZS )-r   zC
    Base class to extend when implementing a storage backend.
    zlist[str] | NoneSTORAGE_SCHEMEr   r   r   Nonec                    dD ].}t          | |t          t          | |                               / t                      j        di | d S )N>   getincrcheckclearreset
get_expiry setattrr!   getattrsuper__init_subclass__clsr   method	__class__s      r   r2   zStorage.__init_subclass__*   sb    
 	E 	EF Cgc6.B.B!C!CDDDD!!++F+++++r"   NFuri
str | Noner   booloptionsfloat | str | boolc                V    t                                                       || _        dS )z
        :param wrap_exceptions: Whether to wrap storage exceptions in
         :exc:`limits.errors.StorageError` before raising it.
        N)r1   __init__r   )selfr7   r   r:   r6   s       r   r=   zStorage.__init__6   s)     	.r"   -type[Exception] | tuple[type[Exception], ...]c                    t           )NNotImplementedErrorr>   s    r   r   zStorage.base_exceptionsD   s
     "!r"      keystrexpiryintamountc                    t           )z
        increments the counter for a given rate limit key

        :param key: the key to increment
        :param expiry: amount in seconds for the key to expire in
        :param amount: the number to increment by
        rA   )r>   rE   rG   rI   s       r   r(   zStorage.incrI   s
     "!r"   c                    t           )zB
        :param key: the key to get the counter value for
        rA   r>   rE   s     r   r'   zStorage.getT   
    
 "!r"   floatc                    t           )z;
        :param key: the key to get the expiry for
        rA   rL   s     r   r,   zStorage.get_expiry[   rM   r"   c                    t           )z-
        check if storage is healthy
        rA   rC   s    r   r)   zStorage.checkb   rM   r"   
int | Nonec                    t           )z/
        reset storage to clear limits
        rA   rC   s    r   r+   zStorage.reseti   rM   r"   c                    t           )za
        resets the rate limit key

        :param key: the key to clear rate limits for
        rA   rL   s     r   r*   zStorage.clearp   s
     "!r"   r   r   r   r%   )NF)r7   r8   r   r9   r:   r;   )r   r?   rD   )rE   rF   rG   rH   rI   rH   r   rH   )rE   rF   r   rH   )rE   rF   r   rN   )r   r9   )r   rQ   )rE   rF   r   r%   )__name__
__module____qualname____doc____annotations__r2   r=   propertyr   r   r(   r'   r,   r)   r+   r*   __classcell__r6   s   @r   r   r   "   st          %$$$E
, 
, 
, 
, 
, 
,  %/ / / / / / / " " " ^ X" " " " " ^" " " " ^" " " " ^" " " " ^" " " " ^" " " " ^" " " " "r"   r   )	metaclassc                  V     e Zd ZdZd fdZeddd            Zedd            Z xZS )MovingWindowSupportzh
    Abstract base class for storages that support
    the :ref:`strategies:moving window` strategy
    r   r   r   r%   c                    dD ].}t          | |t          t          | |                               / t                      j        di | d S )N>   acquire_entryget_moving_windowr-   r.   r3   s      r   r2   z%MovingWindowSupport.__init_subclass__   sm    
 	 	F WS&1122   
 	"!++F+++++r"   rD   rE   rF   limitrH   rG   rI   r9   c                    t           )z
        :param key: rate limit key to acquire an entry in
        :param limit: amount of entries allowed
        :param expiry: expiry of the entry
        :param amount: the number of entries to acquire
        rA   r>   rE   rd   rG   rI   s        r   rb   z!MovingWindowSupport.acquire_entry   s
     "!r"   tuple[float, int]c                    t           )z
        returns the starting point and the number of entries in the moving
        window

        :param key: rate limit key
        :param expiry: expiry of entry
        :return: (start of window, number of acquired entries)
        rA   )r>   rE   rd   rG   s       r   rc   z%MovingWindowSupport.get_moving_window   s
     "!r"   rT   rU   
rE   rF   rd   rH   rG   rH   rI   rH   r   r9   )rE   rF   rd   rH   rG   rH   r   rg   )	rV   rW   rX   rY   r2   r   rb   rc   r\   r]   s   @r   r`   r`   z   s         

, 
, 
, 
, 
, 
, " " " " ^" 	" 	" 	" ^	" 	" 	" 	" 	"r"   r`   c                  p     e Zd ZdZd fdZe	 ddd            Zedd            Zedd            Z xZ	S )SlidingWindowCounterSupportzr
    Abstract base class for storages that support
    the :ref:`strategies:sliding window counter` strategy.
    r   r   r   r%   c                    dD ].}t          | |t          t          | |                               / t                      j        di | d S )N>   get_sliding_windowclear_sliding_windowacquire_sliding_window_entryr-   r.   r3   s      r   r2   z-SlidingWindowCounterSupport.__init_subclass__   sm    
 		 		F
 WS&1122   
 	"!++F+++++r"   rD   rE   rF   rd   rH   rG   rI   r9   c                    t           )aU  
        Acquire an entry if the weighted count of the current and previous
        windows is less than or equal to the limit

        :param key: rate limit key to acquire an entry in
        :param limit: amount of entries allowed
        :param expiry: expiry of the entry
        :param amount: the number of entries to acquire
        rA   rf   s        r   ro   z8SlidingWindowCounterSupport.acquire_sliding_window_entry   s
     "!r"   tuple[int, float, int, float]c                    t           )a  
        Return the previous and current window information.

        :param key: the rate limit key
        :param expiry: the rate limit expiry, needed to compute the key in some implementations
        :return: a tuple of (int, float, int, float) with the following information:
          - previous window counter
          - previous window TTL
          - current window counter
          - current window TTL
        rA   r>   rE   rG   s      r   rm   z.SlidingWindowCounterSupport.get_sliding_window   s
     "!r"   c                    dS )z
        Resets the rate limit key(s) for the sliding window

        :param key: the key to clear rate limits for
        :param expiry: the rate limit expiry, needed to compute the key in some implemenations
        Nr-   rs   s      r   rn   z0SlidingWindowCounterSupport.clear_sliding_window   s	     	r"   rT   rU   ri   )rE   rF   rG   rH   r   rq   )rE   rF   rG   rH   r   r%   )
rV   rW   rX   rY   r2   r   ro   rm   rn   r\   r]   s   @r   rk   rk      s         
, , , , , , ?@" " " " ^" " " " ^"     ^    r"   rk   c                  *    e Zd ZdZedd
            ZdS )TimestampedSlidingWindowz\Helper class for storage that support the sliding window counter, with timestamp based keys.rE   rF   rG   rH   atrN   r   tuple[str, str]c                d    | dt          ||z
  |z             | dt          ||z             fS )a-  
        returns the previous and the current window's keys.

        :param key: the key to get the window's keys from
        :param expiry: the expiry of the limit item, in seconds
        :param at: the timestamp to get the keys from. Default to now, ie ``time.time()``

        Returns a tuple with the previous and the current key: (previous, current).

        Example:
          - key = "mykey"
          - expiry = 60
          - at = 1738576292.6631825

        The return value will be the tuple ``("mykey/28976271", "mykey/28976270")``.
        /)rH   )r4   rE   rG   rw   s       r   sliding_window_keysz,TimestampedSlidingWindow.sliding_window_keys   sH    $ 55R&[F23355#7R7RBK@P@P7R7RRRr"   N)rE   rF   rG   rH   rw   rN   r   rx   )rV   rW   rX   rY   classmethodr{   r-   r"   r   rv   rv      s>        ffS S S [S S Sr"   rv   )r   r   r   r   )
__future__r   r   abcr   r   limitsr   limits.storage.registryr   limits.typingr   r	   r
   r   r   limits.utilr   r!   r   r`   rk   rv   r-   r"   r   <module>r      s   " " " " " "     # # # # # # # #       3 3 3 3 3 3              ' & & & & &    U" U" U" U" U"n U" U" U" U"p&" &" &" &" &"# &" &" &"R; ; ; ; ;# ; ; ;|S S S S S S S S S Sr"   