
    Ngw                     \    d dl Z d dlZd dlZd dl mZ d dlmZmZmZ d Zd Z	d Z
d Zd ZdS )	    N)	timedelta)_init_wait_gen_maybe_call
_next_waitc                 r     t          j                   r S t          j                    fd            }|S )Nc                     K    | i |S )N )argskwargscoro_or_funcs     J/var/www/html/ai-engine/env/lib/python3.11/site-packages/backoff/_async.pyfz_ensure_coroutine.<locals>.f   s      <0000    )asyncioiscoroutinefunction	functoolswraps)r   r   s   ` r   _ensure_coroutiner   
   sO    "<00 		&	&	1 	1 	1 	1 
'	&	1r   c                     d | D             S )Nc                 ,    g | ]}t          |          S r	   )r   ).0r   s     r   
<listcomp>z&_ensure_coroutines.<locals>.<listcomp>   s!    999Qa  999r   r	   )coros_or_funcss    r   _ensure_coroutinesr      s    99.9999r   c                p   K   |||||d}|                     |           | D ]} ||           d {V  d S )Ntargetr
   r   trieselapsed)update)	handlersr   r
   r   r   r   extradetailshandlers	            r   _call_handlersr%      su      
  G NN5  gg r   c                H   	 t                    t                    t                    t          j                  rJ t          j                  rJ t          j                   sJ t          j                    	f
d            }
|
S )Nc                    
K   t                    }t                    }d}t          j                                        }t                    }	 |dz  }t	          j        t          j                                        |z
            }| |||d} | i | d {V }	 |	          r||k    }
|d uo||k    }|
s|rt          fi |d|	i d {V  n	 t          ||	||          }n'# t          $ r t          fi |d|	i d {V  Y nOw xY wt          fi ||	|d d {V  t          j
        |           d {V  t          fi |d|	i d {V  	 |	S )Nr   T   r   value)r)   waitr   datetimenowr   r   total_secondsr%   r   StopIterationr   sleep)r
   r   max_tries_valuemax_time_valuer   startr*   r   r#   retmax_tries_exceededmax_time_exceededsecondsjittermax_time	max_tries
on_backoff	on_giveup
on_success	predicater   wait_genwait_gen_kwargss                r   retryzretry_predicate.<locals>.retry7   sg      &i00$X..!%%''h88,	QJE-h.?.C.C.E.E.MNNG  " G /////////Cy~~  &+&>"%34%? &?%,%> " & ): (IIgIISIIIIIIIIII(sFG)79 9GG$   (IIgIISIIIIIIIIIIE %Z 3 37 3#*13 3 3 3 3 3 3 3 3 3 3 mG,,,,,,,,,$ZFF7FF#FFFFFFFFFF
s   C- -!DD)r   r   r   r   r   )r   r?   r>   r:   r9   r8   r=   r;   r<   r@   rA   s   `````````` r   retry_predicaterB   (   s    
 $J//J#J//J"9--I *955555*622222&v....._V7 7 7 7 7 7 7 7 7 7 7 7 7 7r Lr   c       	         B   	
 t                    t                    t          	          	t                    t          j                  rJ t          j                  rJ t	          j                   	
 fd            }|S )Nc                     K   t                    }t                    }d}t          j                                        }t                    }	 |dz  }t	          j        t          j                                        |z
            }| |||d}	  | i | d {V }	t          fi | d {V  |	S # $ r}
 |
           d {V }||k    }|d uo||k    }|s|s|r t          fi |d|
i d {V  r Y d }
~
d S 	 t          ||
||          }n'# t          $ r t          fi |d|
i d {V  |
w xY wt          fi |||
d d {V  t          j
        |           d {V  Y d }
~
nd }
~
ww xY w-)Nr   Tr(   r   	exception)r*   rE   r+   )r
   r   r1   r2   r   r3   r*   r   r#   r4   egiveup_resultr5   r6   r7   rE   giveupr8   r9   r:   r;   r<   r=   raise_on_giveupr   r?   r@   s                  r   rA   zretry_exception.<locals>.retry   s      &i00$X..!%%''h880	QJE-h.?.C.C.E.E.MNNG  " G%"FD3F33333333D %Z;;7;;;;;;;;;
G  - - -&,fQii&+&>"%34%? &?%,%> " !  $6  :K  (KKgKKKKKKKKKKKK& 44444(q&')79 9GG$   (KKgKKKKKKKKKKKKG %Z 2 27 2/02 2 2 2 2 2 2 2 2 2 2 mG,,,,,,,,,,,,,,?-0	s1   B7 7E;<AE6DE6$D<<5E66E;)r   r   r   r   r   r   )r   r?   rE   r:   r9   r8   rH   r=   r;   r<   rI   r@   rA   s   ```````````` r   retry_exceptionrJ   t   s    
 $J//J#J//J"9--Iv&&F *955555*622222_V8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8r Lr   )r,   r   r   r   backoff._commonr   r   r   r   r   r%   rB   rJ   r	   r   r   <module>rL      s                E E E E E E E E E E  : : :   I I IXH H H H Hr   