o
    tf3                     @  s2  d Z ddlm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 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mZ ddlmZ ddlmZmZmZ ddlm Z  ddl!m"Z"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-m.Z.m/Z/ ddl0m1Z1 ddl2m3Z3 ee4j56 Z7ej8ej9e:ej;e:df f ej;ej9ej8e:ej<f e1f e:f f Z=ee Z>e3Z?G dd deeeZ@G dd de@ZAG dd de@ZBG dd de@ZCG d d! d!e@ZDG d"d# d#e@ZEG d$d% d%e@ZFeGeZHG d&d' d'e)e ZIeIjJ ZKZLeMd(kreK  dS dS ))zJupyter notebook application.    )annotationsN)Path)ensure_async)base_aliases)jupyter_config_dir)JupyterHandler)ExtensionHandlerJinjaMixinExtensionHandlerMixin)flags)
url_escapeurl_is_absolute)url_path_join)get_app_dirget_user_settings_dirget_workspaces_dir)LabServerApp)	LabConfigget_page_configrecursive_update)
_camelCaseis_url)NotebookConfigShimMixin)web)BoolUnicodedefault)Config   )__version__.c                   @  s(   e Zd ZdZed
ddZdddZd	S )NotebookBaseHandlerzThe base notebook API handler.returnt.Anyc                 C  s   | j ddS )N
custom_cssT)settingsgetself r'   U/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/notebook/app.pyr"   4      zNotebookBaseHandler.custom_cssdict[str, t.Any]c              	   C  s  t  }| j}| jdd}| jdi }i |t| j| jdd| jd t| jd| jt| jd|j	d}| jd	d
}|
tjd}tjt| }z| jj|krcdtj| jj| |d< nd|d< W n tyu   d|d< Y nw | jdd}| jdd}t|s|| jst| j|}|d| |d| |dt  | D ]}	t||	|t|	< q| D ] }	|	dsqtd|	 }
t||	}t|st||}|||
< q|j|j }t|t || j!d |S )zGet the page config.base_url/page_config_dataZterminals_availableFtokenstatic)Z
appVersionZbaseUrlZterminalsAvailabler.   ZfullStaticUrlZfrontendUrlZexposeAppInBrowserZserver_root_dir ZpreferredPathmathjax_configzTeX-AMS_HTML-full,Safemathjax_urlz?https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.jsZmathjaxConfigZfullMathjaxUrljupyterConfigDir_urlZfull_)logger)"r   Zextensionappr#   r$   
setdefaultversionr+   ujoinnameexpose_app_in_browserreplaceosseppathnormpathr   
expanduser	serverappZpreferred_dirrelpath	Exceptionr   
startswithr   Ztrait_namesgetattrr   endswithr   Zextra_labextensions_pathlabextensions_pathr   r   log)r&   configZappr+   r-   page_configZserver_rootr1   r2   r9   Z	full_namefull_urlrG   r'   r'   r(   r   8   sr   




z#NotebookBaseHandler.get_page_configNr    r!   )r    r*   )__name__
__module____qualname____doc__propertyr"   r   r'   r'   r'   r(   r   1   s
    r   c                   @  s"   e Zd ZdZejd
dddZd	S )TreeHandlerzA tree page handler.r0   r>   strr    Nonec                   s
  | d}| j}t|j|dI dH r@t||I dH r,|js,| jd t	d| 
 }||d< | jd|d}| |S t||I dH rt|j|d	d
I dH }|d dkrft| jdt|}n	t| jdt|}| jd| jj| | | dS t	d)z
        Display appropriate page for given path.

        - A directory listing is shown if path is a directory
        - Redirected to notebook page if path is a notebook
        - Render the raw file if path is any other file
        r,   )r>   Nz1Refusing to serve hidden directory, via 404 Errori  ZtreePathz	tree.htmlrJ   F)contenttypenotebookZ	notebooksfileszRedirecting %s to %s)stripZcontents_managerr   Z
