B
    18™\‰  ã               @   s²   d Z ddlZddlZddlZddlmZmZ dd„ Zedkr®ej	d Z
eej	ƒdkrbeej	d ƒnd	Ze d
ee¡Zed e
e¡ƒ ye ¡  W n ek
r¬   edƒ Y nX dS )a
  
Small wsgiref based web server. Takes a path to serve from and an
optional port number (defaults to 8000), then tries to serve files.
Mime types are guessed from the file names, 404 errors are raised
if the file is not found. Used for the make serve target in Doc.
é    N)Úsimple_serverÚutilc             C   sŽ   t j t| d dd … ¡}d| t jj¡d kr>t j |d¡}t |¡d }t j |¡rx|dd|fgƒ t 	t
|d	ƒ¡S |d
dgƒ dgS d S )NZ	PATH_INFOé   Ú.éÿÿÿÿz
index.htmlr   z200 OKzContent-TypeÚrbz404 Not Found)zContent-Typez
text/plains	   not found)ÚosÚpathÚjoinÚsplitÚsepÚ	mimetypesÚ
guess_typeÚexistsr   ZFileWrapperÚopen)ÚenvironZrespondÚfnÚtype© r   úS/oak/stanford/groups/akundaje/marinovg/programs/Python-3.7.3/Tools/scripts/serve.pyÚapp   s    r   Ú__main__r   é   i@  Ú z(Serving {} on port {}, control-C to stopzShutting down.)Ú__doc__Úsysr   r   Zwsgirefr   r   r   Ú__name__Úargvr	   ÚlenÚintÚportZmake_serverZhttpdÚprintÚformatZserve_foreverÚKeyboardInterruptr   r   r   r   Ú<module>   s   
 