o
    ýÞhü  ã                   @   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   ú`/var/www/html/premium_crap/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)   )ÚAsyncExponentialBackoffz‚An 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