B 䊇c@s@dZddlZddlZddlmZGdddZGdddZdS)zEThis module implements token buckets used for client side throttling.N)CapacityNotAvailableErrorc@s$eZdZddZddZddZdS)ClockcCsdS)N)selfrrr/private/var/folders/8c/hx9_v10d5x38qmnzt13b7b8j1k3n5b/T/pip-target-x6xd5gna/lib/python/botocore/retries/bucket.py__init__ szClock.__init__cCst|dS)N)timesleep)ramountrrrr sz Clock.sleepcCstS)N)r)rrrr current_timeszClock.current_timeN)__name__ __module__ __qualname__rr r rrrrrsrc@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_raterrrrs zTokenBucket.__init__cCs|jS)N)r)rrrrr"szTokenBucket.max_ratec Cs\|jL|t||j|_|dkr.||_nd|_t|j|j|_|jWdQRXdS)N) r_refillmaxrrrminrnotify)rvaluerrrr&scCs|jS)N)r)rrrr max_capacity;szTokenBucket.max_capacitycCs|jS)N)r)rrrravailable_capacity?szTokenBucket.available_capacityrTc Cs |j|j||dSQRXdS)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.acquirecCsz|||jkr$|j|8_dS|s.t||}x*|dkrb|j||||}q:W|j|8_dSdS)NTr)rrr _sleep_amountrwait)rr r%Z sleep_amountrrrr&Ps    zTokenBucket._acquirecCs||j|jS)N)rr)rr rrrr(gszTokenBucket._sleep_amountcCsT|j}|jdkr||_dS|j}||j|j}t|j||}||_||_dS)N)rr rrrr r)r timestampZcurrent_capacityZ fill_amountZ new_capacityrrrrjs  zTokenBucket._refillN)rT)r r rZ _MIN_RATErpropertyrsetterr#r$r'r&r(rrrrrrs    r)__doc__rrZbotocore.exceptionsrrrrrrrs