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: //usr/lib/python3.6/site-packages/botocore/__pycache__/retryhandler.cpython-36.pyc
3

�T_�5�@s$ddlZddlZddlZddlmZddlmZmZmZm	Z	m
Z
eje�Z
de	e
eegiZdd�Zdd�Zd%d	d
�Zd&dd�Zd'd
d�Zdd�Zdd�Zdd�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd �d e�ZGd!d"�d"e�ZGd#d$�d$e�ZdS)(�N)�crc32)�
ChecksumError�EndpointConnectionError�ReadTimeoutError�ConnectionError�ConnectionClosedErrorZGENERAL_CONNECTION_ERRORcCs:|dkrtj�}n|dkr&td|��|||d}|S)a1Calculate time to sleep based on exponential function.

    The format is::

        base * growth_factor ^ (attempts - 1)

    If ``base`` is set to 'rand' then a random number between
    0 and 1 will be used as the base.
    Base must be greater than 0, otherwise a ValueError will be
    raised.

    Zrandrz0The 'base' param must be greater than 0, got: %s�)�random�
ValueError)�base�
growth_factor�attemptsZ
time_to_sleep�r�"/usr/lib/python3.6/retryhandler.py�delay_exponential's

rcCstjt||d�S)z�Create an exponential delay function based on the attempts.

    This is used so that you only have to pass it the attempts
    parameter to calculate the delay.

    )rr)�	functools�partialr)rrrrr�!create_exponential_delay_function=srcCs$t||d�}t||d�}t||d�S)N)�operation_name)�checker�action)� create_checker_from_retry_config�create_retry_action_from_config�RetryHandler)�configrrrrrr�create_retry_handlerHs


rcCs0|dd}|ddkr,t|d|dd�SdS)N�__default__Zdelay�typeZexponentialrr)rr)r)rrZdelay_configrrrrPs
rcCsg}d}g}d|krn|djdg�}|dd}x<|D]4}||}|jt|��t|�}|dk	r6|j|�q6W|dk	r�|j|�dk	r�||d}	x<|	D]4}|jt|	|��t|	|�}|dk	r�|j|�q�Wt|�dkr�t|d|d�St|�}
t|
|t|�d�SdS)Nr�policies�max_attemptsrr)r)r�retryable_exceptions)	�get�append�_create_single_checker�_extract_retryable_exception�extend�len�MaxAttemptsDecorator�MultiChecker�tuple)rr�checkersrr r�keyZcurrent_configZretry_exceptionZoperation_policiesZ
multi_checkerrrrr\s4


rcCs2d|dkrt|dd�Sd|dkr.t�SdS)N�response�applies_when�
socket_errors)�_create_single_response_checker�ExceptionRaiser)rrrrr#{s
r#cCs^d|krt|d|dd�}n<d|kr6t|dd�}n$d|krNt|dd�}ntdt��|S)NZservice_error_codeZhttp_status_code)�status_code�
error_code)r1�	crc32body)�headerzUnknown retry policy: %s)�ServiceErrorCodeChecker�HTTPStatusCodeChecker�CRC32Checkerr
r)r,rrrrr/�sr/cCsR|d}d|jdi�krtgSd|krNg}x|dD]}|jt|�q4W|SdS)Nr-r3r,r.)r!rr%�
EXCEPTION_MAP)rr-�
exceptions�namerrrr$�sr$c@s eZdZdZdd�Zdd�ZdS)ra�Retry handler.

    The retry handler takes two params, ``checker`` object
    and an ``action`` object.

    The ``checker`` object must be a callable object and based on a response
    and an attempt number, determines whether or not sufficient criteria for
    a retry has been met.  If this is the case then the ``action`` object
    (which also is a callable) determines what needs to happen in the event
    of a retry.

    cCs||_||_dS)N)�_checker�_action)�selfrrrrr�__init__�szRetryHandler.__init__cKs8|j|||�r*|j|d�}tjd|�|Stjd�dS)z�Handler for a retry.

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

        )r
