o .&a5@s$ddlZddlZddlZddlmZddlmZmZmZm Z m Z e e Z de e eegiZddZddZd%d d Zd%d d Zd%d dZddZddZddZGdddeZGdddeZGdddeZGdddeZGdddeZGdd d eZGd!d"d"eZGd#d$d$eZdS)&N)crc32) ChecksumErrorEndpointConnectionErrorReadTimeoutErrorConnectionErrorConnectionClosedErrorGENERAL_CONNECTION_ERRORcCs:|dkr t}n |dkrtd||||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. randrz0The 'base' param must be greater than 0, got: %s)random ValueError)base growth_factorattempts time_to_sleepr7/usr/lib/python3/dist-packages/botocore/retryhandler.pydelay_exponential's rcCstjt||dS)zCreate 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. r r) functoolspartialrrrrr!create_exponential_delay_function=srcCs$t||d}t||d}t||dS)N)operation_name)checkeraction) create_checker_from_retry_configcreate_retry_action_from_config RetryHandler)configrrrrrrcreate_retry_handlerHs rcCs0|dd}|ddkrt|d|ddSdS)N __default__delaytype exponentialr rr)r)rr delay_configrrrrPs  rc Csg}d}g}d|vr5|ddg}|dd}|D]}||}|t|t|}|dur4||q|durc||durc||d} | D]}|t| |t| |}|durb||qHt|dkrqt|d|dSt|} t| |t|dS)Nr policies max_attemptsr r)r&)r&retryable_exceptions) getappend_create_single_checker_extract_retryable_exceptionextendlenMaxAttemptsDecorator MultiCheckertuple) rrcheckersr&r'r%keycurrent_configretry_exceptionoperation_policies multi_checkerrrrr\s<     rcCs2d|dvrt|ddSd|dvrtSdS)Nresponse applies_when socket_errors)_create_single_response_checkerExceptionRaiser)rrrrr*{s   r*cCs\d|vrt|d|dd}|Sd|vrt|dd}|Sd|vr*t|dd}|Std)Nservice_error_codehttp_status_code) status_code error_code)r> crc32body)headerzUnknown retry policy)ServiceErrorCodeCheckerHTTPStatusCodeChecker CRC32Checkerr )r7rrrrr:s r:cCsN|d}d|divrtgSd|vr%g}|dD] }|t|q|SdS)Nr8r@r7r9)r(rr, EXCEPTION_MAP)rr8 exceptionsnamerrrr+s r+c@s eZdZdZddZddZdS)raRetry 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. cC||_||_dSN)_checker_action)selfrrrrr__init__ zRetryHandler.__init__cKs8||||r|j|d}td||StddS)zHandler for a retry. Intended to be hooked up to an event handler (hence the **kwargs), this will process retries appropriately. )rzRetry needed, action of: %szNo retry needed.N)rJrKloggerdebug)rLrr7caught_exceptionkwargsresultrrr__call__s   zRetryHandler.__call__N)__name__ __module__ __qualname____doc__rMrTrrrrrs rc@s(eZdZdZddZddZddZdS) BaseCheckerzBase class for retry checkers. Each class is responsible for checking a single criteria that determines whether or not a retry should not happen. cCs0|dur |||S|dur|||Std)aDetermine 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 )rLattempt_numberr7rQrrrrTs zBaseChecker.__call__cCdSrIrrLr\r7rrrrZzBaseChecker._check_responsecCr]rIrrLr\rQrrrr[r_z#BaseChecker._check_caught_exceptionN)rUrVrWrXrTrZr[rrrrrYs  rYc@s*eZdZdZd ddZddZddZdS) r.aAllow 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||_||_||_dSrI)rJ _max_attempts_retryable_exceptions)rLrr&r'rrrrMs zMaxAttemptsDecorator.__init__cCsX||||}|r*||jkr(|dur d|dvr d|ddd<td|dS|SdS)NResponseMetadatar TMaxAttemptsReachedz0Reached the maximum number of retry attempts: %sF) _should_retryrarOrP)rLr\r7rQ should_retryrrrrTs zMaxAttemptsDecorator.__call__c Csh|jr-||jkr-z||||WS|jy,}ztjd|ddWYd}~dSd}~ww||||S)Nz,retry needed, retryable exception caught: %sT)exc_info)rbrarJrOrP)rLr\r7rQerrrre s z"MaxAttemptsDecorator._should_retryrI)rUrVrWrXrMrTrerrrrr.s   r.c@eZdZddZddZdS)rCcC ||_dSrI) _status_code)rLr>rrrrM zHTTPStatusCodeChecker.__init__cCs&|dj|jkrtd|jdSdS)Nrz5retry needed: retryable HTTP status code received: %sTF)r>rkrOrPr^rrrrZsz%HTTPStatusCodeChecker._check_responseNrUrVrWrMrZrrrrrC rCc@ri)rBcCrHrI)rk _error_code)rLr>r?rrrrM'rNz ServiceErrorCodeChecker.__init__cCsJ|dj|jkr#|ddid}||jkr#td|j|jdSdS)Nrr ErrorCodez>retry needed: matching HTTP status and error code seen: %s, %sTF)r>rkr(rorOrP)rLr\r7actual_error_coderrrrZ+s z'ServiceErrorCodeChecker._check_responseNrmrrrrrB& rBc@ri)r/cCrjrI _checkers)rLr1rrrrM7rlzMultiChecker.__init__cCs(|jD]}||||}|r|SqdS)NFrt)rLr\r7rQrchecker_responserrrrT:s zMultiChecker.__call__N)rUrVrWrMrTrrrrr/6rnr/c@ri)rDcCrjrI) _header_name)rLrArrrrMDs zCRC32Checker.__init__cCsv|d}|j|j}|durtd|jdSt|djd@}|t|ks9tdt||tdt||ddS)Nrz?crc32 check skipped, the %s header is not in the http response.lz>retry needed: crc32 check failed, expected != actual: %s != %sr) checksum_typeexpected_checksumactual_checksum) headersr(rwrOrPrcontentintr)rLr\r7 http_response expected_crc actual_crc32rrrrZHs" zCRC32Checker._check_responseNrmrrrrrDCrsrDc@seZdZdZddZdS)r;z`Raise any caught exceptions. This class will raise any non None ``caught_exception``. cCs|rIrr`rrrr[_sz'ExceptionRaiser._check_caught_exceptionN)rUrVrWrXr[rrrrr;Ys r;rI) r rloggingbinasciirbotocore.exceptionsrrrrr getLoggerrUrOrErrrrrr*r:r+objectrrYr.rCrBr/rDr;rrrrs6      ,.