Ë
    ±Œjð)  ã                  ó  — 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 ddlmZ ddlmZ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dœZy)z'
Asynchronous rate limiting strategies
é    )ÚannotationsN)ÚABCÚabstractmethod)ÚfloorÚinf)Úversionaddedé   )ÚRateLimitItem)ÚStorageTypes)Úcast)ÚWindowStatsé   )ÚMovingWindowSupportÚStorage)ÚSlidingWindowCounterSupportc                  ój   — 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/aio/strategies.pyÚ__init__zRateLimiter.__init__   s   € Ü˜'¤7Ô+Ð+Ð+Ø 'ˆ�ó    r   ©Úcostc             ‡  ó   K  — t         ‚­w)áB  
        Consume the rate limit

        :param item: the rate limit item
        :param identifiers: variable list of strings to uniquely identify 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   ó   è ø€ ô "Ð!ùó   ‚	c             ‡  ó   K  — t         ‚­w)á:  
        Check if the rate limit can be consumed

        :param item: the rate limit item
        :param identifiers: variable list of strings to uniquely identify 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              ‡  ó   K  — t         ‚­w)zú
        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 the
         limit
        :return: (reset time, remaining))
        r    ©r   r#   r$   s      r   Úget_window_statszRateLimiter.get_window_stats6   r&   r'   c              ‡  ón   K  — | j                   j                   |j                  |Ž «      ƒ d {  –—† S 7 Œ­wr   )r   ÚclearÚkey_forr,   s      r   r/   zRateLimiter.clearD   s,   è ø€ Ø—\‘\×'Ñ'¨¨¯©°kÐ(BÓC×CÐCÐCús   ‚,5®3¯5N©r   r   ©r#   r
   r$   Ústrr   ÚintÚreturnÚbool©r#   r
   r$   r3   r5   r   ©r#   r
   r$   r3   r5   ÚNone)	Ú__name__Ú
__module__Ú__qualname__r   r   r%   r*   r-   r/   © r   r   r   r      sg   „ ó(ð ØLMô "ó ð"ð ØMNô "ó ð"ð ð"Ø!ð"Ø14ð"à	ò"ó ð"ôDr   r   c                  óT   ‡ — 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__M   sI   ø€ ä�G˜_Ô-´¸ÐBUÔ1Vä%ðØ"×,Ñ,Ð-ð/óð ô 	‰Ñ˜Õ!r   r   r   c             ‡  óÂ   K  — t        t        | j                  «      j                   |j                  |Ž |j
                  |j                  «       |¬«      ƒ d{  –—† S 7 Œ­w©r   )ÚamountN)r   r   r   rA   r0   rJ   Ú
get_expiryr"   s       r   r%   zMovingWindowRateLimiter.hitW   sV   è ø€ ô Ô-¨t¯|©|Ó<×JÑJØˆD�L‰L˜+Ð&¨¯©°T·_±_Ó5FÈtð Kó 
÷ 
ð 	
ð 
ús   ‚AAÁAÁAc             ‡  óì   K  — t        t        | j                  «      j                   |j                  |Ž |j
                  |j                  «       «      ƒ d{  –—† }|d   }||j
                  |z
  k  S 7 Œ­w©r)   Nr   )r   r   r   rB   r0   rJ   rK   )r   r#   r   r$   ÚresrJ   s         r   r*   zMovingWindowRateLimiter.testg   sl   è ø€ ô Ô,¨d¯l©lÓ;×MÑMØˆD�L‰L˜+Ð&Ø�K‰KØ�O‰OÓó
÷ 
ˆð
 �Q‘ˆà˜Ÿ™ tÑ+Ñ+Ð+ð
