U
    be+                     @   s,   d Z ddlmZ dd ZG dd deZdS )z5 Module containing the RetryingClient wrapper class.     )sleepc                 C   sT   |dkrt  S t|t ttfs*td|  t |}tdd |D sPtd|  |S )aV  
    Helper function to ensure the given arguments are tuples of Exceptions (or
    subclasses), or can at least be converted to such.

    Args:
      argument_name: str, name of the argument we're checking, only used for
        raising meaningful exceptions.
      argument: any, the argument itself.

    Returns:
      tuple[Exception]: A tuple with the elements from the argument if they are
        valid.

    Exceptions:
      ValueError: If the argument was not None, tuple or Iterable.
      ValueError: If any of the elements of the argument is not a subclass of
        Exception.
    Nz+%s must be either a tuple, a set or a list.c                 S   s   g | ]}t |tqS  )
issubclass	Exception).0argr   r   \/var/www/html/services/stratfitenv/lib/python3.8/site-packages/pymemcache/client/retrying.py
<listcomp>%   s     z*_ensure_tuple_argument.<locals>.<listcomp>zH%s is only allowed to contain elements that are subclasses of Exception.)tuple
isinstancesetlist
ValueErrorall)argument_nameZargument_valueZargument_tupler   r   r   _ensure_tuple_argument   s    r   c                   @   sJ   e Zd ZdZdddZdd Zd	d
 Zdd Zdd Zdd Z	dd Z
dS )RetryingClientzB
    Client that allows retrying calls for the other clients.
       r   Nc                 C   sp   |dk rt d|| _|| _|| _td|| _td|| _| jD ]}|| jkr@t dt| q@t| j| _	dS )a  
        Constructor for RetryingClient.

        Args:
          client: Client|PooledClient|HashClient, inner client to use for
            performing actual work.
          attempts: optional int, how many times to attempt an action before
            failing. Must be 1 or above. Defaults to 2.
          retry_delay: optional int|float, how many seconds to sleep between
            each attempt.
            Defaults to 0.

          retry_for: optional None|tuple|set|list, what exceptions to
            allow retries for. Will allow retries for all exceptions if None.
            Example:
                `(MemcacheClientError, MemcacheUnexpectedCloseError)`
            Accepts any class that is a subclass of Exception.
            Defaults to None.

          do_not_retry_for: optional None|tuple|set|list, what
            exceptions should be retried. Will not block retries for any
            Exception if None.
            Example:
                `(IOError, MemcacheIllegalInputError)`
            Accepts any class that is a subclass of Exception.
            Defaults to None.

        Exceptions:
          ValueError: If `attempts` is not 1 or above.
          ValueError: If `retry_for` or `do_not_retry_for` is not None, tuple or
            Iterable.
          ValueError: If any of the elements of `retry_for` or
            `do_not_retry_for` is not a subclass of Exception.
          ValueError: If there is any overlap between `retry_for` and
            `do_not_retry_for`.
           zG`attempts` argument must be at least 1. Otherwise no attempts are made.	retry_fordo_not_retry_forzException class "%s" was present in both `retry_for` and `do_not_retry_for`. Any exception class is only allowed in a single argument.N)
r   _client	_attempts_retry_delayr   
_retry_for_do_not_retry_forreprdir_client_dir)selfclientZattemptsZretry_delayr   r   	exc_classr   r   r   __init__3   s(    ( 

zRetryingClient.__init__c                 O   s   t | jD ]}z|||}|W   S  tk
r } zN|| jd ksp| jrTt|| jrp| jrft|| jsp|| jkrt|t| j W 5 d}~X Y q
X q
dS )a3  
        Workhorse function, handles retry logic.

        Args:
          name: str, Name of the function called.
          func: callable, the function to retry.
          *args: args, array arguments to pass to the function.
          **kwargs: kwargs, keyword arguments to pass to the function.
        r   N)	ranger   r   r   r   r   r   r   r   )r   namefuncargskwargsattemptresultexcr   r   r   _retryu   s&    




	zRetryingClient._retryc                    s    fddS )Nc                     s   j  j f| |S N)r+   r   __getattribute__)r&   r'   r$   r   r   r   <lambda>   s    
z,RetryingClient.__getattr__.<locals>.<lambda>r   )r   r$   r   r.   r   __getattr__   s    zRetryingClient.__getattr__c                 C   s   | j S r,   )r   )r   r   r   r   __dir__   s    zRetryingClient.__dir__c                 C   s   | j ||dd d S NT)Znoreply)r   r   keyvaluer   r   r   __setitem__   s    zRetryingClient.__setitem__c                 C   s   |  |}|d krt|S r,   )getKeyErrorr3   r   r   r   __getitem__   s    
zRetryingClient.__getitem__c                 C   s   | j |dd d S r2   )delete)r   r4   r   r   r   __delitem__   s    zRetryingClient.__delitem__)r   r   NN)__name__
__module____qualname____doc__r"   r+   r0   r1   r6   r9   r;   r   r   r   r   r   .   s          
B&	r   N)r?   timer   r   objectr   r   r   r   r   <module>   s   (