
    b                         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j0                  d          yy)z4PostProcessor for serving reveal.js HTML slideshows.    N)gen
httpserveriolooplogweb)AsyncHTTPClient)BoolIntUnicode   )PostProcessorBasec                   4    e Zd ZdZej
                  d        Zy)ProxyHandlerz9handler the proxies requests from a local prefix to a CDNc              #   0  K   dj                  | j                  d   |g      }| j                  d   }|j                  |      }dD ]0  }||j                  v s| j	                  ||j                  |          2 | j                  |j                         yw)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          @/usr/lib/python3/dist-packages/nbconvert/postprocessors/serve.pygetzProxyHandler.get   s      HHdmmE2C89	x(i00[ 	BF)))(8(8(@A	B 	HMM"s   AB=BN)__name__
__module____qualname____doc__r   	coroutiner$        r#   r   r      s    C]]	# 	#r+   r   c                   N   e Zd ZdZ edd      j                  d      Z edd      j                  d      Z edd	      j                  d      Z	 ed
d      j                  d      Z
 edd      j                  d      Z edd      j                  d      Zd Zy)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                   	
 t         j                  j                  |      \  }}dt        j                  d|ifdt        j
                  dd|z  ifg}d| j                  v s| j                  j                  d      rnt         j                  j                  t         j                  j                  || j                              r'| j                  j                  d| j                         nV| j                  j                  d	| j                  | j                         |j                  d
d| j                  z  t        f       t        j                  || j                  t!                     }| j                  t        _        t%        j&                  |      }|j)                  | j*                  | j,                         d| j,                  | j*                  |fz  
t/        d
z         t/        d       | j0                  rN	 t3        j4                  | j6                  xs d      		
fd}t9        j:                  |      j=                          	 tB        jD                  jG                         j=                          y# t2        j>                  $ r*}| j                  jA                  d|z         d	Y d}~fd}~ww xY w# tH        $ r t/        d       Y y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                  *     j                  d      S )N   )new)open)browserr   s   r#   <lambda>z0ServePostProcessor.postprocess.<locals>.<lambda>b   s    GLL!L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#   GGMM%0s,,vw.?@3&&0@(AB

 D&&&$*<*<*G*G*MWW]]277<<1C1CDEHHMM,d.@.@AHHMM94;M;Mt_OOA0B0B BLQRoo"$
 hh ++C0499dgg6477DIIx"@@)C/012$..)=>4  *002
	#MM""$**, ##   !<q!@A ! 	#/"	#s+   =AI8 ,J8 8J5 J00J58KKN)r%   r&   r'   r(   r	   tagrL   r   r8   rC   r?   rJ   r
   rI   r^   r*   r+   r#   r-   r-   "   s    
 4&WX\\ ] O 

 
cc  @Gc	cc  K.HIMMUYMZM	#A	B	F	Fd	F	SBt=>BB$BOD,#r+   r-   c                 (    t               } ||        y)z-allow running this module to serve the slidesN)r-   )r2   servers     r#   mainrb   n   s    !F
4Lr+   __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      sn    : 
   5 5 . ( ( ##3%% # I#* I#X z! r+   