
    vKgn9                     `   S SK r S SKrS SKrS SKJr  S SKJrJrJrJ	r	J
r
  \R                  " \5      rS\\\
\	/0rS rS rSS jrSS jrSS	 jrS
 rS rS r " S S5      r " S S5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rg)    N)crc32)ChecksumErrorConnectionClosedErrorConnectionErrorEndpointConnectionErrorReadTimeoutErrorGENERAL_CONNECTION_ERRORc                 z    U S:X  a  [         R                   " 5       n OU S::  a  [        SU  35      eXUS-
  -  -  nU$ )a  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       U/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/botocore/retryhandler.pydelay_exponentialr   +   sM     v~}}	<TFC
 	
 hl;<M    c                 4    [         R                  " [        XS9$ )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      r   c                 8    [        XS9n[        XS9n[        X#S9$ )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   s+    .G -F 77r   c                 F    U S   S   nUS   S:X  a  [        US   US   S9$ g )N__default__delaytypeexponentialr   r   r   )r   )r"   r   delay_configs      r   r    r    X   sB    
 -(1LF},0f%&7
 	
 -r   c                 "   / nS n/ nSU ;   ae  U S   R                  S/ 5      nU S   S   nU HB  nXV   nUR                  [        U5      5        [        U5      nUc  M1  UR	                  U5        MD     Uba  U R                  U5      bO  X   S   n	U	 HB  nUR                  [        X   5      5        [        X   5      nUc  M1  UR	                  U5        MD     [        U5      S:X  a  [        US   US9$ [        U5      n
[        U
U[        U5      S9$ )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   s0   HL-(,,Z<m,^<C%]NOO2>BC:>JO*$++O<  !fjj&@&L#3J?%COO23E3JKL:"'O *$++O< & 8}#HQKlKK$X.#%!&';!<
 	
r   c                 ^    SU S   ;   a  [        U S   S   5      $ SU S   ;   a
  [        5       $ g )Nresponseapplies_whensocket_errors)_create_single_response_checkerExceptionRaiser)r"   s    r   r0   r0      sF    VN++.>":.
 	
 
F>2	2   
3r   c                     SU ;   a  [        U S   U S   S9nU$ SU ;   a  [        U S   S9nU$ SU ;   a  [        U S   S9nU$ [        S5      e)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
 N 
x	'' !34
 N 
	 h{&;< N /00r   c                     U S   nSUR                  S0 5      ;   a  [        /$ SU;   a(  / nUS    H  nUR                  [        U   5        M     U$ g )Nr?   rH   r>   r@   )r.   r   r2   EXCEPTION_MAP)r"   r?   
exceptionsnames       r   r1   r1      sc    .)Ll&&z266	L	(
 1DmD12 2	 
)r   c                   $    \ rS rSrSrS rS rSrg)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                     Xl         X l        g N)_checker_action)selfr   r   s      r   __init__RetryHandler.__init__   s    r   c                 H   UUUS.n[        U R                  [        5      (       a*  US   S   R                  S5      nUR	                  SU05        U R                  " S
0 UD6(       a'  U R                  US9n[        R                  SU5        U$ [        R                  S5        g	)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 )
isinstancerU   r4   r.   updaterV   loggerdebug)rW   r   r>   r\   kwargschecker_kwargsr`   results           r   __call__RetryHandler.__call__   s     '  0

 dmm%9::$^4Y?CCINO!!#4o"FG==*>*\\8\4FLL6?M'(r   )rV   rU   N)__name__
__module____qualname____firstlineno____doc__rX   ri   __static_attributes__ra   r   r   r!   r!      s    )r   r!   c                   *    \ rS rSrSrS rS rS rSrg)BaseChecker   zBase class for retry checkers.

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

c                 h    Ub  U R                  X5      $ Ub  U R                  X5      $ [        S5      e)ad  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.

