>ac@s^dZddlZddlZddlmZdefdYZdefdYZdS(sEThis module implements token buckets used for client side throttling.iN(tCapacityNotAvailableErrortClockcBs#eZdZdZdZRS(cCsdS(N((tself((s8/usr/lib/fence-agents/bundled/botocore/retries/bucket.pyt__init__ scCstj|dS(N(ttimetsleep(Rtamount((s8/usr/lib/fence-agents/bundled/botocore/retries/bucket.pyR scCs tjS(N(R(R((s8/usr/lib/fence-agents/bundled/botocore/retries/bucket.pyt current_times(t__name__t __module__RRR(((s8/usr/lib/fence-agents/bundled/botocore/retries/bucket.pyRs  t TokenBucketcBseZdZedZedZejdZedZedZde dZ dZ d Z d Z RS( g?cCsgd|_d|_d|_||_d|_||_tj|_ tj |j |_ ||_ dS(Ni( tNonet _fill_ratet _max_capacityt_current_capacityt_clockt_last_timestampt _min_ratet threadingtLockt_lockt Conditiont_new_fill_rate_conditiontmax_rate(RRtclocktmin_rate((s8/usr/lib/fence-agents/bundled/botocore/retries/bucket.pyRs      cCs|jS(N(R (R((s8/usr/lib/fence-agents/bundled/botocore/retries/bucket.pyR"scCsy|jj|jt||j|_|dkrA||_n d|_t|j|j|_|jjWdQXdS(Ni( Rt_refilltmaxRR R tminRtnotify(Rtvalue((s8/usr/lib/fence-agents/bundled/botocore/retries/bucket.pyR&s     cCs|jS(N(R (R((s8/usr/lib/fence-agents/bundled/botocore/retries/bucket.pyt max_capacity<scCs|jS(N(R(R((s8/usr/lib/fence-agents/bundled/botocore/retries/bucket.pytavailable_capacity@sic Cs*|j|jd|d|SWdQXdS(sJAcquire 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. RtblockN(Rt_acquire(RRR!((s8/usr/lib/fence-agents/bundled/botocore/retries/bucket.pytacquireDs cCs|j||jkr,|j|8_tS|s>tn|j|}x9|dkr|jj||j|j|}qPW|j|8_tSdS(Ni(RRtTrueRt _sleep_amountRtwait(RRR!t sleep_amount((s8/usr/lib/fence-agents/bundled/botocore/retries/bucket.pyR"Qs   cCs||j|jS(N(RR (RR((s8/usr/lib/fence-agents/bundled/botocore/retries/bucket.pyR%hscCst|jj}|jdkr+||_dS|j}||j|j}t|j||}||_||_dS(N(RRRR RR RR (Rt timestamptcurrent_capacityt fill_amountt new_capacity((s8/usr/lib/fence-agents/bundled/botocore/retries/bucket.pyRks   (RR t _MIN_RATERtpropertyRtsetterRR R$R#R"R%R(((s8/usr/lib/fence-agents/bundled/botocore/retries/bucket.pyR s   (t__doc__RRtbotocore.exceptionsRtobjectRR (((s8/usr/lib/fence-agents/bundled/botocore/retries/bucket.pyts