a
    !f]                     @   s   d dl Z d dlZddlmZm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e jee jf Ze jg e je f Ze je jee jf ge jd f Ze je jee jf eege jd f Zdd	d
dZG dd deZG dd deZdS )    N   )RequestResponse)AsyncByteStream   )AsyncBaseTransport)NNNEventreturnc                  C   s0   t  dkrdd l} |  S dd l}| S d S )Ntrior   )sniffioZcurrent_async_libraryr   r   asyncio)r   r    r   W/var/www/html/python-backend/venv/lib/python3.9/site-packages/httpx/_transports/asgi.pycreate_event   s
    r   c                   @   s6   e Zd Zeje ddddZeje dddZdS )ASGIResponseStreamN)bodyr
   c                 C   s
   || _ d S N)_body)selfr   r   r   r   __init__'   s    zASGIResponseStream.__init__r	   c                 C  s   d | jV  d S )N    )joinr   )r   r   r   r   	__aiter__*   s    zASGIResponseStream.__aiter__)	__name__
__module____qualname__typingListbytesr   AsyncIteratorr   r   r   r   r   r   &   s   r   c                   @   sB   e Zd ZdZdeeeejee	f ddddZ
eed	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 transport instance explicitly.
    This allows you to include any additional configuration arguments specific
    to the ASGITransport class:

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

    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{   N)appraise_app_exceptions	root_pathclientr
   c                 C   s   || _ || _|| _|| _d S r   )r%   r&   r'   r(   )r   r%   r&   r'   r(   r   r   r   r   O   s    zASGITransport.__init__)requestr
   c                    sn  t jtsJ dddidjdd jjD jjjjjj	jj
jjjjf| j| jd}j dd d g  dt tjttjf d	fd
d}tjttjf d d fdd}z| |||I d H  W nB ty,   | jr   d u rdd u r(i Y n0  s<J d usJJ d usXJ t }t|dS )Nhttpversionz3.0z1.1c                 S   s   g | ]\}}|  |fqS r   )lower).0kvr   r   r   
<listcomp>g   r   z6ASGITransport.handle_async_request.<locals>.<listcomp>)typeZasgihttp_versionmethodheadersschemepathraw_pathZquery_stringserverr(   r'   Fr	   c                     s\   r  I d H  ddiS z  I d H } W n" tyN   ddddd Y S 0 d| ddS )Nr1   zhttp.disconnectTzhttp.requestr   F)r1   r   	more_body)wait	__anext__StopAsyncIteration)r   )request_body_chunksrequest_completeresponse_completer   r   receive~   s    z3ASGITransport.handle_async_request.<locals>.receive)messager
   c                    s   | d dkr.rJ | d |  dg dnT| d dkr rFJ |  dd}|  d	d
}|rvjdkrv | |s  d S )Nr1   zhttp.response.startstatusr4   Tzhttp.response.bodyr   r   r9   FHEAD)getis_setr3   appendset)rA   r   r9   )
body_partsr)   r?   response_headersresponse_startedstatus_coder   r   send   s    
z0ASGITransport.handle_async_request.<locals>.sendi  )r4   stream)
isinstancerM   r   r3   r4   rawurlr5   r6   r7   queryhostportr(   r'   r   r   r   DictstrAnyr%   	Exceptionr&   rG   rE   r   r   )r   r)   scoper@   rL   rM   r   )rH   r)   r=   r>   r?   rI   rJ   rK   r   handle_async_request[   sL    
"*


z"ASGITransport.handle_async_request)Tr"   r#   )r   r   r   __doc___ASGIAppboolrU   r   Tupleintr   r   r   rY   r   r   r   r   r!   .   s   #   r!   )r   r   Z_modelsr   r   _typesr   baser   TYPE_CHECKINGr   r   Unionr   rT   rU   rV   Z_MessageCallable	AwaitableZ_Receive	CoroutineZ_Sendr[   r   r   r!   r   r   r   r   <module>   s&   