
    Mh$                       d dl mZ d dlZd dlZddlmZmZmZ 	 d dlZn# e	e
f$ r dZY nw xY w	 d dlZn# e	$ r dZY nw xY wddZ G d d	          Z G d
 d          Z G d d          Z G d d          Z G d d          Z G d d          Z G d d          Z G d d          Z G d d          Z G d d          ZdS )    )annotationsN   )ExceptionMappingPoolTimeoutmap_exceptionsreturnstrc                     	 dd l } |                                 }n# t          $ r d}Y nw xY w|dvrt          d          |dk    rt          t          d          |dk    rt
          t          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current_async_libraryImportErrorRuntimeErroranyior   )r   environments     Y/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/httpcore/_synchronization.pyr   r      s    6 3355        
 ---LMMMiEMP
 
 	
 fJ
 
 	
 s    **c                  :    e Zd ZdZddZddZddZ	 	 	 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.
    r   Nonec                    d| _         d S N _backendselfs    r   __init__zAsyncLock.__init__8           c                    t                      | _        | j        dk    rt          j                    | _        dS | j        dk    rt          j                    | _        dS 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   s    r   setupzAsyncLock.setup;   sX    
 .//=F"""ikkDOOO]i''$z||D ('r!   c                   K   | j         s|                                  | j         dk    r | j                                         d {V  n*| j         dk    r| j                                         d {V  | S Nr   r   )r   r'   r%   acquirer&   r   s    r   
__aenter__zAsyncLock.__aenter__F   s      } 	JJLLL=F""/))++++++++++]i''"**,,,,,,,,,r!   Nexc_typetype[BaseException] | None	exc_valueBaseException | None	tracebacktypes.TracebackType | Nonec                   K   | j         dk    r| j                                         d S | j         dk    r| j                                         d S d S r)   )r   r%   releaser&   r   r,   r.   r0   s       r   	__aexit__zAsyncLock.__aexit__Q   s_       =F""O##%%%%%]i''$$&&&&& ('r!   r   r   )r   r   NNNr,   r-   r.   r/   r0   r1   r   r   )__name__
__module____qualname____doc__r   r'   r+   r5    r!   r   r   r   0   s~            	, 	, 	, 	,	 	 	 	 04*.04		' 	' 	' 	' 	' 	' 	'r!   r   c                  *    e Zd ZdZddZ	 	 	 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                    | S Nr=   r   s    r   	__enter__zAsyncThreadLock.__enter__e       r!   Nr,   r-   r.   r/   r0   r1   r   c                    d S rB   r=   r4   s       r   __exit__zAsyncThreadLock.__exit__h   	     	r!   )r   r?   r7   r8   )r9   r:   r;   r<   rC   rF   r=   r!   r   r?   r?   ]   sV            
 04*.04	      r!   r?   c                  0    e Zd Zd
dZd
dZd
dZddd	ZdS )
AsyncEventr   r   c                    d| _         d S r   r   r   s    r   r   zAsyncEvent.__init__r   r    r!   c                    t                      | _        | j        dk    rt          j                    | _        dS | j        dk    rt          j                    | _        dS dS r#   )r   r   r   Event_trio_eventr   _anyio_eventr   s    r   r'   zAsyncEvent.setupu   s[    
 .//=F""#z||D]i'' %D ('r!   c                    | j         s|                                  | j         dk    r| j                                         d S | j         dk    r| j                                         d S d S r)   )r   r'   rM   setrN   r   s    r   rP   zAsyncEvent.set   sq    } 	JJLLL=F""  """""]i''!!##### ('r!   Ntimeoutfloat | Nonec                  K   | j         s|                                  | j         dk    rt          j        t          i}|t          d          n|}t          |          5  t          j        |          5  | j        	                                 d {V  d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S | j         dk    rt          t          i}t          |          5  t          j        |          5  | j        	                                 d {V  d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S d S )Nr   infr   )r   r'   r   TooSlowErrorr   floatr   
