o
    a+)hG                  
   @   s  d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZm	Z	 d dl
mZ d dlmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl m"Z" ddl m#Z# ddl m$Z$ ddl m%Z% ddl m&Z& ddl'm(Z( ddl'm)Z) ddl'm*Z* ddl'm+Z+ dd l'm,Z, dd!l'm-Z- dd"l'm.Z. dd#l'm/Z/ dd#l'm/Z0 dd$l'm1Z1 dd%l2m3Z3 dd&l2m4Z4 dd'l5m6Z6 dd(l5m7Z7 dd)l8m9Z9 dd*l8m:Z: dZ;ej<r&d dl=Z=dd+l'm>Z> dd,l m?Z? ej@d-ejAd.ZBe@d/ZCejDd0eBd1eBfd2d3ZejDd4ejEd5ejEd1ejAeBgeBf fd6d3Zd4ejEd5ejEd1ejFeBejAeBgeBf f fd7d3ZG d8d9 d9eGZHeI ZJG d:d; d;ZKG d<d= d=eLZMG d>d? d?ZNG d@dA dAeNZOeI ZPdBejFejEeIf dCejEd1ejEfdDdEZQG dFdG dGeGZRG dHdI dIZSG dJdK dKeZTG dLdM dMeTZUG dNdO dOejVZVG dPdQ dQZWd dRlXmYZY e;rd dSlZm[Z[ dS dS )T    N)ABCabstractmethod)futures)iscoroutinefunction   )
retry_base)	retry_all)retry_always)	retry_any)retry_if_exception)retry_if_exception_type)retry_if_exception_cause_type)retry_if_not_exception_type)retry_if_not_result)retry_if_result)retry_never)retry_unless_exception_type)retry_if_exception_message)retry_if_not_exception_messagesleep)sleep_using_event)stop_after_attempt)stop_after_delay)stop_all)stop_any)
stop_never)stop_when_event_set)
wait_chain)wait_combine)wait_exponential)
wait_fixed)wait_incrementing)	wait_none)wait_random)wait_random_exponential)wait_exponential_jitter)
before_log)before_nothing)	after_log)after_nothing)before_sleep_log)before_sleep_nothing)	wait_base)	stop_base	WrappedFn)bound_RetValTfnreturnc                 C      d S N )r2   r6   r6   \C:\Users\User\Downloads\Proyecto_IoT\venv\Lib\site-packages\pip/_vendor/tenacity/__init__.pyretryc      r8   dargsdkwc                  O   r4   r5   r6   r:   r;   r6   r6   r7   r8   h   r9   c                     sB   t  dkrt d rt  d S dtdtf fdd}|S )zWrap a function with a new `Retrying` object.

    :param dargs: positional arguments passed to Retrying object
    :param dkw: keyword arguments passed to the Retrying object
    r   r   fr3   c                    s   t | trtd| jj d| jj d t| r!t i }ntr7t	tj
dr7tj
| r7t i }nt i }|| S )NzGot retry_base instance (zQ) as callable argument, this will probably hang indefinitely (did you mean retry=z(...)?)is_coroutine_function)
isinstancer   warningswarn	__class____name__r   AsyncRetryingtornadohasattrgenr>   TornadoRetryingRetryingwraps)r=   rr<   r6   r7   wrapx   s   

