o
    d+                     @   sp   d dl Z d dlZd dlZd dlZd dlZdZdd Zdd ZG dd deZ	G d	d
 d
eZ
G dd deZdS )    Ni?c                    s    fdd}|S )Nc                    s
   t |  S N)
isinstance)	exceptionretryable_types M/var/www/html/visualizacion-main/env/lib/python3.10/site-packages/retrying.py_retry_if_exception_these_types      
zD_retry_if_exception_of_type.<locals>._retry_if_exception_these_typesr   )r   r	   r   r   r   _retry_if_exception_of_type   s   r   c                     s>   t  dkrt d rdd }| d S  fdd}|S )z
    Decorator function that instantiates the Retrying object
    @param *dargs: positional arguments passed to Retrying object
    @param **dkw: keyword arguments passed to the Retrying object
       r   c                    s   t   fdd}|S )Nc                     s   t  j g| R i |S r   Retryingcallargskwfr   r   	wrapped_f+   s   z-retry.<locals>.wrap_simple.<locals>.wrapped_fsixwrapsr   r   r   r   r   wrap_simple*   s   zretry.<locals>.wrap_simplec                    s   t   fdd}|S )Nc                     s"   t  i jg| R i |S r   r   r   )dargsdkwr   r   r   r   6   s   "z&retry.<locals>.wrap.<locals>.wrapped_fr   r   r   r   r   r   wrap5   s   zretry.<locals>.wrap)lencallable)r   r   r   r   r   r   r   retry!   s
   r!   c                   @   s   e Zd Z																				dddZdd Zdd Zed	d
 Zdd Zdd Z	dd Z
