o
    h                     @   s   d dl Z d dlZd dlmZ ddlmZm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   )
PoolLimitsTimeoutConfigc                   @   s.   e Zd ZdZd
ddZd
ddZd
dd	ZdS )TimeoutFlaga  
    A timeout flag holds a state of either read-timeout or write-timeout mode.

    We use this so that we can attempt both reads and writes concurrently, while
    only enforcing timeouts in one direction.

    During a request/response cycle we start in write-timeout mode.

    Once we've sent a request fully, or once we start seeing a response,
    then we switch to read-timeout mode instead.
    returnNc                 C   s   d| _ d| _d S )NFTZraise_on_read_timeoutZraise_on_write_timeoutself r   ^/var/www/html/magazine_api/magazine_env/lib/python3.10/site-packages/httpx/concurrency/base.py__init__   s   
zTimeoutFlag.__init__c                 C      d| _ d| _dS )z4
        Set the flag to read-timeout mode.
        TFNr   r	   r   r   r   set_read_timeouts      
zTimeoutFlag.set_read_timeoutsc                 C   r   )z5
        Set the flag to write-timeout mode.
        FTNr   r	   r   r   r   set_write_timeouts    r   zTimeoutFlag.set_write_timeoutsr   N)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r      s
    

r   c                	   @   s   e Zd ZdZdefddZ	ddededej	de
fd	d
Zde
ddfddZdde
deddfddZdddZdefddZdS )BaseTCPStreamz
    A TCP stream with read/write operations. Abstracts away any asyncio-specific
    interfaces into a more generic base class, that we can use with alternate
    backends, or for stand-alone test cases.
    r   c                 C      t  NNotImplementedErrorr	   r   r   r   get_http_version/      zBaseTCPStream.get_http_versionNntimeoutflagc                       t  r   r   )r
   r   r   r    r   r   r   read2      zBaseTCPStream.readdatac                 C   r   r   r   )r
   r$   r   r   r   write_no_block7   r   zBaseTCPStream.write_no_blockc                    r!   r   r   )r
   r$   r   r   r   r   write:      zBaseTCPStream.writec                    r!   r   r   r	   r   r   r   close=   r'   zBaseTCPStream.closec                 C   r   r   r   r	   r   r   r   is_connection_dropped@   r   z#BaseTCPStream.is_connection_dropped)NNr   r   )r   r   r   r   strr   intr   typingAnybytesr"   r%   r&   r(   boolr)   r   r   r   r   r   (   s"    

r   c                   @   s4   e Zd ZdZdejfddZdejddfddZdS )		BaseQueuezG
    A FIFO queue. Abstracts away any asyncio-specific interfaces.
    r   c                    r!   r   r   r	   r   r   r   getI   r'   zBaseQueue.getvalueNc                    r!   r   r   )r
   r2   r   r   r   putL   r'   zBaseQueue.put)r   r   r   r   r,   r-   r1   r3   r   r   r   r   r0   D   s    r0   c                   @   s<   e Zd ZdZdddZdefddZddd	Zdd
dZdS )	BaseEventzJ
    An event object. Abstracts away any asyncio-specific interfaces.
    r   Nc                 C   r   r   r   r	   r   r   r   setU   r   zBaseEvent.setc                 C   r   r   r   r	   r   r   r   is_setX   r   zBaseEvent.is_setc                 C   r   r   r   r	   r   r   r   clear[   r   zBaseEvent.clearc                    r!   r   r   r	   r   r   r   wait^   r'   zBaseEvent.waitr   )	r   r   r   r   r5   r/   r6   r7   r8   r   r   r   r   r4   P   s    

r4   c                   @   s$   e Zd ZdZdddZdddZdS )	BasePoolSemaphorezk
    A semaphore for use with connection pooling.

    Abstracts away any asyncio-specific interfaces.
    r   Nc                    r!   r   r   r	   r   r   r   acquirei   r'   zBasePoolSemaphore.acquirec                 C   r   r   r   r	   r   r   r   releasel   r   zBasePoolSemaphore.releaser   )r   r   r   r   r:   r;   r   r   r   r   r9   b   s    
r9   c                
   @   s   e Zd Zdededejej de	de
f
ddZde
dedejde	de
f
d	d
ZdedefddZdejdejdejdejfddZdd ZdejdejdejdejfddZdd ZdedefddZdefddZdejdejddfd d!Zd"S )#ConcurrencyBackendhostnameportssl_contextr   r   c                    r!   r   r   )r
   r=   r>   r?   r   r   r   r   open_tcp_streamq      z"ConcurrencyBackend.open_tcp_streamstreamc                    r!   r   r   )r
   rB   r=   r?   r   r   r   r   	start_tlsz   rA   zConcurrencyBackend.start_tlslimitsc                 C   r   r   r   )r
   rD   r   r   r   get_semaphore   r   z ConcurrencyBackend.get_semaphorefuncargskwargsc                    r!   r   r   )r
   rF   rG   rH   r   r   r   run_in_threadpool   r#   z$ConcurrencyBackend.run_in_threadpoolc                   sP   G dd dt   fdd}	 z| ||I d H V  W n
  y&   Y d S w q)Nc                   @   s   e Zd ZdS )zCConcurrencyBackend.iterate_in_threadpool.<locals>.IterationCompleteN)r   r   r   r   r   r   r   IterationComplete   s    rJ   c                    s    zt | W S  ty     w r   )nextStopIteration)iteratorrJ   r   r   next_wrapper   s
   
z>ConcurrencyBackend.iterate_in_threadpool.<locals>.next_wrapper)	ExceptionrI   )r
   rM   rO   r   rN   r   iterate_in_threadpool   s   z(ConcurrencyBackend.iterate_in_threadpool	coroutinec                 O   r   r   r   )r
   rR   rG   rH   r   r   r   run      zConcurrencyBackend.runc                 c   s.    	 z	|  |jV  W n
 ty   Y d S w qr   )rS   	__anext__StopAsyncIteration)r
   Zasync_iteratorr   r   r   iterate   s   zConcurrencyBackend.iteratemax_sizec                 C   r   r   r   )r
   rX   r   r   r   create_queue   r   zConcurrencyBackend.create_queuec                 C   r   r   r   r	   r   r   r   create_event   r   zConcurrencyBackend.create_eventBaseBackgroundManagerc                 G   r   r   r   )r
   rR   rG   r   r   r   background_manager   rT   z%ConcurrencyBackend.background_managerN)r   r   r   r*   r+   r,   Optionalssl
SSLContextr   r   r@   rC   r   r9   rE   Callabler-   rI   rQ   rS   rW   r0   rY   r4   rZ   r\   r   r   r   r   r<   p   sj    

	
	

r<   c                	   @   sR   e Zd ZdddZ			ddeje dededdfdd	Zdd
eddfddZ	dS )r[   r   c                    r!   r   r   r	   r   r   r   
__aenter__   r'   z BaseBackgroundManager.__aenter__Nexc_type	exc_value	tracebackc                    r!   r   r   )r
   rb   rc   rd   r   r   r   	__aexit__   s   zBaseBackgroundManager.__aexit__	exceptionc                    sD   |d u r|  d d d I d H  d S |j}|  t|||I d H  d S r   )re   __traceback__type)r
   rf   rd   r   r   r   r(      s
   zBaseBackgroundManager.close)r   r[   )NNNr   )
r   r   r   ra   r,   TypeBaseExceptionr   re   r(   r   r   r   r   r[      s    

r[   )r^   r,   typesr   configr   r   r   r   r0   r4   r9   r<   r[   r   r   r   r   <module>   s     C