var/opt/nydus/ops/primordial/__pycache__/utils.cpython-38.pyc000064400000012132147205545130020250 0ustar00U af' @sNddlZddlmZmZddlmZddlmZmZm Z m Z m Z m Z m Z dZeeZGdddeZe ee edd d Zeeefe eeeefd d d Zeeefe eeeefd ddZdedeeedddZdddeeedddZefedddfe e edfeee e egefe e egefdddZdS)N)partialupdate_wrapper)sleep)AnyDictIterableOptionalTupleTypeCallablec@seZdZdZdS)RetriesExhaustedErrorz9A special type which signals the failure of a retry loop.N)__name__ __module__ __qualname____doc__rrA/opt/nydus/tmp/pip-target-53d1vnqk/lib/python/primordial/utils.pyr sr )hostnamereturncCsF|dkr dS|dr&|dd}|dD]}|r0|Sq0|S)zAbbreviate hostname for use on a Windows machine. :param hostname: the hostname :returns: the first non-empty domain in the hostname, excluding "www." Nzwww..)lower startswithsplit)rdomainrrrabbreviate_hostname_for_windowss  r)dict_keysrcsfdd|DS)a Filter a dictionary to contain only a certain set of keys. :param dict_: The original dictionary to be filtered. :param keys: A list, or other iterable, containing the desired dictionary keys. :returns: A dictionary containing only the desired keys. csi|]\}}|kr||qSrr.0kvrrr +szsubdict..itemsrrrr#rsubdict$sr(csfdd|DS)zFilter a dictionary to omit a set of keys. :param dict_: The original dictionary to be filtered. :param keys: An iterable containing the keys to omit. :returns: A dictionary with the desired keys omitted. csi|]\}}|kr||qSrrrr#rrr$5sz subdict_omit..r%r'rr#r subdict_omit.sr)) curr_attempt max_attempts)r*r+rcOs||kSNr)r*r+_args_kwargsrrr _should_retry8sr/)r* sleep_secs)r*r1rcOs|Sr,r)r*r1r-r.rrr _retry_after=sr2.) on_ex_classesr+r1 should_retry retry_aftercs4ptt|dptt|dfdd}|S)aDecorator that adds retry on error functionality to a function. Currently the retry strategy is 'linear' on errors. i.e. this function waits a set period of time before retrying the failed function again. :param on_ex_classes: A tuple of exceptions to retry on. By default, its all exceptions that derive from the 'Exception' class. :param max_attempts: Limit to how many times we'll retry :param sleep_secs: How long to wait between retries. :param should_retry: A predicate which when called will return a boolean saying whether the call should be retried or not. This parameter overrides the max_attempts parameter and gives more control to dynamically choose on if we need to continue retrying a call. :param retry_after: A callable that returns how long to wait between retries. This parameter overrides the sleep_secs parameter and gives more control to dynamically choose the wait time. :returns: This returns a decorator function that actually provides the retry functionality. )r+)r1cs.tddDfdd}t|S)Ncss|]}t|tr|VqdSr,) issubclass Exception)r Zex_clsrrr [s z.retry_this..wrapper..c sd}z ||WSk r}zx|d7}tdt|j|d|i|sfdj}t|||d|i|}td|jt|t|W5d}~XYqXqdS)Nrr0z)Exception (%s) occured while executing %sr*zMax attempts exhausted for {}z:Sleeping %s secs before retrying %s, due to exception (%s))LOGGERerrorstrrformatr debugr)Zpargskwargsr*emsgZs_secs) ex_classesfr5r4rrnew_func]s"   z-retry_this..wrapper..new_func)tupler)rBrCr3r5r4)rArBrwrapperZszretry_this..wrapper)rr/r2)r3r+r1r4r5rFrrEr retry_thisAsrG)logging functoolsrrtimertypingrrrrr r r Z MAX_RETRIES getLoggerrr9r7r r;rr(r)intboolr/r2rGrrrrs6 $ & &