o
    ¨Ýj0(  ã                	   @  s:  d dl mZ d dlZd dlZddlmZmZmZ zd dlZW n e	e
fy+   dZY nw zd dlZW n e	y=   dZY nw zd dlZW n e	yO   dZY nw 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 )é    )ÚannotationsNé   )ÚExceptionMappingÚPoolTimeoutÚmap_exceptionsÚreturnÚstrc                  C  sZ   t d u rd} nt  ¡ } | dvrtdƒ‚| dkrtd u rtdƒ‚| dkr+td u r+tdƒ‚| S )NÚ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ÚRuntimeErrorÚanyior
   )Úenvironment© r   úU/var/www/html/chatgpt/venv/lib/python3.10/site-packages/httpcore2/_synchronization.pyr      s   r   c                   @  s@   e Zd ZdZddd„Zddd„Zddd	„Z	
	
	
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.
    r   ÚNonec                 C  ó
   d| _ d S ©NÚ ©Ú_backend©Úselfr   r   r   Ú__init__7   ó   
zAsyncLock.__init__c                 C  s@   t ƒ | _| jdkrt ¡ | _dS | jdkrtjdd�| _dS dS )ú~
        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   r   r   r   Úsetup:   s   

ÿzAsyncLock.setupc                 Ã  sL   �| j s|  ¡  | j dkr| j ¡ I d H  | S | j dkr$| j ¡ I d H  | S ©Nr
   r	   )r   r#   r!   Úacquirer"   r   r   r   r   Ú
__aenter__E   s   €

ýzAsyncLock.__aenter__NÚexc_typeútype[BaseException] | NoneÚ	exc_valueúBaseException | NoneÚ	tracebackútypes.TracebackType | Nonec                 Ã  ó6   �| j dkr| j ¡  d S | j dkr| j ¡  d S d S r$   )r   r!   Úreleaser"   ©r   r'   r)   r+   r   r   r   Ú	__aexit__P   s   €

ÿzAsyncLock.__aexit__©r   r   )r   r   ©NNN©r'   r(   r)   r*   r+   r,   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r#   r&   r0   r   r   r   r   r   /   s    


ür   c                   @  s,   e Zd ZdZddd„Z			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 ©Nr   r   r   r   r   Ú	__enter__d   ó   zAsyncThreadLock.__enter__Nr'   r(   r)   r*   r+   r,   r   c                 C  ó   d S r;   r   r/   r   r   r   Ú__exit__g   ó   zAsyncThreadLock.__exit__)r   r8   r2   r3   )r4   r5   r6   r7   r<   r?   r   r   r   r   r8   \   s    
ür8   c                   @  s6   e Zd Zddd„Zddd„Zddd„Zdddd„Zd	S )Ú
AsyncEventr   r   c                 C  r   r   r   r   r   r   r   r   q   r   zAsyncEvent.__init__c                 C  s<   t ƒ | _| jdkrt ¡ | _dS | jdkrt ¡ | _dS dS )r   r
   r	   N)r   r   r
   ÚEventÚ_trio_eventr   Ú_anyio_eventr   r   r   r   r#   t   s   

ÿzAsyncEvent.setupc                 C  sB   | j s|  ¡  | j dkr| j ¡  d S | j dkr| j ¡  d S d S r$   )r   r#   rC   ÚsetrD   r   r   r   r   rE      s   

ÿzAsyncEvent.setNÚtimeoutúfloat | Nonec              	   Ã  s>  �| j s|  ¡  | j dkrXtjti}|d u rtdƒn|}t|ƒ�. t |¡� | j 	¡ I d H  W d   ƒ n1 s9w   Y  W d   ƒ d S W d   ƒ d S 1 sQw   Y  d S | j dkr�t
ti}t|ƒ�. t |¡� | j 	¡ I d H  W d   ƒ n1 s~w   Y  W d   ƒ d S W d   ƒ d S 1 s–w   Y  d S d S )Nr
   Úinfr	   )r   r#   r
   ZTooSlowErrorr   Úfloatr   Z
fail_afterrC   ÚwaitÚTimeoutErrorr   rD   )r   rF   Ztrio_exc_mapZtimeout_or_infZanyio_exc_mapr   r   r   rJ   ˆ   s.   €


ÿÿ"ÿ

ÿÿ"ÿþzAsyncEvent.waitr1   r;   ©rF   rG   r   r   )r4   r5   r6   r   r#   rE   rJ   r   r   r   r   rA   p   s
    


	rA   c                   @  s>   e Zd Zddd„Zddd„Zdd	d
„Zddd„Zddd„ZdS )ÚAsyncSemaphoreÚboundÚintr   r   c                 C  s   || _ d| _d S r   )Ú_boundr   ©r   rN   r   r   r   r   š   s   
zAsyncSemaphore.__init__c                 C  sR   t ƒ | _| jdkrtj| j| jd�| _dS | jdkr'tj| j| jdd�| _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	   T)rR   rS   r   N)r   r   r
   Ú	SemaphorerP   Ú_trio_semaphorer   Ú_anyio_semaphorer   r   r   r   r#   ž   s   

ÿzAsyncSemaphore.setupc                 Ã  sP   �| j s|  ¡  | j dkr| j ¡ I d H  d S | j dkr&| j ¡ I d H  d S d S r$   )r   r#   rU   r%   rV   r   r   r   r   r%   ©   s   €

