o
    Þ­jr  ã                   @  s  d dl mZ 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r6d 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d„ZG dd„ deƒZG dd„ de
ƒZdS )é    )ÚannotationsNé   )ÚRequestÚResponse)ÚAsyncByteStreamé   )ÚAsyncBaseTransportÚASGITransportÚ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   úS/var/www/html/CropPilot/venv/lib/python3.10/site-packages/httpx/_transports/asgi.pyÚcreate_event   s
   r   c                   @  s    e Zd Zddd„Zddd	„Zd
S )ÚASGIResponseStreamÚbodyúlist[bytes]r
   ÚNonec                 C  s
   || _ d S ©N)Ú_body)Úselfr   r   r   r   Ú__init__+   s   
zASGIResponseStream.__init__útyping.AsyncIterator[bytes]c                 C s   �d  | j¡V  d S )Nó    )Újoinr   )r   r   r   r   Ú	__aiter__.   s   €zASGIResponseStream.__aiter__N)r   r   r
   r   )r
   r   )Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   *   s    
r   c                   @  s,   e Zd ZdZ			dddd„Zd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_exceptionsÚboolÚ	root_pathÚstrÚclientútuple[str, int]r
   r   c                 C  s   || _ || _|| _|| _d S r   )r%   r'   r)   r+   )r   r%   r'   r)   r+   r   r   r   r   J   s   
zASGITransport.__init__Úrequestr   r   c                 ƒ  sJ  �t ˆjtƒs	J ‚dddidˆjd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„}d‡ ‡‡‡‡‡fdd„}z|  |||¡I d H  W n ty‡   | jru‚ ˆ ¡  ˆd u rd‰ˆd u r…i ‰Y nw ˆ ¡ sŽJ ‚ˆd us”J ‚ˆd usšJ ‚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>b   s    z6ASGITransport.handle_async_request.<locals>.<listcomp>ó   ?r   )ÚtypeÚasgiÚhttp_versionÚmethodÚheadersÚschemeÚpathÚraw_pathÚquery_stringÚserverr+   r)   Fr
   údict[str, typing.Any]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 )Nr6   zhttp.disconnectTzhttp.requestr   F)r6   r   Ú	more_body)ÚwaitÚ	__anext__ÚStopAsyncIteration)r   )Úrequest_body_chunksÚrequest_completeÚresponse_completer   r   Úreceivey   s   €þz3ASGITransport.handle_async_request.<locals>.receiveÚmessageú&typing.MutableMapping[str, typing.Any]r   c                 “  s’   �| d dkrˆrJ ‚| d ‰|   dg ¡‰d‰d S | d dkrEˆ ¡ r%J ‚|   dd¡}|   d	d
¡}|r=ˆjdkr=ˆ  |¡ |sGˆ ¡  d S d S d S )Nr6   zhttp.response.startÚstatusr:   Tzhttp.response.bodyr   r   rA   FÚHEAD)ÚgetÚis_setr9   ÚappendÚset)rI   r   rA   )Ú
body_partsr-   rG   Úresponse_headersÚresponse_startedÚstatus_coder   r   Úsend‡   s    €
÷z0ASGITransport.handle_async_request.<locals>.sendiô  )r:   Ústream)r
   r@   )rI   rJ   r
   r   )Ú
isinstancerV   r   r9   r:   ÚrawÚurlr;   r<   r=   ÚsplitÚqueryÚhostÚportr+   r)   r   r   r%   Ú	Exceptionr'   rP   rN   r   r   )r   r-   ÚscoperH   rU   rV   r   )rQ   r-   rE   rF   rG   rR   rS   rT   r   Úhandle_async_requestV   sR   €ô
€ø
z"ASGITransport.handle_async_requestN)Tr"   r#   )
r%   r&   r'   r(   r)   r*   r+   r,   r
   r   )r-   r   r
   r   )r   r    r!   Ú__doc__r   r`   r   r   r   r   r	   2   s    û)r
   r   )Ú
__future__r   Útypingr   Ú_modelsr   r   Ú_typesr   Úbaser   ÚTYPE_CHECKINGr   r   ÚUnionr   ÚMutableMappingr*   ÚAnyÚ_MessageÚCallableÚ	AwaitableÚ_ReceiveÚ_Sendr&   Ú__all__r   r   r	   r   r   r   r   Ú<module>   s,    ÿÿ
