o
    hT                     @   sf   d dl Z d dlZddlmZmZmZ ddlmZmZ ddl	m
Z
 G dd de
ZG d	d
 d
e jZdS )    N   )	CertTypesTimeoutTypesVerifyTypes)RequestResponse   )
Dispatcherc                   @   s^   e Zd ZdZ			ddejdededed	d
f
ddZ	
	
	
dde	de
deded	ef
ddZd
S )WSGIDispatchav  
    A custom dispatcher that handles sending requests directly to an ASGI app.

    The simplest way to use this functionality is to use the `app`argument.
    This will automatically infer if 'app' is a WSGI or an ASGI application,
    and will setup an appropriate dispatch class:

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

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

    ```
    dispatch = httpx.WSGIDispatch(
        app=app,
        script_name="/submount",
        remote_addr="1.2.3.4"
    )
    client = httpx.Client(dispatch=dispatch)


    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.
    * `script_name` - The root path on which the ASGI application should be mounted.
    * `remote_addr` - A string indicating the client IP of incoming requests.
    ```
    T 	127.0.0.1appraise_app_exceptionsscript_nameremote_addrreturnNc                 C   s   || _ || _|| _|| _d S N)r   r   r   r   )selfr   r   r   r    r   [/var/www/html/magazine_api/magazine_env/lib/python3.10/site-packages/httpx/dispatch/wsgi.py__init__-   s   
zWSGIDispatch.__init__requestverifycerttimeoutc           
         s"  d|j jt| t ddd|j| j|j j|j j	|j j
t|j j| jd}|j D ]\}}| dd}|dvr?d| }|||< q+d d d  	 dd	td
tdtjdd f fdd}| ||}	d usjJ d uspJ  ry| jry d tt d ddd |	D t|	dd dS )N)r   r   TF)zwsgi.versionzwsgi.url_schemez
wsgi.inputzwsgi.errorszwsgi.multithreadzwsgi.multiprocesszwsgi.run_onceREQUEST_METHODZSCRIPT_NAMEZ	PATH_INFOZQUERY_STRINGZSERVER_NAMEZSERVER_PORTZREMOTE_ADDR-_)ZCONTENT_TYPEZCONTENT_LENGTHZHTTP_statusresponse_headersexc_infor   c                    s   | || d S r   r   )r   r   r    Zseen_exc_infoZseen_response_headersZseen_statusr   r   start_responseZ   s   z)WSGIDispatch.send.<locals>.start_responser   r   zHTTP/1.1c                 s   s    | ]}|V  qd S r   r   ).0chunkr   r   r   	<genexpr>m   s    z$WSGIDispatch.send.<locals>.<genexpr>close)status_codehttp_versionheaderscontentZon_closer   )urlscheme
BodyStreamstreamioBytesIOmethodr   pathqueryhoststrportr   r)   itemsupperreplacelisttypingAnyr   r   r   intsplitgetattr)
r   r   r   r   r   environkeyvaluer"   resultr   r!   r   send9   sZ   




zWSGIDispatch.send)Tr   r   )NNN)__name__
__module____qualname____doc__r;   Callableboolr5   r   r   r   r   r   r   rD   r   r   r   r   r
   	   s<    &
r
   c                   @   s   e Zd Zdeje ddfddZddedefdd	Zdefd
dZ	de
deje fddZdedefddZdefddZddededefddZddedefddZdS )r-   iteratorr   Nc                 C   s   || _ d| _d| _d S )N    F)	_iterator_buffer_closed)r   rK   r   r   r   r   s   s   
zBodyStream.__init__sizec                 C   s   | j rdS |dkr|  S zt| j|k r&|  jt| j7  _t| j|k sW n ty6   d| _ | j Y S w | jd | }| j|d  | _|S )NrL   rP   T)rO   readalllenrN   nextrM   StopIteration)r   rQ   outputr   r   r   readx   s    
zBodyStream.readc                 C   s4   | j rtd| jD ]	}|  j|7  _q
d| _ | jS )NzStream closedT)rO   OSErrorrM   rN   )r   r$   r   r   r   rR      s   
zBodyStream.readallbc                 C   s&   |  t|}t|}||d |< |S r   )rW   rS   )r   rY   rV   countr   r   r   readinto   s   zBodyStream.readintoc                 C      t dNzOperation not supportedrX   )r   rY   r   r   r   write      zBodyStream.writec                 C   r\   r]   r^   )r   r   r   r   fileno   r`   zBodyStream.filenor   offsetwhencec                 C   r\   r]   r^   )r   rb   rc   r   r   r   seek   r`   zBodyStream.seekc                 C   r\   r]   r^   )r   rQ   r   r   r   truncate   r`   zBodyStream.truncate)rP   )r   r   )rE   rF   rG   r;   Iteratorbytesr   r=   rW   rR   	bytearrayOptionalr[   r_   ra   rd   re   r   r   r   r   r-   r   s    
r-   )r/   r;   configr   r   r   modelsr   r   baser	   r
   	RawIOBaser-   r   r   r   r   <module>   s    i