o
    <‘ði“  ã                   @   s²   d dl Z d dlZd dlmZ d dlmZmZmZmZm	Z	m
Z
mZmZmZmZ d dlmZmZ edƒZededd�ZerAd d	lmZ G d
d„ dee e jƒZG dd„ dee ƒZdS )é    N)Úsleep)
ÚTYPE_CHECKINGÚAnyÚCallableÚGenericÚIterableÚOptionalÚTupleÚTypeÚTypeVarÚUnion)ÚConnectionErrorÚTimeoutErrorÚTÚET)ÚboundÚ	covariant)ÚAbstractBackoffc                   @   s¨   e Zd ZU dZeee df ed< dddedeee df fdd	„Z	e
jd
edefdd„ƒZdefdd„Zdeee  ddfdd„Zdefdd„Zdeddfdd„ZdS )ÚAbstractRetryz0Retry a specific number of times after a failure.Ú_supported_errorsÚbackoffr   ÚretriesÚsupported_errorsc                 C   s   || _ || _|| _dS )a'  
        Initialize a `Retry` object with a `Backoff` object
        that retries a maximum of `retries` times.
        `retries` can be negative to retry forever.
        You can specify the types of supported errors which trigger
        a retry with the `supported_errors` parameter.
        N)Ú_backoffÚ_retriesr   ©Úselfr   r   r   © r   úJ/root/parts/websockify/install/lib/python3.10/site-packages/redis/retry.pyÚ__init__   s   
zAbstractRetry.__init__ÚotherÚreturnc                 C   s   t S ©N)ÚNotImplemented©r   r    r   r   r   Ú__eq__0   s   zAbstractRetry.__eq__c                 C   s   t | j| jt| jƒfƒS r"   )Úhashr   r   Ú	frozensetr   ©r   r   r   r   Ú__hash__4   s   zAbstractRetry.__hash__Úspecified_errorsNc                 C   s   t t| jt |ƒ ƒƒ| _dS )zM
        Updates the supported errors with the specified error types
        N)ÚtupleÚsetr   )r   r*   r   r   r   Úupdate_supported_errors7   s   
ÿz%AbstractRetry.update_supported_errorsc                 C   s   | j S )z,
        Get the number of retries.
        ©r   r(   r   r   r   Úget_retries?   s   zAbstractRetry.get_retriesÚvaluec                 C   s
   || _ dS )z,
        Set the number of retries.
        Nr.   )r   r0   r   r   r   Úupdate_retriesE   s   
zAbstractRetry.update_retries)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r
   r   Ú__annotations__Úintr   ÚabcÚabstractmethodr   Úboolr%   r)   r   r-   r/   r1   r   r   r   r   r      s    
 þý
ür   c                       s²   e Zd ZejZeeejffddde	de
ee df f‡ fdd„Zded	efd
d„Z		ddeg ef deeegef eee	gef f deeegef  ded	ef
dd„Z‡  ZS )ÚRetryr   r   r   r   .c                    s   t ƒ  |||¡ d S r"   )Úsuperr   r   ©Ú	__class__r   r   r   O   s   
zRetry.__init__r    r!   c                 C   s:   t |tƒstS | j|jko| j|jkot| jƒt|jƒkS r"   )Ú
isinstancer;   r#   r   r   r,   r   r$   r   r   r   r%   [   s   

ÿýzRetry.__eq__NFÚdoÚfailÚis_retryableÚwith_failure_countc              
   C   s¤   | j  ¡  d}	 z|ƒ W S  | jyP } z7|r||ƒs‚ |d7 }|r(|||ƒ n||ƒ | jdkr8|| jkr8|‚| j  |¡}|dkrFt|ƒ W Y d}~nd}~ww q)aÔ  
        Execute an operation that might fail and returns its result, or
        raise the exception that was thrown depending on the `Backoff` object.
        `do`: the operation to call. Expects no argument.
        `fail`: the failure handler, expects the last error that was thrown
        ``is_retryable``: optional function to determine if an error is retryable
        ``with_failure_count``: if True, the failure count is passed to the failure handler
        r   Té   N)r   Úresetr   r   Úcomputer   )r   r@   rA   rB   rC   ÚfailuresÚerrorr   r   r   r   Úcall_with_retrye   s(   
€òýzRetry.call_with_retry)NF)r2   r3   r4   r   r)   r   r   ÚsocketÚtimeoutr7   r	   r
   Ú	Exceptionr   r   r:   r%   r   r   r   r   rI   Ú__classcell__r   r   r=   r   r;   L   s6    ýüþýüû
þ ýüûúr;   )r8   rJ   Útimer   Útypingr   r   r   r   r   r   r	   r
   r   r   Úredis.exceptionsr   r   r   rL   r   Úredis.backoffr   ÚABCr   r;   r   r   r   r   Ú<module>   s    02