
    &g                         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dS )    N)
exceptions   g      ?g?g       @c                   Z    e Zd ZdZeeeefdZe	d             Z
e	d             Zd Zd ZdS )_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| _        d S )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        R/var/www/api/venv/lib/python3.11/site-packages/google/auth/_exponential_backoff.py__init__z _BaseExponentialBackoff.__init__B   sj     A)]^]]    .%9"(,(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                 ,    d| _         | j        | _        d S )Nr   )r   r   r   r   s    r   _resetz_BaseExponentialBackoff._reseta   s    (,(B%%%r   c                 n    | 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   s@    7$: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   *   s         2 5>:&       * $ $ X$ # # X#C C 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                 H     t          t          |           j        |i | d S r   )superr0   r   r   argskwargs	__class__s      r   r   zExponentialBackoff.__init__t   s,    0 $''0$A&AAAAAr   c                 .    |                                   | 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 |                                 }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%%""r   )r%   r&   r'   r(   r   r9   rA   __classcell__r6   s   @r   r0   r0   o   se         B B B B 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                 H     t          t          |           j        |i | d S r   )r2   rE   r   r3   s      r   r   z AsyncExponentialBackoff.__init__   s,    5%t,,5tFvFFFFFr   c                 .    |                                   | 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 |                                 }t	          j        |           d {V  | xj        | j        z  c_        | j         S r<   )r   r
   StopAsyncIterationr$   asyncior?   r   r   r@   s     r   	__anext__z!AsyncExponentialBackoff.__anext__   s      $"666$$q !##&&''))mF#########%%)99%%""r   )r%   r&   r'   r(   r   rH   rL   rB   rC   s   @r   rE   rE      se         G G G G G  # # # # # # #r   rE   )rK   r    r>   google.authr   r)   r*   r+   r,   r   r0   rE   r.   r   r   <module>rN      s       " " " " " " !"  %( ! !$   B B B B B B B BJ# # # # #0 # # #8# # # # #5 # # # # #r   