
    XDiq                        S SK r S SKrS SKrS SKJr  \R
                  (       a  S SKJr   " S S\ R                  5      r\R                  \\R                  S/\R                  \\4   4   4   r " S S\5      r " S	 S
\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rg)    N)_utils)RetryCallStatec                   ~    \ rS rSrSr\R                  SSS\4S j5       rSS jr	SS S\
R                  S	   4S
 jrSrg)	wait_base   z(Abstract base class for wait strategies.retry_stater   returnc                     g N selfr   s     U/var/www/html/Aiprofessor/professorTrac/lib/python3.13/site-packages/tenacity/wait.py__call__wait_base.__call__   s        otherc                     [        X5      $ r   )wait_combiner   r   s     r   __add__wait_base.__add__"   s    D((r   )r   r   c                 4    US:X  a  U $ U R                  U5      $ Nr   )r   r   s     r   __radd__wait_base.__radd__%   s    A:K||E""r   r   N)r   r   r	   r   )__name__
__module____qualname____firstlineno____doc__abcabstractmethodfloatr   r   typingUnionr   __static_attributes__r   r   r   r   r      sN    2$4   )#k #fll;V.W #r   r   r   c                   P    \ rS rSrSrS\R                  SS4S jrSSS\4S	 jr	S
r
g)
wait_fixed1   zCWait strategy that waits a fixed amount of time between each retry.waitr	   Nc                 :    [         R                  " U5      U l        g r   )r   
to_secondsr)   )r   r+   s     r   __init__wait_fixed.__init__4   s     ++D1r   r   r   c                     U R                   $ r   r)   r   s     r   r   wait_fixed.__call__7   s    r   r1   r   r   r   r    r!   r   time_unit_typer.   r$   r   r'   r   r   r   r)   r)   1   s2    M2V22 2t 2$4  r   r)   c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )	wait_none;   z7Wait strategy that doesn't wait at all before retrying.c                 $   > [         TU ]  S5        g r   )superr.   )r   	__class__s    r   r.   wait_none.__init__>   s    r   r   )r	   N)r   r   r   r    r!   r.   r'   __classcell__r:   s   @r   r6   r6   ;   s    A r   r6   c                   n    \ rS rSrSr SS\R                  S\R                  SS4S jjrSS	S\4S
 jr	Sr
g)wait_randomB   zAWait strategy that waits a random amount of time between min/max.minmaxr	   Nc                 p    [         R                  " U5      U l        [         R                  " U5      U l        g r   )r   r-   wait_random_minwait_random_max)r   rA   rB   s      r   r.   wait_random.__init__E   s*      &005%005r   r   r   c                 z    U R                   [        R                  " 5       U R                  U R                   -
  -  -   $ r   )rD   randomrE   r   s     r   r   wait_random.__call__K   s4    ##MMOt33d6J6JJK
 	
