a
    ø£BeÓ  ã                   @   sf   d Z ddlZddl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
„ d
e
ƒZdefgZdS )zAPI Handlers for nbconvert.é    N)Úrun_sync)Úweb)Ú
authorizedé   )Ú
APIHandlerZ	nbconvertc                       sB   e Zd ZU dZeZejed< ‡ fdd„Z	e
jedd„ ƒƒZ‡  ZS )ÚNbconvertRootHandlerzThe nbconvert root API handler.Ú_exporter_lockc                    s8   t ƒ jf i |¤Ž t| jdƒs*t ¡ | j_| jj| _dS )z%Initialize an nbconvert root handler.r   N)ÚsuperÚ
initializeÚhasattrÚ	__class__ÚasyncioÚLockr   )ÚselfÚkwargs©r   © úm/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/jupyter_server/services/nbconvert/handlers.pyr
      s    zNbconvertRootHandler.initializec              
   Ã   sð   zddl m} W n6 tyF } zt dd| ¡|‚W Y d}~n
d}~0 0 i }t|jƒI dH }| j4 I dH š\ |D ]@}zt|j|ƒI dH }W n t	y    Y qpY n0 d|j
i||< qpW d  ƒI dH  qÜ1 I dH sÒ0    Y  |  t |¡¡ dS )z$Get the list of nbconvert exporters.r   )Úbaseiô  zCould not import nbconvert: %sNÚoutput_mimetype)Znbconvert.exportersr   ÚImportErrorr   Ú	HTTPErrorr   Zget_export_namesr   Zget_exporterÚ
ValueErrorr   ÚfinishÚjsonÚdumps)r   r   ÚeÚresZ	exportersZexporter_nameZexporter_classr   r   r   Úget   s    (
ÿ4zNbconvertRootHandler.get)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚAUTH_RESOURCEZauth_resourcer   r   Ú__annotations__r
   r   Úauthenticatedr   r   Ú__classcell__r   r   r   r   r      s   

r   z/api/nbconvert)r"   r   r   Zanyio.to_threadr   Útornador   Zjupyter_server.authr   Zbase.handlersr   r#   r   Zdefault_handlersr   r   r   r   Ú<module>   s   /ÿ