B
    3\C
                 @   sr   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 G d	d
 d
eZdZdefgZdS )z'Tornado handler for bundling notebooks.   )tools    )url2path)IPythonHandler)ConfigManager)import_item)webgenc               @   s0   e Zd Zdd Zdd Zejejdd Z	dS )BundlerHandlerc             C   s
   t | _ dS )z~Make tools module available on the handler instance for compatibility
        with existing bundler API and ease of reference.N)r   )self r   8lib/python3.7/site-packages/notebook/bundler/handlers.py
initialize   s    zBundlerHandler.initializec             C   s   t  }|ddi | S )a  
        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
        ZnotebookZbundlerextensions)r   get)r   
bundler_idcmr   r   r   get_bundler   s    zBundlerHandler.get_bundlerc             c   s   |  d}| jjt|d}y| |}W n$ tk
rN   tdd| Y nX |d }yt|}W n t	k
r   |
d}Y nX yt|}W n$ tk
r   tdd| Y nX t|| |V  d	S )
zBundle the given notebook.
        
        Parameters
        ----------
        path: str
            Path to the notebook (path parameter)
        bundler: str
            Bundler ID to use (query parameter)
        bundler)pathi  zBundler %s not enabledmodule_namezutf-8i  zCould not import bundler %s N)Zget_query_argumentZcontents_managerr   r   r   KeyErrorr   Z	HTTPErrorstrUnicodeEncodeErrorencoder   ImportErrorr	   Zmaybe_futureZbundle)r   r   r   Zmodelr   r   Zbundler_modr   r   r   r   *   s     
zBundlerHandler.getN)
__name__
__module____qualname__r   r   r   Zauthenticatedr	   	coroutiner   r   r   r   r   r
      s   r
   z(?P<bundler_id>[A-Za-z0-9_]+)z/bundle/(.*)N)__doc__ r   Znotebook.utilsr   Znotebook.base.handlersr   Znotebook.services.configr   Zipython_genutils.importstringr   Ztornador   r	   r
   Z_bundler_id_regexZdefault_handlersr   r   r   r   <module>   s   B