Ë
    t®Ìd/  ã                   ó@   — d dl Z d dlZd dlmZ d dlmZ  G d„ d«      Zy)é    N)Údeque)ÚUnionc                   ó<   — e Zd ZdZdZd	dedeeef   fd„Zd„ Z	d„ Z
y)
Ú	Throttlera  
    Context manager for limiting rate of accessing to context block.

    Example usages:
        - https://github.com/uburuntu/throttler/blob/master/examples/example_throttlers.py
        - https://github.com/uburuntu/throttler/blob/master/examples/example_throttlers_aiohttp.py
    )Ú_rate_limitÚ_periodÚ_timesÚ
rate_limitÚperiodc                 ó  — t        |t        «      r|dkD  st        d«      ‚t        |t        t        f«      r|dkD  st        d«      ‚t        |«      | _        t        |«      | _        t        d„ t        |«      D «       «      | _        y )Nr   z'`rate_limit` should be positive integerç        z!`period` should be positive floatc              3   ó    K  — | ]  }d –— Œ y­w)r   N© )Ú.0Ú_s     ú3lib/python3.12/site-packages/throttler/throttler.pyú	<genexpr>z%Throttler.__init__.<locals>.<genexpr>   s   è ø€ Ò: 1œBÑ:ùs   ‚)	Ú
isinstanceÚintÚ
ValueErrorÚfloatr   r   r   Úranger	   )Úselfr
   r   s      r   Ú__init__zThrottler.__init__   sm   € Ü˜:¤sÔ+°
¸Q²ÜÐFÓGÐGä˜6¤C¬ <Ô0°V¸b²[ÜÐ@ÓAÐAä  Ó,ˆÔÜ˜V“}ˆŒäÑ:¬¨jÓ(9Ô:Ó:ˆó    c              ƒ   ó,  K  — 	 t        j                  «       }|| j                  d   | j                  z   z
  }|dkD  r| j                  j	                  «        nt        j                  | «      ƒ d {  –—†  Œr| j                  j                  |«       y 7 Œ!­w)Nr   r   )ÚtimeÚ	monotonicr	   r   ÚpopleftÚasyncioÚsleepÚappend)r   Úcurr_tsÚdiffs      r   Ú
__aenter__zThrottler.__aenter__   s|   è ø€ ØÜ—n‘nÓ&ˆGØ˜dŸk™k¨!™n¨t¯|©|Ñ;Ñ<ˆDØbŠyØ—‘×#Ñ#Ô%ØÜ—-‘-  Ó&×&Ð&ð ð 	‰×Ñ˜7Õ#ð 'ús   ‚A.BÁ0BÁ1"Bc              ƒ   ó   K  — y ­w)Nr   )r   Úexc_typeÚexc_valÚexc_tbs       r   Ú	__aexit__zThrottler.__aexit__(   s	   è ø€ Øùs   ‚N)g      ð?)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r   r   r   r%   r*   r   r   r   r   r      s4   „ ñð 6€Iñ
; 3ð 
;°°c¸5°jÑ0Aó 
;ò	$ór   r   )r    r   Úcollectionsr   Útypingr   r   r   r   r   ú<module>r2      s   ðÛ Û Ý Ý ÷"ò "r   