
    9i>                         S r SSKrSSKrSSKJr  SSKJr  SSKJr  \R                  " \
5      r " S S\5      r " S S	\5      rg)
z;
This module defines a common configuration class for BCE.
    N)str)bytes)BceServerErrorc                   $    \ rS rSrSrS rS rSrg)NoRetryPolicy   zA policy that never retries.c                     g)zrAlways returns False.

:param error: ignored
:param retries_attempted: ignored
:return: always False
:rtype: bool
F selferrorretries_attempteds      [/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/baidubce/retry/retry_policy.pyshould_retryNoRetryPolicy.should_retry   s         c                     g)ziAlways returns 0.

:param error: ignored
:param retries_attempted: ignored
:return: always 0
:rtype: int
r   r
   r   s      r   %get_delay_before_next_retry_in_millis3NoRetryPolicy.get_delay_before_next_retry_in_millis)   s     r   r
   N)__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes__r
   r   r   r   r      s    &r   r   c                   4    \ rS rSrSr   SS jrS rS rSrg)	BackOffRetryPolicy4   a  A policy that retries with exponential back-off strategy.

This policy will keep retrying until the maximum number of retries is reached. The delay time
will be a fixed interval for the first time then 2 * interval for the second, 4 * internal for
the third, and so on. In general, the delay time will be 2^number_of_retries_attempted*interval.

When a maximum of delay time is specified, the delay time will never exceed this limit.
c                 l    US:  a  [        S5      eUS:  a  [        S5      eXl        X l        X0l        g)an  
:param max_error_retry: the maximum number of retries.
:type max_error_retry: int
:param max_delay_in_millis: the maximum of delay time in milliseconds.
:type max_delay_in_millis: int
:param base_interval_in_millis: the base delay interval in milliseconds.
:type base_interval_in_millis: int
:raise ValueError if max_error_retry or max_delay_in_millis is negative.
r   s1   max_error_retry should be a non-negative integer.s5   max_delay_in_millis should be a non-negative integer.N)
ValueErrormax_error_retrymax_delay_in_millisbase_interval_in_millis)r   r!   r"   r#   s       r   __init__BackOffRetryPolicy.__init__>   s>     QQRR"UVV.#6 '>$r   c                    X R                   :  a  g[        U[        5      (       a  [        R	                  S5        g[        U[
        5      (       a  UR                  [        R                  R                  :X  a  [        R	                  S5        gUR                  [        R                  R                  :X  a  [        R	                  S5        gUR                  [
        R                  :X  a  [        R	                  S5        gg)a'  Return true if the http client should retry the request.

:param error: the caught error.
:type error: Exception
:param retries_attempted: the number of retries which has been attempted before.
:type retries_attempted: int
:return: true if the http client should retry the request.
:rtype: bool
Fs   Retry for IOError.Ts    Retry for internal server error.s   Retry for service unavailable.s   Retry for request expired.)r!   
isinstanceIOError_loggerdebugr   status_codehttpclientINTERNAL_SERVER_ERRORSERVICE_UNAVAILABLEcodeREQUEST_EXPIREDr   s      r   r   BackOffRetryPolicy.should_retryT   s      4 44 eW%%MM/0 e^,,  DKK$E$EEAB  DKK$C$CC?@zz^;;;;<r   c                 n    US:  a  gSU-  U R                   -  nX0R                  :  a  U R                  $ U$ )a/  Returns the delay time in milliseconds before the next retry.

:param error: the caught error.
:type error: Exception
:param retries_attempted: the number of retries which has been attempted before.
:type retries_attempted: int
:return: the delay time in milliseconds before the next retry.
:rtype: int
r      )r#   r"   )r   r   r   delay_in_milliss       r   r   8BackOffRetryPolicy.get_delay_before_next_retry_in_millisv   sC     q  11T5Q5QQ555+++r   )r#   r"   r!   N)   i N  i,  )	r   r   r   r   r   r$   r   r   r   r
   r   r   r   r   4   s"     "#%.),?, Dr   r   )r   http.clientr,   loggingbuiltinsr   r   baidubce.exceptionr   	getLoggerr   r)   objectr   r   r
   r   r   <module>r>      sG        - 

H
%F 0Q Qr   