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   environment r   X/var/www/html/Darija-Ai-API/env/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 r4   r   r+   r   r   r   __exit__g   s    zAsyncThreadLock.__exit__)NNN)
r-   r.   r/   r0   r5   r   r   r1   r   r6   r   r   r   r   r2   \   s      
r2   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"   r9   setr:   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   Z
fail_afterr9   waitTimeoutErrorr   r:   )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   r7   p   s   	r7   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_valueZ	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"   rI   r$   rJ   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   rI   r*   rJ   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   Z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   rN   r5   rO   r   r   r   r   r5      s
    


z!AsyncShieldCancellation.__enter__r&   c                 C   s:   | j dkr| j||| n| j dkr6| j||| d S r#   )r   rN   r6   rO   r+   r   r   r   r6      s    

z AsyncShieldCancellation.__exit__)NNN)
r-   r.   r/   r   r5   r   r   r1   r   r6   r   r   r   r   rL      s   	   
rL   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 r4   	threadingr   _lockr   r   r   r   r      s    zLock.__init__c                 C   s   | j   | S r4   rR   r$   r   r   r   r   r5      s    
zLock.__enter__r&   c                 C   s   | j   d S r4   rR   r*   r+   r   r   r   r6      s    zLock.__exit__)NNNr-   r.   r/   r0   r   r5   r   r   r1   r   r6   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 )
ThreadLockr3   Nr	   c                 C   s   t  | _d S r4   rP   r   r   r   r   r     s    zThreadLock.__init__c                 C   s   | j   | S r4   rS   r   r   r   r   r5   
  s    
zThreadLock.__enter__r&   c                 C   s   | j   d S r4   rT   r+   r   r   r   r6     s    zThreadLock.__exit__)NNNrU   r   r   r   r   rV      s      
rV   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 )r8   Nr	   c                 C   s   t  | _d S r4   )rQ   r8   _eventr   r   r   r   r     s    zEvent.__init__c                 C   s   | j   d S r4   )rW   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?   rW   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   r8     s   r8   c                   @   s8   e Zd ZeddddZddddZdddd	ZdS )
rH   NrC   c                 C   s   t j|d| _d S )N)value)rQ   rH   
_semaphorerF   r   r   r   r   &  s    zSemaphore.__init__r	   c                 C   s   | j   d S r4   )rY   r$   r   r   r   r   r$   )  s    zSemaphore.acquirec                 C   s   | j   d S r4   )rY   r*   r   r   r   r   r*   ,  s    zSemaphore.release)r-   r.   r/   rK   r   r$   r*   r   r   r   r   rH   %  s   rH   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 r4   r   r   r   r   r   r5   4  s    zShieldCancellation.__enter__Nr&   c                 C   s   d S r4   r   r+   r   r   r   r6   7  s    zShieldCancellation.__exit__)NNN)	r-   r.   r/   r5   r   r   r1   r   r6   r   r   r   r   rZ   0  s      
rZ   )rQ   typesr   typingr   r   _exceptionsr   r   r   r   r   r   strr   r   r2   r7   rB   rL   r   rV   r8   rH   rZ   r   r   r   r   <module>   s,   

-)$*