
    /Jfl9                        d dl Z d dlZd dlZd dlmZ d dlmZmZmZm	Z	m
Z
  ej        e          Zdeee
e	giZd Zd ZddZddZdd	Zd
 Zd Zd Z G d d          Z G d d          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          ZdS )    N)crc32)ChecksumErrorConnectionClosedErrorConnectionErrorEndpointConnectionErrorReadTimeoutErrorGENERAL_CONNECTION_ERRORc                     | dk    rt          j                     } n| dk    rt          d|            | ||dz
  z  z  }|S )a1  Calculate 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.

    randr   z.The 'base' param must be greater than 0, got:    )random
ValueError)basegrowth_factorattemptstime_to_sleeps       X/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/botocore/retryhandler.pydelay_exponentialr   +   s[     v~~}	CTCC
 
 	
 Mhl;<M    c                 :    t          j        t          | |          S )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   )	functoolspartialr   r   s     r   !create_exponential_delay_functionr   B   s%     M   r   c                 h    t          | |          }t          | |          }t          ||          S )N)operation_name)checkeraction) create_checker_from_retry_configcreate_retry_action_from_configRetryHandler)configr   r   r   s       r   create_retry_handlerr#   N   sK    .~  G -~  F 7777r   c                 t    | d         d         }|d         dk    rt          |d         |d                   S d S )N__default__delaytypeexponentialr   r   r   )r   )r"   r   delay_configs      r   r    r    X   sR    
 -(1LF},,0f%&7
 
 
 	
 -,r   c                    g }d }g }d| v r| d                              dg           }| d         d         }|D ]R}||         }|                    t          |                     t          |          }||                    |           S|||                      |          g| |         d         }	|	D ]V}|                    t          |	|                              t          |	|                   }||                    |           Wt          |          dk    rt          |d         |          S t          |          }
t          |
|t          |                    S )Nr%   policiesmax_attemptsr   r   )r,   )r,   retryable_exceptions)	getappend_create_single_checker_extract_retryable_exceptionextendlenMaxAttemptsDecoratorMultiCheckertuple)r"   r   checkersr,   r-   r+   keycurrent_configretry_exceptionoperation_policiesmulti_checkers              r   r   r   e   s   HL-(,,Z<<m,^< 	= 	=C%c]NOO2>BBCCC:>JJO*$++O<<<!fjj&@&@&L#N3J?% 	= 	=COO23Ec3JKKLLL:"3' O *$++O<<<
8}}#HQKlKKKK$X..#%!&';!<!<
 
 
 	
r   c                     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_checkerExceptionRaiser)r"   s    r   r0   r0      sW    VN+++.>":.
 
 	
 
F>2	2	2    
3	2r   c                     d| v rt          | d         | d                   }nEd| v rt          | d                   }n*d| v rt          | d                   }nt          d          |S )Nservice_error_codehttp_status_code)status_code
error_code)rF   	crc32body)headerzUnknown retry policy)ServiceErrorCodeCheckerHTTPStatusCodeCheckerCRC32Checkerr   )r>   r   s     r   rA   rA      s    x'') !34 45
 
 
 
x	'	'' !34
 
 
 
	 	 h{&;<<< /000Nr   c                     | d         }d|                     di           v rt          gS d|v r/g }|d         D ]"}|                    t          |                    #|S d S )Nr?   rH   r>   r@   )r.   r   r2   EXCEPTION_MAP)r"   r?   
exceptionsnames       r   r1   r1      s}    .)Ll&&z26666	L	(	(
 1 	3 	3DmD12222	 
)	(r   c                       e Zd ZdZd Zd ZdS )r!   a  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.

    c                 "    || _         || _        d S N)_checker_action)selfr   r   s      r   __init__zRetryHandler.__init__   s    r   c                 j   |||d}t          | j        t                    r8|d         d                             d          }|                    d|i            | j        d
i |r3|                     |          }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_context)r   zRetry needed, action of: %szNo retry needed.N )
isinstancerT   r4   r.   updaterU   loggerdebug)rV   r   r>   rZ   kwargschecker_kwargsr^   results           r   __call__zRetryHandler.__call__   s     '  0
 

 dm%9:: 	H$^4Y?CCINNO!!#4o"FGGG4=**>** 	\\8\44FLL6???M'(((((r   N)__name__
