Ë
    ±Œjì)  ã                  ó8  — U d Z ddlmZ ddlZddlmZm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 ddlmZ ddlmZ  G d„ de¬«      Z G d„ de«      Z G d„ de«      Z ed¬«       G d„ de«      «       Zee   ee   z  ee   z  ZeeedœZded<   y)z
Rate limiting strategies
é    )ÚannotationsN)ÚABCMetaÚabstractmethod)ÚfloorÚinf)Úversionadded)ÚSlidingWindowCounterSupporté   )ÚRateLimitItem)ÚMovingWindowSupportÚStorageÚStorageTypes)Úcast)ÚWindowStatsc                  ó^   — e Zd Zd	d„Zeddœd
d„«       Zeddœd
d„«       Zedd„«       Zdd„Zy)ÚRateLimiterc                ó6   — t        |t        «      sJ ‚|| _        y ©N)Ú
isinstancer   Ústorage)Úselfr   s     ú[/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/limits/strategies.pyÚ__init__zRateLimiter.__init__   s   € Ü˜'¤7Ô+Ð+Ð+Ø 'ˆ�ó    r
   ©Úcostc               ó   — t         ‚©áS  
        Consume the rate limit

        :param item: The rate limit item
        :param identifiers: variable list of strings to uniquely identify this
         instance of the limit
        :param cost: The cost of this hit, default 1

        :return: True if ``cost`` could be deducted from the rate limit without exceeding it
        ©ÚNotImplementedError©r   Úitemr   Úidentifierss       r   ÚhitzRateLimiter.hit   ó
   € ô "Ð!r   c               ó   — t         ‚)aT  
        Check the rate limit without consuming from it.

        :param item: The rate limit item
        :param identifiers: variable list of strings to uniquely identify this
          instance of the limit
        :param cost: The expected cost to be consumed, default 1

        :return: True if the rate limit is not depleted
        r    r"   s       r   ÚtestzRateLimiter.test(   r&   r   c                ó   — t         ‚)á
  
        Query the reset time and remaining amount for the limit

        :param item: The rate limit item
        :param identifiers: variable list of strings to uniquely identify this
         instance of the limit
        :return: (reset time, remaining)
        r    ©r   r#   r$   s      r   Úget_window_statszRateLimiter.get_window_stats6   s
   € ô "Ð!r   c                óR   — | j                   j                   |j                  |Ž «      S r   )r   ÚclearÚkey_forr+   s      r   r.   zRateLimiter.clearB   s"   € Ø�|‰|×!Ñ! , $§,¡,°Ð"<Ó=Ð=r   N©r   r   ©r#   r   r$   Ústrr   ÚintÚreturnÚbool©r#   r   r$   r2   r4   r   ©r#   r   r$   r2   r4   ÚNone)	Ú__name__Ú
__module__Ú__qualname__r   r   r%   r(   r,   r.   © r   r   r   r      sN   „ ó(ð ØFGô "ó ð"ð ØGHô "ó ð"ð ò	"ó ð	"ô>r   r   )Ú	metaclassc                  óH   ‡ — e Zd ZdZdˆ fd„Zddœd	d„Zddœd	d„Zd
d„Zˆ xZS )ÚMovingWindowRateLimiterz4
    Reference: :ref:`strategies:moving window`
    c                ó„   •— t        |d«      s$t        |d«      st        d|j                  › �«      ‚t        ‰| �  |«       y )NÚacquire_entryÚget_moving_windowz@MovingWindowRateLimiting is not implemented for storage of type ©Úhasattrr!   Ú	__class__Úsuperr   ©r   r   rE   s     €r   r   z MovingWindowRateLimiter.__init__K   sI   ø€ ä�G˜_Ô-´¸ÐBUÔ1Vä%ðØ"×,Ñ,Ð-ð/óð ô 	‰Ñ˜Õ!r   r
   r   c               ó¦   — t        t        | j                  «      j                   |j                  |Ž |j
                  |j                  «       |¬«      S ©r   )Úamount)r   r   r   rA   r/   rJ   Ú
