
    g                     z    d dl Z d dlZd dlZd dlmZ dZdZdZdZ	  G d d      Z	 G d	 d
e	      Z
 G d de	      Zy)    N)
exceptions   g      ?g?g       @c                   L    e Zd ZdZeeeefdZe	d        Z
e	d        Zd Zd Zy)_BaseExponentialBackoffa  An exponential backoff iterator base class.

    Args:
        total_attempts Optional[int]:
            The maximum amount of retries that should happen.
            The default value is 3 attempts.
        initial_wait_seconds Optional[int]:
            The amount of time to sleep in the first backoff. This parameter
            should be in seconds.
            The default value is 1 second.
        randomization_factor Optional[float]:
            The amount of jitter that should be in each backoff. For example,
            a value of 0.1 will introduce a jitter range of 10% to the
            current backoff period.
            The default value is 0.1.
        multiplier Optional[float]:
            The backoff multipler. This adjusts how much each backoff will
            increase. For example a value of 2.0 leads to a 200% backoff
            on each attempt. If the initial_wait is 1.0 it would look like
            this sequence [1.0, 2.0, 4.0, 8.0].
            The default value is 2.0.
    c                     |dk  rt        j                  d|       || _        || _        | j                  | _        || _        || _        d| _        y )N   z:total_attempts must be greater than or equal to 1 but was r   )r   InvalidValue_total_attempts_initial_wait_seconds_current_wait_in_seconds_randomization_factor_multiplier_backoff_count)selftotal_attemptsinitial_wait_secondsrandomization_factor
multipliers        }/var/www/html/FastMealFinder_FlaskServer-InitialRelease/venv/lib/python3.12/site-packages/google/auth/_exponential_backoff.py__init__z _BaseExponentialBackoff.__init__B   sb     A))L^L\]   .%9"(,(B(B%%9"%    c                     | j                   S )z7The total amount of backoff attempts that will be made.)r
   r   s    r   r   z&_BaseExponentialBackoff.total_attemptsW   s     ###r   c                     | j                   S )z;The current amount of backoff attempts that have been made.)r   r   s    r   backoff_countz%_BaseExponentialBackoff.backoff_count\   s     """r   c                 4    d| _         | j                  | _        y )Nr   )r   r   r   r   s    r   _resetz_BaseExponentialBackoff._reseta   s    (,(B(B%r   c                     | j                   | j                  z  }t        j                  | j                   |z
  | j                   |z         }|S N)r   r   randomuniform)r   jitter_variancejitters      r   _calculate_jitterz)_BaseExponentialBackoff._calculate_jittere   sI    77$:T:TT))O;))O;

 r   N)__name__
__module____qualname____doc___DEFAULT_RETRY_TOTAL_ATTEMPTS!_DEFAULT_INITIAL_INTERVAL_SECONDS_DEFAULT_RANDOMIZATION_FACTOR_DEFAULT_MULTIPLIERr   propertyr   r   r   r$    r   r   r   r   *   sM    2 5>:& * $ $ # #Cr   r   c                   .     e Zd ZdZ fdZd Zd Z xZS )ExponentialBackoffzvAn exponential backoff iterator. This can be used in a for loop to
    perform requests with exponential backoff.
    c                 ,    t        t        | 
  |i | y r   )superr0   r   r   argskwargs	__class__s      r   r   zExponentialBackoff.__init__t   s     $0$A&Ar   c                 &    | j                          | S r   r   r   s    r   __iter__zExponentialBackoff.__iter__w       r   c                 @   | j                   | j                  k\  rt        | xj                   dz  c_         | j                   dk  r| j                   S | j                         }t	        j
                  |       | xj                  | j                  z  c_        | j                   S Nr   )r   r
   StopIterationr$   timesleepr   r   r   r#   s     r   __next__zExponentialBackoff.__next__{   s    $"6"66q !#&&&'')

6%%)9)99%"""r   )r%   r&   r'   r(   r   r9   rA   __classcell__r6   s   @r   r0   r0   o   s    B#r   r0   c                   .     e Zd ZdZ fdZd Zd Z xZS )AsyncExponentialBackoffzAn async exponential backoff iterator. This can be used in a for loop to
    perform async requests with exponential backoff.
    c                 ,    t        t        | 
  |i | y r   )r2   rE   r   r3   s      r   r   z AsyncExponentialBackoff.__init__   s    %t5tFvFr   c                 &    | j                          | S r   r8   r   s    r   	__aiter__z!AsyncExponentialBackoff.__aiter__   r:   r   c                 \  K   | j                   | j                  k\  rt        | xj                   dz  c_         | j                   dk  r| j                   S | j                         }t	        j
                  |       d {    | xj                  | j                  z  c_        | j                   S 7 /wr<   )r   r
   StopAsyncIterationr$   asyncior?   r   r   r@   s     r   	__anext__z!AsyncExponentialBackoff.__anext__   s     $"6"66$$q !#&&&'')mmF###%%)9)99%""" 	$s   A8B,:B*;0B,)r%   r&   r'   r(   r   rH   rL   rB   rC   s   @r   rE   rE      s    G#r   rE   )rK   r    r>   google.authr   r)   r*   r+   r,   r   r0   rE   r.   r   r   <module>rN      s_       " !"  %( ! !$   B BJ#0 #8#5 #r   