
    *n6hX                        d dl Z d dlZd dlZd dlmZ ej
                  rd dlmZ  G d de j                        Zej                  eej                  dgej                  eef   f   f   Z G d de      Z G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zy)    N)_utils)RetryCallStatec                   p    e Zd ZdZej
                  dddefd       ZddZdd de	j                  d   fd	Zy
)	wait_basez(Abstract base class for wait strategies.retry_stater   returnc                      y N selfr   s     j/var/www/django-portfolio.reubendavern.link/venv/lib/python3.12/site-packages/pip/_vendor/tenacity/wait.py__call__zwait_base.__call__   s        otherc                     t        | |      S r
   )wait_combiner   r   s     r   __add__zwait_base.__add__"   s    D%((r   )r   r   c                 2    |dk(  r| S | j                  |      S Nr   )r   r   s     r   __radd__zwait_base.__radd__%   s    A:K||E""r   N)r   r   r   r   )__name__
__module____qualname____doc__abcabstractmethodfloatr   r   typingUnionr   r   r   r   r   r      sN    2$4   )#k #fll;V.W #r   r   r   c                   D    e Zd ZdZdej
                  ddfdZdddefdZy)	
wait_fixedzCWait strategy that waits a fixed amount of time between each retry.waitr   Nc                 8    t        j                  |      | _        y r
   )r   
to_secondsr#   )r   r$   s     r   __init__zwait_fixed.__init__2   s     ++D1r   r   r   c                     | j                   S r
   )r#   r   s     r   r   zwait_fixed.__call__5   s    r   	r   r   r   r   r   time_unit_typer'   r   r   r   r   r   r#   r#   /   s2    M2V22 2t 2$4  r   r#   c                   $     e Zd ZdZd fdZ xZS )	wait_nonez7Wait strategy that doesn't wait at all before retrying.c                 $    t         |   d       y r   )superr'   )r   	__class__s    r   r'   zwait_none.__init__<   s    r   )r   N)r   r   r   r   r'   __classcell__r/   s   @r   r,   r,   9   s    A r   r,   c                   ^    e Zd ZdZd
dej
                  dej
                  ddfdZdddefd	Zy)wait_randomzAWait strategy that waits a random amount of time between min/max.minmaxr   Nc                 l    t        j                  |      | _        t        j                  |      | _        y r
   )r   r&   wait_random_minwait_random_max)r   r4   r5   s      r   r'   zwait_random.__init__C   s(    %005%005r   r   r   c                 x    | j                   t        j                         | j                  | j                   z
  z  z   S r
   )r7   randomr8   r   s     r   r   zwait_random.__call__G   s0    ##v}}$:N:NQUQeQe:e'fggr   )r      r)   r   r   r   r3   r3   @   sC    K6F11 6F<Q<Q 6Z^ 6h$4 h hr   r3   c                   0    e Zd ZdZdeddfdZdddefdZy)	r   z#Combine several waiting strategies.
strategiesr   Nc                     || _         y r
   )
wait_funcsr   r=   s     r   r'   zwait_combine.__init__N   	    $r   r   r   c                 @    t        fd| j                  D              S )Nc              3   0   K   | ]  } |         yw)r   Nr   ).0xr   s     r   	<genexpr>z(wait_combine.__call__.<locals>.<genexpr>R   s     G!1--Gs   )sumr?   r   s    `r   r   zwait_combine.__call__Q   s    GtGGGr   r   r   r   r   r   r'   r   r   r   r   r   r   r   K   s/    -%I %$ %H$4 H Hr   r   c                   0    e Zd ZdZdeddfdZdddefdZy)	
wait_chaina  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.")
    r=   r   Nc                     || _         y r
   )r=   r@   s     r   r'   zwait_chain.__init__e   rA   r   r   r   c                     t        t        |j                  d      t        | j                              }| j                  |dz
     } ||      S )Nr;   rD   )r4   r5   attempt_numberlenr=   )r   r   wait_func_no	wait_funcs       r   r   zwait_chain.__call__h   sB    3{991=s4???STOOL1$45	[11r   rI   r   r   r   rK   rK   U   s.    %I %$ %2$4 2 2r   rK   c            	           e Zd ZdZddej
                  fdej                  dej                  dej                  ddfd	Zd
ddefdZ	y)wait_incrementingzWait 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	incrementr5   r   Nc                     t        j                  |      | _        t        j                  |      | _        t        j                  |      | _        y r
   )r   r&   rU   rV   r5   )r   rU   rV   r5   s       r   r'   zwait_incrementing.__init__u   s:     &&u-
