U
    #FZh                     @   sf   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   ZInvalidValue_total_attempts_initial_wait_seconds_current_wait_in_seconds_randomization_factor_multiplier_backoff_count)selftotal_attemptsZinitial_wait_secondsZrandomization_factorZ
multiplier r   g/home/aprabhat/apps/x.techxrdev.in/venv/lib/python3.8/site-packages/google/auth/_exponential_backoff.py__init__B   s    z _BaseExponentialBackoff.__init__c                 C   s   | j S )z7The total amount of backoff attempts that will be made.)r   r   r   r   r   r   W   s    z&_BaseExponentialBackoff.total_attemptsc                 C   s   | j S )z;The current amount of backoff attempts that have been made.)r   r   r   r   r   backoff_count\   s    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   Z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                       s0   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                    s   t t| j|| d S r   )superr"   r   r   argskwargs	__class__r   r   r   t   s    zExponentialBackoff.__init__c                 C   s   |    | S r   r   r   r   r   r   __iter__w   s    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   r*   r0   __classcell__r   r   r'   r   r"   o   s   r"   c                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )AsyncExponentialBackoffzAn async exponential backoff iterator. This can be used in a for loop to
    perform async requests with exponential backoff.
    c                    s   t t| j|| d S r   )r#   r2   r   r$   r'   r   r   r      s    z AsyncExponentialBackoff.__init__c                 C   s   |    | S r   r)   r   r   r   r   	__aiter__   s    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 r+   )r   r   StopAsyncIterationr   asyncior.   r   r
   r/   r   r   r   	__anext__   s    
z!AsyncExponentialBackoff.__anext__)r   r   r   r   r   r3   r6   r1   r   r   r'   r   r2      s   r2   )r5   r   r-   Zgoogle.authr   r   r   r   r    r   r"   r2   r   r   r   r   <module>   s   
E