
    osj$                    P   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	 d dlZ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y# e	e
f$ r dZY yw xY w# e	$ r dZY w xY w)    )annotationsN   )ExceptionMappingPoolTimeoutmap_exceptionsc                     	 dd l } | j                         }|dvrt        d      |dk(  rt        t        d      |dk(  rt
        t        d      |S # t        $ r d}Y Jw xY w)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     M/root/.hermes/venv/lib/python3.12/site-packages/httpcore2/_synchronization.pyr   r      s{    6 335--LMMiEM_``fYZZ    s   A A! A!c                  F    e Zd ZdZddZddZddZ	 	 	 d		 	 	 	 	 	 	 d
dZy)	AsyncLock
    This is a standard lock.

    In the sync case `Lock` provides thread locking.
    In the async case `AsyncLock` provides async locking.
    c                    d| _         y N _backendselfs    r   __init__zAsyncLock.__init__4   	        c                    t               | _        | j                  dk(  rt        j                         | _        y| j                  dk(  rt        j                  d      | _        yy)~
        Detect if we're running under 'asyncio' or 'trio' and create
        a lock with the correct implementation.
        r
   r	   T)fast_acquireN)r   r   r
   Lock
_trio_lockr   _anyio_lockr   s    r   setupzAsyncLock.setup7   sI    
 ./==F""iikDO]]i'$zzt<D (r   c                  K   | j                   s| j                          | j                   dk(  r$| j                  j                          d {    | S | j                   dk(  r"| j                  j                          d {    | S 7 97 wNr
   r	   )r   r%   r#   acquirer$   r   s    r   
__aenter__zAsyncLock.__aenter__B   ss     }}JJL==F"//))+++  ]]i'""**,,,	 ,,s$   A	B	B2B	>B?B	B	Nc                   K   | j                   dk(  r| j                  j                          y | j                   dk(  r| j                  j                          y y wr'   )r   r#   releaser$   r   exc_type	exc_value	tracebacks       r   	__aexit__zAsyncLock.__aexit__M   sG      ==F"OO##%]]i'$$& (   AAreturnNone)r3   r   NNNr-   ztype[BaseException] | Noner.   zBaseException | Noner/   ztypes.TracebackType | Noner3   r4   )__name__
__module____qualname____doc__r   r%   r)   r0    r   r   r   r   ,   sL    	=	 04*.04		',	' (	' .		'
 
	'r   r   c                  6    e Zd ZdZddZ	 	 	 d	 	 	 	 	 	 	 ddZy)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.
    c                    | S Nr;   r   s    r   	__enter__zAsyncThreadLock.__enter__a       r   Nc                     y r@   r;   r,   s       r   __exit__zAsyncThreadLock.__exit__d        	r   )r3   r=   r5   r6   )r7   r8   r9   r:   rA   rD   r;   r   r   r=   r=   Y   sB    
 04*.04	, ( .	
 
r   r=   c                  .    e Zd ZddZddZddZdddZy)	
AsyncEventc                    d| _         y r   r   r   s    r   r   zAsyncEvent.__init__n   r   r   c                    t               | _        | j                  dk(  rt        j                         | _        y| j                  dk(  rt        j                         | _        yy)r    r
   r	   N)r   r   r
   Event_trio_eventr   _anyio_eventr   s    r   r%   zAsyncEvent.setupq   sG    
 ./==F"#zz|D]]i' %D (r   c                    | j                   s| j                          | j                   dk(  r| j                  j                          y | j                   dk(  r| j                  j                          y y r'   )r   r%   rK   setrL   r   s    r   rN   zAsyncEvent.set|   sS    }}JJL==F"  "]]i'!!# (r   Nc                  K   | j                   s| j                          | j                   dk(  rzt        j                  t        i}|t        d      n|}t        |      5  t        j                  |      5  | j                  j                          d {    d d d        d d d        y | j                   dk(  rat        t        i}t        |      5  t        j                  |      5  | j                  j                          d {    d d d        d d d        y y 7 # 1 sw Y   xY w# 1 sw Y   y xY w7 0# 1 sw Y   /xY w# 1 sw Y   y xY ww)Nr
   infr	   )r   r%   r
   TooSlowErrorr   floatr   
