ó
§‰]c           @  s  d  Z  d d l m 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 d	 e j f d
 „  ƒ  YZ d e f d „  ƒ  YZ d „  Z e d k rd d l Z e e j d ƒ n  d S(   s4   PostProcessor for serving reveal.js HTML slideshows.iÿÿÿÿ(   t   print_functionN(   t   webt   ioloopt
   httpservert   logt   gen(   t   AsyncHTTPClient(   t   Boolt   Unicodet   Inti   (   t   PostProcessorBaset   ProxyHandlerc           B  s    e  Z d  Z e j d „  ƒ Z RS(   s9   handler the proxies requests from a local prefix to a CDNc         c  s–   d j  |  j d | g ƒ } |  j d } | j | ƒ V} xF d d d d d g D]/ } | | j k rO |  j | | j | ƒ qO qO W|  j | j ƒ d	 S(
   s   proxy a request to a CDNt   /t   cdnt   clients   Content-Types   Cache-Controlt   Dates   Last-Modifiedt   ExpiresN(   t   joint   settingst   fetcht   headerst
   set_headert   finisht   body(   t   selft   prefixt   urlt	   proxy_urlR   t   responset   header(    (    s=   lib/python2.7/site-packages/nbconvert/postprocessors/serve.pyt   get   s    (   t   __name__t
   __module__t   __doc__R   t	   coroutineR   (    (    (    s=   lib/python2.7/site-packages/nbconvert/postprocessors/serve.pyR      s   t   ServePostProcessorc           B  sË   e  Z d  Z e e d d ƒj d e ƒ Z e d d d ƒj d e ƒ Z e d d d ƒj d e ƒ Z	 e d d d	 ƒj d e ƒ Z
 e d
 d d ƒj d e ƒ Z e d d d ƒj d e ƒ Z d „  Z RS(   sy   Post processor designed to serve files
    
    Proxies reveal.js requests to a CDN if no local reveal.js is present
    t   helps+   Should the browser be opened automatically?t   configu    sþ  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.
                      s6   https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.5.0s   URL for reveal.js CDN.s	   reveal.jss   URL prefix for reveal.jss	   127.0.0.1s   The IP address to listen on.i@  s!   port for the server to listen on.c   	        s*  t  j j | ƒ \ } } d t j i | d 6f d t j i d | d 6f g } d |  j k sè |  j j d ƒ rr nv t  j j t  j j	 | |  j ƒ ƒ r¯ |  j
 j d |  j ƒ n9 |  j
 j d	 |  j |  j ƒ | j d
 d |  j t f ƒ t j | d |  j d t ƒ  ƒ} |  j
 t
 _ t j | ƒ } | j |  j d |  j ƒd |  j |  j | f ‰ t d ˆ ƒ t d ƒ |  j rñyD t j |  j pŒd ƒ ‰  ‡  ‡ f d †  } t j d | ƒ j ƒ  Wqñt j  k
 rí} |  j
 j! d | ƒ d ‰  qñXn  y t" j# j$ ƒ  j ƒ  Wn t% k
 r%t d ƒ n Xd S(   s+   Serve the build directory with a webserver.s   /(.+)t   pathR   s   /%sR   s   ://s   //s   Serving local %ss   Redirecting %s requests to %si    s
   /(%s)/(.*)R   R   t   addresss   http://%s:%i/%ss   Serving your slides at %ss!   Use Control-C to stop this serverc             s   ˆ  j  ˆ d d ƒS(   Nt   newi   (   t   open(    (   t   browserR   (    s=   lib/python2.7/site-packages/nbconvert/postprocessors/serve.pyt   <lambda>a   t    t   targets   No web browser found: %s.s   
InterruptedN(&   t   osR&   t   splitR   t   StaticFileHandlert   RedirectHandlert   reveal_prefixt
   startswitht   isdirR   R   t   infot
   reveal_cdnt   insertR   t   ApplicationR   t   app_logR   t
   HTTPServert   listent   portt   ipt   printt   open_in_browsert
   webbrowserR   R*   t   Nonet	   threadingt   Threadt   startt   Errort   warningR   t   IOLoopt   instancet   KeyboardInterrupt(	   R   t   inputt   dirnamet   filenamet   handlerst   appt   http_servert   bt   e(    (   R*   R   s=   lib/python2.7/site-packages/nbconvert/postprocessors/serve.pyt   postprocess?   s<     !$	
	(   R   R    R!   R   t   Truet   tagR?   R   R*   R6   R2   R=   R	   R<   RR   (    (    (    s=   lib/python2.7/site-packages/nbconvert/postprocessors/serve.pyR#   "   s   						c         C  s   t  ƒ  } | |  ƒ d S(   s-   allow running this module to serve the slidesN(   R#   (   R&   t   server(    (    s=   lib/python2.7/site-packages/nbconvert/postprocessors/serve.pyt   mainl   s    	t   __main__(   R!   t
   __future__R    R.   R@   RB   t   tornadoR   R   R   R   R   t   tornado.httpclientR   t	   traitletsR   R   R	   t   baseR
   t   RequestHandlerR   R#   RV   R   t   syst   argv(    (    (    s=   lib/python2.7/site-packages/nbconvert/postprocessors/serve.pyt   <module>   s   (J	