
    cjh                        d Z ddlmZ ddlZddlZddlmZmZmZm	Z	m
Z
  e	deed   ed         ZdZ G d	 d
ee         Zy)ae  
The MIT License (MIT)

Copyright (c) 2015-2021 Rapptz
Copyright (c) 2021-present Pycord Development

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
    )annotationsN)CallableGenericLiteralTypeVaroverloadTTF)ExponentialBackoffc                  ^    e Zd ZdZd
ddddZedd       Zedd       Zedd       ZddZy	)r
   a3  An implementation of the exponential backoff algorithm

    Provides a convenient interface to implement an exponential backoff
    for reconnecting or retrying transmissions in a distributed network.

    Once instantiated, the delay method will return the next interval to
    wait for when retrying a connection or transmission.  The maximum
    delay increases exponentially with each retry up to a maximum of
    2^10 * base, and is reset if no more attempts are needed in a period
    of 2^11 * base seconds.

    Parameters
    ----------
    base: :class:`int`
        The base delay in seconds. The first retry-delay will be up to
        this many seconds.
    integral: :class:`bool`
        Set to ``True`` if whole periods of base is desirable, otherwise any
        number in between may be returned.
    F)integralc                  || _         d| _        d| _        |dz  | _        t	        j
                         | _        t        j                         }|j                          |r|j                  | _        y |j                  | _        y )Nr   
   i   )_base_exp_max_reset_timetime	monotonic_last_invocationrandomRandomseed	randrangeuniform	_randfunc)selfbaser   rands       B/var/www/html/venv/lib/python3.12/site-packages/discord/backoff.py__init__zExponentialBackoff.__init__;   sb    
		 $u'+~~'7 }}		GOT^^UYUaUa    c                     y N r   s    r   delayzExponentialBackoff.delayI   s    BEr!   c                     y r#   r$   r%   s    r   r&   zExponentialBackoff.delayL   s    ?Br!   c                     y r#   r$   r%   s    r   r&   zExponentialBackoff.delayO   s    >Ar!   c                *   t        j                         }|| j                  z
  }|| _        || j                  kD  rd| _        t        | j                  dz   | j                        | _        | j                  d| j                  d| j                  z  z        S )a  Compute the next delay

        Returns the next delay to wait according to the exponential
        backoff algorithm.  This is a value between 0 and base * 2^exp
        where exponent starts off at 1 and is incremented at every
        invocation of this method up to a maximum of 10.

        If a period of more than base * 2^11 has passed since the last
        retry, the exponent is reset to 1.
        r         )	r   r   r   r   r   minr   r   r   )r   
invocationintervals      r   r&   zExponentialBackoff.delayR   sy     ^^%
 5 55 *d&&&DI		Atyy1	~~aal!:;;r!   N)r*   )r   intr   r	   )r   z"ExponentialBackoff[Literal[False]]returnfloat)r   z!ExponentialBackoff[Literal[True]]r0   r/   )r   zExponentialBackoff[bool]r0   int | float)r0   r2   )__name__
__module____qualname____doc__r    r   r&   r$   r!   r   r
   r
   %   sF    *bu b E EB BA A<r!   r
   )r6   
__future__r   r   r   typingr   r   r   r   r   boolr	   __all__r
   r$   r!   r   <module>r;      sJ   2 #   @ @Cwt}gen5
!@< @<r!   