
    ^g'                        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       ^/var/www/html/suriana-translation/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)aD  
        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 elastic_expiry: whether to keep extending the rate limit
         window every hit.
        :param amount: the number to increment by
        r;   )r7   keyexpiryelastic_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.get\        
 "!rC   c                   K   t         w)z;
        :param key: the key to get the expiry for
        r;   rE   s     r   r+   zStorage.get_expiryc   rF   rC   c                   K   t         w)z-
        check if storage is healthy
        r;   r=   s    r   r(   zStorage.checkj   rF   rC   c                   K   t         w)z/
        reset storage to clear limits
        r;   r=   s    r   r*   zStorage.resetq   rF   rC   c                   K   t         w)za
        resets the rate limit key

        :param key: the key to clear rate limits for
        r;   rE   s     r   r)   zStorage.clearx   s      "!rC   r   r	   r   None)NF)r8   z
str | Noner   boolr9   zfloat | str | boolr   rL   )r   z-type[Exception] | tuple[type[Exception], ...])F   )
r?   strr@   intrA   rM   rB   rP   r   rP   )r?   rO   r   rP   )r?   rO   r   float)r   rM   )r   z
int | None)r?   rO   r   rL   )__name__
__module____qualname____doc____annotations__r.   r6   propertyr   r   r'   r&   r+   r(   r*   r)   __classcell__r4   s   @r   r   r   %   s
    %$E,  %// / &	/
 
/ "  " QR"" #"59"KN"	" " " " " " " " " " " "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@   rB   s        r   r^   z!MovingWindowSupport.acquire_entry   s      "!rC   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      "!rC   rK   rN   
r?   rO   rc   rP   r@   rP   rB   rP   r   rM   )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                  j     e Zd ZdZd fdZe	 d	 	 	 	 	 	 	 	 	 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acquire_sliding_window_entryr,   r`   r1   s      r   r.   z-SlidingWindowCounterSupport.__init_subclass__   sA    L 	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     " "!rC   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   rj   z.SlidingWindowCounterSupport.get_sliding_window   s      "!rC   rK   re   rf   )r?   rO   r@   rP   r   ztuple[int, float, int, float])	rR   rS   rT   rU   r.   r   rk   rj   rX   rY   s   @r   rh   rh      s    
,  "" " 	"
 " 
" "$ "" #"	&" "r!   rh   )r   Callable[P, Awaitable[R]]r   rn   )
__future__r   r   abcr   r   deprecated.sphinxr   limitsr   limits.storage.registryr   limits.typingr	   r
   r   r   r   r   limits.utilr   r    r   r\   rh   r,   r!   r   <module>rv      sz    "  # *  3  '!  eY"n Y" Y"x*"# *"Z1"# 1"r!   