o
    KDi2                     @  s   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dZeddG dd deedZG dd deZG d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                   s   t  d	 fdd}|S )
NargsP.argskwargsP.kwargsr   r   c               
     sV   t t| d }z | i |I d H W S  |jy* } z
|jr%t|| d }~ww )Nr   )r   Storagebase_exceptionswrap_exceptionsr   StorageError)r   r   instanceexcr    P/var/www/Datamplify/venv/lib/python3.10/site-packages/limits/aio/storage/base.pyinner   s   z_wrap_errors.<locals>.inner)r   r   r   r   r   r   )	functoolswraps)r   r   r   r   r   _wrap_errors   s   	r"   z2.1)versionc                      s   e Zd ZU dZded< 	 d+ fdd	Z	
	d,d- fddZeed.ddZ	ed/d0ddZ
ed1dd Zed2d"d#Zed3d$d%Zed4d'd(Zed5d)d*Z  ZS )6r   zJ
    Base class to extend when implementing an async storage backend.
    zlist[str] | NoneSTORAGE_SCHEMEr   r   r   Nonec                   sH   t  jdi | dD ]}t| |tt| | qt  jdi | d S )N>   getincrcheckclearreset
get_expiryr   )super__init_subclass__setattrr"   getattrclsr   method	__class__r   r   r-   .   s   zStorage.__init_subclass__NFuri
str | Noner   booloptionsfloat | str | boolc                   s   t    || _dS )z
        :param wrap_exceptions: Whether to wrap storage exceptions in
         :exc:`limits.errors.StorageError` before raising it.
        N)r,   __init__r   )selfr5   r   r8   r3   r   r   r:   ;   s   


zStorage.__init__-type[Exception] | tuple[type[Exception], ...]c                 C  s   t )NNotImplementedErrorr;   r   r   r   r   H   s   zStorage.base_exceptions   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
        r=   )r;   rA   rC   rE   r   r   r   r'   M   s   	zStorage.incrc                   rF   )zB
        :param key: the key to get the counter value for
        r=   r;   rA   r   r   r   r&   X      zStorage.getfloatc                   rF   )z;
        :param key: the key to get the expiry for
        r=   rG   r   r   r   r+   _   rH   zStorage.get_expiryc                   rF   )z-
        check if storage is healthy
        r=   r?   r   r   r   r(   f   rH   zStorage.check
int | Nonec                   rF   )z/
        reset storage to clear limits
        r=   r?   r   r   r   r*   m   rH   zStorage.resetc                   rF   )za
        resets the rate limit key

        :param key: the key to clear rate limits for
        r=   rG   r   r   r   r)   t   s   zStorage.clearr   r   r   r%   )NF)r5   r6   r   r7   r8   r9   r   r%   )r   r<   r@   )rA   rB   rC   rD   rE   rD   r   rD   )rA   rB   r   rD   )rA   rB   r   rI   )r   r7   )r   rJ   )rA   rB   r   r%   )__name__
__module____qualname____doc____annotations__r-   r:   propertyr   r   r'   r&   r+   r(   r*   r)   __classcell__r   r   r3   r   r   %   s.   
 
r   )	metaclassc                      sB   e Zd ZdZd fddZe	ddddZedddZ  ZS )MovingWindowSupportzn
    Abstract base class for async storages that support
    the :ref:`strategies:moving window` strategy
    r   r   r   r%   c                   6   dD ]}t | |tt| | qt jdi | d S )N>   acquire_entryget_moving_windowr   r.   r"   r/   r,   r-   r0   r3   r   r   r-      s   z%MovingWindowSupport.__init_subclass__r@   rA   rB   limitrD   rC   rE   r7   c                   rF   )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=   r;   rA   rZ   rC   rE   r   r   r   rW      s   
z!MovingWindowSupport.acquire_entrytuple[float, int]c                   rF   )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=   )r;   rA   rZ   rC   r   r   r   rX      s   z%MovingWindowSupport.get_moving_windowrK   rL   
rA   rB   rZ   rD   rC   rD   rE   rD   r   r7   )rA   rB   rZ   rD   rC   rD   r   r\   )	rM   rN   rO   rP   r-   r   rW   rX   rS   r   r   r3   r   rU   ~   s    rU   c                      sP   e Zd ZdZd fddZe	ddddZedddZedddZ  Z	S )SlidingWindowCounterSupportzw
    Abstract base class for async storages that support
    the :ref:`strategies:sliding window counter` strategy
    r   r   r   r%   c                   rV   )N>   get_sliding_windowclear_sliding_windowacquire_sliding_window_entryr   rY   r0   r3   r   r   r-      s   z-SlidingWindowCounterSupport.__init_subclass__r@   rA   rB   rZ   rD   rC   rE   r7   c                   rF   )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=   r[   r   r   r   ra      s   z8SlidingWindowCounterSupport.acquire_sliding_window_entrytuple[int, float, int, float]c                   rF   )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=   r;   rA   rC   r   r   r   r_      s   z.SlidingWindowCounterSupport.get_sliding_windowc                   s   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   rc   r   r   r   r`      s   z0SlidingWindowCounterSupport.clear_sliding_windowrK   rL   r]   )rA   rB   rC   rD   r   rb   )rA   rB   rC   rD   r   r%   )
rM   rN   rO   rP   r-   r   ra   r_   r`   rS   r   r   r3   r   r^      s    r^   )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   rU   r^   r   r   r   r   <module>   s     
X-