HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.60.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 5 05:00:59 EST 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //var/opt/nydus/ops/primordial/__pycache__/utils.cpython-39.pyc
a

�,�h'�	@sNddlZddlmZmZddlmZddlmZmZm	Z	m
Z
mZmZm
Z
dZe�e�ZGdd�de�Ze
ee
ed�d	d
�Zeeefe	eeeefd�dd
�Zeeefe	eeeefd�dd�Zded�eeed�dd�Zddd�eeed�dd�Zefedddfeeedfeee
e
egefe
e
egefd�dd�ZdS)�N)�partial�update_wrapper)�sleep)�Any�Dict�Iterable�Optional�Tuple�Type�Callable�c@seZdZdZdS)�RetriesExhaustedErrorz9A special type which signals the failure of a retry loop.N)�__name__�
__module__�__qualname__�__doc__�rr�A/opt/nydus/tmp/pip-target-wkfpz8uv/lib/python/primordial/utils.pyr

sr
)�hostname�returncCsF|durdS|���d�r&|dd�}|�d�D]}|r0|Sq0|S)z�Abbreviate hostname for use on a Windows machine.

    :param hostname: the hostname
    :returns: the first non-empty domain in the hostname, excluding "www."
    Nzwww.��.)�lower�
startswith�split)r�domainrrr�abbreviate_hostname_for_windowss
r)�dict_�keysrcs�fdd�|��D�S)aFilter 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|]\}}|�vr||�qSrr��.0�k�v�rrr�
<dictcomp>+�zsubdict.<locals>.<dictcomp>��items�rrrr#r�subdict$sr)cs�fdd�|��D�S)z�Filter 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|]\}}|�vr||�qSrrrr#rrr$5r%z subdict_omit.<locals>.<dictcomp>r&r(rr#r�subdict_omit.sr*)�curr_attempt�max_attempts)r+r,rcOs||kS�Nr)r+r,�_args�_kwargsrrr�
_should_retry8sr0�)r+�
sleep_secs)r+r2rcOs|Sr-r)r+r2r.r/rrr�_retry_after=sr3.)�
on_ex_classesr,r2�should_retry�retry_aftercs4�ptt|d���ptt|d�����fdd�}|S)a�Decorator 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,)r2cs.tdd��D�������fdd�}t|��S)Ncss|]}t|t�r|VqdSr-)�
issubclass�	Exception)r Zex_clsrrr�	<genexpr>[r%z.retry_this.<locals>.wrapper.<locals>.<genexpr>c
s�d}z�|i|��WS�y�}z�|d7}t�dt|��j��|d|i|��shd��j�}t|�|��|d|i|��}t�d|�jt|��t|�WYd}~qd}~00qdS)Nrr1z)Exception (%s) occured while executing %sr+zMax attempts exhausted for {}z:Sleeping %s secs before retrying %s, due to exception (%s))�LOGGER�error�strr�formatr
�debugr)Zpargs�kwargsr+�e�msgZs_secs)�
ex_classes�fr6r5rr�new_func]s
�z-retry_this.<locals>.wrapper.<locals>.new_func)�tupler)rCrD�r4r6r5)rBrCr�wrapperZszretry_this.<locals>.wrapper)rr0r3)r4r,r2r5r6rGrrFr�
retry_thisAsrH)�logging�	functoolsrr�timer�typingrrrrr	r
rZMAX_RETRIES�	getLoggerrr:r8r
r<rr)r*�int�boolr0r3rHrrrr�<module>s4$
&
&
����