o
    wi/                     @   s   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Zdd Zdd Z	da
dadd	d
ZG dd deZG dd deZG dd deZdS )    Nwrapsi?c                    s    fdd}|S )Nc                    s
   t |  S N)
isinstance)	exceptionretryable_types E/home/ubuntu/sommelier/.venv/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_fr   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   5   s   "z&retry.<locals>.wrap.<locals>.wrapped_fr   r   r   r   r   r
   wrap4   s   zretry.<locals>.wrap)lencallable)r   r   r   r   r	   r   r
   retry    s
   r    Fc                 C   sF   | dv r!t d u rtta | d u rtsdat t  dt _t S | S )N)TNTF)_default_loggerlogging	getLogger__name___configured_null_logger
addHandlerNullHandler	propagate)loggerr	   r	   r
   _pick_logger@   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                    s6  |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|| _|| _|| _t|| _g  |d urz | 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tfrt|}|| _|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>)anyr2   )
stop_funcsr2   r
   <lambda>       z#Retrying.__init__.<locals>.<lambda>c                  _      dS )Nr   r	   )r   kwargsr	   r	   r
   r:      s    c                    r.   )Nc                 3   r/   r   r	   r0   r2   r	   r
   r5      r6   r7   )maxr2   )
wait_funcsr2   r
   r:      r;   )#_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_attemptsr*   _loggerappendstop_after_attemptstop_after_delaystopgetattrfixed_sleeprandom_sleepincrementing_sleepexponential_sleepwaitalways_reject_retry_on_exceptionr   tuple	Exceptionr   never_reject_retry_on_result_wrap_exception)selfrR   rX   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)   r	   )r9   r?   r
   __init__S   sl   





zRetrying.__init__c                 C   s
   || j kS )z;Stop after the previous attempt >= stop_max_attempt_number.)r@   r`   previous_attempt_numberdelay_since_first_attempt_msr	   r	   r
   rP         
zRetrying.stop_after_attemptc                 C   s
   || j kS )z=Stop after the time from the first attempt >= stop_max_delay.)rA   rt   r	   r	   r
   rQ      rw   zRetrying.stop_after_delayc                 C   r<   )z#Don't sleep at all before retrying.r   r	   )ru   rv   r	   r	   r
   no_sleep   s   zRetrying.no_sleepc                 C   s   | j S )z0Sleep a fixed amount of time between each retry.)rB   rt   r	   r	   r
   rT      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randintrC   rD   rt   r	   r	   r
   rU      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   )rE   rF   rJ   )r`   ru   rv   resultr	   r	   r
   rV      s   
zRetrying.incrementing_sleepc                 C   s2   d| }| j | }|| jkr| j}|dk rd}|S )N   r   )rG   rI   )r`   ru   rv   expr{   r	   r	   r
   rW      s   

zRetrying.exponential_sleepc                 C   r<   )NFr	   r{   r	   r	   r
   r]         zRetrying.never_rejectc                 C   r<   )NTr	   r~   r	   r	   r
   rY      r   zRetrying.always_rejectc                 C   s6   d}|j r|| |jd O }|S || |jO }|S )NFr   )has_exceptionrZ   valuer^   )r`   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y5   t }t||d}Y nw | |sA|	| j
S | j| | jrO| | t tt d | }| ||ro| j
sk|jrk|	 t|| ||}	| jrt | j }
|	td|
 }	| jd|	d dd	 t|	d  |d7 }q)
Nr-   r   TFr   zRetrying in g     @@z.2fz	 seconds.)introundtimerL   Attemptr\   sysexc_infor   getr_   rN   warningrM   rR   r   
RetryErrorrX   rK   ry   r>   infosleep)r`   fnr   r=   
start_timeattempt_numberr   tbrv   r   jitterr	   r	   r
   r   	  s:   


zRetrying.call)NNNNNNNNNNNNNNFNNNNNN)r$   
__module____qualname__rs   rP   rQ   staticmethodrx   rT   rU   rV   rW   r]   rY   r   r   r	   r	   r	   r
   r   R   sJ    
y
	

	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   )r   r   r   )r`   r   r   r   r	   r	   r
   rs   6  s   
zAttempt.__init__Fc                 C   s.   | j r|r	t| | j\}}}||| 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   r   with_traceback)r`   rm   exc_typeexcr   r	   r	   r
   r   ;  s   
zAttempt.getc              	   C   s>   | j rd| j ddt| jd  S d| j d| j S )Nz
Attempts: z	, Error:
 r|   z	, Value: )r   r   join	traceback	format_tbr   r`   r	   r	   r
   __repr__J  s   $zAttempt.__repr__N)F)r$   r   r   __doc__rs   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)r`   r   r	   r	   r
   rs   V  r   zRetryError.__init__c                 C   s   d| j  dS )NzRetryError[]r   r   r	   r	   r
   __str__Y  s   zRetryError.__str__N)r$   r   r   r   rs   r   r	   r	   r	   r
   r   Q  s    r   r   )r"   ry   r   r   r   	functoolsr   rH   r   r    r!   r%   r*   objectr   r   r\   r   r	   r	   r	   r
   <module>   s    
 ^"