zretry.<locals>.wrap)lencallabler8   r/   )r:   r;   rL   r6   r<   r7   r8   m   s   c                   @   s   e Zd ZdZdS )TryAgainz/Always retry the executed function when raised.N)rC   
__module____qualname____doc__r6   r6   r6   r7   rO      s    rO   c                   @      e Zd ZdS )	DoAttemptNrC   rP   rQ   r6   r6   r6   r7   rT          rT   c                   @   rS   )DoSleepNrU   r6   r6   r6   r7   rW      rV   rW   c                   @   sR   e Zd ZU dZdZeje ed< dZ	ej
e ed< defddZdefd	d
ZdS )
BaseActiona5  Base class for representing actions to take by retry object.

    Concrete implementations must define:
    - __init__: to initialize all necessary fields
    - REPR_FIELDS: class variable specifying attributes to include in repr(self)
    - NAME: for identification in retry object methods and callbacks
    r6   REPR_FIELDSNNAMEr3   c                    s.   d  fdd jD } jj d| dS )Nz, c                 3   s$    | ]}| d t  |V  qdS )=N)getattr).0fieldselfr6   r7   	<genexpr>   s   " z&BaseAction.__repr__.<locals>.<genexpr>())joinrY   rB   rC   )r`   	state_strr6   r_   r7   __repr__   s   zBaseAction.__repr__c                 C   s   t | S r5   )reprr_   r6   r6   r7   __str__   s   zBaseAction.__str__)rC   rP   rQ   rR   rY   tSequencestr__annotations__rZ   Optionalrf   rh   r6   r6   r6   r7   rX      s   
 rX   c                   @   s(   e Zd ZdZdZdejddfddZdS )RetryActionr   r8   r   r3   Nc                 C   s   t || _d S r5   )floatr   )r`   r   r6   r6   r7   __init__   s   zRetryAction.__init__)rC   rP   rQ   rY   rZ   ri   SupportsFloatrp   r6   r6   r6   r7   rn      s    rn   firstsecondc                 C   s   | t u r|S | S r5   )_unset)rr   rs   r6   r6   r7   
_first_set   s   ru   c                       s:   e Zd ZdZd fddZdd	d
ZdefddZ  ZS )
RetryErrorz>Encapsulates the last attempt instance right before giving up.last_attemptFuturer3   Nc                    s   || _ t | d S r5   )rw   superrp   )r`   rw   rB   r6   r7   rp      s   zRetryError.__init__
t.NoReturnc                 C   s   | j jr	| j  | r5   )rw   failedresultr_   r6   r6   r7   reraise   s   
zRetryError.reraisec                 C   s   | j j d| j dS )N[])rB   rC   rw   r_   r6   r6   r7   rh         zRetryError.__str__)rw   rx   r3   N)r3   r{   )	rC   rP   rQ   rR   rp   r~   rk   rh   __classcell__r6   r6   rz   r7   rv      s
    
rv   c                	   @   s\   e Zd ZdZdddZddd	Zd
ejeje	  deje	 dejd deje
 fddZdS )AttemptManagerzManage attempt context.retry_stateRetryCallStatec                 C   s
   || _ d S r5   r   )r`   r   r6   r6   r7   rp      s   
zAttemptManager.__init__r3   Nc                 C   r4   r5   r6   r_   r6   r6   r7   	__enter__   s   zAttemptManager.__enter__exc_type	exc_value	tracebacktypes.TracebackTypec                 C   s0   t |tr| j|||f dS | jd  d S )NT)r?   BaseExceptionr   set_exception
set_result)r`   r   r   r   r6   r6   r7   __exit__   s
   
zAttemptManager.__exit__)r   r   r3   N)rC   rP   rQ   rR   rp   r   ri   rm   Typer   boolr   r6   r6   r6   r7   r      s    

