U
    9]T                     @   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                   @   sB   e Zd ZdZdejeeeddddZde	e
eeed	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.1N)appraise_app_exceptionsscript_nameremote_addrreturnc                 C   s   || _ || _|| _|| _d S N)r   r   r   r   )selfr   r   r   r    r   s/var/www/html/staging.mfahmagazine.net/magazine_api/magazine_env/lib/python3.8/site-packages/httpx/dispatch/wsgi.py__init__-   s    zWSGIDispatch.__init__)requestverifycerttimeoutr   c           
         s  d|j jt| t ddd|j| j|j j|j j	|j j
t|j j| jd}|j D ]0\}}| dd}|dkr~d| }|||< qVd d d  dtttjd d	 fd
d}| ||}	d k	std k	st r| jr 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_onceZ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)Zstatus_codeZhttp_versionheaderscontentZon_close)N)urlscheme
BodyStreamstreamioBytesIOmethodr   pathqueryhoststrportr   r&   itemsupperreplacelisttypingZAnyr   AssertionErrorr   r   intsplitgetattr)
r   r   r   r   r   environkeyvaluer!   resultr   r    r   send9   sT    


   

zWSGIDispatch.send)Tr   r   )NNN)__name__
__module____qualname____doc__r8   Callableboolr2   r   r   r   r   r   r   rA   r   r   r   r   r
   	   s*   &      r
   c                   @   s   e Zd Zeje ddddZdeedddZed	d
dZ	e
eje dddZeedddZed	ddZdeeedddZdeedddZdS )r*   N)iteratorr   c                 C   s   || _ d| _d| _d S )N    F)	_iterator_buffer_closed)r   rH   r   r   r   r   s   s    zBodyStream.__init__)sizer   c                 C   s   | j r
dS |dkr|  S z(t| j|k r@|  jt| j7  _qW n  tk
rb   d| _ | j Y S X | jd | }| j|d  | _|S )NrI   rM   T)rL   readalllenrK   nextrJ   StopIteration)r   rN   outputr   r   r   readx   s    zBodyStream.read)r   c                 C   s4   | j rtd| jD ]}|  j|7  _qd| _ | jS )NzStream closedT)rL   OSErrorrJ   rK   )r   r#   r   r   r   rO      s    
zBodyStream.readall)br   c                 C   s&   |  t|}t|}||d |< |S r   )rT   rP   )r   rV   rS   countr   r   r   readinto   s    zBodyStream.readintoc                 C   s   t dd S NzOperation not supportedrU   )r   rV   r   r   r   write   s    zBodyStream.writec                 C   s   t dd S rY   rZ   )r   r   r   r   fileno   s    zBodyStream.filenor   )offsetwhencer   c                 C   s   t dd S rY   rZ   )r   r]   r^   r   r   r   seek   s    zBodyStream.seekc                 C   s   t dd S rY   rZ   )r   rN   r   r   r   truncate   s    zBodyStream.truncate)rM   )r   )N)rB   rC   rD   r8   Iteratorbytesr   r:   rT   rO   	bytearrayOptionalrX   r[   r\   r_   r`   r   r   r   r   r*   r   s   
r*   )r,   r8   configr   r   r   Zmodelsr   r   baser	   r
   	RawIOBaser*   r   r   r   r   <module>   s   i