dd Zedd Zedd Zdd Zdd ZdS )r   NFc                    s&  |d u rdn|| _ |d u rdn|| _|d u rdn|| _|d u r!dn|| _|d u r*dn|| _|d u r3dn|| _|	d u r<dn|	| _|d u rEdn|| _|d u rNtn|| _	|
d u rWtn|
| _
|d u r`dn|| _|| _|| _g  |d uru | j |d ur | j |d ur|| _n|d u r fdd| _nt| || _dd g|d ur| j |d us|d ur| j |d us|	d urĈ| j |d us|d ur҈| j |d ur|| _n|d u rfd	d| _nt| || _|d u r| j| _nt|trt|}|| _|d u r| j| _n|| _|| _d S )
N   d     r   r   c                       t  fddD S )Nc                 3       | ]}| V  qd S r   r   .0r   attemptsdelayr   r   	<genexpr>       

6Retrying.__init__.<locals>.<lambda>.<locals>.<genexpr>)anyr)   )
stop_funcsr)   r   <lambda>       z#Retrying.__init__.<locals>.<lambda>c                  _      dS )Nr   r   )r   kwargsr   r   r   r1      s    c                    r%   )Nc                 3   r&   r   r   r'   r)   r   r   r,      r-   r.   )maxr)   )
wait_funcsr)   r   r1      r2   ) _stop_max_attempt_number_stop_max_delay_wait_fixed_wait_random_min_wait_random_max_wait_incrementing_start_wait_incrementing_increment_wait_exponential_multiplierMAX_WAIT_wait_exponential_max_wait_incrementing_max_wait_jitter_max_before_attempts_after_attemptsappendstop_after_attemptstop_after_delaystopgetattrfixed_sleeprandom_sleepincrementing_sleepexponential_sleepwaitalways_reject_retry_on_exceptionr   tupler   never_reject_retry_on_result_wrap_exception)selfrH   rN   stop_max_attempt_numberstop_max_delay
wait_fixedwait_random_minwait_random_maxwait_incrementing_startwait_incrementing_incrementwait_incrementing_maxwait_exponential_multiplierwait_exponential_maxretry_on_exceptionretry_on_resultwrap_exception	stop_func	wait_funcwait_jitter_maxbefore_attemptsafter_attemptsr   )r0   r6   r   __init__@   sn   





zRetrying.__init__c                 C   s
   || j kS )z;Stop after the previous attempt >= stop_max_attempt_number.)r7   rU   previous_attempt_numberdelay_since_first_attempt_msr   r   r   rF         
zRetrying.stop_after_attemptc                 C   s
   || j kS )z=Stop after the time from the first attempt >= stop_max_delay.)r8   ri   r   r   r   rG      rl   zRetrying.stop_after_delayc                 C   r3   )z#Don't sleep at all before retrying.r   r   )rj   rk   r   r   r   no_sleep   s   zRetrying.no_sleepc                 C   s   | j S )z0Sleep a fixed amount of time between each retry.)r9   ri   r   r   r   rJ      s   zRetrying.fixed_sleepc                 C   s   t | j| jS )zISleep a random amount of time between wait_random_min and wait_random_max)randomrandintr:   r;   ri   r   r   r   rK      s   zRetrying.random_sleepc                 C   s4   | j | j|d   }|| jkr| j}|dk rd}|S )z
        Sleep an incremental amount of time after each attempt, starting at
        wait_incrementing_start and incrementing by wait_incrementing_increment
        r   r   )r<   r=   rA   )rU   rj   rk   resultr   r   r   rL      s   
zRetrying.incrementing_sleepc                 C   s2   d| }| j | }|| jkr| j}|dk rd}|S )N   r   )r>   r@   )rU   rj   rk   exprp   r   r   r   rM      s   

zRetrying.exponential_sleepc                 C   r3   )NFr   rp   r   r   r   rR         zRetrying.never_rejectc                 C   r3   )NTr   rs   r   r   r   rO      rt   zRetrying.always_rejectc                 C   s6   d}|j r|| |jd O }|S || |jO }|S )NFr   )has_exceptionrP   valuerS   )rU   attemptrejectr   r   r   should_reject   s   zRetrying.should_rejectc                 O   s  t tt d }d}	 | jr| | zt||i ||d}W n   t }t||d}Y | |s<|| j	S | j
rD| 
| t tt d | }| ||rd| j	s`|jr`| t|| ||}	| jr{t | j }
|	td|
 }	t|	d  |d7 }q)Nr$   r   TFr   g     @@)introundtimerC   Attemptsysexc_infory   getrT   rD   rH   ru   
RetryErrorrN   rB   rn   r5   sleep)rU   fnr   r4   
start_timeattempt_numberrw   tbrk   r   jitterr   r   r   r      s4   


zRetrying.call)NNNNNNNNNNNNNNFNNNNN)__name__
__module____qualname__rh   rF   rG   staticmethodrm   rJ   rK   rL   rM   rR   rO   ry   r   r   r   r   r   r   ?   sH    
v
	

	r   c                   @   s*   e Zd ZdZdd Zd
ddZdd Zd	S )r}   z
    An Attempt encapsulates a call to a target function that may end as a
    normal return value from the function or an Exception depending on what
    occurred during the execution.
    c                 C   s   || _ || _|| _d S r   )rv   r   ru   )rU   rv   r   ru   r   r   r   rh     s   
zAttempt.__init__Fc                 C   s<   | j r|r	t| t| jd | jd | jd  dS | jS )z
        Return the return value of this Attempt instance or raise an Exception.
        If wrap_exception is true, this Attempt is wrapped inside of a
        RetryError before being raised.
        r   r   rq   N)ru   r   r   reraiserv   )rU   rb   r   r   r   r   #  s
   $zAttempt.getc              	   C   s6   | j rd| jdt| jd S d| j| jS )NzAttempts: {0}, Error:
{1} rq   zAttempts: {0}, Value: {1})ru   formatr   join	traceback	format_tbrv   rU   r   r   r   __repr__1  s
   zAttempt.__repr__N)F)r   r   r   __doc__rh   r   r   r   r   r   r   r}     s
    
r}   c                   @   s    e Zd ZdZdd Zdd ZdS )r   zU
    A RetryError encapsulates the last Attempt instance right before giving up.
    c                 C   s
   || _ d S r   )last_attempt)rU   r   r   r   r   rh   ?  r
   zRetryError.__init__c                 C   s   d | jS )NzRetryError[{0}])r   r   r   r   r   r   __str__B  s   zRetryError.__str__N)r   r   r   r   rh   r   r   r   r   r   r   :  s    r   )rn   r   r~   r|   r   r?   r   r!   objectr   r}   	Exceptionr   r   r   r   r   <module>   s    Y#