
    5j1                        S SK Jr  S SKrS SKJrJr  S SKJr  S SKJ	r	  S SK
Jr  S SKJrJrJrJrJrJr  S SKJr      SS	 jr\" S
S9 " S S\\S95       r " S S\5      r " S S\5      rg)    )annotationsN)ABCabstractmethod)versionadded)errors)StorageRegistry)Any	AwaitableCallablePRcast)LazyDependencyc                J   ^  [         R                  " T 5      SU 4S jj5       nU$ )Nc                    >#    [        [        U S   5      n T" U 0 UD6I S h  vN $  N! UR                   a.  nUR                  (       a  [        R
                  " U5      Uee S nAff = f7f)Nr   )r   Storagebase_exceptionswrap_exceptionsr   StorageError)argskwargsinstanceexcfns       V/root/lseg-credit/backend/venv/lib/python3.13/site-packages/limits/aio/storage/base.pyinner_wrap_errors.<locals>.inner   se     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                     ^  \ rS rSr% SrS\S'    SU 4S jjr  S       SU 4S jjjr\\	SS j5       5       r
\	SSS jj5       r\	SS	 j5       r\	SS
 j5       r\	SS j5       r\	SS j5       r\	SS j5       rSrU =r$ )r   %   zB
Base class to extend when implementing an async storage backend.
zlist[str] | NoneSTORAGE_SCHEMEc                   > [         TU ]  " S0 UD6  S H!  n[        X[        [	        X5      5      5        M#     [         TU ]  " S0 UD6  g )N>   getincrcheckclearreset
get_expiry )super__init_subclass__setattrr!   getattrclsr   method	__class__s      r   r0   Storage.__init_subclass__.   sG    !+F+
F Cgc.B!CD
 	!+F+r"   c                .   > [         TU ]  5         X l        g)zu
:param wrap_exceptions: Whether to wrap storage exceptions in
 :exc:`limits.errors.StorageError` before raising it.
N)r/   __init__r   )selfurir   optionsr6   s       r   r9   Storage.__init__;   s     	.r"   c                    [         e)NNotImplementedErrorr:   s    r   r   Storage.base_exceptionsH   s
     "!r"   c                   #    [         e7f)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:   keyexpiryamounts       r   r)   Storage.incrM   s      "!   	c                   #    [         e7f)z2
:param key: the key to get the counter value for
r?   r:   rD   s     r   r(   Storage.getX        
 "!rH   c                   #    [         e7f)z+
:param key: the key to get the expiry for
r?   rJ   s     r   r-   Storage.get_expiry_   rL   rH   c                   #    [         e7f)z
check if storage is healthy
r?   rA   s    r   r*   Storage.checkf   rL   rH   c                   #    [         e7f)z
reset storage to clear limits
r?   rA   s    r   r,   Storage.resetm   rL   rH   c                   #    [         e7f)zI
resets the rate limit key

:param key: the key to clear rate limits for
r?   rJ   s     r   r+   Storage.cleart   s      "!rH   )r   r   r	   r   None)NF)r;   z
str | Noner   boolr<   zfloat | str | boolr   rV   )r   z-type[Exception] | tuple[type[Exception], ...]   )rD   strrE   intrF   r[   r   r[   )rD   rZ   r   r[   )rD   rZ   r   float)r   rW   )r   z
int | None)rD   rZ   r   rV   )__name__
__module____qualname____firstlineno____doc____annotations__r0   r9   propertyr   r   r)   r(   r-   r*   r,   r+   __static_attributes____classcell__r6   s   @r   r   r   %   s     %$E,  %// / &	/
 
/ / "  " " " " " " " " " " " " "r"   r   )	metaclassc                     ^  \ rS rSrSrSU 4S jjr\ S         S	S jj5       r\        S
S j5       rSr	U =r
$ )MovingWindowSupport~   zb
Abstract base class for async storages that support
the :ref:`strategies:moving window` strategy
c                v   > S H"  n[        U U[        [        X5      5      5        M$     [        TU ]  " S0 UD6  g )N>   acquire_entryget_moving_windowr.   r1   r!   r2   r/   r0   r3   s      r   r0   %MovingWindowSupport.__init_subclass__   s>    
F WS12	
 	!+F+r"   c                   #    [         e7f)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:   rD   limitrE   rF   s        r   rl   !MovingWindowSupport.acquire_entry   s      "!rH   c                   #    [         e7f)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:   rD   rr   rE   s       r   rm   %MovingWindowSupport.get_moving_window   s      "!rH   r.   rU   rX   
rD   rZ   rr   r[   rE   r[   rF   r[   r   rW   )rD   rZ   rr   r[   rE   r[   r   ztuple[float, int])r]   r^   r_   r`   ra   r0   r   rl   rm   rd   re   rf   s   @r   ri   ri   ~   s    

, ?@	"	""	",/	"9<	"		" 	" """",/"	" "r"   ri   c                     ^  \ rS rSrSrSU 4S jjr\ S	         S
S jj5       r\      SS j5       r\SS j5       r	Sr
U =r$ )SlidingWindowCounterSupport   zk
Abstract base class for async storages that support
the :ref:`strategies:sliding window counter` strategy
c                v   > S H"  n[        U U[        [        X5      5      5        M$     [        TU ]  " S0 UD6  g )N>   get_sliding_windowclear_sliding_windowacquire_sliding_window_entryr.   rn   r3   s      r   r0   -SlidingWindowCounterSupport.__init_subclass__   s>    
F
 WS12
 	!+F+r"   c                   #    [         e7f)a  
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?   rq   s        r   r}   8SlidingWindowCounterSupport.acquire_sliding_window_entry   s     " "!rH   c                   #    [         e7f)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:   rD   rE   s      r   r{   .SlidingWindowCounterSupport.get_sliding_window   s      "!rH   c                   #    g7f)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.   r   s      r   r|   0SlidingWindowCounterSupport.clear_sliding_window   s
      	s   r.   rU   rX   rv   )rD   rZ   rE   r[   r   ztuple[int, float, int, float])rD   rZ   rE   r[   r   rV   )r]   r^   r_   r`   ra   r0   r   r}   r{   r|   rd   re   rf   s   @r   rx   rx      s    
,  "" " 	"
 " 
" "$ "" #"	&" "   r"   rx   )r   Callable[P, Awaitable[R]]r   r   )
__future__r   r   abcr   r   deprecated.sphinxr   limitsr   limits._storage_schemer   limits.typingr	   r
   r   r   r   r   limits.utilr   r!   r   ri   rx   r.   r"   r   <module>r      sz    "  # *  2  '!  eU"n U" U"p*"# *"Z?# ?r"   