zRetry needed, action of: %szNo retry needed.N)r;r<�logger�debug)r=r
r,�caught_exception�kwargs�resultrrr�__call__�s
zRetryHandler.__call__N)�__name__�
__module__�__qualname__�__doc__r>rDrrrrr�src@s(eZdZdZdd�Zdd�Zdd�ZdS)	�BaseCheckerz�Base class for retry checkers.

    Each class is responsible for checking a single criteria that determines
    whether or not a retry should not happen.

    cCs4|dk	r|j||�S|dk	r(|j||�Std��dS)a�Determine if retry criteria matches.

        Note that either ``response`` is not None and ``caught_exception`` is
        None or ``response`` is None and ``caught_exception`` is not None.

        :type attempt_number: int
        :param attempt_number: The total number of times we've attempted
            to send the request.

        :param response: The HTTP response (if one was received).

        :type caught_exception: Exception
        :param caught_exception: Any exception that was caught while trying to
            send the HTTP response.

        :return: True, if the retry criteria matches (and therefore a retry
            should occur.  False if the criteria does not match.

        Nz,Both response and caught_exception are None.)�_check_response�_check_caught_exceptionr
)r=�attempt_numberr,rArrrrD�szBaseChecker.__call__cCsdS)Nr)r=rLr,rrrrJ�szBaseChecker._check_responsecCsdS)Nr)r=rLrArrrrK�sz#BaseChecker._check_caught_exceptionN)rErFrGrHrDrJrKrrrrrI�srIc@s*eZdZdZd	dd�Zdd�Zdd�ZdS)
r'a�Allow retries up to a maximum number of attempts.

    This will pass through calls to the decorated retry checker, provided
    that the number of attempts does not exceed max_attempts.  It will
    also catch any retryable_exceptions passed in.  Once max_attempts has
    been exceeded, then False will be returned or the retryable_exceptions
    that was previously being caught will be raised.

    NcCs||_||_||_dS)N)r;�
_max_attempts�_retryable_exceptions)r=rrr rrrr>�szMaxAttemptsDecorator.__init__cCs^|j|||�}|rV||jkrP|dk	r@d|dkr@d|ddd<tjd|�dS|SndSdS)NZResponseMetadatarTZMaxAttemptsReachedz0Reached the maximum number of retry attempts: %sF)�
_should_retryrMr?r@)r=rLr,rAZshould_retryrrrrD�s
zMaxAttemptsDecorator.__call__cCsf|jrT||jkrTy|j|||�S|jk
rP}ztjd|dd�dSd}~XqbXn|j|||�SdS)Nz,retry needed, retryable exception caught: %sT)�exc_info)rNrMr;r?r@)r=rLr,rA�errrrO	s

z"MaxAttemptsDecorator._should_retry)N)rErFrGrHr>rDrOrrrrr'�s	
r'c@seZdZdd�Zdd�ZdS)r6cCs
||_dS)N)�_status_code)r=r1rrrr>szHTTPStatusCodeChecker.__init__cCs*|dj|jkr"tjd|j�dSdSdS)Nrz5retry needed: retryable HTTP status code received: %sTF)r1rRr?r@)r=rLr,rrrrJsz%HTTPStatusCodeChecker._check_responseN)rErFrGr>rJrrrrr6sr6c@seZdZdd�Zdd�ZdS)r5cCs||_||_dS)N)rR�_error_code)r=r1r2rrrr>'sz ServiceErrorCodeChecker.__init__cCsJ|dj|jkrF|djdi�jd�}||jkrFtjd|j|j�dSdS)Nrr�ErrorZCodez>retry needed: matching HTTP status and error code seen: %s, %sTF)r1rRr!rSr?r@)r=rLr,Zactual_error_coderrrrJ+s
z'ServiceErrorCodeChecker._check_responseN)rErFrGr>rJrrrrr5&sr5c@seZdZdd�Zdd�ZdS)r(cCs
||_dS)N)�	_checkers)r=r*rrrr>7szMultiChecker.__init__cCs(x"|jD]}||||�}|r|SqWdS)NF)rU)r=rLr,rArZchecker_responserrrrD:szMultiChecker.__call__N)rErFrGr>rDrrrrr(6sr(c@seZdZdd�Zdd�ZdS)r7cCs
||_dS)N)�_header_name)r=r4rrrr>DszCRC32Checker.__init__cCst|d}|jj|j�}|dkr.tjd|j�nBt|dj�d@}|t|�ksptjdt|�|�tdt|�|d��dS)Nrz?crc32 check skipped, the %s header is not in the http response.l��z>retry needed: crc32 check failed, expected != actual: %s != %sr)Z
checksum_typeZexpected_checksumZactual_checksum)	Zheadersr!rVr?r@rZcontent�intr)r=rLr,Z
http_responseZexpected_crcZactual_crc32rrrrJHs
zCRC32Checker._check_responseN)rErFrGr>rJrrrrr7Csr7c@seZdZdZdd�ZdS)r0z`Raise any caught exceptions.

    This class will raise any non None ``caught_exception``.

    cCs|�dS)Nr)r=rLrArrrrK_sz'ExceptionRaiser._check_caught_exceptionN)rErFrGrHrKrrrrr0Ysr0)N)N)N) r	rZloggingZbinasciirZbotocore.exceptionsrrrrrZ	getLoggerrEr?r8rrrrrr#r/r$�objectrrIr'r6r5r(r7r0rrrr�<module>s0



 ,.