
    @=d                         d Z ddlZddlZddlZddlmZ ddlmZ ddl	m
Z
mZ ddlmZ ddlmZ ddlmZ d	d
lmZ d Z G d de          Zd e            z  efgZdS )z'Tornado handler for bundling notebooks.    N)nbclassic_path)import_item)webgen)url2path)JupyterHandler)ConfigManager   toolsc                    t          j        |           rt          j        |           S t	          | t
          j        j                  rt          j        |           S t          j                    }|	                    |            |S )zxLike tornado's deprecated gen.maybe_future

    but more compatible with asyncio for recent versions
    of tornado
    )
inspectisawaitableasyncioensure_future
isinstance
concurrentfuturesFuturewrap_future
set_result)objfs     :lib/python3.11/site-packages/nbclassic/bundler/handlers.pymaybe_futurer      sw     3 $S)))	C+2	3	3 "3''' N	S    c                   T    e Zd Zd Zd Zej        ej        d                         Z	dS )BundlerHandlerc                     t           | _         dS )z~Make tools module available on the handler instance for compatibility
        with existing bundler API and ease of reference.Nr   )selfs    r   
initializezBundlerHandler.initialize(   s     


r   c                 |    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cms      r   get_bundlerzBundlerHandler.get_bundler-   s5    ( __vvj!!%%&92>>zJJr   c              #   F  K   |                      d          }| j                            t          |                    }	 |                     |          }n+# t
          $ r}t          j        dd|z            |d}~ww xY w|d         }	 t          |          }n%# t          $ r |
                    d          }Y nw xY w	 t          |          }n+# t          $ r}t          j        dd	|z            |d}~ww xY wt          |                    | |                    V  dS )
zBundle the given nbclassic.
        
        Parameters
        ----------
        path: str
            Path to the notebook (path parameter)
        bundler: str
            Bundler ID to use (query parameter)
        bundler)pathi  zBundler %s not enabledNmodule_namezutf-8i  zCould not import bundler %s )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.getD   sl      ,,Y77
%))x~~)>>	3&&z22GG 	3 	3 	3-%= *&+ , ,123	3 m,	6k**KK! 	6 	6 	6%,,W55KKK	6	3%k22KK 	3 	3 	3-%C *&+ , ,123	3 ;--dE::;;;;;;;sB   A 
A?!A::A?B B=<B=C 
C9C44C9N)
__name__
__module____qualname__r!   r(   r   authenticatedr   	coroutiner%    r   r   r   r   '   s`          
K K K. 	]#< #< ] #< #< #<r   r   z%s/bundle/(.*))__doc__r   r   concurrent.futuresr   	nbclassicr   traitlets.utils.importstringr   tornador   r   jupyter_server.utilsr   jupyter_server.base.handlersr   jupyter_server.services.configr	    r   r   r   default_handlersr>   r   r   <module>rI      s   - -
       $ $ $ $ $ $ 4 4 4 4 4 4         ) ) ) ) ) ) 7 7 7 7 7 7 8 8 8 8 8 8        "B< B< B< B< B<^ B< B< B<L )))>:   r   