U C^5@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) ChecksumErrorEndpointConnectionErrorReadTimeoutErrorConnectionErrorConnectionClosedErrorZGENERAL_CONNECTION_ERRORcCs:|dkrt}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_factorattemptsZ time_to_sleepr;/tmp/pip-install-6_kvzl1k/botocore/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=s rcCs$t||d}t||d}t||dS)N)operation_name)checkeraction) create_checker_from_retry_configcreate_retry_action_from_config RetryHandler)configrrrrrrcreate_retry_handlerHsrcCs0|dd}|ddkr,t|d|ddSdS)N __default__delaytypeZ exponentialr r r)r)rrZ delay_configrrrrPs   rc Csg}d}g}d|krj|ddg}|dd}|D]4}||}|t|t|}|dk r4||q4|dk r||dk r||d} | D]4}|t| |t| |}|dk r||qt|dkrt|d|dSt|} t| |t|dSdS)Nrpolicies max_attemptsrr)r!)r!retryable_exceptions) getappend_create_single_checker_extract_retryable_exceptionextendlenMaxAttemptsDecorator MultiCheckertuple) rrcheckersr!r"r keyZcurrent_configZretry_exceptionZoperation_policiesZ multi_checkerrrrr\s:     rcCs2d|dkrt|ddSd|dkr.tSdS)Nresponse applies_when socket_errors)_create_single_response_checkerExceptionRaiser)rrrrr%{s    r%cCs^d|krt|d|dd}nr?loggerdebug)r@r r.caught_exceptionkwargsresultrrr__call__s   zRetryHandler.__call__N)__name__ __module__ __qualname____doc__rArGrrrrrs 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. cCs4|dk r|||S|dk r(|||StddS)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 )r@attempt_numberr.rDrrrrGs zBaseChecker.__call__cCsdSr=rr@rOr.rrrrMszBaseChecker._check_responsecCsdSr=rr@rOrDrrrrNsz#BaseChecker._check_caught_exceptionN)rHrIrJrKrGrMrNrrrrrLsrLc@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||_||_||_dSr=)r> _max_attempts_retryable_exceptions)r@rr!r"rrrrAszMaxAttemptsDecorator.__init__cCs^||||}|rV||jkrP|dk r@d|dkr@d|ddd<td|dS|SndSdS)NZResponseMetadatarTZMaxAttemptsReachedz0Reached the maximum number of retry attempts: %sF) _should_retryrRrBrC)r@rOr.rDZ should_retryrrrrGs zMaxAttemptsDecorator.__call__c Csp|jr^||jkr^z||||WS|jk rZ}ztjd|ddWYdSd}~XYqlXn||||SdS)Nz,retry needed, retryable exception caught: %sT)exc_info)rSrRr>rBrC)r@rOr.rDerrrrT sz"MaxAttemptsDecorator._should_retry)N)rHrIrJrKrArGrTrrrrr)s r)c@seZdZddZddZdS)r8cCs ||_dSr=) _status_code)r@r3rrrrAszHTTPStatusCodeChecker.__init__cCs*|dj|jkr"td|jdSdSdS)Nrz5retry needed: retryable HTTP status code received: %sTF)r3rWrBrCrPrrrrMsz%HTTPStatusCodeChecker._check_responseNrHrIrJrArMrrrrr8sr8c@seZdZddZddZdS)r7cCs||_||_dSr=)rW _error_code)r@r3r4rrrrA'sz ServiceErrorCodeChecker.__init__cCsJ|dj|jkrF|ddid}||jkrFtd|j|jdSdS)NrrErrorZCodez>retry needed: matching HTTP status and error code seen: %s, %sTF)r3rWr#rYrBrC)r@rOr.Zactual_error_coderrrrM+s z'ServiceErrorCodeChecker._check_responseNrXrrrrr7&sr7c@seZdZddZddZdS)r*cCs ||_dSr=Z _checkers)r@r,rrrrA7szMultiChecker.__init__cCs(|jD]}||||}|r|SqdS)NFr[)r@rOr.rDrZchecker_responserrrrG:s  zMultiChecker.__call__N)rHrIrJrArGrrrrr*6sr*c@seZdZddZddZdS)r9cCs ||_dSr=) _header_name)r@r6rrrrADszCRC32Checker.__init__cCst|d}|j|j}|dkr.td|jnBt|djd@}|t|ksptdt||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)Z checksum_typeZexpected_checksumZactual_checksum) headersr#r\rBrCrcontentintr)r@rOr. http_responseZ expected_crcZ actual_crc32rrrrMHs" zCRC32Checker._check_responseNrXrrrrr9Csr9c@seZdZdZddZdS)r2z`Raise any caught exceptions. This class will raise any non None ``caught_exception``. cCs|dSr=rrQrrrrN_sz'ExceptionRaiser._check_caught_exceptionN)rHrIrJrKrNrrrrr2Ysr2)N)N)N) r rloggingbinasciirZbotocore.exceptionsrrrrr getLoggerrHrBr:rrrrrr%r1r&objectrrLr)r8r7r*r9r2rrrrs8      ,.