U
    	f$                     @   s"  d dl Z d dlmZ d dlmZmZ ddlmZmZm	Z	 zd dl
Z
W n ek
r\   dZ
Y nX zd dlZW n ek
r   dZY nX edddZG d	d
 d
ZG dd dZG dd dZG dd dZG dd dZG dd dZG dd dZG dd dZG dd dZG dd dZdS )    N)TracebackType)OptionalType   )ExceptionMappingPoolTimeoutmap_exceptionsreturnc                  C   sr   zdd l } W n tk
r$   d}Y n
X |  }|dkr>td|dkrVtd krVtd|dkrntd krntd|S )Nr   asyncio)r   trioz/Running under an unsupported async environment.zBRunning with asyncio requires installation of 'httpcore[asyncio]'.r   z<Running with trio requires installation of 'httpcore[trio]'.)sniffioImportErrorcurrent_async_libraryRuntimeErroranyior   )r   Zenvironment r   \/var/www/html/apigroqsegura/apigroq/lib/python3.8/site-packages/httpcore/_synchronization.pyr      s     
r   c                   @   s`   e Zd ZdZddddZddddZd ddd	Zdeee	  ee	 ee
 dd
ddZdS )	AsyncLock
    This is a standard lock.

    In the sync case `Lock` provides thread locking.
    In the async case `AsyncLock` provides async locking.
    Nr	   c                 C   s
   d| _ d S N _backendselfr   r   r   __init__7   s    zAsyncLock.__init__c                 C   s6   t  | _| jdkrt | _n| jdkr2t | _dS z~
        Detect if we're running under 'asyncio' or 'trio' and create
        a lock with the correct implementation.
        r   r   N)r   r   r   Lock
_trio_lockr   _anyio_lockr   r   r   r   setup:   s
    

zAsyncLock.setupc                    sH   | j s|   | j dkr*| j I d H  n| j dkrD| j I d H  | S Nr   r   )r   r!   r   acquirer    r   r   r   r   
__aenter__E   s    

zAsyncLock.__aenter__exc_type	exc_value	tracebackr
   c                    s.   | j dkr| j  n| j dkr*| j  d S r"   )r   r   releaser    r   r&   r'   r(   r   r   r   	__aexit__P   s    

zAsyncLock.__aexit__)NNN)__name__
__module____qualname____doc__r   r!   r$   r   r   BaseExceptionr   r+   r   r   r   r   r   /   s      
r   c                   @   sD   e Zd ZdZd dddZd	eee  ee ee ddddZ	dS )
AsyncThreadLock
    This is a threading-only lock for no-I/O contexts.

    In the sync case `ThreadLock` provides thread locking.
    In the async case `AsyncThreadLock` is a no-op.
    r	   c                 C   s   | S Nr   r   r   r   r   	__enter__d   s    zAsyncThreadLock.__enter__Nr%   c                 C   s   d S r3   r   r*   r   r   r   __exit__g   s    zAsyncThreadLock.__exit__)NNN)
r,   r-   r.   r/   r4   r   r   r0   r   r5   r   r   r   r   r1   \   s      
r1   c                   @   sL   e Zd ZddddZddddZddddZdee dd	d
dZdS )
AsyncEventNr	   c                 C   s
   d| _ d S r   r   r   r   r   r   r   q   s    zAsyncEvent.__init__c                 C   s6   t  | _| jdkrt | _n| jdkr2t | _dS r   )r   r   r   Event_trio_eventr   _anyio_eventr   r   r   r   r!   t   s
    

zAsyncEvent.setupc                 C   s<   | j s|   | j dkr$| j  n| j dkr8| j  d S r"   )r   r!   r8   setr9   r   r   r   r   r:      s    

zAsyncEvent.settimeoutr
   c              
      s   | j s|   | j dkrrtjti}|d kr2tdn|}t|, t| | j	 I d H  W 5 Q R X W 5 Q R X nL| j dkrt
ti}t|, t| | j	 I d H  W 5 Q R X W 5 Q R X d S )Nr   infr   )r   r!   r   ZTooSlowErrorr   floatr   
fail_afterr8   waitTimeoutErrorr   r9   )r   r<   Ztrio_exc_mapZtimeout_or_infZanyio_exc_mapr   r   r   r@      s    


&

zAsyncEvent.wait)N)	r,   r-   r.   r   r!   r:   r   r>   r@   r   r   r   r   r6   p   s   	r6   c                   @   sF   e Zd ZeddddZddddZdddd	Zddd
dZdS )AsyncSemaphoreNboundr
   c                 C   s   || _ d| _d S r   )_boundr   r   rD   r   r   r   r      s    zAsyncSemaphore.__init__r	   c                 C   sJ   t  | _| jdkr(tj| j| jd| _n| jdkrFtj| j| jd| _dS )z
        Detect if we're running under 'asyncio' or 'trio' and create
        a semaphore with the correct implementation.
        r   )initial_value	max_valuer   N)r   r   r   	SemaphorerE   _trio_semaphorer   _anyio_semaphorer   r   r   r   r!      s    
 

 zAsyncSemaphore.setupc                    sH   | j s|   | j dkr*| j I d H  n| j dkrD| j I d H  d S r"   )r   r!   rJ   r#   rK   r   r   r   r   r#      s    

zAsyncSemaphore.acquirec                    s.   | j dkr| j  n| j dkr*| j  d S r"   )r   rJ   r)   rK   r   r   r   r   r)      s    

zAsyncSemaphore.release)r,   r-   r.   intr   r!   r#   r)   r   r   r   r   rB      s   	rB   c                   @   sN   e Zd ZddddZd dddZd
eee  ee ee dddd	Z	dS )AsyncShieldCancellationNr	   c                 C   s>   t  | _| jdkr"tjdd| _n| jdkr:tjdd| _dS )z
        Detect if we're running under 'asyncio' or 'trio' and create
        a shielded scope with the correct implementation.
        r   T)shieldr   N)r   r   r   CancelScope_trio_shieldr   _anyio_shieldr   r   r   r   r      s
    

z AsyncShieldCancellation.__init__c                 C   s.   | j dkr| j  n| j dkr*| j  | S r"   )r   rP   r4   rQ   r   r   r   r   r4      s
    


z!AsyncShieldCancellation.__enter__r%   c                 C   s:   | j dkr| j||| n| j dkr6| j||| d S r"   )r   rP   r5   rQ   r*   r   r   r   r5      s    

z AsyncShieldCancellation.__exit__)NNN)
r,   r-   r.   r   r4   r   r   r0   r   r5   r   r   r   r   rM      s   	   
rM   c                   @   sR   e Zd ZdZddddZd dddZdeee  ee ee	 ddd	d
Z
dS )r   r   Nr	   c                 C   s   t  | _d S r3   	threadingr   _lockr   r   r   r   r      s    zLock.__init__c                 C   s   | j   | S r3   rT   r#   r   r   r   r   r4      s    
zLock.__enter__r%   c                 C   s   | j   d S r3   rT   r)   r*   r   r   r   r5      s    zLock.__exit__)NNNr,   r-   r.   r/   r   r4   r   r   r0   r   r5   r   r   r   r   r      s      
r   c                   @   sR   e Zd ZdZddddZd dddZdeee  ee ee	 ddd	d
Z
dS )
ThreadLockr2   Nr	   c                 C   s   t  | _d S r3   rR   r   r   r   r   r     s    zThreadLock.__init__c                 C   s   | j   | S r3   rU   r   r   r   r   r4   
  s    
zThreadLock.__enter__r%   c                 C   s   | j   d S r3   rV   r*   r   r   r   r5     s    zThreadLock.__exit__)NNNrW   r   r   r   r   rX      s      
rX   c                   @   s>   e Zd ZddddZddddZd
ee dddd	ZdS )r7   Nr	   c                 C   s   t  | _d S r3   )rS   r7   _eventr   r   r   r   r     s    zEvent.__init__c                 C   s   | j   d S r3   )rY   r:   r   r   r   r   r:     s    z	Event.setr;   c                 C   s(   |t dkrd }| jj|ds$t d S )Nr=   )r<   )r>   rY   r@   r   )r   r<   r   r   r   r@     s    z
Event.wait)N)r,   r-   r.   r   r:   r   r>   r@   r   r   r   r   r7     s   r7   c                   @   s8   e Zd ZeddddZddddZdddd	ZdS )
rI   NrC   c                 C   s   t j|d| _d S )N)value)rS   rI   
_semaphorerF   r   r   r   r   &  s    zSemaphore.__init__r	   c                 C   s   | j   d S r3   )r[   r#   r   r   r   r   r#   )  s    zSemaphore.acquirec                 C   s   | j   d S r3   )r[   r)   r   r   r   r   r)   ,  s    zSemaphore.release)r,   r-   r.   rL   r   r#   r)   r   r   r   r   rI   %  s   rI   c                   @   s@   e Zd Zd dddZdeee  ee ee ddddZdS )	ShieldCancellationr	   c                 C   s   | S r3   r   r   r   r   r   r4   4  s    zShieldCancellation.__enter__Nr%   c                 C   s   d S r3   r   r*   r   r   r   r5   7  s    zShieldCancellation.__exit__)NNN)	r,   r-   r.   r4   r   r   r0   r   r5   r   r   r   r   r\   0  s      
r\   )rS   typesr   typingr   r   _exceptionsr   r   r   r   r   r   strr   r   r1   r6   rB   rM   r   rX   r7   rI   r\   r   r   r   r   <module>   s,   

-)$*