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 d dlmZmZ edZededdZer?d 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)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   K/var/www/html/flask_server/venv/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__/   s   zAbstractRetry.__eq__c                 C   s   t | j| jt| jfS r!   )hashr   r   	frozensetr   r   r   r   r   __hash__3   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_errors6   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   r/   r   r   r   update_retriesD   s   
zAbstractRetry.update_retries)__name__
__module____qualname____doc__r	   r
   r   __annotations__intr   abcabstractmethodr   boolr$   r(   r   r,   r.   r0   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gef deeegef  d	efddZ  ZS )Retryr   r   r   r   .c                    s   t  ||| d S r!   )superr   r   	__class__r   r   r   N   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$   Z   s   

zRetry.__eq__Ndofailis_retryablec              
   C   s   | j   d}	 z| W S  | jyH } z/|r||s |d7 }|| | jdkr0|| jkr0|| j |}|dkr>t| 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
        r   T   N)r   resetr   r   computer   )r   r?   r@   rA   failureserrorr   r   r   r   call_with_retryd   s$   
zRetry.call_with_retryr!   )r1   r2   r3   r   r(   r   r   sockettimeoutr6   r	   r
   	Exceptionr   r   r9   r$   r   r   r   rG   __classcell__r   r   r<   r   r:   K   s0    
r:   )r7   rH   timer   typingr   r   r   r   r   r   r	   r
   r   redis.exceptionsr   r   r   rJ   r   redis.backoffr   ABCr   r:   r   r   r   r   <module>   s    ,2