z,Both response and caught_exception are None.)_check_response_check_caught_exceptionr   )rW   r[   r>   r\   s       r   ri   BaseChecker.__call__   sE    , ''AA)//  KLLr   c                     g rT   ra   rW   r[   r>   s      r   ru   BaseChecker._check_response       r   c                     g rT   ra   rW   r[   r\   s      r   rv   #BaseChecker._check_caught_exception   r{   r   ra   N)	rk   rl   rm   rn   ro   ri   ru   rv   rp   ra   r   r   rr   rr      s    M>r   rr   c                   .    \ rS rSrSrSS jrS rS rSrg)	r4   i  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                 (    Xl         X l        X0l        g rT   rU   _max_attempts_retryable_exceptions)rW   r   r,   r-   s       r   rX   MaxAttemptsDecorator.__init__  s    )%9"r   c                    U(       a)  [        UR                  SS5      U R                  5      US'   U R                  XU5      nU(       a?  XR                  :  a.  Ub  SUS   ;   a  SUS   S   S'   [        R                  SU5        gU$ g)	Nmaxr   ResponseMetadatar   TMaxAttemptsReachedz0Reached the maximum number of retry attempts: %sF)r   r.   r   _should_retryrd   re   )rW   r[   r>   r\   r`   should_retrys         r   ri   MaxAttemptsDecorator.__call__  s     %(##E1-t/A/A&OE" ))&6
 !3!33',>(1+,M QK 234HI F" ##r   c                     U R                   (       a"  XR                  :  a   U R                  XU5      $ U R                  XU5      $ ! U R                    a  n[        R	                  SUSS9   S nAgS nAff = f)Nz,retry needed, retryable exception caught: %sT)exc_info)r   r   rU   rd   re   )rW   r[   r>   r\   es        r   r   "MaxAttemptsDecorator._should_retry0  s}    %%.;M;M*M
}}".>  ==;KLL -- B!  
 s   A A5A00A5r   rT   )	rk   rl   rm   rn   ro   rX   ri   r   rp   ra   r   r   r4   r4     s    :
8Mr   r4   c                        \ rS rSrS rS rSrg)rK   iC  c                     Xl         g rT   _status_code)rW   rF   s     r   rX   HTTPStatusCodeChecker.__init__D  s    'r   c                     US   R                   U R                  :X  a!  [        R                  SU R                  5        gg)Nr   z5retry needed: retryable HTTP status code received: %sTF)rF   r   rd   re   ry   s      r   ru   %HTTPStatusCodeChecker._check_responseG  s:    A;""d&7&77LLG!! r   r   Nrk   rl   rm   rn   rX   ru   rp   ra   r   r   rK   rK   C  s    (r   rK   c                        \ rS rSrS rS rSrg)rJ   iR  c                     Xl         X l        g rT   )r   _error_code)rW   rF   rG   s      r   rX    ServiceErrorCodeChecker.__init__S  s    '%r   c                     US   R                   U R                  :X  a_  US   R                  S0 5      R                  S5      nX0R                  :X  a,  [        R                  SU R                  U R                  5        gg)Nr   r   ErrorCodez>retry needed: matching HTTP status and error code seen: %s, %sTF)rF   r   r.   r   rd   re   )rW   r[   r>   actual_error_codes       r   ru   'ServiceErrorCodeChecker._check_responseW  sq    A;""d&7&77 ( < @ @ H $4$44%%$$	 r   )r   r   Nr   ra   r   r   rJ   rJ   R  s    &r   rJ   c                        \ rS rSrS rS rSrg)r5   ie  c                     Xl         g rT   	_checkers)rW   r7   s     r   rX   MultiChecker.__init__f  s    !r   c                 R    U R                    H  nU" XU5      nU(       d  M  Us  $    g)NFr   )rW   r[   r>   r\   r   checker_responses         r   ri   MultiChecker.__call__i  s4    ~~G&*:   '' & r   r   N)rk   rl   rm   rn   rX   ri   rp   ra   r   r   r5   r5   e  s    "r   r5   c                        \ rS rSrS rS rSrg)rL   is  c                     Xl         g rT   _header_name)rW   rI   s     r   rX   CRC32Checker.__init__t  s    "r   c                 \   US   nUR                   R                  U R                  5      nUc!  [        R	                  SU R                  5        g [        US   R                  5      S-  nU[        U5      :X  d4  [        R	                  S[        U5      U5        [        S[        U5      US9eg )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   rd   re   r   contentintr   )rW   r[   r>   http_responseexpected_crcactual_crc32s         r   ru   CRC32Checker._check_responsex  s     $,,001B1BCLL(!! !!!4!45
BL3|#44% 	 $")&),&7$0  5r   r   Nr   ra   r   r   rL   rL   s  s    #r   rL   c                       \ rS rSrSrS rSrg)rB   i  zXRaise any caught exceptions.

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

c                     UerT   ra   r}   s      r   rv   'ExceptionRaiser._check_caught_exception  s
     r   ra   N)rk   rl   rm   rn   ro   rv   rp   ra   r   r   rB   rB     s    r   rB   rT   )r   loggingr   binasciir   botocore.exceptionsr   r   r   r   r   	getLoggerrk   rd   rN   r   r   r#   r    r   r0   rA   r1   r!   rr   r4   rK   rJ   r5   rL   rB   ra   r   r   <module>r      s         
		8	$ 	!.	8


D!$&) &)R+ +\<M; <M~K k &; ; <k r   