dir_existsZ	is_hiddenZallow_hiddenrH   infor   	HTTPErrorr   render_templatewriteZfile_existsr$   r8   r+   r   debugrequestr>   redirect)r&   r>   cmrJ   tplmodelurlr'   r'   r(   r$      s(   
	



zTreeHandler.getN)r0   )r>   rS   r    rT   rM   rN   rO   rP   r   authenticatedr$   r'   r'   r'   r(   rR   ~       rR   c                   @  "   e Zd ZdZejd	d
ddZdS )ConsoleHandlerzA console page handler.Nr>   
str | Noner    r!   c                 C     | j d|  d}| |S )zGet the console page.zconsoles.htmlrU   r]   r   r^   r&   r>   rc   r'   r'   r(   r$         
zConsoleHandler.getNr>   rk   r    r!   rf   r'   r'   r'   r(   rj      rh   rj   c                   @  ri   )TerminalHandlerzA terminal page handler.Nr>   rk   r    r!   c                 C  rl   )zGet the terminal page.zterminals.htmlrU   rm   rn   r'   r'   r(   r$      ro   zTerminalHandler.getrp   rq   rf   r'   r'   r'   r(   rr      rh   rr   c                   @  ri   )FileHandlerzA file page handler.Nr>   rk   r    r!   c                 C  rl   )zGet the file page.z	edit.htmlrU   rm   rn   r'   r'   r(   r$      ro   zFileHandler.getrp   rq   rf   r'   r'   r'   r(   rs      rh   rs   c                   @  ri   )NotebookHandlerzA notebook page handler.Nr>   rk   r    r!   c                 C  rl   )zGet the notebook page.znotebooks.htmlrU   rm   rn   r'   r'   r(   r$      ro   zNotebookHandler.getrp   rq   rf   r'   r'   r'   r(   rt      rh   rt   c                   @  s    e Zd ZdZejdddZdS )CustomCssHandlerzA custom CSS handler.r    r!   c                 C  s   |  dd |  }|d  d}t| s.td|d }|dur.| d }| d	}t| }| |	 W  d   S 1 sFw   Y  dS )
zGet the custom css file.zContent-Typeztext/cssr3   /custom/custom.cssz^(.*?)staticZ	staticDirNr   zcustom/custom.css)
Z
set_headerr   r   is_filerematchgroupsopenr^   read)r&   rJ   Zcustom_css_fileZstatic_path_rootZ
custom_dirZcss_fr'   r'   r(   r$      s   
$zCustomCssHandler.getNrL   rf   r'   r'   r'   r(   ru      s    ru   c                      s`  e Zd ZU dZdZdZdZeZeeddZ	dZ
edd	d
dZdZd	ZeZi Zded< edd	ddZed	d	ddZeZded< d dd	iidfed< d dd	iidfed< edd>ddZedd>dd Zed!d>d"d#Zed$d>d%d&Zed'd>d(d)Zed*d>d+d,Zed-d>d.d/Zd? fd1d2Zd@d5d6Zd? fd7d8ZdAdB fd<d=Z   Z!S )CJupyterNotebookAppz"The notebook server extension app.rX   zJupyter NotebookzMJupyter Notebook - A web-based notebook environment for interactive computingzThe version of the application.)helpr,   z/treeTz'The default URL to redirect to from `/`)rI   r~   r*   subcommandsFzJWhether to expose the global app instance to browser via window.jupyterappzeWhether custom CSS is loaded on the page.
        Defaults to True and custom CSS is loaded.
        Flagsr
   r:   z@Expose the global app instance to browser via window.jupyterapp.zexpose-app-in-browserr"   z7Load custom CSS in template html files. Default is Truez
