U .e&@slddlZddlmZddlZddlZddlZdZddZGdddeZ Gdd d eZ Gd d d e Z dS) N)sixi?csBtdkr,tdr,dd}|dSfdd}|SdS)z Decorator function that instantiates the Retrying object @param *dargs: positional arguments passed to Retrying object @param **dkw: keyword arguments passed to the Retrying object rcstfdd}|S)Ncstjf||SNRetryingcallargskwf8/usr/lib/python3.8/site-packages/pip/_vendor/retrying.py wrapped_f$sz-retry..wrap_simple..wrapped_frwrapsr rr r r wrap_simple"szretry..wrap_simplecstfdd}|S)Ncstjf||Srrr)dargsdkwr r rr/sz&retry..wrap..wrapped_frrrrr rwrap-szretry..wrapN)lencallable)rrrrr rrretrys  rc@sneZdZdddZddZddZd d Zd d Zd dZddZ ddZ ddZ ddZ ddZ ddZdS)rNFcs |dkr dn||_|dkrdn||_|dkr0dn||_|dkrBdn||_|dkrTdn||_|dkrfdn||_| dkrxdn| |_| dkrdn| |_| dkrtn| |_ |dkrdn||_ g|dk r̈ |j |dk r |j |dk r||_n&|dkr fdd|_n t|||_ddg|dk r6 |j|dk sJ|dk rV |j|dk sj| dk rv |j| dk s| dk r |j|dk r||_n&|dkr‡fd d|_n t|||_| dkr|j|_n| |_| dkr|j|_n| |_||_dS) NdrrcstfddDS)Nc3s|]}|VqdSrr .0r ZattemptsZdelayr r as6Retrying.__init__....)anyr ) stop_funcsr raz#Retrying.__init__..c_sdS)Nrr )r kwargsr r rr%hr&cstfddDS)Nc3s|]}|VqdSrr rr r rr!ysr")maxr ) wait_funcsr rr%yr&)_stop_max_attempt_number_stop_max_delay _wait_fixed_wait_random_min_wait_random_max_wait_incrementing_start_wait_incrementing_increment_wait_exponential_multiplierMAX_WAIT_wait_exponential_max_wait_jitter_maxappendstop_after_attemptstop_after_delaystopgetattr fixed_sleep random_sleepincrementing_sleepexponential_sleepwait always_reject_retry_on_exception never_reject_retry_on_result_wrap_exception)selfr8r>Zstop_max_attempt_numberZstop_max_delayZ wait_fixedZwait_random_minZwait_random_maxZwait_incrementing_startZwait_incrementing_incrementZwait_exponential_multiplierZwait_exponential_maxZretry_on_exceptionZretry_on_resultwrap_exceptionZ stop_funcZ wait_funcZwait_jitter_maxr )r$r)r__init__:sR                 zRetrying.__init__cCs ||jkS)z;Stop after the previous attempt >= stop_max_attempt_number.)r*rDprevious_attempt_numberdelay_since_first_attempt_msr r rr6szRetrying.stop_after_attemptcCs ||jkS)z=Stop after the time from the first attempt >= stop_max_delay.)r+rGr r rr7szRetrying.stop_after_delaycCsdS)z#Don't sleep at all before retrying.rr rGr r rno_sleepszRetrying.no_sleepcCs|jS)z0Sleep a fixed amount of time between each retry.)r,rGr r rr:szRetrying.fixed_sleepcCst|j|jS)zISleep a random amount of time between wait_random_min and wait_random_max)randomZrandintr-r.rGr r rr;szRetrying.random_sleepcCs$|j|j|d}|dkr d}|S)z Sleep an incremental amount of time after each attempt, starting at wait_incrementing_start and incrementing by wait_incrementing_increment rr)r/r0)rDrHrIresultr r rr<szRetrying.incrementing_sleepcCs2d|}|j|}||jkr"|j}|dkr.d}|S)Nr)r1r3)rDrHrIZexprLr r rr=s  zRetrying.exponential_sleepcCsdS)NFr rDrLr r rrAszRetrying.never_rejectcCsdS)NTr rNr r rr?szRetrying.always_rejectcCs4d}|jr |||jdO}n|||jO}|S)NFr) has_exceptionr@valuerB)rDattemptZrejectr r r should_rejects zRetrying.should_rejectc Ostttd}d}zt||||d}Wn t}t||d}YnX||sf||jStttd|}| ||r|js|j r|qt |n<| ||} |j rt|j } | td| } t| d|d7}qdS)NrrFTrg@@)introundtimeAttemptsysexc_inforRgetrCr8rO RetryErrorr>r4rKr(sleep) rDfnr r'Z start_timeattempt_numberrQtbrIr[Zjitterr r rrs(       z Retrying.call)NNNNNNNNNNNNNFNNN)__name__ __module__ __qualname__rFr6r7rJr:r;r<r=rAr?rRrr r r rr8s: S   rc@s*eZdZdZddZd ddZddZd S) rVz An Attempt encapsulates a call to a target function that may end as a normal return value from the function or an Exception depending on what occurred during the execution. cCs||_||_||_dSr)rPr]rO)rDrPr]rOr r rrFszAttempt.__init__FcCs@|jr6|rt|qs *!