
    $j                         d dl Z d dlZd dlZd dlZd dlmZ ddlmZ  e j                  e	      Z
edd ddd e
ddf	dZedd ddd e
ddf	dZddedd ddd e
ddfd	Zy)
    N)partial   	decoratorFc
           
         ||}}
|
r		  |        S yy# |$ r#}|	 |	|      rY d}~y|
dz  }
|
s |	 | j                   j                  }n$# t        $ r t        | j                         }Y nw xY w|j	                  dj                  |j                  j                  || j                   j                  ||             |r#|j	                  t        j                                t        j                  |       ||z  }t        |t              r|t        j                  | z  }n||z  }|t!        ||      }Y d}~nd}~ww xY w|
r:4)aC  
    Executes a function and retries it if it failed.

    :param f: 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. default: 0.
    :param max_delay: the maximum value of delay. 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 logger: logger.warning(fmt, error, delay) will be called on failed attempts.
                   default: retry.logging_logger. if None, logging is disabled.
    :param on_exception: handler called when exception occurs. will be passed the captured
                         exception as an argument. further retries are stopped when handler
                         returns True. default: None
    :returns: the result of the f function.
    Nr   z*{}: {} in {}.{}, retrying in {} seconds...)func__qualname__AttributeErrorstrwarningformat	__class__
__module__	traceback
format_exctimesleep
isinstancetuplerandomuniformmin)f
exceptionstriesdelay	max_delaybackoffjitterloggerlog_tracebackon_exception_tries_delayefunc_qualnames                 M/var/www/oz-panel.ru/ozpay-pub/venv/lib/python3.12/site-packages/retry/api.py__retry_internalr)      s6   ( EFF
	03J   	0'?aKF!0%&VV%8%8M% 0$'KM0KRRSTS^S^SkSkmn vv00- I J NN9#7#7#9:JJvgF&%(&..&11& $VY/9	0 s=    D:
D5
D5AD5A)&D5(A))CD55D: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. default: 0.
    :param max_delay: the maximum value of delay. 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 logger: logger.warning(fmt, error, delay) will be called on failed attempts.
                   default: retry.logging_logger. if None, logging is disabled.
    :param on_exception: handler called when exception occurs. will be passed the captured
                         exception as an argument. further retries are stopped when handler
                         returns True. default: None
    :returns: a retry decorator.
    c                 ~   	 |r|n	t               }|r|n	t               }t        t        | g|i |
	
      S )Nlistdictr)   r   )r   fargsfkwargsargskwargsr   r   r   r    r"   r!   r   r#   r   s        r(   retry_decoratorzretry.<locals>.retry_decoratorV   sP    u46# ;D ;F ;ZPUW`bikq &|E 	E    r   )
r   r   r   r   r   r    r!   r"   r#   r3   s
   ````````` r(   retryr5   C   s(    & E E E r4   c                 |    |r|n	t               }|r|n	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. default: 0.
    :param max_delay: the maximum value of delay. 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 logger: logger.warning(fmt, error, delay) will be called on failed attempts.
                   default: retry.logging_logger. if None, logging is disabled.
    :param on_exception: handler called when exception occurs. will be passed the captured
                         exception as an argument. further retries are stopped when handler
                         returns True. default: None
    :returns: the result of the f function.
    r,   )r   r/   r0   r   r   r   r   r   r    r!   r"   r#   r1   r2   s                 r(   
retry_callr7   `   sO    , 5tvDWTVFGA777UES\^egmou)<9 9r4   )loggingr   r   r   	functoolsr   compatr   	getLogger__name__logging_logger	Exceptionr)   r5   r7    r4   r(   <module>r@      s         """8, $-Ba4YZcd*%d40n bT1UV_mD: dyRS_cmneRV9r4   