o
    h(                     @   sl   d dl mZ d dlmZmZmZ d dlmZmZm	Z	m
Z
mZmZmZmZ ddlmZmZ G dd deZdS )	   )ConcurrencyBackend)	CertTypesTimeoutTypesVerifyTypes)AsyncRequestAsyncRequestDataAsyncResponseAsyncResponseContentRequestRequestDataResponseResponseContent   )AsyncDispatcher
Dispatcherc                   @   sz   e Zd ZdZdededdfddZ			dded	ed
e	de
def
ddZdddZdedefddZdedefddZdS )ThreadedDispatcherz
    The ThreadedDispatcher class is used to mediate between the Client
    (which always uses async under the hood), and a synchronous `Dispatch`
    class.
    dispatchbackendreturnNc                 C   s   || _ || _d S N)sync_dispatcherr   )selfr   r    r   _/var/www/html/magazine_api/magazine_env/lib/python3.10/site-packages/httpx/dispatch/threaded.py__init__   s   
zThreadedDispatcher.__init__requestverifycerttimeoutc              	      s   | j  t|dt|dd }| |}t|j|j|j|d}| jj}||||d}	| j j	|fi |	I d H t
ts=J tdtdd }
| |
}d fdd	}tjjj|||jd
S )NcontentZcontent_aiter)methodurlheadersdata)r   r   r   r   Z_raw_contentZ_raw_streamr   c                      s     jI d H  d S r   )run_in_threadpoolcloser   Zconcurrency_backendZsync_responser   r   async_on_close>   s   z/ThreadedDispatcher.send.<locals>.async_on_close)status_codehttp_versionr"   r   Zon_closer   historyr   N)r   getattr_sync_request_datar
   r    r!   r"   r   sendr$   
isinstancer   _async_response_contentr   r(   r)   r*   )r   r   r   r   r   r#   Z	sync_dataZsync_requestfunckwargsr   Zasync_contentr'   r   r&   r   r.      s@   

zThreadedDispatcher.sendc                    s    | j j}| j|I dH  dS )z
        The `.close()` method runs the `Dispatcher.close()` within a threadpool,
        so as not to block the async event loop.
        N)r   r%   r   r$   )r   r1   r   r   r   r%   L   s   zThreadedDispatcher.closer   c                 C   s(   t |tr|S t|dsJ | j|S )N__iter__)r/   byteshasattrr   Ziterate_in_threadpool)r   r   r   r   r   r0   T   s   
z*ThreadedDispatcher._async_response_contentr#   c                 C   s   t |tr|S | j|S r   )r/   r4   r   Ziterate)r   r#   r   r   r   r-   ]   s   
z%ThreadedDispatcher._sync_request_data)NNNr+   )__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r.   r%   r   r	   r0   r   r   r-   r   r   r   r   r      s(    

1	r   N)Zconcurrency.baser   configr   r   r   modelsr   r   r   r	   r
   r   r   r   baser   r   r   r   r   r   r   <module>   s
    (
