Ë
    ±Œj_  ã                  óÒ   — 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mZmZmZmZ d dlmZ 	 	 	 	 dd„Z G d	„ d
ee	¬«      Z G d„ de«      Z G d„ de«      Z G d„ d«      Zy)é    )ÚannotationsN)ÚABCÚabstractmethod)Úerrors)ÚStorageRegistry)ÚAnyÚCallableÚPÚRÚcast)ÚLazyDependencyc                óD   ‡ — t        j                  ‰ «      dˆ fd„«       }|S )Nc                 ó°   •— t        t        | d   «      }	  ‰| i |¤ŽS # |j                  $ r(}|j                  rt	        j
                  |«      |‚‚ d }~ww xY w)Nr   )r   ÚStorageÚbase_exceptionsÚwrap_exceptionsr   ÚStorageError)ÚargsÚkwargsÚinstanceÚexcÚfns       €ú]/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/limits/storage/base.pyÚinnerz_wrap_errors.<locals>.inner   s]   ø€ äœ  a¡Ó)ˆð	Ù�tÐ&˜vÑ&Ð&øØ×'Ñ'ò 	Ø×'Ò'Ü×)Ñ)¨#Ó.°CÐ7Øûð	ús   – žA­#AÁA)r   zP.argsr   zP.kwargsÚreturnr   )Ú	functoolsÚwraps)r   r   s   ` r   Ú_wrap_errorsr      s'   ø€ ô ‡_�_�RÓôó ðð €Ló    c                  óØ   ‡ — 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   zC
    Base class to extend when implementing a storage backend.
    zlist[str] | NoneÚSTORAGE_SCHEMEc                ór   •— dD ]"  }t        | |t        t        | |«      «      «       Œ$ t        ‰| �  di |¤Ž y )N>   ÚgetÚincrÚcheckÚclearÚresetÚ
get_expiry© ©Úsetattrr   ÚgetattrÚsuperÚ__init_subclass__©Úclsr   ÚmethodÚ	__class__s      €r   r.   zStorage.__init_subclass__*   s;   ø€ ó
ˆFô �C˜¤¬g°c¸6Ó.BÓ!CÕDð
ô 	‰Ñ!Ñ+ 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   Úoptionsr2   s       €r   r4   zStorage.__init__6   s   ø€ ô 	‰ÑÔØ.ˆÕr   c                ó   — t         ‚)N©ÚNotImplementedError©r5   s    r   r   zStorage.base_exceptionsD   s
   € ô "Ð!r   c                ó   — 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
        r9   )r5   ÚkeyÚexpiryÚamounts       r   r$   zStorage.incrI   s
   € ô "Ð!r   c                ó   — t         ‚)zB
        :param key: the key to get the counter value for
        r9   ©r5   r=   s     r   r#   zStorage.getT   ó
   € ô
 "Ð!r   c                ó   — t         ‚)z;
        :param key: the key to get the expiry for
        r9   rA   s     r   r(   zStorage.get_expiry[   rB   r   c                ó   — t         ‚)z-
        check if storage is healthy
        r9   r;   s    r   r%   zStorage.checkb   rB   r   c                ó   — t         ‚)z/
        reset storage to clear limits
        r9   r;   s    r   r'   zStorage.reseti   rB   r   c                ó   — t         ‚)za
        resets the rate limit key

        :param key: the key to clear rate limits for
        r9   rA   s     r   r&   zStorage.clearp   s
   € ô "Ð!r   ©r   r   r   ÚNone)NF)r6   z
str | Noner   Úboolr7   zfloat | str | bool)r   z-type[Exception] | tuple[type[Exception], ...]©é   )r=   Ústrr>   Úintr?   rM   r   rM   )r=   rL   r   rM   )r=   rL   r   Úfloat)r   rI   )r   z
int | None)r=   rL   r   rH   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r.   r4   Úpropertyr   r   r$   r#   r(   r%   r'   r&   Ú__classcell__©r2   s   @r   r   r   "   sÕ   ø… ñð %Ó$ØEõ
,ð Ø %ð/àð/ð ð/ð &õ	/ð Øò"ó ó ð"ð ó"ó ð"ð ò"ó ð"ð ò"ó ð"ð ò"ó ð"ð ò"ó ð"ð ò"ó ô"r   r   )Ú	metaclassc                  óJ   ‡ — e Zd ZdZdˆ fd„Zeddd„«       Zedd„«       Zˆ xZS )	ÚMovingWindowSupportzh
    Abstract base class for 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/   s      €r   r.   z%MovingWindowSupport.__init_subclass__€   s@   ø€ ó
