o
    h                     @  s   d dl mZ d dlZd dlZd dlZd dlZd dlZd dlm	Z	 d dl
mZ d dlmZmZmZmZmZmZmZmZmZmZmZmZ dddZG dd dZG dd dZz	d dlmZ W dS  eyj   eZY dS w )    )annotationsN)deque)Iterable)ASGIReceiveCallableASGIReceiveEventASGISendCallableASGISendEventEnvironExcInfoHTTPRequestEventHTTPResponseBodyEventHTTPResponseStartEvent	HTTPScopeStartResponseWSGIAppscoper   messager   body
io.BytesIOreturnr	   c                 C  s`  |  dddd}| d dd}||r#|t|d }| d ||| d d	d
| d  d|  dd|tjdddd}|  d}|du rMd}|d |d< |d |d< |  d}|durh|d |d< |  dg D ]?\}}	|d}
|
dkr~d}n|
dkrd}n
d|
 d d! }|	d}||v r|| }t	|t
sJ |d" | }|||< qn|S )#zH
    Builds a scope and request message into a WSGI environ object.
    	root_path utf8latin1pathNmethodquery_stringasciizHTTP/%shttp_version)   r   schemehttpTF)REQUEST_METHODSCRIPT_NAME	PATH_INFOQUERY_STRINGSERVER_PROTOCOLzwsgi.versionzwsgi.url_schemez
wsgi.inputzwsgi.errorszwsgi.multithreadzwsgi.multiprocesszwsgi.run_onceserver)	localhostP   r   SERVER_NAMEr   SERVER_PORTclientREMOTE_ADDRheaderszcontent-lengthCONTENT_LENGTHzcontent-typeCONTENT_TYPEzHTTP_%s-_,)getencodedecode
startswithlensysstdoutupperreplace
isinstancestr)r   r   r   script_name	path_infoenvironr'   r,   namevaluename_strcorrected_name	value_strcorrected_name_environ rH   O/var/www/html/zoom/venv/lib/python3.10/site-packages/uvicorn/middleware/wsgi.pybuild_environ   sN   







rJ   c                   @  s"   e Zd ZddddZdddZdS )_WSGIMiddleware
   appr   workersintc                 C  s&   t dt || _tjj|d| _d S )NzgUvicorn's native WSGI implementation is deprecated, you should switch to a2wsgi (`pip install a2wsgi`).)max_workers)warningswarnDeprecationWarningrM   
concurrentfuturesThreadPoolExecutorexecutor)selfrM   rN   rH   rH   rI   __init__S   s   z_WSGIMiddleware.__init__r   r   receiver   sendr   r   Nonec                   s6   |d dks	J t | j| j|}|||I d H  d S )Ntyper!   )WSGIResponderrM   rW   )rX   r   rZ   r[   instancerH   rH   rI   __call__\   s   z_WSGIMiddleware.__call__N)rL   )rM   r   rN   rO   )r   r   rZ   r   r[   r   r   r\   )__name__
__module____qualname__rY   r`   rH   rH   rH   rI   rK   R   s    	rK   c                   @  sB   e Zd Zd"ddZd#ddZd$ddZ	d%d&ddZd'd d!ZdS )(r^   rM   r   rW   %concurrent.futures.ThreadPoolExecutorr   r   c                 C  sJ   || _ || _|| _d | _d | _t | _t | _	t
 | _d| _d | _d S )NF)rM   rW   r   statusresponse_headersasyncioEvent
send_eventr   
send_queueget_event_looploopresponse_startedexc_info)rX   rM   rW   r   rH   rH   rI   rY   h   s   


zWSGIResponder.__init__rZ   r   r[   r   r   r\   c           
   
     sR  | I d H }t |dd}|dd}|r=|dt j |r8| I d H }||dd |dd}|s!|d t| j||}t	 | _
| j
| j| j|| j}| j
| |}	zt|d I d H  W | jd  | j  t|	d I d H  n| jd  | j  t|	d I d H  w | jd ur| jd | jd | jd d S )Nr       	more_bodyFr   r      )ioBytesIOr4   seekSEEK_ENDwriterJ   r   rg   rk   rl   run_in_executorrW   wsgistart_responsecreate_tasksenderwait_forrj   appendri   setrn   with_traceback)
rX   rZ   r[   r   r   rp   body_messagerA   rx   r{   rH   rH   rI   r`   y   s8   





zWSGIResponder.__call__c                   sL   	 | j r| j  }|d u rd S ||I d H  n| j I d H  | j  qN)rj   popleftri   waitclear)rX   r[   r   rH   rH   rI   r{      s   

zWSGIResponder.senderNre   r>   rf   Iterable[tuple[str, str]]rn   ExcInfo | Nonec           	      C  sh   || _ | js2d| _|dd\}}t|}dd |D }d||d}| j| | j| jj	 d S d S )NT r   c                 S  s$   g | ]\}}| d | d fqS )r   )r5   ).0rB   rC   rH   rH   rI   
<listcomp>   s   $ z0WSGIResponder.start_response.<locals>.<listcomp>zhttp.response.start)r]   re   r.   )
rn   rm   splitrO   rj   r}   rl   call_soon_threadsaferi   r~   )	rX   re   rf   rn   status_code_strr2   status_coder.   http_response_start_eventrH   rH   rI   ry      s   zWSGIResponder.start_responserA   r	   ry   r   c                 C  sf   |  ||D ]}d|dd}| j| | j| jj qdddd}| j| | j| jj d S )Nzhttp.response.bodyT)r]   r   rp   ro   F)rM   rj   r}   rl   r   ri   r~   )rX   rA   ry   chunkresponse_body
empty_bodyrH   rH   rI   rx      s   zWSGIResponder.wsgi)rM   r   rW   rd   r   r   )rZ   r   r[   r   r   r\   )r[   r   r   r\   r   )re   r>   rf   r   rn   r   r   r\   )rA   r	   ry   r   r   r\   )ra   rb   rc   rY   r`   r{   ry   rx   rH   rH   rH   rI   r^   g   s    


r^   )WSGIMiddleware)r   r   r   r   r   r   r   r	   )
__future__r   rg   concurrent.futuresrT   rr   r9   rQ   collectionsr   typingr   uvicorn._typesr   r   r   r   r	   r
   r   r   r   r   r   r   rJ   rK   r^   a2wsgir   ModuleNotFoundErrorrH   rH   rH   rI   <module>   s"    8
7^
