
    Vh|                     J    d dl Z d dlZd dlZ G d d      Zd Z G d d      Zy)    Nc                   $    e Zd ZdZddZd Zd Zy)BackoffIteratora  iterate sleep value based on the exponential or jitter back-off algorithm.
    Args:
        delay (int or float): initial delay.
        backoff (int or float): backoff multiplier e.g. value of 2 will  double the delay each retry.
        max_delay (int or None): maximum amount of time to wait between retries.
        jitter (bool): if set to true, add jitter to the generate value.
    Nc                 <    || _         || _        || _        || _        y Ndelaybackoff	max_delayjitter)selfr   r	   r
   r   s        i/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/amazon/aws/plugins/module_utils/cloud.py__init__zBackoffIterator.__init__,   s    
"    c                 (    | j                   | _        | S r   )r   current_delay)r   s    r   __iter__zBackoffIterator.__iter__2   s    !ZZr   c                     | j                   | j                  nt        | j                  | j                         }| j                  rt	        j
                  d|      }| xj                  | j                  z  c_        |S )Ng        )r
   r   minr   randomuniformr	   )r   return_values     r   __next__zBackoffIterator.__next__6   s^    -1^^-Ct))TM_M_aeaoaoIp;;!>>#|<Ldll*r   )NF)__name__
__module____qualname____doc__r   r   r    r   r   r   r   #   s    r   r   c                     d}|D ]  }	  |        c S  y # t         $ rL}	|dz  }||k(  r |rt        |	|      s  ||	      }
 ||
|      rt        j                  |       n Y d }	~	_d }	~	ww xY w)Nr      )	Exception
isinstancetimesleep)funcsleep_time_generatorretriescatch_extra_error_codesfound_fstatus_code_from_except_f
base_classcounter
sleep_timeexcstatus_codes              r   _retry_funcr/   >   s     G* 
	6M  
	qLG'!*S*"=3C8K{$;<

:& '
	s   	A)AA$$A)c                   v    e Zd ZdZ ed      Zed        Zedd       Ze	d        Z
e	d	d       Ze	d
d       Zy)
CloudRetryzx
    The base class to be used by other cloud providers to provide a backoff/retry decorator based on status codes.
    Nc                     t               )z
        Returns the Error 'code' from an exception.
        Args:
          error: The Exception from which the error code is to be extracted.
            error will be an instance of class.base_class.
        )NotImplementedError)errors    r   status_code_from_exceptionz%CloudRetry.status_code_from_exceptionY   s     "##r   c                 (    fd} |       xr | v S )Nc                  <    	 t                y# t        $ r Y yw xY w)NTF)iter	TypeError)r'   s   r   _is_iterablez&CloudRetry.found.<locals>._is_iterablee   s*    ,-   s    	r   )response_coder'   r:   s    ` r   foundzCloudRetry.foundc   s    	 ~J-3J"JJr   c                 &      fd}|S )Nc                 P     t        j                          fd       }|S )Nc            	      n    t        j                  g| i |}t        |	j                        S )N)r$   r%   r&   r'   r(   r)   r*   )	functoolspartialr/   r*   )
argskwargspartial_funcr'   clsr<   r$   r&   r%   r5   s
      r   _retry_wrapperzJCloudRetry.base_decorator.<locals>.retry_decorator.<locals>._retry_wrappert   sC    (00GGG"%)=#,C!.H"~~ r   )r@   wraps)r$   rF   r'   rE   r<   r&   r%   r5   s   ` r   retry_decoratorz2CloudRetry.base_decorator.<locals>.retry_decorators   s+    __T"
 
 #
 "!r   r   )rE   r&   r<   r5   r'   r%   rH   s   `````` r   base_decoratorzCloudRetry.base_decoratorq   s    	" 	"  r   c                 r    t        |||      }| j                  || j                  | j                  ||      S )a#  Wrap a callable with retry behavior.
        Args:
            retries (int): Number of times to retry a failed request before giving up
                default=10
            delay (int or float): Initial delay between retries in seconds
                default=3
            backoff (int or float): backoff multiplier e.g. value of 2 will  double the delay each retry
                default=2
            max_delay (int or None): maximum amount of time to wait between retries.
                default=60
            catch_extra_error_codes: Additional error messages to catch, in addition to those which may be defined by a subclass of CloudRetry
                default=None
        Returns:
            Callable: A generator that calls the decorated function using an exponential backoff.
        )r   r	   r
   r&   r<   r5   r'   r%   r   rI   r<   r5   rE   r&   r   r	   r
   r'   r%   s          r   exponential_backoffzCloudRetry.exponential_backoff   sE    "  /UGW`a!!))'*'E'E$;!5 " 
 	
r   c                 t    t        |||d      }| j                  || j                  | j                  ||      S )a0  Wrap a callable with retry behavior.
        Args:
            retries (int): Number of times to retry a failed request before giving up
                default=10
            delay (int or float): Initial delay between retries in seconds
                default=3
            backoff (int or float): backoff multiplier e.g. value of 2 will  double the delay each retry
                default=2.0
            max_delay (int or None): maximum amount of time to wait between retries.
                default=60
            catch_extra_error_codes: Additional error messages to catch, in addition to those which may be defined by a subclass of CloudRetry
                default=None
        Returns:
            Callable: A generator that calls the decorated function using using a jittered backoff strategy.
        Tr   rK   rL   rM   s          r   jittered_backoffzCloudRetry.jittered_backoff   sH    "  /UGW`imn!!))'*'E'E$;!5 " 
 	
r   r   )
         <   N)rQ   rR   g       @rT   N)r   r   r   r   typer*   staticmethodr5   r<   classmethodrI   rN   rP   r   r   r   r1   r1   R   sv     dJ$ $ K K  & 
 
2 
 
r   r1   )r@   r   r"   r   r/   r1   r   r   r   <module>rX      s+   <    6(e
 e
r   