o
    di                     @   s   d dl mZmZmZmZmZmZmZmZm	Z	m
Z
mZmZ ddlmZ dddZdddZd	d
 Zdd ZG dd deZG dd deZG dd deZG dd deZdS )    )ChecksumErrorCRC32CheckerExceptionRaiserHTTPStatusCodeCheckerMaxAttemptsDecoratorMultiCheckerRetryHandlerServiceErrorCodeChecker_extract_retryable_exceptioncrc32create_retry_action_from_configlogger   )resolve_awaitableNc                 C   s$   t | |d}t| |d}t||dS )N)operation_name)checkeraction) create_checker_from_retry_configr   AioRetryHandler)configr   r   r    r   L/home/ubuntu/.local/lib/python3.10/site-packages/aiobotocore/retryhandler.pycreate_retry_handler   s   r   c                 C   s   g }d }g }d| v r5| d  dg }| d d }|D ]}|| }|t| t|}|d ur4|| q|d urc|  |d urc| | d }	|	D ]}|t|	|  t|	| }|d urb|| qHt|dkrqt|d |dS t|}
t|
|t|dS )N__default__policiesmax_attemptsr   r   )r   )r   retryable_exceptions)	getappend_create_single_checkerr
   extendlenAioMaxAttemptsDecoratorAioMultiCheckertuple)r   r   checkersr   r   r   keycurrent_configretry_exceptionoperation_policiesmulti_checkerr   r   r   r      s>   

r   c                 C   s2   d| d v rt | d d S d| d v rt S d S )Nresponseapplies_whensocket_errors)_create_single_response_checkerr   )r   r   r   r   r   ?   s   
r   c                 C   s\   d| v rt | d | d d}|S d| v rt| d d}|S d| v r*t| d d}|S td)Nservice_error_codehttp_status_code)status_code
error_code)r1   	crc32body)headerzUnknown retry policy)r	   r   AioCRC32Checker
ValueError)r+   r   r   r   r   r.   H   s   r.   c                   @      e Zd Zdd Zdd ZdS )r   c                    s~   |||d}t | jtr|d d d}|d|i t| jd
i |I dH r8| j|d}td| |S td	 dS )zHandler for a retry.

        Intended to be hooked up to an event handler (hence the **kwargs),
        this will process retries appropriately.

        )attempt_numberr+   caught_exceptionrequest_dictcontextretriesretries_contextN)attemptszRetry needed, action of: %szNo retry needed.r   )	
isinstance_checkerr   r   updater   _actionr   debug)selfr>   r+   r9   kwargschecker_kwargsr=   resultr   r   r   _call[   s   zAioRetryHandler._callc                 O      | j |i |S NrH   rD   argsrE   r   r   r   __call__q      zAioRetryHandler.__call__N__name__
__module____qualname__rH   rN   r   r   r   r   r   Z   s    r   c                   @   $   e Zd Zdd Zdd Zdd ZdS )r"   c                    s|   |rt |dd| j|d< | |||I d H }|r<|| jkr:|d ur2d|d v r2d|d d d< td| dS |S dS )	Nmaxr   ResponseMetadatar   TMaxAttemptsReachedz0Reached the maximum number of retry attempts: %sF)rU   r   _max_attempts_should_retryr   rC   )rD   r8   r+   r9   r=   should_retryr   r   r   rH   v   s(   

zAioMaxAttemptsDecorator._callc                 O   rI   rJ   rK   rL   r   r   r   rN      rO   z AioMaxAttemptsDecorator.__call__c              
      s~   | j r3|| jk r3zt| |||I d H W S  | j y2 } ztjd|dd W Y d }~dS d }~ww t| |||I d H S )Nz,retry needed, retryable exception caught: %sT)exc_info)_retryable_exceptionsrX   r   r@   r   rC   )rD   r8   r+   r9   er   r   r   rY      s$   

z%AioMaxAttemptsDecorator._should_retryN)rQ   rR   rS   rH   rN   rY   r   r   r   r   r"   u   s    r"   c                   @   r7   )r#   c                    s4   | j D ]}t||||I d H }|r|  S qdS )NF)	_checkersr   )rD   r8   r+   r9   r   checker_responser   r   r   rH      s   


zAioMultiChecker._callc                 O   rI   rJ   rK   rL   r   r   r   rN      rO   zAioMultiChecker.__call__NrP   r   r   r   r   r#      s    	r#   c                   @   rT   )r5   c                    s8   |d ur|  ||I d H S |d ur| ||S td)Nz,Both response and caught_exception are None.)_check_response_check_caught_exceptionr6   )rD   r8   r+   r9   r   r   r   rH      s   zAioCRC32Checker._callc                 O   rI   rJ   rK   rL   r   r   r   rN      rO   zAioCRC32Checker.__call__c                    s~   |d }|j | j}|d u rtd| j d S t|d jI d H d@ }|t|ks=tdt|| tdt||dd S )Nr   z?crc32 check skipped, the %s header is not in the http response.l    z>retry needed: crc32 check failed, expected != actual: %s != %sr   )checksum_typeexpected_checksumactual_checksum)	headersr   _header_namer   rC   r   contentintr   )rD   r8   r+   http_responseexpected_crcactual_crc32r   r   r   r`      s*   zAioCRC32Checker._check_responseN)rQ   rR   rS   rH   rN   r`   r   r   r   r   r5      s    
r5   rJ   )botocore.retryhandlerr   r   r   r   r   r   r   r	   r
   r   r   r   _helpersr   r   r   r   r.   r   r"   r#   r5   r   r   r   r   <module>   s   8 


"	5