o
    di                     @   s`   d Z ddlZddlZddlmZmZ ddlmZ ddlm	Z	 e
eZdd ZG d	d
 d
ZdS )zRAn async reimplementation of the blocking elements from botocore.retries.adaptive.    N)standard
throttling)RateClocker   )bucketc                 C   sz   t  }tjd| d}t jd|d}t|}tjt	 d}t
|||||d}| jjd|j | jjd|j |S )	Nr   )starting_max_rate
start_timer   )max_rateclock)retry_event_adapter)rate_adjustorrate_clockertoken_bucketthrottling_detectorr
   zbefore-sendzneeds-retry)r   Clockr   CubicCalculatorcurrent_timeAsyncTokenBucketr   r   ThrottlingErrorDetectorRetryEventAdapterAsyncClientRateLimitermetaeventsregisteron_sending_requeston_receiving_response)clientr
   r   r   r   r   limiter r   P/home/ubuntu/.local/lib/python3.10/site-packages/aiobotocore/retries/adaptive.pyregister_retry_handler   s2   r    c                   @   s,   e Zd ZdZdZdd Zdd Zdd Zd	S )
r   z/An async reimplementation of ClientRateLimiter.g       @c                 C   s2   || _ || _|| _|| _|| _d| _t | _d S )NF)	_rate_adjustor_rate_clocker_token_bucket_throttling_detector_clock_enabledasyncioLock_lock)selfr   r   r   r   r
   r   r   r   __init__9   s   zAsyncClientRateLimiter.__init__c                    s    | j r| j I d H  d S d S )N)r&   r#   acquire)r*   requestkwargsr   r   r   r   I   s   z)AsyncClientRateLimiter.on_sending_requestc              	      s   | j  }| j }| j4 I d H L | jjdi |s#| j|}n!| j	s)|}nt
|| jj}| j||}td||| jj d| _	| jt
|| j| I d H  W d   I d H  d S 1 I d H sdw   Y  d S )NzfThrottling response received, new send rate: %s measured rate: %s, token bucket capacity available: %sTr   )r"   recordr%   r   r)   r$   is_throttling_errorr!   success_receivedr&   minr#   r	   error_receivedloggerdebugavailable_capacityset_max_rate_MAX_RATE_ADJUST_SCALE)r*   r.   measured_rate	timestampnew_raterate_to_user   r   r   r   N   s2   

.z,AsyncClientRateLimiter.on_receiving_responseN)__name__
__module____qualname____doc__r8   r+   r   r   r   r   r   r   r   .   s    r   )r@   r'   loggingbotocore.retriesr   r   botocore.retries.adaptiver    r   	getLoggerr=   r4   r    r   r   r   r   r   <module>   s    