ÿzAsyncSemaphore.acquireÚboolc                 C  sh   | j dkrz| j ¡  W dS  tjy   Y dS w | j dkr2z| j ¡  W dS  tjy1   Y dS w dS )zö
        Acquire a permit if one is immediately available, without blocking.
        Returns True if a permit was acquired.

        Like `release()`, this requires `setup()` to have run, which any
        prior `acquire()` call ensures.
        r
   FTr	   )r   rU   Zacquire_nowaitr
   Z
WouldBlockrV   r   r   r   r   r   Úacquire_if_available²   s   
þÿ
þÿz#AsyncSemaphore.acquire_if_availablec                 Ã  r-   r$   )r   rU   r.   rV   r   r   r   r   r.   È   s   €

ÿzAsyncSemaphore.releaseN©rN   rO   r   r   r1   ©r   rW   )r4   r5   r6   r   r#   r%   rX   r.   r   r   r   r   rM   ™   s    



	rM   c                   @  s2   e Zd Zddd„Zddd„Z			dddd„ZdS )ÚAsyncShieldCancellationr   r   c                 C  sD   t ƒ | _| jdkrtjdd�| _dS | jdkr tjd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
   ZCancelScopeÚ_trio_shieldr   Ú_anyio_shieldr   r   r   r   r   ×   s   

ÿz AsyncShieldCancellation.__init__c                 C  s0   | j dkr| j ¡  | S | j dkr| j ¡  | S r$   )r   r]   r<   r^   r   r   r   r   r<   ã   s   


þ
z!AsyncShieldCancellation.__enter__Nr'   r(   r)   r*   r+   r,   c                 C  s@   | j dkr| j |||¡ d S | j dkr| j |||¡ d S d S r$   )r   r]   r?   r^   r/   r   r   r   r?   ê   s
   

ÿz AsyncShieldCancellation.__exit__r1   )r   r[   r2   r3   )r4   r5   r6   r   r<   r?   r   r   r   r   r[   Ï   s    

	ür[   c                   @  ó6   e Zd ZdZddd„Zddd„Z			dddd„ZdS )r    r   r   r   c                 C  ó   t  ¡ | _d S r;   )Ú	threadingr    Ú_lockr   r   r   r   r     ó   zLock.__init__c                 C  ó   | j  ¡  | S r;   ©rb   r%   r   r   r   r   r<     ó   
zLock.__enter__Nr'   r(   r)   r*   r+   r,   c                 C  ó   | j  ¡  d S r;   ©rb   r.   r/   r   r   r   r?     ó   zLock.__exit__r1   )r   r    r2   r3   ©r4   r5   r6   r7   r   r<   r?   r   r   r   r   r    ù   ó    

ür    c                   @  r_   )Ú
ThreadLockr9   r   r   c                 C  r`   r;   )ra   ÚRLockrb   r   r   r   r   r     rc   zThreadLock.__init__c                 C  rd   r;   re   r   r   r   r   r<     rf   zThreadLock.__enter__Nr'   r(   r)   r*   r+   r,   c                 C  rg   r;   rh   r/   r   r   r   r?      ri   zThreadLock.__exit__r1   )r   rl   r2   r3   rj   r   r   r   r   rl     rk   rl   c                   @  s,   e Zd Zddd„Zddd„Zddd
d„ZdS )rB   r   r   c                 C  r`   r;   )ra   rB   Ú_eventr   r   r   r   r   *  rc   zEvent.__init__c                 C  rg   r;   )rn   rE   r   r   r   r   rE   -  rc   z	Event.setNrF   rG   c                 C  s(   |t dƒkrd }| jj|d�stƒ ‚d S )NrH   )rF   )rI   rn   rJ   r   )r   rF   r   r   r   rJ   0  s
   ÿz
Event.waitr1   r;   rL   )r4   r5   r6   r   rE   rJ   r   r   r   r   rB   )  s    

rB   c                   @  s4   e Zd Zddd„Zddd„Zdd
d„Zddd„ZdS )rT   rN   rO   r   r   c                 C  s   t j|d�| _d S )N)Úvalue)ra   rT   Ú
_semaphorerQ   r   r   r   r   8  s   zSemaphore.__init__c                 C  rg   r;   ©rp   r%   r   r   r   r   r%   ;  rc   zSemaphore.acquirerW   c                 C  s   | j jdd�S )NF)Úblockingrq   r   r   r   r   rX   >  rc   zSemaphore.acquire_if_availablec                 C  rg   r;   )rp   r.   r   r   r   r   r.   A  rc   zSemaphore.releaseNrY   r1   rZ   )r4   r5   r6   r   r%   rX   r.   r   r   r   r   rT   7  s
    


rT   c                   @  s(   e Zd Zddd„Z			dddd„ZdS )ÚShieldCancellationr   c                 C  r:   r;   r   r   r   r   r   r<   I  r=   zShieldCancellation.__enter__Nr'   r(   r)   r*   r+   r,   r   c                 C  r>   r;   r   r/   r   r   r   r?   L  r@   zShieldCancellation.__exit__)r   rs   r2   r3   )r4   r5   r6   r<   r?   r   r   r   r   rs   E  s    
ürs   )r   r   )Ú
__future__r   ra   ÚtypesÚ_exceptionsr   r   r   r
   ÚImportErrorÚNotImplementedErrorr   r   r   r   r8   rA   rM   r[   r    rl   rB   rT   rs   r   r   r   r   Ú<module>   s<    ÿÿÿ
-)6*