
    ZeIi2                        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 d dlmZmZmZmZmZmZ d dlmZ ddZ ed           G d dee                      Z G d de          Z G d de          ZdS )    )annotationsN)ABCabstractmethod)versionadded)errors)StorageRegistry)Any	AwaitableCallablePRcast)LazyDependencyfnCallable[P, Awaitable[R]]returnc                H     t          j                   d fd            }|S )	NargsP.argskwargsP.kwargsr   r   c                    K   t          t          | d                   }	  | i | d {V 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       \/var/www/html/MCyber-Diagnostic/venv/lib/python3.11/site-packages/limits/aio/storage/base.pyinnerz_wrap_errors.<locals>.inner   s      a))	T,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    z2.1)versionc                       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   zJ
    Base class to extend when implementing an async storage backend.
    zlist[str] | NoneSTORAGE_SCHEMEr   r	   r   Nonec                     t                      j        di | dD ].}t          | |t          t	          | |                               / t                      j        di | d S )N>   getincrcheckclearreset
get_expiry )super__init_subclass__setattrr#   getattrclsr   method	__class__s      r   r2   zStorage.__init_subclass__.   s    !!++F+++
 	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   )selfr9   r   r<   r8   s       r   r?   zStorage.__init__;   s)     	.r$   -type[Exception] | tuple[type[Exception], ...]c                    t           )NNotImplementedErrorr@   s    r   r   zStorage.base_exceptionsH   s
     "!r$      keystrexpiryintamountc                   K   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
        rC   )r@   rG   rI   rK   s       r   r+   zStorage.incrM   s       "!r$   c                   K   t           )zB
        :param key: the key to get the counter value for
        rC   r@   rG   s     r   r*   zStorage.getX         
 "!r$   floatc                   K   t           )z;
        :param key: the key to get the expiry for
        rC   rN   s     r   r/   zStorage.get_expiry_   rO   r$   c                   K   t           )z-
        check if storage is healthy
        rC   rE   s    r   r,   zStorage.checkf   rO   r$   
int | Nonec                   K   t           )z/
        reset storage to clear limits
        rC   rE   s    r   r.   zStorage.resetm   rO   r$   c                   K   t           )za
        resets the rate limit key

        :param key: the key to clear rate limits for
        rC   rN   s     r   r-   zStorage.cleart   s       "!r$   r   r	   r   r(   )NF)r9   r:   r   r;   r<   r=   r   r(   )r   rA   rF   )rG   rH   rI   rJ   rK   rJ   r   rJ   )rG   rH   r   rJ   )rG   rH   r   rP   )r   r;   )r   rS   )rG   rH   r   r(   )__name__
__module____qualname____doc____annotations__r2   r?   propertyr   r   r+   r*   r/   r,   r.   r-   __classcell__r8   s   @r   r   r   %   st          %$$$E, , , , , ,  %/ / / / / / / " " " ^ X" " " " " ^" " " " ^" " " " ^" " " " ^" " " " ^" " " " ^" " " " "r$   r   )	metaclassc                  X     e Zd ZdZd fdZe	 ddd            Zedd            Z xZS )MovingWindowSupportzn
    Abstract base class for async 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_windowr0   r3   r#   r4   r1   r2   r5   s      r   r2   z%MovingWindowSupport.__init_subclass__   sm    
 	 	F WS&1122   
 	"!++F+++++r$   rF   rG   rH   limitrJ   rI   rK   r;   c                   K   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
        rC   r@   rG   rg   rI   rK   s        r   rd   z!MovingWindowSupport.acquire_entry   s       "!r$   tuple[float, int]c                   K   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)
        rC   )r@   rG   rg   rI   s       r   re   z%MovingWindowSupport.get_moving_window   s       "!r$   rV   rW   
rG   rH   rg   rJ   rI   rJ   rK   rJ   r   r;   )rG   rH   rg   rJ   rI   rJ   r   rj   )	rX   rY   rZ   r[   r2   r   rd   re   r^   r_   s   @r   rb   rb   ~   s         

, 
, 
, 
, 
, 
, ?@	" 	" 	" 	" ^	" " " " ^" " " " "r$   rb   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 )SlidingWindowCounterSupportzw
    Abstract base class for async 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_entryr0   rf   r5   s      r   r2   z-SlidingWindowCounterSupport.__init_subclass__   sm    
 		 		F
 WS&1122   
 	"!++F+++++r$   rF   rG   rH   rg   rJ   rI   rK   r;   c                   K   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
        rC   ri   s        r   rr   z8SlidingWindowCounterSupport.acquire_sliding_window_entry   s      " "!r$   tuple[int, float, int, float]c                   K   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
        rC   r@   rG   rI   s      r   rp   z.SlidingWindowCounterSupport.get_sliding_window   s       "!r$   c                
   K   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
        Nr0   rv   s      r   rq   z0SlidingWindowCounterSupport.clear_sliding_window   s       	r$   rV   rW   rl   )rG   rH   rI   rJ   r   rt   )rG   rH   rI   rJ   r   r(   )
rX   rY   rZ   r[   r2   r   rr   rp   rq   r^   r_   s   @r   rn   rn      s         
, , , , , ,  " " " " ^"$ " " " ^"     ^    r$   rn   )r   r   r   r   )
__future__r   r!   abcr   r   deprecated.sphinxr   limitsr   limits.storage.registryr   limits.typingr	   r
   r   r   r   r   limits.utilr   r#   r   rb   rn   r0   r$   r   <module>r      s   " " " " " "     # # # # # # # # * * * * * *       3 3 3 3 3 3                ' & & & & &     eU" U" U" U" U"n U" U" U" U"p*" *" *" *" *"# *" *" *"Z? ? ? ? ?# ? ? ? ? ?r$   