a  ze#@sddlZddlZddlZddlmZejr6ddlmZGdddejZGdddeZ Gdd d e Z Gd d d eZ Gd d d eZ GdddeZ GdddeZGdddeZGdddeZdS)N)_utils)RetryCallStatec@sLeZdZdZejdedddZddddd Zde j d dd d Z d S) wait_basez(Abstract base class for wait strategies.r retry_statereturncCsdSNselfrr r [/opt/bitninja-python-dojo/embedded/lib/python3.9/site-packages/pip/_vendor/tenacity/wait.py__call__szwait_base.__call__ wait_combine)otherrcCs t||Sr)rr rr r r __add__"szwait_base.__add__)rrcCs|dkr |S||SNr)rrr r r __radd__%szwait_base.__radd__N) __name__ __module__ __qualname____doc__abcabstractmethodfloatr rtypingUnionrr r r r rs rc@s0eZdZdZeddddZdeddd ZdS) wait_fixedzCWait strategy that waits a fixed amount of time between each retry.N)waitrcCs ||_dSrr)r rr r r __init__/szwait_fixed.__init__rrcCs|jSrrr r r r r 2szwait_fixed.__call__)rrrrrr r r r r r r,srcs&eZdZdZddfdd ZZS) wait_nonez7Wait strategy that doesn't wait at all before retrying.N)rcstddSr)superr )r  __class__r r r 9szwait_none.__init__)rrrrr __classcell__r r r#r r!6sr!c@sHeZdZdZd ejeefejeefddddZded d d Z dS) wait_randomzAWait strategy that waits a random amount of time between min/max.rN)minmaxrcCs||_||_dSr)wait_random_minwait_random_max)r r(r)r r r r @szwait_random.__init__rrcCs|jt|j|jSr)r*randomr+r r r r r Dszwait_random.__call__)rr') rrrrrrintrr r r r r r r&=s(r&c@s0eZdZdZeddddZdeddd ZdS) rz#Combine several waiting strategies.N strategiesrcGs ||_dSr) wait_funcsr r/r r r r Kszwait_combine.__init__rrcstfdd|jDS)Nc3s|]}|dVqdS)rNr ).0xr2r r Oz(wait_combine.__call__..)sumr0r r r2r r Nszwait_combine.__call__rrrrrr rr r r r r rHsrc@s0eZdZdZeddddZdeddd ZdS) wait_chainaChain two or more waiting strategies. If all strategies are exhausted, the very last strategy is used thereafter. For example:: @retry(wait=wait_chain(*[wait_fixed(1) for i in range(3)] + [wait_fixed(2) for j in range(5)] + [wait_fixed(5) for k in range(4))) def wait_chained(): print("Wait 1s for 3 attempts, 2s for 5 attempts and 5s thereafter.") Nr.cGs ||_dSr)r/r1r r r r bszwait_chain.__init__rrcCs0tt|jdt|j}|j|d}||dS)Nr'r2)r(r)attempt_numberlenr/)r r wait_func_no wait_funcr r r r eszwait_chain.__call__r8r r r r r9Rsr9c@s\eZdZdZddejfejee fejee fejee fddddZ de d d d Z dS) wait_incrementingzWait an incremental amount of time after each attempt. Starting at a starting value and incrementing by a value for each attempt (and restricting the upper limit to some maximum value). rdN)start incrementr)rcCs||_||_||_dSr)r@rAr))r r@rAr)r r r r rszwait_incrementing.__init__rrcCs(|j|j|jd}tdt||jSNr'r)r@rAr:r)r()r rresultr r r r |szwait_incrementing.__call__ rrrrrMAX_WAITrrr-rr r r r r r r>ks    r>c@sjeZdZdZdejddfejee fejee fejee fejee fddddZ d e d d d Z dS) wait_exponentialaWait strategy that applies exponential backoff. It allows for a customized multiplier and an ability to restrict the upper and lower limits to some maximum and minimum value. The intervals are fixed (i.e. there is no jitter), so this strategy is suitable for balancing retries against latency when a required resource is unavailable for an unknown duration, but *not* suitable for resolving contention between multiple processes for a shared resource. Use wait_random_exponential for the latter case. r'rN) multiplierr)exp_baser(rcCs||_||_||_||_dSr)rHr(r)rI)r rHr)rIr(r r r r szwait_exponential.__init__rrcCsRz|j|jd}|j|}Wnty6|jYS0ttd|jt||jSrB)rIr:rH OverflowErrorr)r()r rexprCr r r r s   zwait_exponential.__call__rDr r r r rFs     rFcs(eZdZdZdedfdd ZZS)wait_random_exponentialaRandom wait with exponentially widening window. An exponential backoff strategy used to mediate contention between multiple uncoordinated processes for a shared resource in distributed systems. This is the sense in which "exponential backoff" is meant in e.g. Ethernet networking, and corresponds to the "Full Jitter" algorithm described in this blog post: https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/ Each retry occurs at a random time in a geometrically expanding interval. It allows for a custom multiplier and an ability to restrict the upper limit of the random interval to some maximum value. Example:: wait_random_exponential(multiplier=0.5, # initial window 0.5s max=60) # max 60s timeout When waiting for an unavailable resource to become available again, as opposed to trying to resolve contention for a shared resource, the wait_exponential strategy (which uses a fixed interval) may be preferable. rrcstj|d}td|S)Nr2r)r"r r,uniform)r rhighr#r r r sz wait_random_exponential.__call__)rrrrrr r%r r r#r rLsrL)rr,rpip._vendor.tenacityr TYPE_CHECKINGrABCrrr!r&rr9r>rFrLr r r r s     "