HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/botocore/retries/__pycache__/bucket.cpython-36.pyc
3

�T_��@sDdZddlZddlZddlmZGdd�de�ZGdd�de�ZdS)zEThis module implements token buckets used for client side throttling.�N)�CapacityNotAvailableErrorc@s$eZdZdd�Zdd�Zdd�ZdS)�ClockcCsdS)N�)�selfrr�/usr/lib/python3.6/bucket.py�__init__	szClock.__init__cCstj|�dS)N)�time�sleep)r�amountrrrr	szClock.sleepcCstj�S)N)r)rrrr�current_timeszClock.current_timeN)�__name__�
__module__�__qualname__rr	rrrrrrsrc@speZdZdZefdd�Zedd��Zejdd��Zedd��Zed	d
��Z	dd
d�Z
dd�Zdd�Zdd�Z
dS)�TokenBucketg�?cCsFd|_d|_d|_||_d|_||_tj�|_tj	|j�|_
||_dS)Nr)�
_fill_rate�
_max_capacity�_current_capacity�_clock�_last_timestamp�	_min_rate�	threadingZLock�_lockZ	Condition�_new_fill_rate_condition�max_rate)rrZclockZmin_raterrrrs
zTokenBucket.__init__cCs|jS)N)r)rrrrr"szTokenBucket.max_ratec
Cs\|j�L|j�t||j�|_|dkr.||_nd|_t|j|j�|_|jj�WdQRXdS)N�)	r�_refill�maxrrr�minrZnotify)r�valuerrrr&s
cCs|jS)N)r)rrrr�max_capacity:szTokenBucket.max_capacitycCs|jS)N)r)rrrr�available_capacity>szTokenBucket.available_capacityrTcCs |j�|j||d�SQRXdS)aJAcquire token or return amount of time until next token available.

        If block is True, then this method will block until there's sufficient
        capacity to acquire the desired amount.

        If block is False, then this method will return True is capacity
        was successfully acquired, False otherwise.

        )r
�blockN)r�_acquire)rr
r!rrr�acquireBs
zTokenBucket.acquirecCsz|j�||jkr$|j|8_dS|s.t��|j|�}x*|dkrb|jj|�|j�|j|�}q:W|j|8_dSdS)NTr)rrr�
_sleep_amountr�wait)rr
r!Zsleep_amountrrrr"Os


zTokenBucket._acquirecCs||j|jS)N)rr)rr
rrrr$fszTokenBucket._sleep_amountcCsT|jj�}|jdkr||_dS|j}||j|j}t|j||�}||_||_dS)N)rrrrrrr)rZ	timestampZcurrent_capacityZfill_amountZnew_capacityrrrris

zTokenBucket._refillN)rT)rr
rZ	_MIN_RATEr�propertyr�setterrr r#r"r$rrrrrrs

r)�__doc__rrZbotocore.exceptionsr�objectrrrrrr�<module>s