ˆFô ØØÜœW S¨&Ó1Ó2õð	
ô 	‰Ñ!Ñ+ FÓ+r   c                ó   — 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
        r9   ©r5   r=   Úlimitr>   r?   s        r   r[   z!MovingWindowSupport.acquire_entryŒ   s
   € ô "Ð!r   c                ó   — 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)
        r9   )r5   r=   r_   r>   s       r   r\   z%MovingWindowSupport.get_moving_window–   s
   € ô "Ð!r   rG   rJ   ©
r=   rL   r_   rM   r>   rM   r?   rM   r   rI   )r=   rL   r_   rM   r>   rM   r   ztuple[float, int])	rO   rP   rQ   rR   r.   r   r[   r\   rU   rV   s   @r   rY   rY   z   s5   ø„ ñõ

,ð ó"ó ð"ð ò	"ó ô	"r   rY   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 )ÚSlidingWindowCounterSupportzr
    Abstract base class for 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*   r/   s      €r   r.   z-SlidingWindowCounterSupport.__init_subclass__©   s@   ø€ ó
ˆFô
 ØØÜœW S¨&Ó1Ó2õð
ô 	‰Ñ!Ñ+ FÓ+r   c                ó   — 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
        r9   r^   s        r   rg   z8SlidingWindowCounterSupport.acquire_sliding_window_entry¶   s
   € ô "Ð!r   c                ó   — 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
        r9   ©r5   r=   r>   s      r   re   z.SlidingWindowCounterSupport.get_sliding_windowÅ   s
   € ô "Ð!r   c                 ó   — y)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)   rj   s      r   rf   z0SlidingWindowCounterSupport.clear_sliding_windowÖ   s   € ð 	r   rG   rJ   ra   )r=   rL   r>   rM   r   ztuple[int, float, int, float])r=   rL   r>   rM   r   rH   )
rO   rP   rQ   rR   r.   r   rg   re   rf   rU   rV   s   @r   rc   rc   £   sŒ   ø„ ñõ
,ð à?@ð"Øð"Ø"ð"Ø,/ð"Ø9<ð"à	ò"ó ð"ð ð"Øð"Ø #ð"à	&ò"ó ð"ð  òó ôr   rc   c                  ó"   — e Zd ZdZedd„«       Zy)ÚTimestampedSlidingWindowz\Helper class for storage that support the sliding window counter, with timestamp based keys.c                óT   — |› dt        ||z
  |z  «      › �|› dt        ||z  «      › �fS )a-  
        returns the previous and the current window's keys.

        :param key: the key to get the window's keys from
        :param expiry: the expiry of the limit item, in seconds
        :param at: the timestamp to get the keys from. Default to now, ie ``time.time()``

        Returns a tuple with the previous and the current key: (previous, current).

        Example:
          - key = "mykey"
          - expiry = 60
          - at = 1738576292.6631825

        The return value will be the tuple ``("mykey/28976271", "mykey/28976270")``.
        Ú/)rM   )r0   r=   r>   Úats       r   Úsliding_window_keysz,TimestampedSlidingWindow.sliding_window_keysä   s>   € ð$ ��aœ˜R &™[¨FÑ2Ó3Ð4Ð5¸#¸¸aÄÀBÈÁKÓ@PÐ?QÐ7RÐRÐRr   N)r=   rL   r>   rM   rp   rN   r   ztuple[str, str])rO   rP   rQ   rR   Úclassmethodrq   r)   r   r   rm   rm   á   s   „ ÙfàòSó ñSr   rm   )r   úCallable[P, R]r   rs   )Ú
__future__r   r   Úabcr   r   Úlimitsr   Úlimits._storage_schemer   Úlimits.typingr   r	   r
   r   r   Úlimits.utilr   r   r   rY   rc   rm   r)   r   r   Ú<module>rz      so   ðÝ "ã ß #å Ý 2÷õ õ 'ðØðàóô U"ˆn¨õ U"ôp&"˜#ô &"ôR; #ô ;÷|Sò Sr   