custom-cssZ
static_dirr    rS   c                 C     t td S )Nr/   rS   HEREr%   r'   r'   r(   _default_static_dir     z&JupyterNotebookApp._default_static_dirZtemplates_dirc                 C  r   )NZ	templatesr   r%   r'   r'   r(   _default_templates_dir  r   z)JupyterNotebookApp._default_templates_dirZapp_settings_dirc                 C  r   )Nr#   rS   app_dirr%   r'   r'   r(   _default_app_settings_dir  r   z,JupyterNotebookApp._default_app_settings_dirZschemas_dirc                 C  r   )NZschemasr   r%   r'   r'   r(   _default_schemas_dir  r   z'JupyterNotebookApp._default_schemas_dirZ
themes_dirc                 C  r   )Nthemesr   r%   r'   r'   r(   _default_themes_dir  r   z&JupyterNotebookApp._default_themes_dirZuser_settings_dirc                 C     t tt S rp   )tcastrS   r   r%   r'   r'   r(   _default_user_settings_dir"  r)   z-JupyterNotebookApp._default_user_settings_dirZworkspaces_dirc                 C  r   rp   )r   r   rS   r   r%   r'   r'   r(   _default_workspaces_dir&  r)   z*JupyterNotebookApp._default_workspaces_dirrT   c                   s$   t t|   | jjj| jd d S )N)r"   )superr   _prepare_templatesZ
jinja2_envglobalsupdater"   r%   	__class__r'   r(   r   *  s   z%JupyterNotebookApp._prepare_templates	extensionboolc              
   C  sH   | j du rdS z| j jj| jdu }W |S  tttfy#   d}Y |S w )z%Check if server extension is enabled.NFT)rA   Zextension_manager
extensionsenabledAttributeErrorKeyError	TypeError)r&   r   Zextension_enabledr'   r'   r(   server_extension_is_enabled.  s   
z.JupyterNotebookApp.server_extension_is_enabledc                   s
  | j dusJ | j jjdi }| d}||d< d| j jv rN| j j}|d }||d< |d |d< |d	 |d
< t|d|d< t| j drJ| j j|d< d|d< | j	
dtf | j	
dtf | j	
dtf | j	
dtf | j	
dtf | j	
dtf t   dS )zInitialize handlers.Nr-   Z	nbclassicnbclassic_enabled
hub_prefixZ	hubPrefixZhub_hostZhubHostuserZhubUserzuser-redirectZshareUrlserver_nameZhubServerNamer0   r.   z	/tree(.*)z/notebooks(.*)z	/edit(.*)z/consoles/(.*)z/terminals/(.*)rv   )rA   Zweb_appr#   r6   r   tornado_settingsr8   hasattrr   handlersappendrR   rt   rs   rj   rr   ru   r   initialize_handlers)r&   rJ   r   r   r   r   r'   r(   r   :  s*   
z&JupyterNotebookApp.initialize_handlersNargvlist[str] | Nonec                   s   t    dS )zMSubclass because the ExtensionApp.initialize() method does not take argumentsN)r   
initialize)r&   r   r   r'   r(   r   Z  r)   zJupyterNotebookApp.initialize)r    rS   )r    rT   )r   rS   r    r   rp   )r   r   r    rT   )"rM   rN   rO   rP   r9   Zapp_namedescriptionr7   r   Zapp_versionZextension_urlZdefault_urlZfile_url_prefixZload_other_extensionsr   r   __annotations__r   r:   r"   r
   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r'   r'   r   r(   r}      s`   
 


 r}   __main__)NrP   
__future__r   r<   rx   typingr   pathlibr   Zjupyter_client.utilsr   Zjupyter_core.applicationr   Zjupyter_core.pathsr   Zjupyter_server.base.handlersr   Z jupyter_server.extension.handlerr   r	   Zjupyter_server.serverappr
   Zjupyter_server.utilsr   r   r   r8   Zjupyterlab.commandsr   r   r   Zjupyterlab_serverr   Zjupyterlab_server.configr   r   r   Zjupyterlab_server.handlersr   r   Znotebook_shim.shimr   tornador   Z	traitletsr   r   r   Ztraitlets.config.loaderr   _versionr   __file__parentresolver   DictUnionrS   TupleAnyr   r   r7   r   rR   rj   rr   rs   rt   ru   dictaliasesr}   Zlaunch_instancemainZlaunch_new_instancerM   r'   r'   r'   r(   <module>   sP    B
M(




y

