o
    hV                     @   sr   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
 d dlmZmZ e
dZer0d dlmZ G dd dZdS )	    N)sleep)TYPE_CHECKINGAnyCallableIterableTupleTypeTypeVar)ConnectionErrorTimeoutErrorT)AbstractBackoffc                	   @   s   e Zd ZdZeeejffdddede	e
e df fddZ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eg ef deegef d
efddZdS )Retryz0Retry a specific number of times after a failurebackoffr   retriessupported_errors.c                 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_retries_supported_errors)selfr   r   r    r   M/var/www/html/optinet_system/venv/lib/python3.10/site-packages/redis/retry.py__init__   s   
zRetry.__init__otherreturnc                 C   s:   t |tstS | j|jko| j|jkot| jt|jkS N)
isinstancer   NotImplementedr   r   setr   )r   r   r   r   r   __eq__%   s   

zRetry.__eq__c                 C   s   t | j| jt| jfS r   )hashr   r   	frozensetr   r   r   r   r   __hash__/   s   zRetry.__hash__specified_errorsNc                 C   s   t t| jt | | _dS )zM
        Updates the supported errors with the specified error types
        N)tupler   r   )r   r$   r   r   r   update_supported_errors2   s   
zRetry.update_supported_errorsc                 C   s   | j S )z,
        Get the number of retries.
        r   r"   r   r   r   get_retries<   s   zRetry.get_retriesvaluec                 C   s
   || _ dS )z,
        Set the number of retries.
        Nr'   )r   r)   r   r   r   update_retriesB   s   
zRetry.update_retriesdofailc              
   C   s   | j   d}	 z| W S  | jyA } z(|d7 }|| | jdkr)|| jkr)|| j |}|dkr7t| 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,   failureserrorr   r   r   r   call_with_retryH   s    
zRetry.call_with_retry)__name__
__module____qualname____doc__r
   r   sockettimeoutintr   r   	Exceptionr   r   boolr   r#   r   r&   r(   r*   r   r   r2   r   r   r   r   r      s:    





r   )r7   timer   typingr   r   r   r   r   r   r	   redis.exceptionsr
   r   r   redis.backoffr   r   r   r   r   r   <module>   s    $