get_expiryr"   s       r   r%   zMovingWindowRateLimiter.hitU   sH   € ô Ô'¨¯©Ó6×DÑDØˆD�L‰L˜+Ð&¨¯©°T·_±_Ó5FÈtð Eó 
ð 	
r   c               óÈ   — t        t        | j                  «      j                   |j                  |Ž |j
                  |j                  «       «      d   |j
                  |z
  k  S ©aK  
        Check if the rate limit can be consumed

        :param item: The rate limit item
        :param identifiers: variable list of strings to uniquely identify this
         instance of the limit
        :param cost: The expected cost to be consumed, default 1

        :return: True if the rate limit is not depleted
        r
   )r   r   r   rB   r/   rJ   rK   r"   s       r   r(   zMovingWindowRateLimiter.teste   s_   € ô Ô$ d§l¡lÓ3×EÑEØ�—‘˜kÐ*Ø—‘Ø—‘Ó!óð ñ	ð
 �{‰{˜TÑ!ñ"ð	
r   c                ó   — t        t        | j                  «      j                   |j                  |Ž |j
                  |j                  «       «      \  }}||j                  «       z   }t        ||j
                  |z
  «      S )a  
        returns the number of requests remaining within this limit.

        :param item: The rate limit item
        :param identifiers: variable list of strings to uniquely identify this
         instance of the limit
        :return: tuple (reset time, remaining)
        )r   r   r   rB   r/   rJ   rK   r   )r   r#   r$   Úwindow_startÚwindow_itemsÚresets         r   r,   z(MovingWindowRateLimiter.get_window_statsz   sl   € ô &*Ü §¡ó&
ç
Ñ
˜L˜DŸL™L¨+Ð6¸¿¹ÀTÇ_Á_ÓEVÓ
Wñ 	#ˆ�lð ˜tŸ™Ó0Ñ0ˆä˜5 $§+¡+°Ñ"<Ó=Ð=r   r0   r1   r6   )	r9   r:   r;   Ú__doc__r   r%   r(   r,   Ú__classcell__©rE   s   @r   r?   r?   F   s*   ø„ ñõ"ð GHõ 
ð  HIõ 
÷*>r   r?   c                  ó4   — e Zd ZdZddœdd„Zddœdd„Zd	d„Zy)
ÚFixedWindowRateLimiterz3
    Reference: :ref:`strategies:fixed window`
    r
   r   c               óŽ   — | j                   j                   |j                  |Ž |j                  «       |¬«      |j                  k  S rI   )r   Úincrr/   rK   rJ   r"   s       r   r%   zFixedWindowRateLimiter.hit�   sI   € ð �L‰L×ÑØ�—‘˜kÐ*Ø—‘Ó!Øð ó ð
 �{‰{ñð	
r   c               óx   — | j                   j                   |j                  |Ž «      |j                  |z
  dz   k  S rM   )r   Úgetr/   rJ   r"   s       r   r(   zFixedWindowRateLimiter.test¥   s8   € ð �|‰|×Ñ  §¡¨kÐ :Ó;¸d¿k¹kÈDÑ>PÐSTÑ>TÑTÐTr   c           	     óè   — t        d|j                  | j                  j                   |j                  |Ž «      z
  «      }| j                  j                   |j                  |Ž «      }t        ||«      S )r*   r   )ÚmaxrJ   r   rZ   r/   rK   r   )r   r#   r$   Ú	remainingrQ   s        r   r,   z'FixedWindowRateLimiter.get_window_stats³   s_   € ô ˜˜4Ÿ;™;¨¯©×)9Ñ)9¸,¸$¿,¹,ÈÐ:TÓ)UÑUÓVˆ	Ø—‘×'Ñ'¨¨¯©°kÐ(BÓCˆä˜5 )Ó,Ð,r   Nr1   r6   )r9   r:   r;   rR   r%   r(   r,   r<   r   r   rV   rV   ‹   s%   „ ñð GHõ 
ð* HIõ Uô-r   rV   z4.1)Úversionc                  ól   ‡ — e Zd ZdZd
ˆ fd„Z	 	 	 	 	 	 	 	 	 	 dd„Zddœdd„Zddœdd„Zdd„Zdd	„Z	ˆ xZ
S )ÚSlidingWindowCounterRateLimiterz=
    Reference: :ref:`strategies:sliding window counter`
    c                ó„   •— t        |d«      rt        |d«      st        d|j                  › �«      ‚t        ‰| �  |«       y )NÚget_sliding_windowÚacquire_sliding_window_entryzHSlidingWindowCounterRateLimiting is not implemented for storage of type rC   rG   s     €r   r   z(SlidingWindowCounterRateLimiter.__init__È   sO   ø€ Ü�wÐ 4Ô5¼WØÐ3ô>
ô &ðØ"×,Ñ,Ð-ð/óð ô 	‰Ñ˜Õ!r   c                ó4   — ||z  |j                  «       z  |z   S )zu
        Return the approximated by weighting the previous window count and adding the current window count.
        )rK   )r   r#   Úprevious_countÚprevious_expires_inÚcurrent_counts        r   Ú_weighted_countz/SlidingWindowCounterRateLimiter._weighted_countÒ   s!   € ð Ð 3Ñ3°d·o±oÓ6GÑGÈ-ÑWÐWr   r
   r   c               ó¤   — t        t        | j                  «      j                   |j                  |Ž |j
                  |j                  «       |«      S r   )r   r	   r   rc   r/   rJ   rK   r"   s       r   r%   z#SlidingWindowCounterRateLimiter.hitÞ   sG   € ô Ü'¨¯©ó
