o
    ‡­Rh  ã                   @   sÜ   d dl Z d dlZd dlmZ ejrd dlZd dlmZ G dd„ de jƒZej	eej
dgef f ZG dd„ deƒZG d	d
„ d
eƒZG dd„ deƒZeƒ ZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS )é    N)Ú_utils)ÚRetryCallStatec                   @   s<   e Zd ZdZejdddefdd„ƒZdd	d
„Zddd„Z	dS )Ú	stop_basez(Abstract base class for stop strategies.Úretry_stater   Úreturnc                 C   s   d S ©N© ©Úselfr   r   r   úO/home/air/sanwanet/backup_V2/venv/lib/python3.10/site-packages/tenacity/stop.pyÚ__call__   s   zstop_base.__call__ÚotherÚstop_allc                 C   ó
   t | |ƒS r   )r   ©r
   r   r   r   r   Ú__and__"   ó   
zstop_base.__and__Ústop_anyc                 C   r   r   )r   r   r   r   r   Ú__or__%   r   zstop_base.__or__N)r   r   r   r   )r   r   r   r   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚabcÚabstractmethodÚboolr   r   r   r   r   r   r   r      s    
r   r   c                   @   ó4   e Zd ZdZdeddfdd„Zdddefd	d
„ZdS )r   z+Stop if any of the stop condition is valid.Ústopsr   Nc                 G   ó
   || _ d S r   ©r   ©r
   r   r   r   r   Ú__init__/   r   zstop_any.__init__r   r   c                    ó   t ‡ fdd„| jD ƒƒS )Nc                 3   ó    | ]}|ˆ ƒV  qd S r   r   ©Ú.0Úx©r   r   r   Ú	<genexpr>3   ó   € z$stop_any.__call__.<locals>.<genexpr>)Úanyr   r	   r   r'   r   r   2   ó   zstop_any.__call__©r   r   r   r   r   r!   r   r   r   r   r   r   r   ,   ó    r   c                   @   r   )r   z*Stop if all the stop conditions are valid.r   r   Nc                 G   r   r   r   r    r   r   r   r!   9   r   zstop_all.__init__r   r   c                    r"   )Nc                 3   r#   r   r   r$   r'   r   r   r(   =   r)   z$stop_all.__call__.<locals>.<genexpr>)Úallr   r	   r   r'   r   r   <   r+   zstop_all.__call__r,   r   r   r   r   r   6   r-   r   c                   @   s"   e Zd ZdZdddefdd„ZdS )Ú_stop_neverzNever stop.r   r   r   c                 C   s   dS )NFr   r	   r   r   r   r   C   s   z_stop_never.__call__N)r   r   r   r   r   r   r   r   r   r   r/   @   s    r/   c                   @   s,   e Zd ZdZddd„Zdd	defd
d„ZdS )Ústop_when_event_setz!Stop when the given event is set.Úeventúthreading.Eventr   Nc                 C   r   r   )r1   )r
   r1   r   r   r   r!   M   r   zstop_when_event_set.__init__r   r   c                 C   s
   | j  ¡ S r   )r1   Úis_setr	   r   r   r   r   P   r   zstop_when_event_set.__call__)r1   r2   r   N)r   r   r   r   r!   r   r   r   r   r   r   r0   J   s    
r0   c                   @   r   )Ústop_after_attemptz.Stop when the previous attempt >= max_attempt.Úmax_attempt_numberr   Nc                 C   r   r   )r5   )r
   r5   r   r   r   r!   W   r   zstop_after_attempt.__init__r   r   c                 C   s   |j | jkS r   )Úattempt_numberr5   r	   r   r   r   r   Z   s   zstop_after_attempt.__call__)r   r   r   r   Úintr!   r   r   r   r   r   r   r4   T   r-   r4   c                   @   ó6   e Zd ZdZdejddfdd„Zdddefd	d
„ZdS )Ústop_after_delayaS  
    Stop when the time from the first attempt >= limit.

    Note: `max_delay` will be exceeded, so when used with a `wait`, the actual total delay will be greater
    than `max_delay` by some of the final sleep period before `max_delay` is exceeded.

    If you need stricter timing with waits, consider `stop_before_delay` instead.
    Ú	max_delayr   Nc                 C   ó   t  |¡| _d S r   ©r   Ú
to_secondsr:   ©r
   r:   r   r   r   r!   h   ó   zstop_after_delay.__init__r   r   c                 C   s   |j d u r	tdƒ‚|j | jkS ©Nz4__call__() called but seconds_since_start is not set)Úseconds_since_startÚRuntimeErrorr:   r	   r   r   r   r   k   s   
zstop_after_delay.__call__©	r   r   r   r   r   Útime_unit_typer!   r   r   r   r   r   r   r9   ^   s    	r9   c                   @   r8   )Ústop_before_delaya  
    Stop right before the next attempt would take place after the time from the first attempt >= limit.

    Most useful when you are using with a `wait` function like wait_random_exponential, but need to make
    sure that the max_delay is not exceeded.
    r:   r   Nc                 C   r;   r   r<   r>   r   r   r   r!   y   r?   zstop_before_delay.__init__r   r   c                 C   s$   |j d u r	tdƒ‚|j |j | jkS r@   )rA   rB   Úupcoming_sleepr:   r	   r   r   r   r   |   s   

ÿÿzstop_before_delay.__call__rC   r   r   r   r   rE   q   s    rE   )r   ÚtypingÚtenacityr   ÚTYPE_CHECKINGÚ	threadingr   ÚABCr   ÚUnionÚCallabler   Ú	StopBaseTr   r   r/   Ú
stop_neverr0   r4   r9   rE   r   r   r   r   Ú<module>   s    