r   )rE   rD   )r      r3   r   r   r   r?   r?   B   sI    K LM6((6393H3H6	6
$4 
 
r   r?   c                   <    \ rS rSrSrS\SS4S jrSSS\4S	 jrS
r	g)r   Q   z#Combine several waiting strategies.
strategiesr	   Nc                     Xl         g r   
wait_funcsr   rM   s     r   r.   wait_combine.__init__T       $r   r   r   c                 B   ^ [        U4S jU R                   5       5      $ )Nc              3   .   >#    U  H
  o" TS 9v   M     g7f)r   Nr   ).0xr   s     r   	<genexpr>(wait_combine.__call__.<locals>.<genexpr>X   s     G!1-s   )sumrP   r   s    `r   r   wait_combine.__call__W   s    GtGGGr   rO   
r   r   r   r    r!   r   r.   r$   r   r'   r   r   r   r   r   Q   s/    -%I %$ %H$4 H Hr   r   c                   <    \ rS rSrSrS\SS4S jrSSS\4S	 jrS
r	g)
wait_chain[   a  Chain two or more waiting strategies.

If all strategies are exhausted, the very last strategy is used
thereafter.

For example::

    @retry(wait=wait_chain(*[wait_fixed(1) for i in range(3)] +
                           [wait_fixed(2) for j in range(5)] +
                           [wait_fixed(5) for k in range(4)))
    def wait_chained():
        print("Wait 1s for 3 attempts, 2s for 5 attempts and 5s
               thereafter.")
rM   r	   Nc                     Xl         g r   rM   rQ   s     r   r.   wait_chain.__init__k   rS   r   r   r   c                     [        [        UR                  S5      [        U R                  5      5      nU R                  US-
     nU" US9$ )NrJ   rV   )rA   rB   attempt_numberlenrM   )r   r   wait_func_no	wait_funcs       r   r   wait_chain.__call__n   sB    3{991=s4???STOOL1$45	[11r   rb   r]   r   r   r   r_   r_   [   s.    %I %$ %2$4 2 2r   r_   c            	           \ rS rSrSrSS\R                  4S\R                  S\R                  S\R                  SS	4S
 jjrSSS\	4S jr
Srg	)wait_incrementingt   zWait an incremental amount of time after each attempt.

Starting at a starting value and incrementing by a value for each attempt
(and restricting the upper limit to some maximum value).
r   d   start	incrementrB   r	   Nc                     [         R                  " U5      U l        [         R                  " U5      U l        [         R                  " U5      U l        g r   )r   r-   rn   ro   rB   )r   rn   ro   rB   s       r   r.   wait_incrementing.__init__{   s:     &&u-
**95$$S)r   r   r   c                     U R                   U R                  UR                  S-
  -  -   n[        S[	        X R                  5      5      $ NrJ   r   )rn   ro   re   rB   rA   )r   r   results      r   r   wait_incrementing.__call__   s:    t~~1K1Ka1OPQ1c&((+,,r   )ro   rB   rn   )r   r   r   r    r!   r   MAX_WAITr4   r.   r$   r   r'   r   r   r   rk   rk   t   sg     ()+.%+__	*$$* ((* ""	*
 
*-$4 - -r   rk   c                       \ rS rSrSrS\R                  SS4S\R                  \	\
4   S\R                  S\R                  \	\
4   S	\R                  S
S4
S jjrSSS
\
4S jrSrg)wait_exponential   a  Wait strategy that applies exponential backoff.

It allows for a customized multiplier and an ability to restrict the
upper and lower limits to some maximum and minimum value.

The intervals are fixed (i.e. there is no jitter), so this strategy is
suitable for balancing retries against latency when a required resource is
unavailable for an unknown duration, but *not* suitable for resolving
contention between multiple processes for a shared resource. Use
wait_random_exponential for the latter case.
rJ      r   
multiplierrB   exp_baserA   r	   Nc                     Xl         [        R                  " U5      U l        [        R                  " U5      U l        X0l        g r   )r{   r   r-   rA   rB   r|   )r   r{   rB   r|   rA   s        r   r.   wait_exponential.__init__   s2     %$$S)$$S) r   r   r   c                      U R                   UR                  S-
  -  nU R                  U-  n[	        [	        SU R
                  5      [        X0R                  5      5      $ ! [         a    U R                  s $ f = frs   )r|   re   r{   OverflowErrorrB   rA   )r   r   exprt   s       r   r   wait_exponential.__call__   sk    	--K$>$>$BCC__s*F 3q$((#S%:;;  	88O	s   +A   A98A9)r|   rB   rA   r{   )r   r   r   r    r!   r   rv   r%   r&   intr$   r4   r.   r   r'   r   r   r   rx   rx      s    
 01%+__-.%&
!LLe,
! ""
! ,,sEz*	
!
 ""
! 

!<$4 < <r   rx   c                   8   ^  \ rS rSrSrSSS\4U 4S jjrSrU =r$ )wait_random_exponential   a  Random wait with exponentially widening window.

An exponential backoff strategy used to mediate contention between multiple
uncoordinated processes for a shared resource in distributed systems. This
is the sense in which "exponential backoff" is meant in e.g. Ethernet
networking, and corresponds to the "Full Jitter" algorithm described in
this blog post:

https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/

Each retry occurs at a random time in a geometrically expanding interval.
It allows for a custom multiplier and an ability to restrict the upper
limit of the random interval to some maximum value.

Example::

    wait_random_exponential(multiplier=0.5,  # initial window 0.5s
                            max=60)          # max 60s timeout

When waiting for an unavailable resource to become available again, as
opposed to trying to resolve contention for a shared resource, the
wait_exponential strategy (which uses a fixed interval) may be preferable.

r   r   r	   c                 `   > [         TU ]  US9n[        R                  " U R                  U5      $ )NrV   )r9   r   rH   uniformrA   )r   r   highr:   s      r   r    wait_random_exponential.__call__   s*    wK8~~dhh--r   r   )	r   r   r   r    r!   r$   r   r'   r<   r=   s   @r   r   r      s!    2.$4 . . .r   r   c                   h    \ rS rSrSrS\R                  SS4S\S\S\S\S	S
4
S jjrSSS	\4S jr	Sr
g
)wait_exponential_jitter   aH  Wait strategy that applies exponential backoff and jitter.

It allows for a customized initial wait, maximum wait and jitter.

This implements the strategy described here:
https://cloud.google.com/storage/docs/retry-strategy

The wait time is min(initial * 2**n + random.uniform(0, jitter), maximum)
where n is the retry count.
rJ   rz   initialrB   r|   jitterr	   Nc                 4    Xl         X l        X0l        X@l        g r   )r   rB   r|   r   )r   r   rB   r|   r   s        r   r.    wait_exponential_jitter.__init__   s      r   r   r   c                    [         R                  " SU R                  5      n U R                  UR                  S-
  -  nU R
                  U-  U-   n[        S[        X@R                  5      5      $ ! [         a    U R                  n N7f = f)Nr   rJ   )	rH   r   r   r|   re   r   r   rB   rA   )r   r   r   r   rt   s        r   r    wait_exponential_jitter.__call__   sy    4;;/	--K$>$>$BCC\\C'&0F 1c&((+,,  	XXF	s   .A0 0B	B	)r|   r   r   rB   )r   r   r   r    r!   r   rv   r$   r.   r   r'   r   r   r   r   r      sb    	 __

 
 	

 
 

-$4 - -r   r   )r"   rH   r%   tenacityr   TYPE_CHECKINGr   ABCr   r&   Callabler$   r   	WaitBaseTr)   r6   r?   r   r_   rk   rx   r   r   r   r   r   <module>r      s   "    	'# #" LLv 016<<s
3KKLL	
 
 
) 
H9 H2 22-	 -,<y <D.. .>-i -r   