__module____qualname____doc__rW   rg   r_   r   r   r!   r!      s<           ) ) ) ) )r   r!   c                   $    e Zd ZdZd Zd Zd ZdS )BaseCheckerzBase class for retry checkers.

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

    c                     ||                      ||          S ||                     ||          S t          d          )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   )rV   rY   r>   rZ   s       r   rg   zBaseChecker.__call__   sU    , ''AAA)// 0   KLLLr   c                     d S rS   r_   rV   rY   r>   s      r   ro   zBaseChecker._check_response       r   c                     d S rS   r_   rV   rY   rZ   s      r   rp   z#BaseChecker._check_caught_exception   rs   r   N)rh   ri   rj   rk   rg   ro   rp   r_   r   r   rm   rm      sN         M M M>      r   rm   c                   &    e Zd ZdZddZd Zd ZdS )r4   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.

    Nc                 0    || _         || _        || _        d S rS   )rT   _max_attempts_retryable_exceptions)rV   r   r,   r-   s       r   rW   zMaxAttemptsDecorator.__init__  s    )%9"""r   c                 "   |r,t          |                    dd          | j                  |d<   |                     |||          }|rG|| j        k    r:|d|d         v rd|d         d         d<   t                              d|           dS |S dS )	Nmaxr   ResponseMetadatar   TMaxAttemptsReachedz0Reached the maximum number of retry attempts: %sF)r{   r.   rx   _should_retryrb   rc   )rV   rY   r>   rZ   r^   should_retrys         r   rg   zMaxAttemptsDecorator.__call__  s      	%(##E1--t/A& &OE" ))H&6
 
  	!333',>(1+,M,M  QK 23, F"   u##5r   c                     | j         rX|| j        k     rM	 |                     |||          S # | j         $ r(}t                              d|d           Y d }~dS d }~ww xY w|                     |||          S )Nz,retry needed, retryable exception caught: %sT)exc_info)ry   rx   rT   rb   rc   )rV   rY   r>   rZ   es        r   r~   z"MaxAttemptsDecorator._should_retry0  s    % 	M.4;M*M*M
}}"H.>   -   B!    
 ttttt ==;KLLLs   + 
AAArS   )rh   ri   rj   rk   rW   rg   r~   r_   r   r   r4   r4     sU         : : : :
  8M M M M Mr   r4   c                       e Zd Zd Zd ZdS )rK   c                     || _         d S rS   )_status_code)rV   rF   s     r   rW   zHTTPStatusCodeChecker.__init__D  s    'r   c                 v    |d         j         | j        k    r"t                              d| j                   dS dS )Nr   z5retry needed: retryable HTTP status code received: %sTF)rF   r   rb   rc   rr   s      r   ro   z%HTTPStatusCodeChecker._check_responseG  sB    A;"d&777LLG!   45r   Nrh   ri   rj   rW   ro   r_   r   r   rK   rK   C  s2        ( ( (    r   rK   c                       e Zd Zd Zd ZdS )rJ   c                 "    || _         || _        d S rS   )r   _error_code)rV   rF   rG   s      r   rW   z ServiceErrorCodeChecker.__init__S  s    '%r   c                     |d         j         | j        k    rb|d                             di                               d          }|| j        k    r(t                              d| j        | j                   dS dS )Nr   r   ErrorCodez>retry needed: matching HTTP status and error code seen: %s, %sTF)rF   r   r.   r   rb   rc   )rV   rY   r>   actual_error_codes       r   ro   z'ServiceErrorCodeChecker._check_responseW  s~    A;"d&777 ( < < @ @ H H D$444%$	   tur   Nr   r_   r   r   rJ   rJ   R  s2        & & &    r   rJ   c                       e Zd Zd Zd ZdS )r5   c                     || _         d S rS   	_checkers)rV   r7   s     r   rW   zMultiChecker.__init__f  s    !r   c                 @    | j         D ]} ||||          }|r|c S dS )NFr   )rV   rY   r>   rZ   r   checker_responses         r   rg   zMultiChecker.__call__i  sM    ~ 	( 	(G&w*:      (''''(ur   N)rh   ri   rj   rW   rg   r_   r   r   r5   r5   e  s2        " " "    r   r5   c                       e Zd Zd Zd ZdS )rL   c                     || _         d S rS   )_header_name)rV   rI   s     r   rW   zCRC32Checker.__init__t  s    "r   c                    |d         }|j                             | j                  }|"t                              d| j                   d S t          |d         j                  dz  }|t          |          k    sHt                              dt          |          |           t          dt          |          |          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.   r   rb   rc   r   contentintr   )rV   rY   r>   http_responseexpected_crcactual_crc32s         r   ro   zCRC32Checker._check_responsex  s     $,001BCCLL(!     !!!455
BL3|#4#444%% 	   $")&),&7&7$0    54r   Nr   r_   r   r   rL   rL   s  s2        # # #    r   rL   c                       e Zd ZdZd ZdS )rB   z`Raise any caught exceptions.

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

    c                     |rS   r_   ru   s      r   rp   z'ExceptionRaiser._check_caught_exception  s
     r   N)rh   ri   rj   rk   rp   r_   r   r   rB   rB     s-             r   rB   rS   )r   loggingr   binasciir   botocore.exceptionsr   r   r   r   r   	getLoggerrh   rb   rN   r   r   r#   r    r   r0   rA   r1   r!   rm   r4   rK   rJ   r5   rL   rB   r_   r   r   <module>r      s                            
	8	$	$ 	!  .	 	 	8 8 8 8

 

 

 


 
 
 
D! ! !  $  &) &) &) &) &) &) &) &)R+ + + + + + + +\<M <M <M <M <M; <M <M <M~    K       k   &    ;       ;   <    k     r   