Ë
    Eü´j(  ã                  óæ   — d dl mZ d dlZd dl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                  rd dlmZ d d	lmZ  ej$                  d
«      ZdgZdd„Z G d„ de
«      Z G d„ de«      Zy)é    )ÚannotationsNé   )ÚRequestÚResponse)ÚSyncByteStreamé   )ÚBaseTransport)Ú
OptExcInfo)ÚWSGIApplicationÚ_TÚWSGITransportc                ó`   — t        | «      } | D ]  }|sŒt        j                  |g| «      c S  g S ©N)ÚiterÚ	itertoolsÚchain)ÚbodyÚchunks     úU/root/workspace/ytshorts/venv/lib/python3.12/site-packages/httpx2/_transports/wsgi.pyÚ_skip_leading_empty_chunksr      s7   € Ü�‹:€DØò 2ˆÚÜ—?‘? E 7¨DÓ1Ò1ð2ð €Ió    c                  ó$   — e Zd Zdd„Zdd„Zdd„Zy)ÚWSGIByteStreamc                óH   — t        |dd «      | _        t        |«      | _        y )NÚclose)ÚgetattrÚ_closer   Ú_result)ÚselfÚresults     r   Ú__init__zWSGIByteStream.__init__   s   € Ü˜f g¨tÓ4ˆŒÜ1°&Ó9ˆ�r   c              #  ó8   K  — | j                   E d {  –—†  y 7 Œ­wr   )r   ©r   s    r   Ú__iter__zWSGIByteStream.__iter__#   s   è ø€ Ø—<‘<×Òús   ‚’“c                ó>   — | j                   �| j                  «        y y r   )r   r#   s    r   r   zWSGIByteStream.close&   s   € Ø�;‰;Ð"Ø�K‰K�Mð #r   N)r    ztyping.Iterable[bytes]ÚreturnÚNone)r&   ztyping.Iterator[bytes])r&   r'   )Ú__name__Ú
__module__Ú__qualname__r!   r$   r   © r   r   r   r      s   „ ó:ó ôr   r   c                  ó@   — e Zd ZdZ	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 dd„Zdd„Zy)r   a  
    A custom transport that handles sending requests directly to an WSGI app.
    The simplest way to use this functionality is to use the `app` argument.

    ```
    client = httpx2.Client(app=app)
    ```

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

    ```
    transport = httpx2.WSGITransport(
        app=app,
        script_name="/submount",
        remote_addr="1.2.3.4"
    )
    client = httpx2.Client(transport=transport)
    ```

    Arguments:
        app: The WSGI 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.
        script_name: The root path on which the WSGI application should be mounted.
        remote_addr: A string indicating the client IP of incoming requests.
    Nc                óJ   — || _         || _        || _        || _        || _        y r   )ÚappÚraise_app_exceptionsÚscript_nameÚremote_addrÚwsgi_errors)r   r.   r/   r0   r1   r2   s         r   r!   zWSGITransport.__init__J   s+   € ð ˆŒØ$8ˆÔ!Ø&ˆÔØ&ˆÔØ&ˆÕr   c                óð  ‡‡‡— |j                  «        t        j                  |j                  «      }|j                  j
                  xs dddœ|j                  j                     }d|j                  j                  || j                  xs t        j                  ddd|j                  | j                  |j                  j                  |j                  j                  j                  d«      |j                  j                  t!        |«      d| j"                  d	œ}|j                  r/d
|j$                  vr!t!        t'        |j                  «      «      |d<   |j$                  j(                  D ]Q  \  }}|j                  d«      j+                  «       j-                  dd«      }|dvrd|z   }|j                  d«      ||<   ŒS d Šd Šd Š	 d	 	 	 	 	 	 	 dˆˆˆfd„}| j/                  ||«      }	t1        |	«      }
‰€J ‚‰€J ‚‰r‰d   r| j2                  r‰d   ‚t5        ‰j7                  «       d   «      }‰D ��cg c]'  \  }}|j9                  d«      |j9                  d«      f‘Œ) }}}t;        |||
¬«      S c c}}w )NéP   i»  )ÚhttpÚhttps)r   r   TFÚasciizHTTP/1.1)zwsgi.versionzwsgi.url_schemez
wsgi.inputzwsgi.errorszwsgi.multithreadzwsgi.multiprocesszwsgi.run_onceÚREQUEST_METHODÚSCRIPT_NAMEÚ	PATH_INFOÚQUERY_STRINGÚSERVER_NAMEÚSERVER_PORTÚSERVER_PROTOCOLÚREMOTE_ADDRzContent-LengthÚCONTENT_LENGTHú-Ú_)ÚCONTENT_TYPEr@   ÚHTTP_c                ó   •— | Š|Š|Šd„ S )Nc                 ó   — y r   r+   )rB   s    r   ú<lambda>zFWSGITransport.handle_request.<locals>.start_response.<locals>.<lambda>ƒ   s   � r   r+   )ÚstatusÚresponse_headersÚexc_infoÚseen_exc_infoÚseen_response_headersÚseen_statuss      €€€r   Ústart_responsez4WSGITransport.handle_request.<locals>.start_responsez   s   ø€ ð !ˆKØ$4Ð!Ø$ˆMÙ!Ð!r   r   r   )ÚheadersÚstreamr   )rH   ÚstrrI   zlist[tuple[str, str]]rJ   zOptExcInfo | Noner&   z$typing.Callable[[bytes], typing.Any])ÚreadÚioÚBytesIOÚcontentÚurlÚportÚschemer2   ÚsysÚstderrÚmethodr0   ÚpathÚqueryÚdecodeÚhostrQ   r1   rO   ÚlenÚrawÚupperÚreplacer.   r   r/   ÚintÚsplitÚencoder   )r   ÚrequestÚ
wsgi_inputrW   ÚenvironÚ
header_keyÚheader_valueÚkeyrN   r    rP   Ústatus_codeÚvaluerO   rK   rL   rM   s                 @@@r   Úhandle_requestzWSGITransport.handle_requestX   sT  ú€ Ø�‰ŒÜ—Z‘Z §¡Ó0ˆ
à�{‰{×ÑÒQ¨B¸Ñ#=¸g¿k¹k×>PÑ>PÑ#Qˆà"Ø&Ÿ{™{×1Ñ1Ø$Ø×+Ñ+Ò9¬s¯z©zØ $Ø!&Ø"Ø%Ÿn™nØ×+Ñ+Ø Ÿ™×)Ñ)Ø#ŸK™K×-Ñ-×4Ñ4°WÓ=Ø"Ÿ;™;×+Ñ+Ü˜t›9Ø)Ø×+Ñ+ñ
ˆð" �?Š?Ð/°w·±ÑFÜ(+¬C°·±Ó,@Ó(AˆGÐ$Ñ%Ø(/¯©×(;Ñ(;ò 	8Ñ$ˆJ˜Ø×#Ñ# GÓ,×2Ñ2Ó4×<Ñ<¸SÀ#ÓFˆCØÐ<Ñ<Ø ‘m�Ø'×.Ñ.¨wÓ7ˆG�CŠLð		8ð ˆØ $ÐØˆð
 +/ð		"Øð		"à3ð		"ð (ð		"ð 2÷			"ð —‘˜' >Ó2ˆä Ó'ˆàÐ&Ð&Ð&Ø$Ð0Ð0Ð0Ù˜]¨1Ò-°$×2KÒ2KØ Ñ"Ð"ä˜+×+Ñ+Ó-¨aÑ0Ó1ˆØRg×hÁJÀCÈ�C—J‘J˜wÓ'¨¯©°gÓ)>Ò?ÐhˆÑhä˜¨W¸VÔDÐDùó is   È5,I2)TÚ z	127.0.0.1N)r.   r   r/   Úboolr0   rQ   r1   rQ   r2   ztyping.TextIO | Noner&   r'   )rg   r   r&   r   )r(   r)   r*   Ú__doc__r!   ro   r+   r   r   r   r   +   s[   „ ñðB &*ØØ&Ø,0ð'àð'ð #ð'ð ð	'ð
 ð'ð *ð'ð 
ó'ô9Er   )r   útyping.Iterable[_T]r&   rs   )Ú
__future__r   rS   r   rY   ÚtypingÚ_modelsr   r   Ú_typesr   Úbaser	   ÚTYPE_CHECKINGÚ	_typeshedr
   Ú_typeshed.wsgir   ÚTypeVarr   Ú__all__r   r   r   r+   r   r   ú<module>r~      sg   ðÝ "ã 	Û Û 
Û ç 'Ý #Ý à	×ÒÝ$Ý.à€V‡^�^�DÓ€ð Ð
€óô
�^ô 
ôfE�Mõ fEr   