ç
&Ñ
&ØˆD�L‰L˜+Ð&Ø�K‰KØ�O‰OÓØó	
ð	
r   c               óä   — t        t        | j                  «      j                   |j                  |Ž |j                  «       «      \  }}}}| j                  ||||«      |j                  |z
  dz   k  S rM   )r   r	   r   rb   r/   rK   rh   rJ   )r   r#   r   r$   re   rf   rg   Ú_s           r   r(   z$SlidingWindowCounterRateLimiter.testò   s|   € ô AEÜ'¨¯©óA
ç
Ñ
˜\˜TŸ\™\¨;Ð7¸¿¹Ó9JÓ
Kñ 	>ˆÐ+¨]¸Að
 × Ñ Ø�nÐ&9¸=óð �k‰k˜DÑ  1Ñ$ñ%ð	
r   c                óÒ  — t        t        | j                  «      j                   |j                  |Ž |j                  «       «      \  }}}}t        d|j                  t        | j                  ||||«      «      z
  «      }t        j                  «       }|s|st        ||«      S |j                  «       }	t        t        }}
|r||	|z  z  }
|r||	z  }t        |t        |
|«      z   |«      S )a  
        Query the reset time and remaining amount for the limit.

        :param item: The rate limit item
        :param identifiers: variable list of strings to uniquely identify this
         instance of the limit
        :return: WindowStats(reset time, remaining)
        r   )r   r	   r   rb   r/   rK   r\   rJ   r   rh   Útimer   r   Úmin)r   r#   r$   re   rf   rg   Úcurrent_expires_inr]   ÚnowÚexpiryÚprevious_reset_inÚcurrent_reset_ins               r   r,   z0SlidingWindowCounterRateLimiter.get_window_stats  sô   € ô RVÜ'¨¯©óR
ç
Ñ
˜\˜TŸ\™\¨;Ð7¸¿¹Ó9JÓ
Kñ 	OˆÐ+¨]Ð<Nô ØØ�K‰KÜØ×$Ñ$Ø˜.Ð*=¸}óóñó
ˆ	ô �i‰i‹kˆá¡-Ü˜s IÓ.Ð.à—‘Ó"ˆä.1´3Ð+ÐÙØ 3°vÀÑ7NÑ OÐÙØ1°FÑ:Ðä˜3¤Ð%6Ð8HÓ!IÑIÈ9ÓUÐUr   c                óŒ   — t        t        | j                  «      j                   |j                  |Ž |j                  «       «      S r   )r   r	   r   Úclear_sliding_windowr/   rK   r+   s      r   r.   z%SlidingWindowCounterRateLimiter.clear.  s8   € ÜÔ/°·±Ó>×SÑSØˆD�L‰L˜+Ð&¨¯©Ó(9ó
ð 	
r   r0   )
r#   r   re   r3   rf   Úfloatrg   r3   r4   rv   r1   r6   r7   )r9   r:   r;   rR   r   rh   r%   r(   r,   r.   rS   rT   s   @r   r`   r`   Â   sl   ø„ ñõ"ð
Xàð
Xð ð
Xð #ð	
Xð
 ð
Xð 
ó
Xð GHõ 
ð( HIõ 
ó,$V÷L
r   r`   )zsliding-window-counterzfixed-windowzmoving-windowzdict[str, KnownStrategy]Ú
STRATEGIES) rR   Ú
__future__r   rm   Úabcr   r   Úmathr   r   Údeprecated.sphinxr   Úlimits.storage.baser	   Úlimitsr   r   r   r   r   Útypingr   Úutilr   r   r?   rV   r`   ÚtypeÚKnownStrategyrw   Ú__annotations__r<   r   r   Ú<module>rƒ      sÀ   ðòõ #ã ß 'ß å *å ;å !ß ?Ñ ?Ý Ý ô.>˜Gõ .>ôbB>˜kô B>ôJ4-˜[ô 4-ñn �eÔôn
 kó n
ó ðn
ðd 	Ð	(Ñ)Ø
Ð!Ñ"ñ#à
Ð"Ñ#ñ$ð ð >Ø*Ø,ñ(€
Ð$ô r   