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   ?/home/ubuntu/.local/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