r   c                   @   sj  e Zd Zeee e eedde	df
de
je
jeef gdf ddddded	e
jd
gdf de
jd
gdf de
je
jd
gdf  dede
je	 de
je
jd
ge
jf  fddZeeeeeeeeeef
de
je
je
jeef gdf ef de
jdef de
jdef de
jeef d	e
je
jd
gdf ef de
je
jd
gdf ef de
je
je
jd
gdf  ef de
jeef de
je
je	 ef de
je
je
jd
ge
jf  ef dd fddZdefddZede
jee
jf fddZdedefddZd)ddZdd
de
je e!e
jf fdd Z"de
j#e$ddf fd!d"Z%e&d#e
jd$e'f d%e
jd&e
jde'fd'd(Z(dS )*BaseRetryingNFr   stopr.   waitr-   r8   beforer   afterbefore_sleepr~   retry_error_clsretry_error_callbackc                 C   sJ   || _ || _|| _|| _|| _|| _|| _|| _t	 | _
|	| _|
| _d S r5   )r   r   r   r8   r   r   r   r~   	threadinglocal_localr   r   r`   r   r   r   r8   r   r   r   r~   r   r   r6   r6   r7   rp      s   

zBaseRetrying.__init__r3   c                 C   sn   | j t|| jt|| jt|| jt|| jt|| jt|| jt|| jt|| j	t|	| j
t|
| jd
S )z8Copy this object with some parameters changed if needed.)
r   r   r   r8   r   r   r   r~   r   r   )rB   ru   r   r   r   r8   r   r   r   r~   r   r   r   r6   r6   r7   copy   s   









zBaseRetrying.copyc                 C   sL   d| j j dt| dd| j d| j d| j d| j d| j d	| j d
S )N<z object at 0xxz (stop=z, wait=z, sleep=z, retry=z	, before=z, after=z)>)	rB   rC   idr   r   r   r8   r   r   r_   r6   r6   r7   rf     s   zBaseRetrying.__repr__c                 C   s.   z| j jW S  ty   i | j _| j j Y S w )aS  Return a dictionary of runtime statistics.

        This dictionary will be empty when the controller has never been
        ran. When it is running or has ran previously it should have (but
        may not) have useful and/or informational keys and values when
        running is underway and/or completed.

        .. warning:: The keys in this dictionary **should** be some what
                     stable (not changing), but there existence **may**
                     change between major releases as new statistics are
                     gathered or removed so before accessing keys ensure that
                     they actually exist and handle when they do not.

        .. note:: The values in this dictionary are local to the thread
                  running call (so if multiple threads share the same retrying
                  object - either directly or indirectly) they will each have
                  there own view of statistics they have collected (in the
                  future we may provide a way to aggregate the various
                  statistics from each thread).
        )r   
statisticsAttributeErrorr_   r6   r6   r7   r   $  s   
zBaseRetrying.statisticsr=   c                    s\   t  dtjdtjdtjf fdd}dtjdtjdtf fdd}|_||_|S )	z[Wrap a function for retrying.

        :param f: A function to wraps for retrying.
        argskwr3   c                     s    g| R i |S r5   r6   )r   r   r=   r`   r6   r7   	wrapped_fF  s   z%BaseRetrying.wraps.<locals>.wrapped_fkwargsc                     s   j | i | S r5   )r   rJ   )r   r   r   r6   r7   
retry_withJ  r   z&BaseRetrying.wraps.<locals>.retry_with)	functoolsrJ   ri   Anyr/   r8   r   )r`   r=   r   r   r6   r   r7   rJ   @  s   $ zBaseRetrying.wrapsc                 C   s0   | j   t | j d< d| j d< d| j d< d S )N
start_timer   attempt_numberr   idle_for)r   cleartime	monotonicr_   r6   r6   r7   beginR  s   

zBaseRetrying.beginr   c                 C   s&  |j }|d u r| jd ur| | t S |j jot|j  t}|s,| j|ds,| S | j	d ur6| 	| |j
| jd< | j|dr[| jrJ| |S | |}| jrV| || | jre| j|d}nd}t||_| j|7  _| jd  |7  < | jd  d7  < | jd ur| | t|S )Nr   delay_since_first_attempt        r   r   r   )outcomer   rT   r|   r?   	exceptionrO   r8   r}   r   seconds_since_startr   r   r   r   r~   r   rn   next_actionr   r   rW   )r`   r   futis_explicit_retry	retry_excr   r6   r6   r7   iterX  s8   









zBaseRetrying.iterc                 c   sd    |    t| d di d}	 | j|d}t|tr t|dV  nt|tr/|  | | nd S q)Nr6   )r2   r   r   Tr   )	r   r   r   r?   rT   r   rW   prepare_for_next_attemptr   )r`   r   dor6   r6   r7   __iter__}  s   

zBaseRetrying.__iter__r2   .r   r   c                 O   r4   r5   r6   )r`   r2   r   r   r6   r6   r7   __call__  r9   zBaseRetrying.__call__r   ))rC   rP   rQ   r   r   r#   r   r(   r*   rv   ri   CallableUnionintro   r   rm   r   r   r   rp   rt   objectr   rk   rf   propertyDictr   r/   rJ   r   rT   rW   r   	Generatorr   r   r   r1   r   r6   r6   r6   r7   r      s    	

