
    :Mc                         d 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	e	j                  Z G d
 de          Zd Zedk    rddlZ eej        d                    dS dS )z4PostProcessor for serving reveal.js HTML slideshows.    N)gen
httpserveriolooplogweb)AsyncHTTPClient)BoolIntUnicode   )PostProcessorBasec                   2    e Zd ZdZej        d             ZdS )ProxyHandlerz9handler the proxies requests from a local prefix to a CDNc              #   (  K   d                     | j        d         |g          }| j        d         }|                    |          V }dD ],}||j        v r!|                     ||j        |                    -|                     |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headers          >lib/python3.11/site-packages/nbconvert/postprocessors/serve.pygetzProxyHandler.get   s       HHdmE2C899	x(i0000[ 	B 	BF)) B(8(@AAAHM"""""    N)__name__
__module____qualname____doc__r   	coroutiner$    r%   r#   r   r      s5        CC]	# 	# ]	# 	# 	#r%   r   c                      e Zd ZdZ edd                              d          Z edd                              d          Z edd	                              d          Z	 ed
d                              d          Z
 edd                              d          Z edd                              d          Z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                 8  	
 t           j                            |          \  }}dt          j        d|ifdt          j        dd|z  ifg}d| j        v s| j                            d          rnt           j                            t           j        	                    || j                            r!| j
                            d| j                   nK| j
                            d	| j        | j                   |                    d
d| j        z  t          f           t          j        || j        t!                                }| j
        t          _        t%          j        |          }|                    | j        | j                   d| j        | j        |fz  
t/          d
z             t/          d           | j        r	 t3          j        | j        pd          		
fd}t9          j        |                                           n;# t2          j        $ r)}| j
                             d|z             d	Y d}~nd}~ww xY w	 tB          j"        #                                                                 dS # tH          $ r t/          d           Y dS w xY 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                  2                          d          S )N   )new)open)browserr   s   r#   <lambda>z0ServePostProcessor.postprocess.<locals>.<lambda>b   s    GLL!L44 r%   )targetzNo web browser found: %s.z
Interrupted)%osr2   splitr   StaticFileHandlerRedirectHandlerreveal_prefix
startswithisdirr   r   info
reveal_cdninsertr   Applicationr   app_logr   
HTTPServerlistenportipprintopen_in_browser
webbrowserr$   r8   	threadingThreadstartErrorwarningr   IOLoopinstanceKeyboardInterrupt)r   inputdirnamefilenamehandlersapphttp_serverber8   r   s            @@r#   postprocesszServePostProcessor.postprocess?   s   GMM%00s,vw.?@3&0@(AB

 D&& 	S$*<*G*G*M*M 	SW]]27<<1CDDEE 	SHMM,d.@AAAAHMM94;Mt___OOA0B BLQRRRo"$$
 
 
 h +C0049dg66647DIx"@@)C/0001222 	$.)=>>44444 ***002222#     !<q!@AAA	#M""$$**,,,,,  	# 	# 	#/""""""	#s+   AH III
0I< <JJN)r&   r'   r(   r)   r	   tagrL   r   r8   rC   r?   rJ   r
   rI   r^   r+   r%   r#   r-   r-   "   s6        
 d4&WXXX\\ ]  O g

 
 
 
cc  @Gc  	cc  GK.HIIIMMUYMZZM	#A	B	B	B	F	Fd	F	S	SB3t=>>>BB$BOOD,# ,# ,# ,# ,#r%   r-   c                 8    t                      } ||            dS )z-allow running this module to serve the slidesN)r-   )r2   servers     r#   mainrb   n   s    !!F
F4LLLLLr%   __main__)r)   r;   rN   rM   tornador   r   r   r   r   tornado.httpclientr   	traitletsr	   r
   r   baser   RequestHandlerr   r-   rb   r&   sysargvr+   r%   r#   <module>rk      sH   : : 
			         5 5 5 5 5 5 5 5 5 5 5 5 5 5 . . . . . . ( ( ( ( ( ( ( ( ( ( # # # # # ## # # # #3% # # # I# I# I# I# I#* I# I# I#X   z JJJD! r%   