
    gw                     Z    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y)	    N)	timedelta)_init_wait_gen_maybe_call
_next_waitc                 p     t        j                         r S t        j                          fd       }|S )Nc                     K    | i |S wN )argskwargscoro_or_funcs     C/var/www/openai/venv/lib/python3.12/site-packages/backoff/_async.pyfz_ensure_coroutine.<locals>.f   s     000s   	)asyncioiscoroutinefunction	functoolswraps)r   r   s   ` r   _ensure_coroutiner   
   s7    ""<0		&	1 
'	1    c                 >    | D cg c]  }t        |       c}S c c}w r	   )r   )coros_or_funcsr   s     r   _ensure_coroutinesr      s     *89.Qa .999s   c                p   K   |||||d}|j                  |       | D ]  } ||       d {     y 7 w)Ntargetr   r   trieselapsed)update)	handlersr   r   r   r   r   extradetailshandlers	            r   _call_handlersr#      sG     
 G NN5g s   *646c                2   	 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                  j                         }t              }	 |dz  }t	        j
                  t        j                  j                         |z
        }| |||d} | i | d {   }	 |	      rv||k(  }
|d uxr ||k\  }|
s|rt        fi |d|	i d {    	 |	S 	 t        ||	||      }t        fi ||	|d d {    t        j                  |       d {    t        fi |d|	i d {    	 |	S 7 7 k# t        $ r t        fi |d|	i d {  7   Y |	S w xY w7 j7 O7 8w)Nr      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   s     &i0$X.!!%%'h8QJE--h.?.?.C.C.E.MNG  "G ///C~&+&>"%34%? &?%,%> " &):(IgISIII6 
3(sFG)79G %Z 37 3#*13 3 3 mmG,,,$ZF7F#FFF
G 0 J % (IgISIII( 
-3 - Gs   BE$D13E$D3E$D5 E$3E4E$E E$)E"*E$3E$5EEEE$EE$ E$"E$)r   r   r   r   r   )r   r=   r<   r8   r7   r6   r;   r9   r:   r>   r?   s   `````````` r   retry_predicater@   (   s    
 $J/J#J/J"9-I **9555**6222&&v...__V7 7 7r Lr   c       	         "   	
 t              t              t        	      	t              t        j                        rJ t        j                        rJ t	        j
                         	
 fd       }|S )Nc                    K   t              }t              }d}t        j                  j                         }t              }	 |dz  }t	        j
                  t        j                  j                         |z
        }| |||d}	  | i | d {   }	t        fi | d {    |	S 7 7 # $ r}
 |
       d {  7  }||k(  }|d uxr ||k\  }|s|s|r!t        fi |d|
i d {  7   r Y d }
~
y 	 t        ||
||      }n(# t        $ r t        fi |d|
i d {  7   |
w xY wt        fi |||
d d {  7   t        j                  |       d {  7   Y d }
~
nd }
~
ww xY w9w)Nr   r&   r   	exception)r(   rC   r)   )r   r   r/   r0   r   r1   r(   r   r!   r2   egiveup_resultr3   r4   r5   rC   giveupr6   r7   r8   r9   r:   r;   raise_on_giveupr   r=   r>   s                  r   r?   zretry_exception.<locals>.retry   s     &i0$X.!!%%'h8QJE--h.?.?.C.C.E.MNG  "G%"D3F33D %Z;7;;;
I 4D <C  -&,Qi&+&>"%34%? &?%,%> " !$6:K(KgKKKK&(q&')79G$ (KgKKKKG %Z 27 2/02 2 2 mmG,,,?- s   BF 	B3 B/B3 F (B1)F /B3 1F 3E;8E6C.E62C53E6;F DE6D6-D0.D66E6EE6+E.,E61F 6E;;F )r   r   r   r   r   r   )r   r=   rC   r8   r7   r6   rF   r;   r9   r:   rG   r>   r?   s   ```````````` r   retry_exceptionrH   t   s    
 $J/J#J/J"9-Iv&F **9555**6222__V8 8 8r Lr   )r*   r   r   r   backoff._commonr   r   r   r   r   r#   r@   rH   r
   r   r   <module>rJ      s3        E E: IXHr   