o
    Ehw                     @   s   d dl Z d dl mZmZmZmZmZ d dlZd dlZddlm	Z	 ddl
mZ e jr:d dlZd dlZe jejejf Zddd	ZG d
d dejZG dd deZdS )    N)CallableDictListOptionalTuple   )
ByteStream)warn_deprecatedreturnEventc                  C   s,   t  dkrdd l} |  S dd l}| S )Ntrior   )sniffiocurrent_async_libraryr   r   asyncio)r   r    r   Q/var/www/html/env_mimamsha/lib/python3.10/site-packages/httpx/_transports/asgi.pycreate_event   s
   r   c                   @   s   e Zd ZdZ			ddedededeeef d	d
f
ddZ		
	
	
dde
dee
e
ee e
f deee
e
f  dejdeeee f d	ee
ee
eee
e
f  ejf fddZd
S )ASGITransporta  
    A custom AsyncTransport that handles sending requests directly to an ASGI app.
    The simplest way to use this functionality is to use the `app` argument.

    ```
    client = httpx.AsyncClient(app=app)
    ```

    Alternatively, you can setup the dispatch instance explicitly.
    This allows you to include any additional configuration arguments specific
    to the ASGITransport class:

    ```
    dispatch = httpx.ASGITransport(
        app=app,
        root_path="/submount",
        client=("1.2.3.4", 123)
    )
    client = httpx.AsyncClient(dispatch=dispatch)
    ```

    Arguments:

    * `app` - The ASGI application.
    * `raise_app_exceptions` - Boolean indicating if exceptions in the application
       should be raised. Default to `True`. Can be set to `False` for use cases
       such as testing the content of a client 500 response.
    * `root_path` - The root path on which the ASGI application should be mounted.
    * `client` - A two-tuple indicating the client IP and port of incoming requests.
    ```
    T z	127.0.0.1{   appraise_app_exceptions	root_pathclientr
   Nc                 C   s   || _ || _|| _|| _d S )Nr   r   r   r   selfr   r   r   r   r   r   r   __init__=   s   
zASGITransport.__init__methodurlheadersstreamtimeoutc                    sP  |\}}}}	|	 d\}
}}dddid ||d|
d||d|f| j| jd}d d g  ddt |d u rAg n|}|d u rKtd	n|}| d
tffdd}dtd
d f fdd}z| |||I d H  W n t	y   | j
ss Y nw  sJ d usJ d usJ td	 }dd	|fS )N   ?httpversionz3.0z1.1ascii)typeasgihttp_versionr   r!   schemepathquery_stringserverr   r   F    r
   c                     s^   r  I d H  ddiS z	  I d H } W n ty(   ddddd Y S w d| ddS )Nr(   zhttp.disconnectTzhttp.requestr/   F)r(   body	more_body)wait	__anext__StopAsyncIteration)r0   )request_body_chunksrequest_completeresponse_completer   r   receivel   s   z&ASGITransport.request.<locals>.receivemessagec                    s   | d dkrrJ | d |  dg dd S | d dkrD r%J |  dd}|  d	d
}|r<dkr< | |sF  d S d S d S )Nr(   zhttp.response.startstatusr!   Tzhttp.response.bodyr0   r/   r1   Fs   HEAD)getis_setappendset)r9   r0   r1   )
body_partsr   r7   response_headersresponse_startedstatus_coder   r   sendz   s    
z#ASGITransport.request.<locals>.sends   HTTP/1.1)	partitiondecoder   r   r   r   	__aiter__dictr   	Exceptionr   r<   join)r   r   r    r!   r"   r#   r+   hostport	full_pathr,   _queryscoper8   rC   r   )r?   r   r5   r6   r7   r@   rA   rB   r   requestI   sL    
zASGITransport.requestTr   r   )NNN)__name__
__module____qualname____doc__r   boolstrr   intr   bytesr   r   httpcoreAsyncByteStreamr   floatrP   r   r   r   r   r      s@    #

r   c                       sB   e Zd Z			ddedededeeef dd	f
 fd
dZ  Z	S )ASGIDispatchTr   r   r   r   r   r   r
   Nc                    s    t d t j||||d d S )Nz4ASGIDispatch is deprecated, please use ASGITransportr   )r	   superr   r   	__class__r   r   r      s   
zASGIDispatch.__init__rQ   )
rR   rS   rT   r   rV   rW   r   rX   r   __classcell__r   r   r_   r   r]      s    
r]   )r
   r   )typingr   r   r   r   r   rZ   r   _content_streamsr   _utilsr	   TYPE_CHECKINGr   r   Unionr   r   AsyncHTTPTransportr   r]   r   r   r   r   <module>   s    
 