
2\c           @   s   d  Z  d d l m Z d d l m Z d d l m Z d d l m Z d d l	 m
 Z
 d d l m Z m Z d	 e f d
     YZ d Z d e f g Z d S(   s'   Tornado handler for bundling notebooks.i   (   t   toolsi(   t   url2path(   t   IPythonHandler(   t   ConfigManager(   t   import_item(   t   webt   gent   BundlerHandlerc           B   s5   e  Z d    Z d   Z e j e j d     Z RS(   c         C   s   t  |  _  d S(   s~   Make tools module available on the handler instance for compatibility
        with existing bundler API and ease of reference.N(   R    (   t   self(    (    s8   lib/python2.7/site-packages/notebook/bundler/handlers.pyt
   initialize   s    c         C   s&   t    } | j d  j d i   | S(   s  
        Get bundler metadata from config given a bundler ID.
        
        Parameters
        ----------
        bundler_id: str
            Unique bundler ID within the notebook/bundlerextensions config section
        
        Returns
        -------
        dict
            Bundler metadata with label, group, and module_name attributes
        
        
        Raises
        ------
        KeyError
            If the bundler ID is unknown
        t   notebookt   bundlerextensions(   R   t   get(   R   t
   bundler_idt   cm(    (    s8   lib/python2.7/site-packages/notebook/bundler/handlers.pyt   get_bundler   s    	c         c   s   |  j  d  } |  j j d t |   } y |  j |  } Wn' t k
 rf t j d d |   n X| d } y t |  } Wn  t	 k
 r | j
 d  } n Xy t |  } Wn' t k
 r t j d d |   n Xt j | j |  |   Vd	 S(
   s   Bundle the given notebook.
        
        Parameters
        ----------
        path: str
            Path to the notebook (path parameter)
        bundler: str
            Bundler ID to use (query parameter)
        t   bundlert   pathi  s   Bundler %s not enabledt   module_names   utf-8i  s   Could not import bundler %s N(   t   get_query_argumentt   contents_managerR   R   R   t   KeyErrorR   t	   HTTPErrort   strt   UnicodeEncodeErrort   encodeR   t   ImportErrorR   t   maybe_futuret   bundle(   R   R   R   t   modelR   R   t   bundler_mod(    (    s8   lib/python2.7/site-packages/notebook/bundler/handlers.pyR   *   s     
(	   t   __name__t
   __module__R	   R   R   t   authenticatedR   t	   coroutineR   (    (    (    s8   lib/python2.7/site-packages/notebook/bundler/handlers.pyR      s   		s   (?P<bundler_id>[A-Za-z0-9_]+)s   /bundle/(.*)N(   t   __doc__t    R    t   notebook.utilsR   t   notebook.base.handlersR   t   notebook.services.configR   t   ipython_genutils.importstringR   t   tornadoR   R   R   t   _bundler_id_regext   default_handlers(    (    (    s8   lib/python2.7/site-packages/notebook/bundler/handlers.pyt   <module>   s   B