o ?c@s@dZddlZddlZddlmZGdddZGdddZdS)zEThis module implements token buckets used for client side throttling.N)CapacityNotAvailableErrorc@s$eZdZddZddZddZdS)ClockcCsdSNselfrrr/private/var/folders/cw/wlscbxl13mj6wd668h7l9g9sllkg5j/T/pip-target-b31awkwq/lib/python/botocore/retries/bucket.py__init__ szClock.__init__cCst|dSr)timesleepramountrrrr sz Clock.sleepcCstSr)r rrrr current_timeszClock.current_timeN)__name__ __module__ __qualname__r r rrrrrrs rc@speZdZdZefddZeddZejddZeddZed d Z dd dZ ddZ ddZ ddZ dS) TokenBucketg?cCsFd|_d|_d|_||_d|_||_t|_t |j|_ ||_ dS)Nr) _fill_rate _max_capacity_current_capacity_clock_last_timestamp _min_rate threadingLock_lock Condition_new_fill_rate_conditionmax_rate)rrclockZmin_raterrrr s  zTokenBucket.__init__cC|jSr)rrrrrr"zTokenBucket.max_ratecCsr|j,|t||j|_|dkr||_nd|_t|j|j|_|jWddS1s2wYdS)N) r_refillmaxrrrminrnotify)rvaluerrrr&s "cCr r)rrrrr max_capacity;r!zTokenBucket.max_capacitycCr r)rrrrravailable_capacity?r!zTokenBucket.available_capacityr"TcCs8|j|j||dWdS1swYdS)aJAcquire token or return amount of time until next token available. If block is True, then this method will block until there's sufficient capacity to acquire the desired amount. If block is False, then this method will return True is capacity was successfully acquired, False otherwise. )r blockN)r_acquire)rr r*rrracquireCs $zTokenBucket.acquirecCsx|||jkr|j|8_dS|st||}|dkr3|j||||}|dks |j|8_dS)NTr)r#rr _sleep_amountrwait)rr r*Z sleep_amountrrrr+Ps     zTokenBucket._acquirecCs||j|jSr)rrr rrrr-gszTokenBucket._sleep_amountcCsT|j}|jdur||_dS|j}||j|j}t|j||}||_||_dSr)rrrrrr%r)r timestampZcurrent_capacityZ fill_amountZ new_capacityrrrr#js   zTokenBucket._refillN)r"T)rrrZ _MIN_RATEr propertyrsetterr(r)r,r+r-r#rrrrrs        r)__doc__rr Zbotocore.exceptionsrrrrrrrs