fail_afterrM   waitTimeoutErrorr   rN   )r   rQ   trio_exc_maptimeout_or_infanyio_exc_maps        r   rX   zAsyncEvent.wait   sh     } 	JJLLL=F"".2.?-ML-4_U5\\\'N-- 2 2_^44 2 2*//1111111112 2 2 2 2 2 2 2 2 2 2 2 2 2 22 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ]i''/;[.IM.. 3 3%g.. 3 3+002222222223 3 3 3 3 3 3 3 3 3 3 3 3 3 33 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ('sl   B73 BB7B#	#B7&B#	'B77B;>B;,E D-!E-D1	1E4D1	5EE	E	r6   rB   rQ   rR   r   r   )r9   r:   r;   r   r'   rP   rX   r=   r!   r   rI   rI   q   si           	. 	. 	. 	.$ $ $ $3 3 3 3 3 3 3r!   rI   c                  .    e Zd Zd
dZddZddZddZd	S )AsyncSemaphoreboundintr   r   c                "    || _         d| _        d S r   )_boundr   r   r`   s     r   r   zAsyncSemaphore.__init__   s    r!   c                    t                      | _        | j        dk    r't          j        | j        | j                  | _        dS | j        dk    r't          j        | j        | j                  | _        dS 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   	Semaphorerc   _trio_semaphorer   _anyio_semaphorer   s    r   r'   zAsyncSemaphore.setup   s    
 .//=F""#'>"kT[$ $ $D    ]i''$)O"kT[% % %D!!! ('r!   c                   K   | j         s|                                  | j         dk    r!| j                                         d {V  d S | j         dk    r!| j                                         d {V  d S d S r)   )r   r'   ri   r*   rj   r   s    r   r*   zAsyncSemaphore.acquire   s      } 	JJLLL=F""&..00000000000]i'''//11111111111 ('r!   c                   K   | j         dk    r| j                                         d S | j         dk    r| j                                         d S d S r)   )r   ri   r3   rj   r   s    r   r3   zAsyncSemaphore.release   s^      =F"" ((*****]i''!))+++++ ('r!   Nr`   ra   r   r   r6   )r9   r:   r;   r   r'   r*   r3   r=   r!   r   r_   r_      sd              2 2 2 2, , , , , ,r!   r_   c                  .    e Zd ZddZddZ	 	 	 dddZdS )AsyncShieldCancellationr   r   c                    t                      | _        | j        dk    rt          j        d          | _        dS | j        dk    rt          j        d          | _        dS 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   s    r   r   z AsyncShieldCancellation.__init__   sk    
 .//=F"" $ 0 = = =D]i''!&!2$!?!?!?D ('r!   c                    | j         dk    r| j                                         n$| j         dk    r| j                                         | S r)   )r   rs   rC   rt   r   s    r   rC   z!AsyncShieldCancellation.__enter__   sN    =F""''))))]i''((***r!   Nr,   r-   r.   r/   r0   r1   c                    | j         dk    r| j                            |||           d S | j         dk    r| j                            |||           d S d S r)   )r   rs   rF   rt   r4   s       r   rF   z AsyncShieldCancellation.__exit__   sh     =F""&&xIFFFFF]i'''')YGGGGG ('r!   r6   )r   ro   r7   r8   )r9   r:   r;   r   rC   rF   r=   r!   r   ro   ro      sk        
@ 
@ 
@ 
@    04*.04		H 	H 	H 	H 	H 	H 	Hr!   ro   c                  2    e Zd ZdZddZddZ	 	 	 dddZdS )r$   r   r   r   c                6    t          j                    | _        d S rB   	threadingr$   _lockr   s    r   r   zLock.__init__       ^%%


r!   c                8    | j                                          | S rB   r{   r*   r   s    r   rC   zLock.__enter__       
r!   Nr,   r-   r.   r/   r0   r1   c                8    | j                                          d S rB   r{   r3   r4   s       r   rF   zLock.__exit__        	
r!   r6   )r   r$   r7   r8   r9   r:   r;   r<   r   rC   rF   r=   r!   r   r$   r$      j         & & & &    04*.04	      r!   r$   c                  2    e Zd ZdZddZddZ	 	 	 dddZdS )
ThreadLockr@   r   r   c                6    t          j                    | _        d S rB   ry   r   s    r   r   zThreadLock.__init__  r|   r!   c                8    | j                                          | S rB   r~   r   s    r   rC   zThreadLock.__enter__  r   r!   Nr,   r-   r.   r/   r0   r1   c                8    | j                                          d S rB   r   r4   s       r   rF   zThreadLock.__exit__  r   r!   r6   )r   r   r7   r8   r   r=   r!   r   r   r      r   r!   r   c                  (    e Zd Zd	dZd	dZd
ddZdS )rL   r   r   c                6    t          j                    | _        d S rB   )rz   rL   _eventr   s    r   r   zEvent.__init__  s    o''r!   c                8    | j                                          d S rB   )r   rP   r   s    r   rP   z	Event.set  s    r!   NrQ   rR   c                    |t          d          k    rd }| j                            |          st                      d S )NrT   )rQ   )rV   r   rX   r   )r   rQ   s     r   rX   z
Event.wait  sG    eEll""G{00 	 --	  	 r!   r6   rB   r]   )r9   r:   r;   r   rP   rX   r=   r!   r   rL   rL     sU        ( ( ( (                r!   rL   c                  &    e Zd Zd	dZd
dZd
dZdS )rh   r`   ra   r   r   c                :    t          j        |          | _        d S )N)value)rz   rh   
_semaphorerd   s     r   r   zSemaphore.__init__'  s    #-E:::r!   c                8    | j                                          d S rB   )r   r*   r   s    r   r*   zSemaphore.acquire*      !!!!!r!   c                8    | j                                          d S rB   )r   r3   r   s    r   r3   zSemaphore.release-  r   r!   Nrm   r6   )r9   r:   r;   r   r*   r3   r=   r!   r   rh   rh   &  sP        ; ; ; ;" " " "" " " " " "r!   rh   c                  &    e Zd ZddZ	 	 	 dddZdS )ShieldCancellationr   c                    | S rB   r=   r   s    r   rC   zShieldCancellation.__enter__5  rD   r!   Nr,   r-   r.   r/   r0   r1   r   c                    d S rB   r=   r4   s       r   rF   zShieldCancellation.__exit__8  rG   r!   )r   r   r7   r8   )r9   r:   r;   rC   rF   r=   r!   r   r   r   1  sL           
 04*.04	      r!   r   )r   r	   )
__future__r   rz   types_exceptionsr   r   r   r   r   NotImplementedErrorr   r   r   r?   rI   r_   ro   r$   r   rL   rh   r   r=   r!   r   <module>r      sr   " " " " " "      F F F F F F F F F F
KKKK()   DDDLLLL   EEE   4*' *' *' *' *' *' *' *'Z       (&3 &3 &3 &3 &3 &3 &3 &3R!, !, !, !, !, !, !, !,H$H $H $H $H $H $H $H $HT       0       0               " " " " " " " "         s    	++4 >>