
    IbT
                     |    d Z ddlmZ ddlmZmZ ddlmZmZ ddl	m
Z
 ddlmZ ddlmZ  G d	 d
e
      ZdZdefgZy)z'Tornado handler for bundling notebooks.    )import_item)webgen)maybe_futureurl2path)IPythonHandler)ConfigManager   toolsc                   Z    e Zd Zd Zd Zej                  ej                  d               Z	y)BundlerHandlerc                     t         | _         y)z~Make tools module available on the handler instance for compatibility
        with existing bundler API and ease of reference.Nr   )selfs    ;/usr/lib/python3/dist-packages/notebook/bundler/handlers.py
initializezBundlerHandler.initialize   s     
    c                 ^    t               }|j                  d      j                  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
        notebookbundlerextensions)r	   get)r   
bundler_idcms      r   get_bundlerzBundlerHandler.get_bundler   s-    ( _vvj!%%&92>zJJr   c              #      K   | j                  d      }| j                  j                  t        |            }	 | j	                  |      }|d   }	 t        |      }	 t        |      }t        |j                  | |             y# t
        $ r }t        j                  dd| d      |d}~ww xY w# t        $ r |j                  d      }Y rw xY w# t        $ r }t        j                  d	d
| d      |d}~ww xY ww)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 z not enabledNmodule_namezutf-8i  zCould not import bundler  )get_query_argumentcontents_managerr   r   r   KeyErrorr   	HTTPErrorstrUnicodeEncodeErrorencoder   ImportErrorr   bundle)r   r   r   modelr   er   bundler_mods           r   r   zBundlerHandler.get-   s     ,,Y7
%%))x~)>	Q&&z2G m,	6k*K
	W%k2K ;--dE:;;%  	Q--x
|<%HIqP	Q " 	6%,,W5K	6  	W--'@A%NOUVV	Wsj   7C>B C>B2 C (C>	B/B**B//C>2CC>CC>	C;C66C;;C>N)
__name__
__module____qualname__r   r   r   authenticatedr   	coroutiner    r   r   r   r      s3    
K. 	]]!<  !<r   r   z(?P<bundler_id>[A-Za-z0-9_]+)z/bundle/(.*)N)__doc__ipython_genutils.importstringr   tornador   r   notebook.utilsr   r   notebook.base.handlersr   notebook.services.configr	    r   r   _bundler_id_regexdefault_handlersr1   r   r   <module>r;      sE    -
 6  1 1 2 @<^ @<D 5  n% r   