Yohohohohohooho | Sanrei Aya
Sanrei Aya


Server : LiteSpeed
System : Linux barito.iixcp.rumahweb.net 5.14.0-611.49.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Apr 21 16:39:08 EDT 2026 x86_64
User : elvh3918 ( 1528)
PHP Version : 8.2.31
Disable Function : mail
Directory :  /usr/local/lib/python3.9/site-packages/kombu/utils/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/local/lib/python3.9/site-packages/kombu/utils/__pycache__/limits.cpython-39.pyc
a

��Sh�	�@s>dZddlmZddlmZddlmZdZGdd�d�ZdS)	z.Token bucket implementation for rate limiting.�)�annotations)�deque)�	monotonic)�TokenBucketc@sZeZdZdZdZdZdZddd�Zdd�Zdd	�Z	d
d�Z
ddd
�Zddd�Zdd�Z
dS)ra�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�cCs.t|�|_||_t|�|_t�|_t�|_dS�N)�float�capacity�_tokens�	fill_rater�	timestampr�contents)�selfrr	�r�</usr/local/lib/python3.9/site-packages/kombu/utils/limits.py�__init__%s


zTokenBucket.__init__cCs|j�|�dSr)r
�append)r�itemrrr�add,szTokenBucket.addcCs
|j��Sr)r
�popleft�rrrr�pop/szTokenBucket.popcCs|j��dSr)r
�clearrrrr�
clear_pending2szTokenBucket.clear_pendingcCs"||��kr|j|8_dSdS)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�tokensrrr�can_consume5szTokenBucket.can_consumecCs |��}t||�}|||jS)z~Return estimated time of token availability.

        Returns
        -------
            float: the time in seconds.
        )r�maxr)rrr
rrr�
expected_timeFs
zTokenBucket.expected_timecCsB|j|jkr<t�}|j||j}t|j|j|�|_||_|jSr)r
r	rrr�min)r�now�deltarrrrQszTokenBucket._get_tokens)r)r)r)�__name__�
__module__�__qualname__�__doc__rr	rrrrrrrrrrrrrs


rN)	r%�
__future__r�collectionsr�timer�__all__rrrrr�<module>s


Yohohohohohooho | Sanrei Aya