
    pge                         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j
        e          Zd Z G d d	          ZdS )
zRAn async reimplementation of the blocking elements from botocore.retries.adaptive.    N)standard
throttling)RateClocker   )bucketc                    t          j                    }t          j        d|                                          }t          j        d|          }t          |          }t          j        t          j	                              }t          |||||          }| 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   limiters          <lib/python3.11/site-packages/aiobotocore/retries/adaptive.pyregister_retry_handlerr!      s    LNNE.(:(:(<(<  M *AUCCCLu%%L":$688   %#!!/  G K"   K%   N    c                   (    e Zd ZdZdZd Zd Zd ZdS )r   z/An async reimplementation of ClientRateLimiter.g       @c                     || _         || _        || _        || _        || _        d| _        t          j                    | _        d S )NF)	_rate_adjustor_rate_clocker_token_bucket_throttling_detector_clock_enabledasyncioLock_lock)selfr   r   r   r   r   s         r    __init__zAsyncClientRateLimiter.__init__8   sC     ,))$7!\^^


r"   c                 Z   K   | j         r!| j                                         d {V  d S d S )N)r*   r'   acquire)r.   requestkwargss      r    r   z)AsyncClientRateLimiter.on_sending_requestH   sG      = 	/$,,...........	/ 	/r"   c                 r  K   | j                                         }| j                                        }| j        4 d {V   | j        j        di |s| j                            |          }nm| j	        s|}nt          || j        j                  }| j                            ||          }t                              d||| j        j                   d| _	        | j                            t          || j        |z                       d {V  d d d           d {V  d S # 1 d {V swxY w Y   d S )NzfThrottling response received, new send rate: %s measured rate: %s, token bucket capacity available: %sT )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.   r3   measured_rate	timestampnew_raterate_to_uses         r    r   z,AsyncClientRateLimiter.on_receiving_responseM   s     *1133K,,..	: 	 	 	 	 	 	 	 	@4,@JJ6JJ %.??	JJ} "/KK"%%t'9'B# #K  .==  $ !&9   !%$11Hd9MIJJ        -	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   CD&&
D03D0N)__name__
__module____qualname____doc__r?   r/   r   r   r5   r"   r    r   r   -   sO        99 !$ $ $ / / /
    r"   r   )rG   r+   loggingbotocore.retriesr   r   botocore.retries.adaptiver    r   	getLoggerrD   r;   r!   r   r5   r"   r    <module>rM      s    X X   1 1 1 1 1 1 1 1
 2 1 1 1 1 1      		8	$	$  8; ; ; ; ; ; ; ; ; ;r"   