o
    iT
                     @   sv   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
 d
e
ZdZdefgZdS )z'Tornado handler for bundling notebooks.    )import_item)webgen)maybe_futureurl2path)IPythonHandler)ConfigManager   toolsc                   @   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.Nr
   )self r   T/var/www/edux/Edux_v2/venv/lib/python3.10/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
        notebookbundlerextensions)r   get)r   
bundler_idcmr   r   r   get_bundler   s   zBundlerHandler.get_bundlerc              
   c   s    |  d}| jjt|d}z| |}W n ty- } ztdd| d|d}~ww |d }zt|}W n t	yF   |
d}Y nw zt|}W n tyd } ztd	d
| d|d}~ww 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 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_modr   r   r   r   -   s,   
zBundlerHandler.getN)
__name__
__module____qualname__r   r   r   authenticatedr   	coroutiner   r   r   r   r   r      s    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_handlersr   r   r   r   <module>   s    B