o
    i                     @  s   d Z 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
mZmZmZ ddlmZ ddlmZmZmZ ddlmZ G d	d
 d
ejZG dd deZdd ZedkrbddlZeejd  dS dS )z4PostProcessor for serving reveal.js HTML slideshows.    )annotationsN)gen
httpserveriolooplogweb)AsyncHTTPClient)BoolIntUnicode   )PostProcessorBasec                   @  s   e Zd ZdZejdd ZdS )ProxyHandlerz9handler the proxies requests from a local prefix to a CDNc                 c  sb    d | jd |g}| jd }||V }dD ]}||jv r(| ||j|  q| |j dS )zproxy a request to a CDN/cdnclient)zContent-TypezCache-ControlDatezLast-ModifiedExpiresN)joinsettingsfetchheaders
set_headerfinishbody)selfprefixurl	proxy_urlr   responseheader r!   Y/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/nbconvert/postprocessors/serve.pyget   s   

zProxyHandler.getN)__name__
__module____qualname____doc__r   	coroutiner#   r!   r!   r!   r"   r      s    r   c                   @  s   e Zd ZdZedddjddZedddjddZedd	djddZ	ed
ddjddZ
edddjddZedddjddZdd ZdS )ServePostProcessorzuPost processor designed to serve files

    Proxies reveal.js requests to a CDN if no local reveal.js is present
    Tz+Should the browser be opened automatically?)help)config a  Specify what browser should be used to open slides. See
                      https://docs.python.org/3/library/webbrowser.html#webbrowser.register
                      to see how keys are mapped to browser executables. If
                      not specified, the default browser will be determined
                      by the `webbrowser`
                      standard library module, which allows setting of the BROWSER
                      environment variable to override it.
                      z6https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.5.0zURL for reveal.js CDN.z	reveal.jszURL prefix for reveal.jsz	127.0.0.1zThe IP address to listen on.i@  z!port for the server to listen on.c           	   
     s  t j|\}}dtjd|ifdtjdd| ifg}d| jv s%| jdr&n*t jt j	|| jr;| j
d| j n| j
d	| j| j |d
d| j tf tj|| jt d}| j
t
_t|}|j| j| jd d| j| j|f td  td | jrzt| jpd  fdd}tj|d  W n tjy } z| j
 d| d W Y d}~nd}~ww z
t!j"#   W dS  t$y   td Y dS w )z+Serve the build directory with a webserver.z/(.+)pathr   r   z/%sz://z//zServing local %szRedirecting %s requests to %sr   z
/(%s)/(.*))r   r   )addresszhttp://%s:%i/%szServing your slides at %sz!Use Control-C to stop this serverNc                     s    j ddS )N   )new)openr!   browserr   r!   r"   <lambda>c   s    z0ServePostProcessor.postprocess.<locals>.<lambda>)targetzNo web browser found: %s.z
Interrupted)%osr-   splitr   StaticFileHandlerRedirectHandlerreveal_prefix
startswithisdirr   r   info
reveal_cdninsertr   Applicationr   app_logr   
HTTPServerlistenportipprintopen_in_browser
webbrowserr#   r3   	threadingThreadstartErrorwarningr   IOLoopinstanceKeyboardInterrupt)	r   inputdirnamefilenamehandlersapphttp_serverber!   r2   r"   postprocess@   sH   
zServePostProcessor.postprocessN)r$   r%   r&   r'   r	   tagrG   r   r3   r>   r:   rE   r
   rD   rY   r!   r!   r!   r"   r)   #   s(    
r)   c                 C  s   t  }||  dS )z-allow running this module to serve the slidesN)r)   )r-   serverr!   r!   r"   maino   s   r\   __main__)r'   
__future__r   r6   rI   typingtrH   tornador   r   r   r   r   tornado.httpclientr   	traitletsr	   r
   r   baser   RequestHandlerr   r)   r\   r$   sysargvr!   r!   r!   r"   <module>   s"    L