o
    ~j6h                     @   sh   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 dZ	G d	d
 d
e	Z
G dd de	ZdS )    N)
exceptions   g      ?g?g       @c                   @   sJ   e Zd ZdZeeeefddZe	dd Z
e	dd Zdd	 Zd
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                 C   sB   |dk rt 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
multiplier r   o/var/www/html/chefvision.cloud.itp360.com/venv/lib/python3.10/site-packages/google/auth/_exponential_backoff.py__init__B   s   
z _BaseExponentialBackoff.__init__c                 C      | j S )z7The total amount of backoff attempts that will be made.)r   r   r   r   r   r   W      z&_BaseExponentialBackoff.total_attemptsc                 C   r   )z;The current amount of backoff attempts that have been made.)r   r   r   r   r   backoff_count\   r   z%_BaseExponentialBackoff.backoff_countc                 C   s   d| _ | j| _d S )Nr   )r   r   r	   r   r   r   r   _reseta   s   z_BaseExponentialBackoff._resetc                 C   s(   | j | j }t| j | | j | }|S N)r	   r
   randomuniform)r   jitter_variancejitterr   r   r   _calculate_jittere   s   z)_BaseExponentialBackoff._calculate_jitterN)__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   r   *   s    


r   c                       0   e Zd ZdZ fddZdd Zdd Z  ZS )ExponentialBackoffzvAn exponential backoff iterator. This can be used in a for loop to
    perform requests with exponential backoff.
    c                       t t| j|i | d S r   )superr*   r   r   argskwargs	__class__r   r   r   t      zExponentialBackoff.__init__c                 C      |    | S r   r   r   r   r   r   __iter__w      zExponentialBackoff.__iter__c                 C   sV   | j | jkrt|  j d7  _ | j dkr| j S |  }t| |  j| j9  _| j S Nr   )r   r   StopIterationr   timesleepr	   r   r   r   r   r   r   __next__{   s   

zExponentialBackoff.__next__)r    r!   r"   r#   r   r5   r<   __classcell__r   r   r0   r   r*   o   
    r*   c                       r)   )AsyncExponentialBackoffzAn async exponential backoff iterator. This can be used in a for loop to
    perform async requests with exponential backoff.
    c                    r+   r   )r,   r?   r   r-   r0   r   r   r      r2   z AsyncExponentialBackoff.__init__c                 C   r3   r   r4   r   r   r   r   	__aiter__   r6   z!AsyncExponentialBackoff.__aiter__c                    s^   | j | jkr	t|  j d7  _ | j dkr| j S |  }t|I d H  |  j| j9  _| j S r7   )r   r   StopAsyncIterationr   asyncior:   r	   r   r;   r   r   r   	__anext__   s   
z!AsyncExponentialBackoff.__anext__)r    r!   r"   r#   r   r@   rC   r=   r   r   r0   r   r?      r>   r?   )rB   r   r9   google.authr   r$   r%   r&   r'   r   r*   r?   r   r   r   r   <module>   s   E