
    Mh}                       d dl m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gZddZddZ G d de          Z G d de	          ZdS )    )annotationsN   )RequestResponse)AsyncByteStream   )AsyncBaseTransportASGITransportreturnboolc                 f    	 dd l } |                                 dk    rdS n# t          $ r Y nw xY wdS )Nr   trioTF)sniffiocurrent_async_libraryImportError)r   s    V/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/httpx/_transports/asgi.pyis_running_trior      sZ    	 	((**f444 5    5s   ! 
..Eventc                 j    t                      rdd l}  | j                    S dd l} |j                    S )Nr   )r   r   r   asyncio)r   r   s     r   create_eventr   ,   s>     tz||NNN7=??    c                      e Zd Zd	dZd
dZdS )ASGIResponseStreambodylist[bytes]r   Nonec                    || _         d S N)_body)selfr   s     r   __init__zASGIResponseStream.__init__8   s    


r   typing.AsyncIterator[bytes]c               D   K   d                     | j                  W V  d S )Nr   )joinr    )r!   s    r   	__aiter__zASGIResponseStream.__aiter__;   s)      hhtz""""""""r   N)r   r   r   r   )r   r#   )__name__
__module____qualname__r"   r&    r   r   r   r   7   s<           # # # # # #r   r   c                  *    e Zd ZdZ	 	 	 dddZddZdS )r
   a  
    A custom AsyncTransport that handles sending requests directly to an ASGI app.

    ```python
    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{   app_ASGIAppraise_app_exceptionsr   	root_pathstrclienttuple[str, int]r   r   c                >    || _         || _        || _        || _        d S r   )r/   r1   r2   r4   )r!   r/   r1   r2   r4   s        r   r"   zASGITransport.__init__W   s%     $8!"r   requestr   r   c                  	
K   t          j        t                    sJ dddidj        d j        j        D             j        j        j        j        j        j	        
                    d          d         j        j        j        j        j        j        f| j        | j        d}j                                        d	d d 
g d	t#                      	d	fd}d	
fd}	 |                     |||           d {V  n4# t&          $ r' | j        r 	                                 d
i 
Y nw xY w	                                sJ J 
J t/                    }t1          
|          S )Nhttpversionz3.0z1.1c                @    g | ]\  }}|                                 |fS r*   )lower).0kvs      r   
<listcomp>z6ASGITransport.handle_async_request.<locals>.<listcomp>o   s(    III6AqAIIIr      ?r   )typeasgihttp_versionmethodheadersschemepathraw_pathquery_stringserverr4   r2   Fr   dict[str, typing.Any]c                    K   r                                  d {V  ddiS 	                                  d {V } n# t          $ r dddddcY S w xY wd| ddS )NrB   zhttp.disconnectTzhttp.requestr   F)rB   r   	more_body)wait	__anext__StopAsyncIteration)r   request_body_chunksrequest_completeresponse_completes    r   receivez3ASGITransport.handle_async_request.<locals>.receive   s         3',,......... 122Q0::<<<<<<<<% Q Q Q#'  .%PPPPPQ +DtLLLs   A   AAmessage&typing.MutableMapping[str, typing.Any]r   c                  K   | d         dk    r&rJ | d         |                      dg           dd S | d         dk    r|                                rJ |                      dd          }|                      d	d
          }|r j        dk    r                    |           |s                                 d S d S d S )NrB   zhttp.response.startstatusrF   Tzhttp.response.bodyr   r   rN   FHEAD)getis_setrE   appendset)	rV   r   rN   
body_partsr7   rT   response_headersresponse_startedstatus_codes	      r   sendz0ASGITransport.handle_async_request.<locals>.send   s       v"777++++%h/#*;;y"#=#= #'   $888,3355555{{63//#KKU;;	 ,GNf44%%d+++  ,%))+++++ 98, ,r   i  )rF   stream)r   rL   )rV   rW   r   r   )
isinstancerd   r   rE   rF   rawurlrG   rH   rI   splitqueryhostportr4   r2   r&   r   r/   	Exceptionr1   r^   r\   r   r   )r!   r7   scoperU   rc   rd   r_   rR   rS   rT   r`   ra   rb   s    `    @@@@@@@r   handle_async_requestz"ASGITransport.handle_async_requestc   s,      './::::: &!nIIW_5HIIIk(K$,22488;#K-{')9:k
 
  &n6688  
 (NN	M 	M 	M 	M 	M 	M 	M 	M	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,*
	&((5'40000000000 	& 	& 	&( !!###"!'#% 	& !'')))))&&&+++#J//-=fMMMMs   7D .EEN)Tr,   r-   )
r/   r0   r1   r   r2   r3   r4   r5   r   r   )r7   r   r   r   )r'   r(   r)   __doc__r"   rn   r*   r   r   r
   r
   ?   sb         4 &*"4
 
 
 
 
XN XN XN XN XN XNr   )r   r   )r   r   )
__future__r   typing_modelsr   r   _typesr   baser	   TYPE_CHECKINGr   r   Unionr   MutableMappingr3   Any_MessageCallable	Awaitable_Receive_Sendr0   __all__r   r   r   r
   r*   r   r   <module>r      s   " " " " " "  ' ' ' ' ' ' ' ' $ $ $ $ $ $ $ $ $ $ $ $	 4NNNKKKL
23E  fj1?2v/99:3
?+,f.>t.DD	 ?3
?+Xu=v?OPT?UU 
      # # # # # # # #|N |N |N |N |N& |N |N |N |N |Nr   