U
    N8c                     @   s   d Z ddlZG dd dZdS )zRetry quota implementation.


    Nc                   @   s:   e Zd ZdZedfddZdd Zdd Zed	d
 ZdS )
RetryQuotai  Nc                 C   s&   || _ || _|d krt }|| _d S N)_max_capacity_available_capacity	threadingLock_lock)selfZinitial_capacitylock r   :/tmp/pip-unpacked-wheel-ozje0y8b/botocore/retries/quota.py__init__   s
    zRetryQuota.__init__c              	   C   sF   | j 6 || jkr W 5 Q R  dS |  j|8  _W 5 Q R  dS Q R X dS )zAttempt to aquire a certain amount of capacity.

        If there's not sufficient amount of capacity available, ``False``
        is returned.  Otherwise, ``True`` is returned, which indicates that
        capacity was successfully allocated.

        FTN)r   r   )r	   capacity_amountr   r   r   acquire   s
    

zRetryQuota.acquirec              	   C   sF   | j | jkrdS | j& t| j | j |}|  j|7  _W 5 Q R X dS )zRelease capacity back to the retry quota.

        The capacity being released will be truncated if necessary
        to ensure the max capacity is never exceeded.

        N)r   r   r   min)r	   r   amountr   r   r   release"   s    
 zRetryQuota.releasec                 C   s   | j S r   )r   )r	   r   r   r   available_capacity6   s    zRetryQuota.available_capacity)	__name__
__module____qualname__ZINITIAL_CAPACITYr   r   r   propertyr   r   r   r   r   r      s   r   )__doc__r   r   r   r   r   r   <module>   s   