"	
 

 %.r   c                   @   s8   e Zd ZdZdejdef dejdejdefddZd	S )
rI   zRetrying controller.r2   .r   r   r3   c                 O   s   |    t| |||d}	 | j|d}t|tr8z	||i |}W n ty1   |t  Y nw |	| nt|t
rG|  | | n|S q)N)retry_objectr2   r   r   Tr   )r   r   r   r?   rT   r   r   sysexc_infor   rW   r   r   )r`   r2   r   r   r   r   r}   r6   r6   r7   r     s    

zRetrying.__call__N)	rC   rP   rQ   rR   ri   r   r1   r   r   r6   r6   r6   r7   rI     s    ,rI   c                	       s\   e Zd ZdZdeddf fddZedefddZe	ded	e
jd
edd fddZ  ZS )rx   zDEncapsulates a (future or past) attempted call to a target function.r   r3   Nc                    s   t    || _d S r5   )ry   rp   r   )r`   r   rz   r6   r7   rp     s   

zFuture.__init__c                 C   s   |   duS )z8Return whether a exception is being held in this future.N)r   r_   r6   r6   r7   r|     s   zFuture.failedvaluehas_exceptionc                 C   s(   | |}|r| | |S || |S )zConstruct a new Future object.)r   r   )clsr   r   r   r   r6   r6   r7   	construct  s   

zFuture.construct)rC   rP   rQ   rR   r   rp   r   r   r|   classmethodri   r   r   r   r6   r6   rz   r7   rx     s    &rx   c                
   @   s   e Zd ZdZdedeje dejdejddf
dd	Z	e
deje fd
dZdddZdejddfddZdejeje edf ddfddZdd ZdS )r   z5State related to a single call wrapped with Retrying.r   r2   r   r   r3   Nc                 C   sD   t  | _|| _|| _|| _|| _d| _d | _d | _	d| _
d | _d S )Nr   r   )r   r   r   r   r2   r   r   r   r   outcome_timestampr   r   )r`   r   r2   r   r   r6   r6   r7   rp     s   

zRetryCallState.__init__c                 C   s   | j d u rd S | j | j S r5   )r   r   r_   r6   r6   r7   r     s   
z"RetryCallState.seconds_since_startc                 C   s$   d | _ d | _|  jd7  _d | _d S Nr   )r   r   r   r   r_   r6   r6   r7   r     s   
z'RetryCallState.prepare_for_next_attemptvalc                 C   s.   t  }t| j}|| ||| _| _d S r5   )r   r   rx   r   r   r   r   )r`   r   tsr   r6   r6   r7   r     s   

zRetryCallState.set_resultr   r   c                 C   s2   t  }t| j}||d  ||| _| _d S r   )r   r   rx   r   r   r   r   )r`   r   r   r   r6   r6   r7   r     s   
zRetryCallState.set_exceptionc                 C   s   | j d u rd}n| j jr| j  }d|jj d| d}nd| j   }tt| jd}| jj}d| dt	|  d| j
 d	| d
| dS )Nznone yetzfailed ( rc   z	returned    r   z: attempt #z; slept for z; last result: >)r   r|   r   rB   rC   r}   ro   roundr   r   r   )r`   r}   r   sleptclsnamer6   r6   r7   rf     s   

*zRetryCallState.__repr__r   )rC   rP   rQ   rR   r   ri   rm   r/   r   rp   r   ro   r   r   r   Tupler   r   r   rf   r6   r6   r6   r7   r     s&    

$r   )rD   )rH   )\r   r   r   r   typingri   r@   abcr   r   
concurrentr   inspectr   r8   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   napr   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   wait_full_jitterr&   r   r'   r(   r   r)   r*   r   r+   r,   rE   TYPE_CHECKINGtypesr-   r.   TypeVarr   r/   r1   overloadr   r   	ExceptionrO   r   	NO_RESULTrT   ro   rW   rX   rn   rt   ru   rv   r   r   rI   rx   r   pip._vendor.tenacity._asynciorD   Zpip._vendor.tenacity.tornadowebrH   r6   r6   r6   r7   <module>   s   
(0& -F