**95$$S)r   r   r   c                     | j                   | j                  |j                  dz
  z  z   }t        dt	        || j                              S Nr;   r   )rU   rV   rN   r5   r4   )r   r   results      r   r   zwait_incrementing.__call__   s<    t~~1K1Ka1OPQ1c&$((+,,r   )
r   r   r   r   r   MAX_WAITr*   r'   r   r   r   r   r   rS   rS   n   sg     ()+.%+__	*$$* ((* ""	*
 
*-$4 - -r   rS   c                       e Zd ZdZdej
                  ddfdej                  ee	f   dej                  dej                  ee	f   dej                  d	d
f
dZddd	e	fdZy
)wait_exponentiala  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.
    r;      r   
multiplierr5   exp_baser4   r   Nc                     || _         t        j                  |      | _        t        j                  |      | _        || _        y r
   )r_   r   r&   r4   r5   r`   )r   r_   r5   r`   r4   s        r   r'   zwait_exponential.__init__   s6     %$$S)$$S) r   r   r   c                     	 | j                   |j                  dz
  z  }| j                  |z  }t	        t	        d| j
                        t        || j                              S # t        $ r | j                  cY S w xY wrY   )r`   rN   r_   OverflowErrorr5   r4   )r   r   exprZ   s       r   r   zwait_exponential.__call__   sm    	--K$>$>$BCC__s*F 3q$((#S%:;;  	88O	s   +A! !A98A9)r   r   r   r   r   r[   r    r!   intr   r*   r'   r   r   r   r   r]   r]      s    
 01%+__-.%&
!LLe,
! ""
! ,,sEz*	
!
 ""
! 

!<$4 < <r   r]   c                   ,     e Zd ZdZdddef fdZ xZS )wait_random_exponentiala  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                 P    t         |   |      }t        j                  d|      S )NrD   r   )r.   r   r:   uniform)r   r   highr/   s      r   r   z wait_random_exponential.__call__   s&    wK8~~a&&r   )r   r   r   r   r   r   r0   r1   s   @r   rg   rg      s!    2'$4 ' ' 'r   rg   c                   Z    e Zd ZdZdej
                  ddfdededededd	f
d
ZdddefdZy	)wait_exponential_jittera`  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.
    r;   r^   initialr5   r`   jitterr   Nc                 <    || _         || _        || _        || _        y r
   )rm   r5   r`   rn   )r   rm   r5   r`   rn   s        r   r'   z wait_exponential_jitter.__init__   s       r   r   r   c                    t        j                  d| j                        }	 | j                  |j                  dz
  z  }| j
                  |z  |z   }t        dt        || j                              S # t        $ r | j                  }Y 7w xY w)Nr   r;   )	r:   ri   rn   r`   rN   rm   rc   r5   r4   )r   r   rn   rd   rZ   s        r   r   z wait_exponential_jitter.__call__   s{    4;;/	--K$>$>$BCC\\C'&0F 1c&$((+,,  	XXF	s   .A0 0BB)	r   r   r   r   r   r[   r   r'   r   r   r   r   rl   rl      sb    	 __

 
 	

 
 

-$4 - -r   rl   )r   r:   r    pip._vendor.tenacityr   TYPE_CHECKINGr   ABCr   r!   Callabler   re   	WaitBaseTr#   r,   r3   r   rK   rS   r]   rg   rl   r   r   r   <module>rv      s   "    '	3# #" LLFOO5E4FUZ\_U_H`4`$aab	 
 h) hH9 H2 22-	 -,<y <D'. '>-i -r   