§
    ëXÊ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dS )é    )ÚannotationsNé   )ÚRequestÚResponse)ÚSyncByteStreamé   )ÚBaseTransport)Ú
OptExcInfo)ÚWSGIApplicationÚ_TÚWSGITransportÚbodyútyping.Iterable[_T]Úreturnc                ób   — t          | ¦  «        } | D ]}|rt          j        |g| ¦  «        c S Œg S ©N)ÚiterÚ	itertoolsÚchain)r   Úchunks     úHC:\Projects\Historical\venv\Lib\site-packages\httpx2/_transports/wsgi.pyÚ_skip_leading_empty_chunksr      sH   € Ý�‰:Œ:€DØð 2ð 2ˆØð 	2Ý”? E 7¨DÑ1Ô1Ð1Ð1Ð1ð	2à€Ió    c                  ó&   — e Zd Zd
d„Zdd„Zdd„Zd	S )ÚWSGIByteStreamÚresultútyping.Iterable[bytes]r   ÚNonec                óZ   — t          |dd ¦  «        | _        t          |¦  «        | _        d S )NÚclose)ÚgetattrÚ_closer   Ú_result)Úselfr   s     r   Ú__init__zWSGIByteStream.__init__   s(   € Ý˜f g¨tÑ4Ô4ˆŒÝ1°&Ñ9Ô9ˆŒˆˆr   útyping.Iterator[bytes]c              #  ó$   K  — | j         E d {V —† d S r   )r#   ©r$   s    r   Ú__iter__zWSGIByteStream.__iter__#   s&   è è € Ø”<ÐÐÐÐÐÐÐÐÐr   c                ó@   — | j         �|                       ¦   «          d S d S r   )r"   r(   s    r   r    zWSGIByteStream.close&   s#   € ØŒ;Ð"Ø�KŠK‰MŒMˆMˆMˆMð #Ð"r   N)r   r   r   r   )r   r&   )r   r   )Ú__name__Ú
__module__Ú__qualname__r%   r)   r    © r   r   r   r      sP   € € € € € ð:ð :ð :ð :ð ð  ð  ð  ðð ð ð ð ð r   r   c                  ó,   — e Zd ZdZ	 	 	 	 ddd„Zdd„ZdS )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.
    TÚ ú	127.0.0.1NÚappr   Úraise_app_exceptionsÚboolÚscript_nameÚstrÚremote_addrÚwsgi_errorsútyping.TextIO | Noner   r   c                óL   — || _         || _        || _        || _        || _        d S r   )r2   r3   r5   r7   r8   )r$   r2   r3   r5   r7   r8   s         r   r%   zWSGITransport.__init__J   s1   € ð ˆŒØ$8ˆÔ!Ø&ˆÔØ&ˆÔØ&ˆÔÐÐr   Úrequestr   r   c                ó  ‡‡‡— |                      ¦   «          t          j        |j        ¦  «        }|j        j        pdddœ|j        j                 }d|j        j        || j        pt          j	        ddd|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 ]a\  }}|                     d¦  «                             ¦   «                              dd¦  «        }|dvrd|z   }|                     d¦  «        ||<   Œbd Šd Šd Š	 ddˆˆˆfd„}|                      ||¦  «        }	t1          |	¦  «        }
