Ë
    UV.j÷	  ã                  óD   — d Z ddlmZ ddlmZ ddlmZ dZ G d„ d«      Zy)	z.Token bucket implementation for rate limiting.é    )Úannotations)Údeque)Ú	monotonic)ÚTokenBucketc                  óL   — e Zd ZdZdZdZdZdd„Zd„ Zd„ Z	d„ Z
dd„Zdd	„Zd
„ Zy)r   aÀ  Token Bucket Algorithm.

    See Also
    --------
        https://en.wikipedia.org/wiki/Token_Bucket

        Most of this code was stolen from an entry in the ASPN Python Cookbook:
        https://code.activestate.com/recipes/511490/

    Warning:
    -------
        Thread Safety: This implementation is not thread safe.
        Access to a `TokenBucket` instance should occur within the critical
        section of any multithreaded code.
    Né   c                óŽ   — t        |«      | _        || _        t        |«      | _        t	        «       | _        t        «       | _        y ©N)ÚfloatÚcapacityÚ_tokensÚ	fill_rater   Ú	timestampr   Úcontents)Úselfr   r   s      úTC:\xampp\htdocs\tradingbinance\backend\.venv\Lib\site-packages\kombu/utils/limits.pyÚ__init__zTokenBucket.__init__%   s2   € Ü˜h›ˆŒØˆŒÜ˜yÓ)ˆŒÜ"›ˆŒÜ›ˆ�ó    c                ó:   — | j                   j                  |«       y r
   )r   Úappend)r   Úitems     r   ÚaddzTokenBucket.add,   s   € Ø�‰×Ñ˜TÕ"r   c                ó6   — | j                   j                  «       S r
   )r   Úpopleft©r   s    r   ÚpopzTokenBucket.pop/   s   € Ø�}‰}×$Ñ$Ó&Ð&r   c                ó8   — | j                   j                  «        y r
   )r   Úclearr   s    r   Úclear_pendingzTokenBucket.clear_pending2   s   € Ø�‰×ÑÕr   c                óV   — || j                  «       k  r| xj                  |z  c_        yy)aÕ  Check if one or more tokens can be consumed.

        Returns
        -------
            bool: true if the number of tokens can be consumed
                from the bucket.  If they can be consumed, a call will also
                consume the requested number of tokens from the bucket.
                Calls will only consume `tokens` (the number requested)
                or zero tokens -- it will never consume a partial number
                of tokens.
        TF)Ú_get_tokensr   )r   Útokenss     r   Úcan_consumezTokenBucket.can_consume5   s)   € ð �T×%Ñ%Ó'Ò'Ø�LŠL˜FÑ"�LØØr   c                ó^   — | j                  «       }t        ||«      }||z
  | j                  z  S )z~Return estimated time of token availability.

        Returns
        -------
            float: the time in seconds.
        )r!   Úmaxr   )r   r"   r   s      r   Úexpected_timezTokenBucket.expected_timeF   s2   € ð ×"Ñ"Ó$ˆÜ�V˜WÓ%ˆØ˜Ñ  D§N¡NÑ2Ð2r   c                óö   — | j                   | j                  k  rUt        «       }| j                  || j                  z
  z  }t        | j                  | j                   |z   «      | _         || _        | j                   S r
   )r   r   r   r   r   Úmin)r   ÚnowÚdeltas      r   r!   zTokenBucket._get_tokensQ   s\   € Ø�<‰<˜$Ÿ-™-Ò'Ü“+ˆCØ—N‘N c¨D¯N©NÑ&:Ñ;ˆEÜ˜tŸ}™}¨d¯l©l¸UÑ.BÓCˆDŒLØ ˆDŒNØ�|‰|Ðr   )r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r#   r&   r!   © r   r   r   r      s?   „ ñð" €Ið €Hð €Ió ò#ò'òóó"	3ór   r   N)	r.   Ú
__future__r   Úcollectionsr   Útimer   Ú__all__r   r/   r   r   Ú<module>r4      s"   ðÙ 4å "å Ý à
€÷Lò Lr   