U
    Sd&2                     @   s  d Z ddlmZmZ ddlZddlZddlZddlmZ ddl	Z	ddl	m
Z
mZmZ ddlmZ ddlmZmZmZmZ ddlm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dl&m'Z' dZ(i Z)i Z*dddiiedfe)d< dddiidfe)d< dddiiedfe)d< e*+d d!d"d#d$d%d&d'd( G d)d de%eee'Z,e,j- Z.Z/dS )*z(A tornado based Jupyter notebook server.    )absolute_importprint_functionN)RedirectHandler)DEFAULT_STATIC_FILES_PATHDEFAULT_TEMPLATE_PATH_LISTnbclassic_path)__version__)UnicodeListBooldefault)jupyter_path)FileFindHandler)url_path_join)ExtensionAppExtensionAppJinjaMixin)_i18n)load_handlers   )TerminalHandler)NotebookConfigShimMixin)NotebookAppTraitsz
jupyter nbclassic                       # start the notebook
jupyter nbclassic --certfile=mycert.pem # use SSL/TLS certificate
jupyter nbclassic password              # enter a password to protect the server
Z	ServerAppopen_browserFz3Don't open the notebook in a browser after startup.z
no-browserNotebookAppZenable_mathjaxa4  Disable MathJax

    MathJax is the javascript library Jupyter uses to render math/LaTeX. It is
    very large, so you may want to disable it if you have a slow internet
    connection, or for offline use of the notebook.

    When disabled, equations etc. will appear as their untransformed TeX source.
    z
no-mathjaxZ
allow_rootTz,Allow the notebook to be run from root user.z
allow-rootzServerApp.ipzServerApp.portzServerApp.port_retrieszServerApp.keyfilezServerApp.certfilezServerApp.client_cazServerApp.notebook_dirzServerApp.browser)ZipZportzport-retriesZkeyfileZcertfilez	client-caznotebook-dirZbrowserc                       s   e Zd ZdZeZedZeZe	Z	dZ
i Zede  jddZedddjddZedd	djddZed
dddZee eddZeddd Zee deddZedd Zedd Zedd Z fddZ fddZdd Zdd Z   Z!S ) r   	nbclassiczThe Jupyter HTML Notebook.

    This launches a Tornado based HTML Notebook Server that serves up an HTML5/Javascript Notebook client.z/treez%s/treeT)configzbWhether the banner is displayed on the page.
        By default, the banner is displayed.
        )helpa  Whether to open in a browser after starting.
        The specific browser used is platform dependent and
        determined by the python standard library `webbrowser`
        module, unless it is overridden using the --browser
        (ServerApp.browser) configuration option.
        Zjupyter_notebook_configzSpecify a config file to load.)r   r   z!Path to search for custom.js, cssstatic_custom_pathc                 C   s   dd | j tfD S )Nc                 S   s   g | ]}t j|d qS )custom)ospathjoin).0d r$   4lib/python3.8/site-packages/nbclassic/notebookapp.py
<listcomp>   s    z;NotebookApp._default_static_custom_path.<locals>.<listcomp>)Z
config_dirr   selfr$   r$   r%   _default_static_custom_path   s
    z'NotebookApp._default_static_custom_pathz6extra paths to look for Javascript notebook extensionsc                 C   s   | j td }|S )z3The path to look for Javascript notebook extensionsZnbextensions)extra_nbextensions_pathr   )r(   r    r$   r$   r%   nbextensions_path   s    zNotebookApp.nbextensions_pathc                 C   s   | j tg S )zRename trait in jupyter_server.)extra_static_pathsr   r'   r$   r$   r%   static_paths   s    zNotebookApp.static_pathsc                 C   s
   | j t S )z Rename trait for Jupyter Server.)Zextra_template_pathsr   r'   r$   r$   r%   template_paths   s    zNotebookApp.template_pathsc                    sl   t t|   tjtj}tj	dtj