‰€J ‚‰€J ‚‰r‰d         r| j        r‰d         ‚t5          ‰                     ¦   «         d         ¦  «        }d„ ‰D ¦   «         }t9          |||
¬¦  «        S )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_TYPErI   ÚHTTP_Ústatusr6   Úresponse_headersúlist[tuple[str, str]]Úexc_infoúOptExcInfo | Noner   ú$typing.Callable[[bytes], typing.Any]c                ó   •— | Š|Š|Šd„ S )Nc                ó   — d S r   r.   )rK   s    r   ú<lambda>zFWSGITransport.handle_request.<locals>.start_response.<locals>.<lambda>ƒ   s   € ˜T€ r   r.   )rN   rO   rQ   Úseen_exc_infoÚseen_response_headersÚseen_statuss      €€€r   Ústart_responsez4WSGITransport.handle_request.<locals>.start_responsez   s   ø€ ð !ˆKØ$4Ð!Ø$ˆMØ!�>Ð!r   r   r   c                óh   — g | ]/\  }}|                      d ¦  «        |                      d ¦  «        f‘Œ0S )r@   )Úencode)Ú.0ÚkeyÚvalues      r   ú
<listcomp>z0WSGITransport.handle_request.<locals>.<listcomp>�   s9   € ÐhÐhÐhÁJÀCÈ�C—J’J˜wÑ'Ô'¨¯ª°gÑ)>Ô)>Ð?ÐhÐhÐhr   )ÚheadersÚstreamr   )rN   r6   rO   rP   rQ   rR   r   rS   )ÚreadÚioÚBytesIOÚcontentÚurlÚportÚschemer8   ÚsysÚstderrÚmethodr5   ÚpathÚqueryÚdecodeÚhostr6   r7   ra   ÚlenÚrawÚupperÚreplacer2   r   r3   ÚintÚsplitr   )r$   r;   Ú
wsgi_inputrh   ÚenvironÚ
header_keyÚheader_valuer^   rZ   r   rb   Ústatus_codera   rW   rX   rY   s                @@@r   Úhandle_requestzWSGITransport.handle_requestX   sP  øøø€ Ø�Š‰ŒˆÝ”Z ¤Ñ0Ô0ˆ
àŒ{ÔÐQ¨B¸Ð#=Ð#=¸g¼kÔ>PÔ#Qˆà"Ø&œ{Ô1Ø$ØÔ+Ð9­s¬zØ $Ø!&Ø"Ø%œnØÔ+Ø œÔ)Ø#œKÔ-×4Ò4°WÑ=Ô=Ø"œ;Ô+Ý˜t™9œ9Ø)ØÔ+ð
ð 
ˆð" Œ?ð 	BÐ/°w´ÐFÐFÝ(+­C°´Ñ,@Ô,@Ñ(AÔ(AˆGÐ$Ñ%Ø(/¬Ô(;ð 	8ð 	8Ñ$ˆJ˜Ø×#Ò# GÑ,Ô,×2Ò2Ñ4Ô4×<Ò<¸SÀ#ÑFÔFˆCØÐ<Ð<Ð<Ø ‘m�Ø'×.Ò.¨wÑ7Ô7ˆG�C‰LˆLàˆØ $ÐØˆð
 +/ð		"ð 		"ð 		"ð 		"ð 		"ð 		"ð 		"ð 		"ð 		"ð —’˜' >Ñ2Ô2ˆå Ñ'Ô'ˆàÐ&Ð&Ð&Ø$Ð0Ð0Ð0Øð 	#˜]¨1Ô-ð 	#°$Ô2Kð 	#Ø Ô"Ð"å˜+×+Ò+Ñ-Ô-¨aÔ0Ñ1Ô1ˆØhÐhÐRgÐhÑhÔhˆå˜¨W¸VÐDÑDÔDÐDr   )Tr0   r1   N)r2   r   r3   r4   r5   r6   r7   r6   r8   r9   r   r   )r;   r   r   r   )r+   r,   r-   Ú__doc__r%   r|   r.   r   r   r   r   +   s`   € € € € € ðð ðB &*ØØ&Ø,0ð'ð 'ð 'ð 'ð 'ð9Eð 9Eð 9Eð 9Eð 9Eð 9Er   )r   r   r   r   )Ú
__future__r   rd   r   rj   ÚtypingÚ_modelsr   r   Ú_typesr   Úbaser	   ÚTYPE_CHECKINGÚ	_typeshedr
   Ú_typeshed.wsgir   ÚTypeVarr   Ú__all__r   r   r   r.   r   r   ú<module>rˆ      sJ  ðØ "Ð "Ð "Ð "Ð "Ð "à 	€	€	€	Ø Ð Ð Ð Ø 
€
€
€
Ø €€€à 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø #Ð #Ð #Ð #Ð #Ð #Ø Ð Ð Ð Ð Ð à	Ôð /Ø$Ð$Ð$Ð$Ð$Ð$Ø.Ð.Ð.Ð.Ð.Ð.à€V„^�DÑÔ€ð Ð
€ðð ð ð ð
ð 
ð 
ð 
ð 
�^ñ 
ô 
ð 
ðfEð fEð fEð fEð fE�Mñ fEô fEð fEð fEð fEr   