fail_afterrK   waitTimeoutErrorr   rL   )r   timeouttrio_exc_maptimeout_or_infanyio_exc_maps        r   rT   zAsyncEvent.wait   s!    }}JJL==F".2.?.?-ML-4_U5\'N- 2__^4 2**//11122 2 ]]i'/;[.IM. 3%%g. 3++0022233 3 ( 22 22 2 33 33 3s   AED'4DDDD'/EE$D5D3D5E
EDD$	 D''D0,E3D55D>	:EE
Er2   r@   rV   zfloat | Noner3   r4   )r7   r8   r9   r   r%   rN   rT   r;   r   r   rG   rG   m   s    	.$3r   rG   c                  ,    e Zd ZddZddZddZddZy)AsyncSemaphorec                     || _         d| _        y r   )_boundr   r   bounds     r   r   zAsyncSemaphore.__init__   s    r   c                $   t               | _        | j                  dk(  r1t        j                  | j                  | j                        | _        y| j                  dk(  r2t        j                  | j                  | j                  d      | _        yy)z
        Detect if we're running under 'asyncio' or 'trio' and create
        a semaphore with the correct implementation.
        r
   )initial_value	max_valuer	   T)rb   rc   r!   N)r   r   r
   	Semaphorer^   _trio_semaphorer   _anyio_semaphorer   s    r   r%   zAsyncSemaphore.setup   sj    
 ./==F"#'>>W[WbWb#cD ]]i'$)OO$++Y]YdYdsw$xD! (r   c                  K   | j                   s| j                          | j                   dk(  r#| j                  j                          d {    y | j                   dk(  r#| j                  j                          d {    y y 7 87 wr'   )r   r%   re   r(   rf   r   s    r   r(   zAsyncSemaphore.acquire   sl     }}JJL==F"&&..000]]i'''//111 ( 11s$   A	BB1B=B>BBc                   K   | j                   dk(  r| j                  j                          y | j                   dk(  r| j                  j                          y y wr'   )r   re   r+   rf   r   s    r   r+   zAsyncSemaphore.release   sG     ==F"  ((*]]i'!!))+ (r1   Nr`   intr3   r4   r2   )r7   r8   r9   r   r%   r(   r+   r;   r   r   r\   r\      s    	y2,r   r\   c                  :    e Zd ZddZddZ	 	 	 d	 	 	 	 	 	 	 ddZy)	AsyncShieldCancellationc                    t               | _        | j                  dk(  rt        j                  d      | _        y| j                  dk(  rt        j                  d      | _        yy)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__   sQ    
 ./==F" $ 0 0 =D]]i'!&!2!2$!?D (r   c                    | j                   dk(  r| j                  j                          | S | j                   dk(  r| j                  j                          | S r'   )r   rp   rA   rq   r   s    r   rA   z!AsyncShieldCancellation.__enter__   sL    ==F"'')  ]]i'((*r   Nc                    | j                   dk(  r| j                  j                  |||       y | j                   dk(  r| j                  j                  |||       y y r'   )r   rp   rD   rq   r,   s       r   rD   z AsyncShieldCancellation.__exit__   sQ     ==F"&&xIF]]i''')YG (r   r2   )r3   rl   r5   r6   )r7   r8   r9   r   rA   rD   r;   r   r   rl   rl      sH    
@ 04*.04		H,	H (	H .		H
 
	Hr   rl   c                  >    e Zd ZdZddZddZ	 	 	 d	 	 	 	 	 	 	 d	dZy)
r"   r   c                6    t        j                         | _        y r@   )	threadingr"   _lockr   s    r   r   zLock.__init__   s    ^^%
r   c                :    | j                   j                          | S r@   rw   r(   r   s    r   rA   zLock.__enter__       

r   Nc                8    | j                   j                          y r@   rw   r+   r,   s       r   rD   zLock.__exit__        	

r   r2   )r3   r"   r5   r6   r7   r8   r9   r:   r   rA   rD   r;   r   r   r"   r"      sG    & 04*.04	, ( .	
 
r   r"   c                  >    e Zd ZdZddZddZ	 	 	 d	 	 	 	 	 	 	 d	dZy)

ThreadLockr>   c                6    t        j                         | _        y r@   )rv   RLockrw   r   s    r   r   zThreadLock.__init__   s    __&
r   c                :    | j                   j                          | S r@   ry   r   s    r   rA   zThreadLock.__enter__  rz   r   Nc                8    | j                   j                          y r@   r|   r,   s       r   rD   zThreadLock.__exit__  r}   r   r2   )r3   r   r5   r6   r~   r;   r   r   r   r      sG    ' 04*.04	, ( .	
 
r   r   c                  &    e Zd ZddZddZdddZy)rJ   c                6    t        j                         | _        y r@   )rv   rJ   _eventr   s    r   r   zEvent.__init__  s    oo'r   c                8    | j                   j                          y r@   )r   rN   r   s    r   rN   z	Event.set  s    r   Nc                p    |t        d      k(  rd }| j                  j                  |      s
t               y )NrP   )rV   )rR   r   rT   r   )r   rV   s     r   rT   z
Event.wait  s5    eEl"G{{0- 1r   r2   r@   rZ   )r7   r8   r9   r   rN   rT   r;   r   r   rJ   rJ     s    ( r   rJ   c                  $    e Zd ZddZddZddZy)rd   c                :    t        j                  |      | _        y )N)value)rv   rd   
_semaphorer_   s     r   r   zSemaphore.__init__  s    #--E:r   c                8    | j                   j                          y r@   )r   r(   r   s    r   r(   zSemaphore.acquire"      !r   c                8    | j                   j                          y r@   )r   r+   r   s    r   r+   zSemaphore.release%  r   r   Nri   r2   )r7   r8   r9   r   r(   r+   r;   r   r   rd   rd     s    ;""r   rd   c                  2    e Zd ZddZ	 	 	 d	 	 	 	 	 	 	 ddZy)ShieldCancellationc                    | S r@   r;   r   s    r   rA   zShieldCancellation.__enter__-  rB   r   Nc                     y r@   r;   r,   s       r   rD   zShieldCancellation.__exit__0  rE   r   )r3   r   r5   r6   )r7   r8   r9   rA   rD   r;   r   r   r   r   )  s=    
 04*.04	, ( .	
 
r   r   )r3   str)
__future__r   rv   types_exceptionsr   r   r   r
   r   NotImplementedErrorr   r   r   r=   rG   r\   rl   r"   r   rJ   rd   r   r;   r   r   <module>r      s    "   F F

,*' *'Z (&3 &3R, ,@$H $HT 0 0   " " y 	() D
  Es"   B B 	BBB%$B%