o .&a@sDdZddlZddlZddlmZGdddeZGdddeZdS)zEThis module implements token buckets used for client side throttling.N)CapacityNotAvailableErrorc@s$eZdZddZddZddZdS)ClockcCsdSNselfrr9/usr/lib/python3/dist-packages/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)rrclockmin_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+rrracquireDs $zTokenBucket.acquirecCsx|||jkr|j|8_dS|st||}|dkr3|j||||}|dks |j|8_dS)NTr)r$rr _sleep_amountrwait)rr r+ sleep_amountrrrr,Qs     zTokenBucket._acquirecCs||j|jSr)rrr rrrr.hszTokenBucket._sleep_amountcCsT|j}|jdur||_dS|j}||j|j}t|j||}||_||_dSr)rrrrrr&r)r timestampcurrent_capacity fill_amount new_capacityrrrr$ks   zTokenBucket._refillN)r#T)rrr _MIN_RATEr propertyrsetterr)r*r-r,r.r$rrrrrs        r)__doc__r rbotocore.exceptionsrobjectrrrrrrs