
    Mh                        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     V/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/httpx/_transports/wsgi.py_skip_leading_empty_chunksr      sH    ::D 2 2 	2?E7D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(    fgt441&99r   typing.Iterator[bytes]c              #  &   K   | j         D ]}|V  d S r   )r#   )r$   parts     r   __iter__zWSGIByteStream.__iter__#   s,      L 	 	DJJJJ	 	r   c                @    | j         |                                   d S d S r   )r"   )r$   s    r   r    zWSGIByteStream.close'   s#    ;"KKMMMMM #"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 = httpx.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 = httpx.WSGITransport(
        app=app,
        script_name="/submount",
        remote_addr="1.2.3.4"
    )
    client = httpx.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__M   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        j        D ]a\  }}|                    d                                                              d
d          }|dvrd|z   }|                    d          ||<   bd d d 	 ddfd}|                     ||          }	t/          |	          }
J J rd         r| j        rd         t3                                          d                   }d D             }t7          |||
          S )NP   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_ADDR-_)CONTENT_TYPECONTENT_LENGTH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.   )rJ   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_response{   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>   sI     
 
 
U ZZ  %,,w"7"78
 
 
r   )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   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_request[   s'   Z00
{QB#=#=gk>P#Q"&{1$+9sz $!&"%n+ )#K-44W==";+t99)+
 
" )0(; 	8 	8$J##G,,2244<<S#FFC<<<m'..w77GCLL $
 +/		" 		" 		" 		" 		" 		" 		" 		" 		" '>22''&&&$000 	#]1- 	#$2K 	#""+++--a011
 
3
 
 

 WV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`         F &*&,0' ' ' ' ':E :E :E :E :E :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 
       ^   iE iE iE iE iEM iE iE iE iE iEr   