
    9i2                        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y)    )annotationsN)ABCabstractmethod)versionadded)errors)StorageRegistry)Any	AwaitableCallablePRcast)LazyDependencyc                D     t        j                         d fd       }|S )Nc                    K   t        t        | d         }	  | i | d {   S 7 # |j                  $ r(}|j                  rt	        j
                  |      | d }~ww xY ww)Nr   )r   Storagebase_exceptionswrap_exceptionsr   StorageError)argskwargsinstanceexcfns       J/var/www/html/venv/lib/python3.12/site-packages/limits/aio/storage/base.pyinnerz_wrap_errors.<locals>.inner   sf     a)	T,V,,,,'' 	''))#.C7	s0   A$* (* A$* A!#AA!!A$)r   zP.argsr   zP.kwargsreturnr   )	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_SCHEMEc                    t        |   di | dD ]"  }t        | |t        t	        | |                   $ t        |   di | y )N>   getincrcheckclearreset
get_expiry )super__init_subclass__setattrr    getattrclsr   method	__class__s      r   r.   zStorage.__init_subclass__.   sR    !+F+
 	EF Cgc6.B!CD	E 	!+F+r!   c                0    t         |           || _        y)z
        :param wrap_exceptions: Whether to wrap storage exceptions in
         :exc:`limits.errors.StorageError` before raising it.
        N)r-   __init__r   )selfurir   optionsr4   s       r   r6   zStorage.__init__;   s     	.r!   c                    t         )NNotImplementedErrorr7   s    r   r   zStorage.base_exceptionsH   s
     "!r!   c                   K   t         w)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
        r;   )r7   keyexpiryamounts       r   r'   zStorage.incrM   s      "!   	c                   K   t         w)zB
        :param key: the key to get the counter value for
        r;   r7   r?   s     r   r&   zStorage.getX        
 "!rB   c                   K   t         w)z;
        :param key: the key to get the expiry for
        r;   rD   s     r   r+   zStorage.get_expiry_   rE   rB   c                   K   t         w)z-
        check if storage is healthy
        r;   r=   s    r   r(   zStorage.checkf   rE   rB   c                   K   t         w)z/
        reset storage to clear limits
        r;   r=   s    r   r*   zStorage.resetm   rE   rB   c                   K   t         w)za
        resets the rate limit key

        :param key: the key to clear rate limits for
        r;   rD   s     r   r)   zStorage.cleart   s      "!rB   r   r	   r   None)NF)r8   z
str | Noner   boolr9   zfloat | str | boolr   rK   )r   z-type[Exception] | tuple[type[Exception], ...]   )r?   strr@   intrA   rP   r   rP   )r?   rO   r   rP   )r?   rO   r   float)r   rL   )r   z
int | None)r?   rO   r   rK   )__name__
__module____qualname____doc____annotations__r.   r6   propertyr   r   r'   r&   r+   r(   r*   r)   __classcell__r4   s   @r   r   r   %   s     %$E,  %// / &	/
 
/ "  " " " " " " " " " " " " "r!   r   )	metaclassc                  n     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
    c                r    dD ]"  }t        | |t        t        | |                   $ t        |   di | y )N>   acquire_entryget_moving_windowr,   r/   r    r0   r-   r.   r1   s      r   r.   z%MovingWindowSupport.__init_subclass__   sE    
 	F WS&12		 	!+F+r!   c                   K   t         w)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
        r;   r7   r?   limitr@   rA   s        r   r^   z!MovingWindowSupport.acquire_entry   s      "!rB   c                   K   t         w)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)
        r;   )r7   r?   rc   r@   s       r   r_   z%MovingWindowSupport.get_moving_window   s      "!rB   rJ   rM   
r?   rO   rc   rP   r@   rP   rA   rP   r   rL   )r?   rO   rc   rP   r@   rP   r   ztuple[float, int])	rR   rS   rT   rU   r.   r   r^   r_   rX   rY   s   @r   r\   r\   ~   s    

, ?@	"	""	",/	"9<	"		" 	" """",/"	" "r!   r\   c                  |     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
    c                r    dD ]"  }t        | |t        t        | |                   $ t        |   di | y )N>   get_sliding_windowclear_sliding_windowacquire_sliding_window_entryr,   r`   r1   s      r   r.   z-SlidingWindowCounterSupport.__init_subclass__   sE    
 		F
 WS&12		 	!+F+r!   c                   K   t         w)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
        r;   rb   s        r   rk   z8SlidingWindowCounterSupport.acquire_sliding_window_entry   s     " "!rB   c                   K   t         w)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
        r;   r7   r?   r@   s      r   ri   z.SlidingWindowCounterSupport.get_sliding_window   s      "!rB   c                   K   yw)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,   rn   s      r   rj   z0SlidingWindowCounterSupport.clear_sliding_window   s      	s   rJ   rM   re   )r?   rO   r@   rP   r   ztuple[int, float, int, float])r?   rO   r@   rP   r   rK   )
rR   rS   rT   rU   r.   r   rk   ri   rj   rX   rY   s   @r   rg   rg      s    
,  "" " 	"
 " 
" "$ "" #"	&" "   r!   rg   )r   Callable[P, Awaitable[R]]r   rp   )
__future__r   r   abcr   r   deprecated.sphinxr   limitsr   limits.storage.registryr   limits.typingr	   r
   r   r   r   r   limits.utilr   r    r   r\   rg   r,   r!   r   <module>rx      sz    "  # *  3  '!  eU"n U" U"p*"# *"Z?# ?r!   