|ddd}| jj|dd | jjjtd | jjj| jd d S )	Nnbuiznbclassic/i18nT)	localedirfallbackF)Znewstyle)r   )show_banner)superr   _prepare_templatesr   r    dirnamer   __file__gettexttranslationr!   Z
jinja2_envZinstall_gettext_translationsglobalsupdater   r2   )r(   base_dirr/   	__class__r$   r%   r4      s     zNotebookApp._prepare_templatesc                    s4   dd }t ||j_dd }t || j_t |S )Nc                 S   s   | j tjtjg S ))return extra paths + the default location)r,   jupyter_serverr   r   r'   r$   r$   r%   static_file_path_jupyter_server   s    zSNotebookApp._link_jupyter_server_extension.<locals>.static_file_path_jupyter_serverc                 S   s   | j tjtjdtjg S )r>   Znotebook)r,   r   r    r!   r   r   r'   r$   r$   r%   static_file_path_nbclassic   s    
zNNotebookApp._link_jupyter_server_extension.<locals>.static_file_path_nbclassic)propertyr=   Zstatic_file_pathr3   _link_jupyter_server_extension)r(   	serverappr@   rA   r<   r$   r%   rC      s    z*NotebookApp._link_jupyter_server_extensionc                 C   s   | j r:| jtd | jtdd  ttdt t| jdt	| j
jd| jdgi| j | j| j| jd}| jjf | d	S )
z Add settings to the tornado app.z@The `ignore_minified_js` flag is deprecated and no longer works.zIAlternatively use `%s` when working on the notebook's Javascript and LESSznpm run build:watchzOThe `ignore_minified_js` flag is deprecated and will be removed in Notebook 6.0no_cache_pathsZstaticr   )r   Zstatic_handler_argsignore_minified_jsmathjax_urlmathjax_configr+   N)rF   logZwarningr   warningswarnDeprecationWarningdictr   r   rD   base_urlnamerG   rH   r+   settingsr:   )r(   rP   r$   r$   r%   initialize_settings   s>    zNotebookApp.initialize_settingsc                 C   sd  g }t t dkr.|dtd| jjd if | jd D ]}|t| q8|td |td |td | j	| g }| jj}t
}|||d	td
| jif |||dt| jd dgdf |||dt| jd dgdf td}t |d }| jjj}|jd|  }	|j| d }
g |_||	 || ||
 td dS )z:Load the (URL pattern, handler) tuples for each component.r   z
/nbclassicZurlznbclassic/treeZextra_servicesznbclassic.tree.handlersznbclassic.notebook.handlersznbclassic.edit.handlersz/terminals/(\w+)rO   z/nbextensions/(.*)r+   /)r    rE   z/custom/(.*)r   zjupyter_server.base.handlers   Na  
  _   _          _      _
 | | | |_ __  __| |__ _| |_ ___
 | |_| | '_ \/ _` / _` |  _/ -_)
  \___/| .__/\__,_\__,_|\__\___|
       |_|
                                                                           
Read the migration plan to Notebook 7 to learn about the new features and the actions to take if you are using extensions.

https://jupyter-notebook.readthedocs.io/en/latest/migrate_to_notebook7.html

Please note that updating to Notebook 7 might break some of your extensions.
)lenr   appendr   rD   rN   rP   extendr   handlersr   r   rO   r   Zweb_appZwildcard_routerZrulesZ	add_rulesprint)r(   rW   ZserviceZstatic_handlersrN   ZujoinZbase_handlersnZrouterZ
core_rulesZfinal_rulesr$   r$   r%   initialize_handlers   sT    	






zNotebookApp.initialize_handlers)"__name__
__module____qualname__rO   r   versionr   descriptionaliasesflagsZextension_urlsubcommandsr	   r   tagZdefault_urlr   r2   r   Zconfig_file_namer
   r   r   r)   r*   rB   r+   r-   r.   r4   rC   rQ   rZ   __classcell__r$   r$   r<   r%   r   g   s^   	



)0__doc__Z
__future__r   r   r   r7   rJ   Ztornado.webr   r   r   r   r   Znbclassic._versionr   Z	traitletsr	   r
   r   r   Zjupyter_core.pathsr   r?   Zjupyter_server.base.handlersr   Zjupyter_server.utilsr   Z$jupyter_server.extension.applicationr   r   Zjupyter_server.transutilsr   Zjupyter_server.serverappr   Zterminal.handlersr   Znotebook_shim.shimr   Znotebook_shim.traitsr   Z	_examplesra   r`   r:   r   Zlaunch_instancemainZlaunch_new_instancer$   r$   r$   r%   <module>   sb   




 u