ús   ‚AA4ÁA2ÁA4c              ‡  ó  K  — t        t        | j                  «      j                   |j                  |Ž |j
                  |j                  «       «      ƒ d{  –—† \  }}||j                  «       z   }t        ||j
                  |z
  «      S 7 Œ3­w)zý
        returns the number of requests remaining within this limit.

        :param item: the rate limit item
        :param identifiers: variable list of strings to uniquely identify the
         limit
        :return: (reset time, remaining)
        N)r   r   r   rB   r0   rJ   rK   r   )r   r#   r$   Úwindow_startÚwindow_itemsÚresets         r   r-   z(MovingWindowRateLimiter.get_window_stats{   sz   è ø€ ô ,0Ü §¡ó,
ç
Ñ
˜L˜DŸL™L¨+Ð6¸¿¹ÀTÇ_Á_ÓEVÓ
W÷&XÑ"ˆ�lð ˜tŸ™Ó0Ñ0ˆä˜5 $§+¡+°Ñ"<Ó=Ð=ð&Xús   ‚ABÁB
Á4B)r   r   r5   r9   r2   r7   )	r:   r;   r<   Ú__doc__r   r%   r*   r-   Ú__classcell__©rE   s   @r   r?   r?   H   sB   ø„ ñõ"ð MNõ 
ð  NOõ ,ð(>Ø!ð>Ø14ð>à	÷>r   r?   c                  ó@   — 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             ‡  óª   K  — | j                   j                   |j                  |Ž |j                  «       |¬«      ƒ d{  –—† |j                  k  S 7 Œ­wrI   )r   Úincrr0   rK   rJ   r"   s       r   r%   zFixedWindowRateLimiter.hit“   sW   è ø€ ð —,‘,×#Ñ#Ø�—‘˜kÐ*Ø—‘Ó!Øð $ó ÷ ð
 �{‰{ñð	
ðús   ‚=A¿AÁ Ac             ‡  ó”   K  — | j                   j                   |j                  |Ž «      ƒ d{  –—† |j                  |z
  dz   k  S 7 Œ­wrM   )r   Úgetr0   rJ   r"   s       r   r*   zFixedWindowRateLimiter.test¨   sD   è ø€ ð —,‘,×"Ñ" < 4§<¡<°Ð#=Ó>×>ÀÇÁÈtÑASÐVWÑAWÑWð	
Ø>ús   ‚,A®A¯Ac           	   ‡  ó  K  — t        d|j                  | j                  j                   |j                  |Ž «      ƒ d{  –—† z
  «      }| j                  j                   |j                  |Ž «      ƒ d{  –—† }t        ||«      S 7 ŒF7 Œ­w)z÷
        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 the
         limit
        :return: reset time, remaining
        r   N)ÚmaxrJ   r   r[   r0   rK   r   )r   r#   r$   Ú	remainingrR   s        r   r-   z'FixedWindowRateLimiter.get_window_stats¸   sy   è ø€ ô ØØ�K‰K §¡× 0Ñ 0°°·±¸{Ð1KÓ L×LÑLó
ˆ	ð —l‘l×-Ñ-¨l¨d¯l©l¸KÐ.HÓI×Iˆä˜5 )Ó,Ð,ð	 MøàIús"   ‚=B
¿BÁ 5B
Á5BÁ6B
ÂB
Nr2   r7   )r:   r;   r<   rS   r%   r*   r-   r=   r   r   rW   rW   Ž   s<   „ ñð MNõ 
ð* NOõ 
ð -Ø!ð-Ø14ð-à	ô-r   rW   z4.1)Úversionc                  óx   ‡ — 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             ‡  óÀ   K  — t        t        | j                  «      j                   |j                  |Ž |j
                  |j                  «       |«      ƒ d{  –—† S 7 Œ­w)aS  
        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
        N)r   r   r   rd   r0   rJ   rK   r"   s       r   r%   z#SlidingWindowCounterRateLimiter.hitè   sU   è ø€ ô Ü'¨¯©ó
