
    X9c                         d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlZddlm	Z	  ej                  e      Zedd ddd dedf	dZedd ddd dedf	dZd	 Zd
 Zd Zd ZdedfdZedd ddd dedf	dZddedd ddd dedfdZy)    N)partial   	decoratorFc
           	          ||}}
|
r		  |        S y y # |$ rQ}|
dz  }
|rt        ||||
||       |
s |	 |	|       t        j                  |       t        ||||      }Y d }~nd }~ww xY w|
rf_Nr   )_log_attempttimesleep
_new_delayf
exceptionstriesdelay	max_delaybackoffjittershow_tracebackloggerfail_callback_tries_delayes                +lib/python3.12/site-packages/reretry/api.py__retry_internalr      s     EFF
	D3J   	DaKFUNFFFAN(a JJv	7FFCF	D	 s    A'AA""A'c
           	        K   ||}}
|
r	  |         d {   S y y 7 # |$ rc}|
dz  }
|rt        ||||
||       |
s |	 |	|       d {  7   t        j                  |       d {  7   t        ||||      }Y d }~nd }~ww xY w|
rswr	   )r
   asyncior   r   r   s                r   __retry_internal_asyncr    2   s      EFF
	D9  	DaKFUNFFFAN(#A&&&--'''	7FFCF	D	 sN   B
  B B'B 	A
B 'A*(B ;B BBc                     |r\|rAdj                  t        j                  d ||j                              }|j	                  |       |j	                  d|| |z
  | |       y | dkD  r|j	                  d|| |z
  |        y y )N z4%s, attempt %s/%s failed - retrying in %s seconds...r   z%%s, attempt %s/%s failed - giving up!)join	tracebackformat_exception__traceback__warning)r   r   r   r   r   r   tb_strs          r   r
   r
   U   s{    WWY77aQRFNN6"BFN	
 
3Q	
 
    c                 z    ||z  }|t        |t              rt        j                  | n|z  }| t	        ||       }|S N)
isinstancetuplerandomuniformmin)r   r   r   r   s       r   r   r   i   sA    
gF
FE)Bfnnf%NFVY'Mr)   c                 \    t        j                  |       xr t        j                  |        S r+   )r   iscoroutinefunctioninspectisgeneratorfunctionr   s    r   	_is_asyncr6   s   s&    &&q)P'2M2Ma2P.PPr)   c                 0    t        |       rt        S t        S r+   )r6   r    r   r5   s    r   _get_internal_functionr8   w   s    %.q\!G7GGr)   c                     |r	|J d       |r5t        |       rt        |      st        |       st        |      rJ d       y y y )Nz`show_traceback` needs `logger`zWIf the retried function is async, fail_callback needs to be async as well or vice versa)r6   )r   r   r   r   s       r   _check_paramsr:   {   sQ    !3V5VV	1)M2!Y}%=a aa%= 3 r)   c	           
      D     t          f	d       }	|	S )a  Returns a retry decorator.

    :param exceptions: an exception or a tuple of exceptions to catch. default: Exception.
    :param tries: the maximum number of attempts. default: -1 (infinite).
    :param delay: initial delay between attempts (in seconds). default: 0.
    :param max_delay: the maximum value of delay (in seconds). default: None (no limit).
    :param backoff: multiplier applied to delay between attempts. default: 1 (no backoff).
    :param jitter: extra seconds added to delay between attempts. default: 0.
                   fixed if a number, random if a range tuple (min, max)
    :param show_traceback: if True, the traceback of the exception will be logged.
    :param logger: logger.warning(fmt, error, delay) will be called on failed attempts.
                   default: retry.logging_logger. if None, logging is disabled.
    :param fail_callback: fail_callback(e) will be called on failed attempts.
    :returns: a retry decorator.
    c                 0   	 t        | ||	
      S r+   )
retry_call)r   fargsfkwargsr   r   r   r   r   r   r   r   r   s      r   retry_decoratorzretry.<locals>.retry_decorator   s4    
 	
r)   r   )
r   r   r   r   r   r   r   r   r   r@   s
   ````````` r   retryrA      s%    6 
 
 
  r)   c                     |xs
 t               }|xs
 t               }t        | |	|
|       t        |       } |t	        | g|i ||||||||	|
|
      S )a  
    Calls a function and re-executes it if it failed.

    :param f: the function to execute.
    :param fargs: the positional arguments of the function to execute.
    :param fkwargs: the named arguments of the function to execute.
    :param exceptions: an exception or a tuple of exceptions to catch. default: Exception.
    :param tries: the maximum number of attempts. default: -1 (infinite).
    :param delay: initial delay between attempts (in seconds). default: 0.
    :param max_delay: the maximum value of delay (in seconds). default: None (no limit).
    :param backoff: multiplier applied to delay between attempts. default: 1 (no backoff).
    :param jitter: extra seconds added to delay between attempts. default: 0.
                   fixed if a number, random if a range tuple (min, max)
    :param show_traceback: if True, the traceback of the exception will be logged.
    :param logger: logger.warning(fmt, error, delay) will be called on failed attempts.
                   default: retry.logging_logger. if None, logging is disabled.
    :param fail_callback: fail_callback(e) will be called on failed attempts.
    :returns: the result of the f function.
    )listdictr:   r8   r   )r   r>   r?   r   r   r   r   r   r   r   r   r   argskwargsfuncs                  r   r=   r=      sn    B ?DFDF!^V];!!$D#D#F# r)   )r   loggingr.   r   r$   	functoolsr   r3   compatr   	getLogger__name__logging_logger	Exceptionr   r    r
   r   r6   r8   r:   rA   r=    r)   r   <module>rP      s           """8,
 

 DJ 

 DF
(QH %*.PT a 

,b 

2r)   