ç
&Ñ
&ØˆD�L‰L˜+Ð&Ø�K‰KØ�O‰OÓØó	
÷
ð 	
ð 
ús   ‚AAÁAÁAc             ‡  ó   K  — t        t        | j                  «      j                   |j                  |Ž |j                  «       «      ƒ d{  –—† \  }}}}| j                  ||||«      |j                  |z
  dz   k  S 7 Œ0­w)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
        Nr   )r   r   r   rc   r0   rK   ri   rJ   )r   r#   r   r$   rf   rg   rh   Ú_s           r   r*   z$SlidingWindowCounterRateLimiter.testü   sŒ   è ø€ ô GKÜ'¨¯©óG
ç
Ñ
˜\˜TŸ\™\¨;Ð7¸¿¹Ó9JÓ
K÷ALÑ=ˆÐ+¨]¸Að
 × Ñ Ø�nÐ&9¸=óð �k‰k˜DÑ  1Ñ$ñ%ð	
ð	ALús   ‚A	A>ÁA<Á1A>c              ‡  óî  K  — t        t        | j                  «      j                   |j                  |Ž |j                  «       «      ƒ d{  –—† \  }}}}t        d|j                  t        | j                  ||||«      «      z
  «      }t        j                  «       }|s|st        ||«      S |j                  «       }	t        t        }}
|r||	|z  z  }
|r||	z  }t        |t        |
|«      z   |«      S 7 Œ§­w)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: (reset time, remaining)
        Nr   )r   r   r   rc   r0   rK   r]   rJ   r   ri   Útimer   r   Úmin)r   r#   r$   rf   rg   rh   Úcurrent_expires_inr^   ÚnowÚexpiryÚprevious_reset_inÚcurrent_reset_ins               r   r-   z0SlidingWindowCounterRateLimiter.get_window_stats  s  è ø€ ô" Ô2°D·L±LÓA×TÑTØˆD�L‰L˜+Ð&¨¯©Ó(9ó
÷ 
ñ	
ØØØØô
 ØØ�K‰KÜØ×$Ñ$Ø˜.Ð*=¸}óóñó
ˆ	ô �i‰i‹kˆá¡-Ü˜s IÓ.Ð.à—‘Ó"ˆä.1´3Ð+ÐÙØ 3°vÀÑ7NÑ OÐÙØ1°FÑ:Ðä˜3¤Ð%6Ð8HÓ!IÑIÈ9ÓUÐUð7
ús   ‚A	C5ÁC3ÁB(C5c              ‡  ó¨   K  — t        t        | j                  «      j                   |j                  |Ž |j                  «       «      ƒ d {  –—† S 7 Œ­wr   )r   r   r   Úclear_sliding_windowr0   rK   r,   s      r   r/   z%SlidingWindowCounterRateLimiter.clearA  sH   è ø€ ÜÜ'¨¯©ó
ç
Ñ
˜|˜tŸ|™|¨[Ð9¸4¿?¹?Ó;LÓ
M÷Nð 	Nð Nús   ‚A	AÁAÁAr1   )
r#   r
   rf   r4   rg   Úfloatrh   r4   r5   rw   r2   r7   r8   )r:   r;   r<   rS   r   ri   r%   r*   r-   r/   rT   rU   s   @r   ra   ra   Ì   sˆ   ø„ ñõ"ð
Xàð
Xð ð
Xð #ð	
Xð
 ð
Xð 
ó
Xð MNõ 
ð( NOõ 
ð.,VØ!ð,VØ14ð,Và	ó,V÷\Nr   ra   )zsliding-window-counterzfixed-windowzmoving-window)rS   Ú
__future__r   rn   Úabcr   r   Úmathr   r   Údeprecated.sphinxr   Úlimitsr
   r   r   Útypingr   Úutilr   r   r   Ústorage.baser   r   r?   rW   ra   Ú
STRATEGIESr=   r   r   Ú<module>r�      s‘   ðñõ #ã ß #ß å *å "Ý "Ý Ý ß 1Ý 5ô0D�#ô 0DôfC>˜kô C>ôL;-˜[ô ;-ñ| �eÔôwN kó wNó ðwNðv >Ø*Ø,ñ�
r   