B
    9‹dy ã               @   sÊ  d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZyddlZW n ek
r
   dZY nX ddlm Z  ddl!m"Z"m#Z# ddl$m%Z%m&Z& yddl'Z'W n2 ek
rv Z( zee&dƒƒe(‚W ddZ([(X Y nX y
e'j)Z)W n2 e*k
r´ Z( zee&dƒƒe(‚W ddZ([(X Y nX e)dk rÒee&d	ƒe'j+ ƒ‚dd
l'm,Z, ddl'm-Z- ddl'm.Z. ddl/m0Z0 ddl1m2Z2m3Z3m4Z4m5Z5 ej6 7d¡s4ddl8m9Z9 ddlm:Z:m;Z;m<Z< ddl=Z=ej> ?ej> @e=jA¡d¡ZBddlCmDZDmEZE ddlFmGZG ddlHmIZImJZJ ddlKmLZL ddlMmNZN ddlOmPZP ddlQmRZR ddlSmTZT ddlUmVZVmWZWmXZXmYZY ddlZm[Z[ ddl\m]Z] ddlCm^Z^ dd l_m`Z` dd!lambZbmcZc dd"ldmeZemfZfmgZg dd#lhmiZi dd$ljmkZk dd%llmmZm dd&lnmoZo dd'lpmqZq dd(lrmsZsmtZtmuZumvZvmwZwmxZxmyZymzZzm{Z{m|Z|m}Z}m~Z~mZm€Z€ dd)lm‚Z‚ dd*lhmƒZƒm„Z„ dd+l…m†Z† dd,l‡mˆZˆm‰Z‰ dd-lŠm‹Z‹mŒZŒmZmŽZŽmZmZm‘Z‘m’Z’m“Z“ dd.l”m•Z• ydd/ljm–Z– d0Z—W n ek
rV   d1Z—Y nX ydd2l˜m™Z™ d0ZšW n ek
r†   d1ZšY nX d3Z›d4d5„ Zœd6d7„ ZG d8d9„ d9e.jžƒZŸG d:d;„ d;eeƒZ dfd=d>„Z¡G d?d@„ d@eeƒZ¢G dAdB„ dBeeƒZ£e¤efƒZ¥dCdDd1iie&dEƒfe¥dF< dCdGdHiie&dIƒfe¥dG< dCdJd1iidKfe¥dL< dCdMd0iie&dNƒfe¥dO< dCdPd0iidQfe¥dP< e¥ ¦ecdRdSdTdTƒ¡ e¤egƒZ§e§ ¦dUdVdWdXdYdZd[d\d]d^d_d`dadbœ¡ G dcdC„ dCeeƒZ¨dgddde„Z©e¨jª Z«Z¬dS )hz(A tornado based Jupyter notebook server.é    N)Úencodebytes)ÚEnvironmentÚFileSystemLoader)ÚtransÚ_z,The Jupyter Notebook requires tornado >= 5.0zBThe Jupyter Notebook requires tornado >= 5.0, but you have < 1.1.0)é   r   z=The Jupyter Notebook requires tornado >= 5.0, but you have %s)Ú
httpserver)Úioloop)Úweb)Ú
url_concat)ÚLogFormatterÚapp_logÚ
access_logÚgen_logÚwin)Úbind_unix_socket)ÚDEFAULT_NOTEBOOK_PORTÚDEFAULT_TEMPLATE_PATH_LISTÚ__version__Ústaticé   )ÚTemplate404ÚRedirectWithParams)Úlog_request)ÚMappingKernelManagerÚAsyncMappingKernelManager)ÚConfigManager)ÚContentsManager)ÚFileContentsManager)ÚLargeFileManager)ÚSessionManager)ÚGatewayKernelManagerÚGatewayKernelSpecManagerÚGatewaySessionManagerÚGatewayClient)ÚLoginHandler)ÚLogoutHandler)ÚFileFindHandler)ÚConfig)Úcatch_config_errorÚboolean_flag)Ú
JupyterAppÚ
base_flagsÚbase_aliases)Újupyter_config_path)ÚKernelManager)ÚKernelSpecManager)ÚSession)ÚNotebookNotary)ÚAnyÚDictÚUnicodeÚIntegerÚListÚBoolÚBytesÚInstanceÚ
TraitErrorÚTypeÚFloatÚobserveÚdefaultÚvalidate)Ú	py3compat)Újupyter_runtime_dirÚjupyter_path)Úget_sys_info)ÚutcnowÚutcfromtimestamp)	Ú	check_pidÚpathname2urlÚrun_syncÚunix_socket_in_useÚ
url_escapeÚurl_path_joinÚurldecode_unix_socket_pathÚurlencode_unix_socketÚurljoin)ÚTypeFromClasses)ÚAsyncMultiKernelManagerTF)ÚTerminalManagerzÎ
jupyter notebook                       # start the notebook
jupyter notebook --certfile=mycert.pem # use SSL/TLS certificate
jupyter notebook password              # enter a password to protect the server
c          	   c   s\   x t td|ƒƒD ]}| | V  qW x4t |d ƒD ]$}td| t d| d| ¡ ƒV  q0W dS )z½Generate a list of n random ports near the given port.

    The first 5 ports will be sequential, and the remaining n-5 will be
    randomly selected in the range [port-2*n, port+2*n].
    r   r   éþÿÿÿé   N)ÚrangeÚminÚmaxÚrandomÚrandint)ÚportÚnÚi© r]   úa/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/notebook/notebookapp.pyÚrandom_ports–   s    r_   c             C   s   t | dgd}|jS )z:Load the (URL pattern, handler) tuples for each component.Údefault_handlers)Úfromlist)Ú
__import__r`   )ÚnameÚmodr]   r]   r^   Úload_handlers¡   s    re   c                   s6   e Zd Z‡ fdd„Zd
dd„Zdd„ Zdd	„ Z‡  ZS )ÚNotebookWebApplicationc                sX   |   |||||||||	|
||¡}|  |¡}|d r<| d¡ tdƒ tƒ j|f|Ž d S )NÚ
autoreloadzMAutoreload enabled: the webapp will restart when any Python src file changes.a¶  
  _   _          _      _
 | | | |_ __  __| |__ _| |_ ___
 | |_| | '_ \/ _` / _` |  _/ -_)
  \___/| .__/\__,_\__,_|\__\___|
       |_|
                       
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.
)Úinit_settingsÚinit_handlersÚinfoÚprintÚsuperÚ__init__)ÚselfÚjupyter_appÚkernel_managerÚcontents_managerÚsession_managerÚkernel_spec_managerÚconfig_managerÚextra_servicesÚlogÚbase_urlÚdefault_urlÚsettings_overridesÚjinja_env_optionsÚsettingsÚhandlers)Ú	__class__r]   r^   rm   ­   s    


zNotebookWebApplication.__init__Nc          /   C   sT  |  d|j¡}t|tjƒr |f}dd„ |D ƒ}ddi}| |rB|ni ¡ tf t|ƒdgdœ|—Ž}tƒ }t	j
 t	j
 tdd¡¡}t	j
 t	j
 |d	¡¡}tjd
t	j
 |d¡dd}|j|dd |rØdd› d}| |¡ |d dkrêd}ntj ¡  d¡}|jr2| tdƒ¡ | tdƒd ¡ t tdƒt¡ tƒ }|j}tjt	j
 d¡t  !¡ d}| "|t	j
j# ¡r€d|t$|ƒd …  }t%j&t'||j(d}t)||	|
||j*|j+t,t-|	dƒdt-|	ddƒgi||j|j.|j/|j0|j1|j2t-|	d ƒ|j3|j4|j5d|j6|j7|j8|j9|||||||i |j:|j;|j<|j=|j>|j?|j@|jA|jB||tCo@|jDd!-}| |¡ |S )"NÚtemplate_pathc             S   s   g | ]}t j |¡‘qS r]   )ÚosÚpathÚ
expanduser)Ú.0r€   r]   r]   r^   ú
<listcomp>Ø   s    z8NotebookWebApplication.init_settings.<locals>.<listcomp>Z
autoescapeTzjinja2.ext.i18n)ÚloaderÚ
extensionsz..z.gitÚnbuiznotebook/i18n)Ú	localedirÚfallbackF)ZnewstylezIt looks like you're running the notebook from source.
    If you're working on the Javascript of the notebook, try running

    znpm run build:watchz

    in another terminal window to have the system incrementally
    watch and build the notebook's JavaScript for you, as you make changes.Zcommit_sourceÚ
repositoryÚ z%Y%m%d%H%M%Sz@The `ignore_minified_js` flag is deprecated and no longer works.zIAlternatively use `%s` when working on the notebook's Javascript and LESSzOThe `ignore_minified_js` flag is deprecated and will be removed in Notebook 6.0ú~)Úencoding)rv   Úlog_jsonz/static/Úno_cache_pathsr   Úcustomz/login)-Úlog_functionrw   rx   r~   Zstatic_pathÚstatic_custom_pathZstatic_handler_classÚstatic_url_prefixZstatic_handler_argsÚversion_hashÚignore_minified_jsÚshow_bannerÚiopub_msg_rate_limitÚiopub_data_rate_limitÚrate_limit_windowÚcookie_secretZ	login_urlÚlogin_handler_classÚlogout_handler_classÚpasswordZxsrf_cookiesÚdisable_check_xsrfÚallow_remote_accessÚlocal_hostnamesÚauthenticate_prometheusrp   rq   rr   rs   rt   ru   ÚstartedÚlast_activity_timesÚjinja_template_varsÚnbextensions_pathÚwebsocket_urlÚmathjax_urlÚmathjax_configZshutdown_buttonÚconfigÚ
config_dirÚallow_password_changeZserver_root_dirÚ
jinja2_envÚterminals_available)EÚgetÚtemplate_file_pathÚ
isinstancerA   Ústring_typesÚupdater   r   rD   r   r€   ÚrealpathÚjoinÚ__file__ÚexistsÚgettextÚtranslationZinstall_gettext_translationsrj   ÚdatetimeÚnowÚstrftimer”   Úwarningr   ÚwarningsÚwarnÚDeprecationWarningrE   Úroot_dirZstr_to_unicoder   ÚsysÚgetfilesystemencodingÚ
startswithÚsepÚlenÚ	functoolsÚpartialr   r   ÚdictÚstatic_file_pathr‘   r'   rL   r•   r–   r—   r˜   r™   rš   r›   rœ   r   rž   rŸ   r    r£   r¤   r¥   r¦   r§   Úquit_buttonr¨   r©   rª   Úterminado_availableÚterminals_enabled)rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   Z_template_pathr~   Zjenv_optÚenvZsys_infoÚbase_dirÚdev_moder†   ZDEV_NOTE_NPMr“   r¹   r¿   Úhomer   r{   r]   r]   r^   rh   Ì   sž    

z$NotebookWebApplication.init_settingsc             C   st  g }x|d D ]}|  t|ƒ¡ qW |  tdƒ¡ |  d|d fg¡ |  d|d fg¡ |  tdƒ¡ |  tdƒ¡ |  td	ƒ¡ |  td
ƒ¡ |  tdƒ¡ |  tdƒ¡ |  tdƒ¡ |  tdƒ¡ |  tdƒ¡ |  tdƒ¡ |  tdƒ¡ |  tdƒ¡ |  tdƒ¡ |  tdƒ¡ |  tdƒ¡ |  tdƒ¡ |  |d  ¡ ¡ t ¡ jr¸tdƒ}xVt|ƒD ]J\}}x>t|ƒD ]2\}}|d |d kr||d |d f||< P q|W qjW | dt|d dgdœf¡ | dt|d  dgdœf¡ |  td!ƒ¡ | d"t	|d# d$d%œf¡ g }	xD|D ]<}
t
|d& |
d ƒ}t|gt|
dd'… ƒ ƒ}|	 |¡ q"W |	 d(tf¡ |	S ))z:Load the (URL pattern, handler) tuples for each component.ru   znotebook.tree.handlersz/loginrš   z/logoutr›   znotebook.files.handlersznotebook.view.handlersznotebook.notebook.handlersznotebook.nbconvert.handlersznotebook.bundler.handlersznotebook.kernelspecs.handlersznotebook.edit.handlersznotebook.services.api.handlersz!notebook.services.config.handlersz#notebook.services.contents.handlersz#notebook.services.sessions.handlersz$notebook.services.nbconvert.handlersz#notebook.services.security.handlersznotebook.services.shutdownz"notebook.services.kernels.handlersz&notebook.services.kernelspecs.handlersrq   znotebook.gateway.handlersr   r   z/nbextensions/(.*)r¤   ú/)r€   rŽ   z/custom/(.*)r‘   znotebook.base.handlersz/?rx   F)ÚurlZ	permanentrw   Nz(.*))Úextendre   Zget_extra_handlersr$   ÚinstanceÚgateway_enabledÚ	enumerateÚappendr'   r   rL   ÚtupleÚlistr   )rn   r{   r|   ZserviceZgateway_handlersr\   ZgwhÚjÚhZnew_handlersÚhandlerÚpatternZnew_handlerr]   r]   r^   ri   M  sd    
z$NotebookWebApplication.init_handlersc             C   s†   | j d | j d jg}y| | j d ¡ W n tk
r>   Y nX y| | j d ¡ W n tk
rh   Y nX | | j d  ¡ ¡ t|ƒS )z¦Get a UTC timestamp for when the server last did something.

        Includes: API activity, kernel activity, kernel shutdown, and terminal
        activity.
        r¡   rp   Zapi_last_activityZterminal_last_activityr¢   )r{   Zlast_kernel_activityrÖ   ÚKeyErrorrÒ   ÚvaluesrW   )rn   Úsourcesr]   r]   r^   Úlast_activity–  s    z$NotebookWebApplication.last_activity)N)Ú__name__Ú
__module__Ú__qualname__rm   rh   ri   rà   Ú__classcell__r]   r]   )r}   r^   rf   «   s   #
}Irf   c               @   s$   e Zd ZdZeZdd„ Zdd„ ZdS )ÚNotebookPasswordAppz™Set a password for the notebook server.

    Setting a password secures the notebook server
    and removes the need for token-based authentication.
    c             C   s   t j | jd¡S )Nzjupyter_notebook_config.json)r   r€   r³   r©   )rn   r]   r]   r^   Ú_config_file_defaultµ  s    z(NotebookPasswordApp._config_file_defaultc             C   s0   ddl m} || jd | j d| j› ¡ d S )Nr   )Úset_password)Úconfig_filezWrote hashed password to )Zauth.securityrç   rè   rv   rj   )rn   rç   r]   r]   r^   Ústart¸  s    zNotebookPasswordApp.startN)rá   râ   rã   Ú__doc__Údescriptionræ   ré   r]   r]   r]   r^   rå   ¬  s   rå   r   c                s–  ddl m‰  ddlm}m}m} ddlm} | d }| d }d}	| d¡rv| 	dd	¡}G ‡ fd
d„d|ƒ}
|
|ƒ d}	||d dddd| d  id}|r¦| 
d|¡ |jd|	d ||ƒ |¡ x:t|d ƒD ]*}t|ƒsð|rì| 
d|¡ dS t d¡ qÐW tj d¡rdS |r"| 
d|¡ t |tj¡ x@t|d ƒD ]0}t|ƒsb|r^| 
d|¡ dS t d¡ q>W |r„| 
d|¡ t |tj¡ dS )a¼  Shutdown a notebook server in a separate process.

    *server_info* should be a dictionary as produced by list_running_servers().

    Will first try to request shutdown using /api/shutdown .
    On Unix, if the server is still running after *timeout* seconds, it will
    send SIGTERM. After another timeout, it escalates to SIGKILL.

    Returns True if the server was stopped by any means, False if stopping it
    failed (on Windows).
    r   )Úgen)ÚAsyncHTTPClientÚ
HTTPClientÚHTTPRequest)ÚResolverrÑ   ÚpidNzhttp+unix://zhttp://c                   s.   e Zd Zdd„ Zdd„ Z” j‡ fdd„ƒZdS )z+shutdown_server.<locals>.UnixSocketResolverc             S   s
   || _ d S )N)Úresolver)rn   rò   r]   r]   r^   Ú
initialize×  s    z6shutdown_server.<locals>.UnixSocketResolver.initializec             S   s   | j  ¡  d S )N)rò   Úclose)rn   r]   r]   r^   rô   Ú  s    z1shutdown_server.<locals>.UnixSocketResolver.closec                s   ˆ   tjt|ƒfg¡‚d S )N)ÚReturnÚsocketÚAF_UNIXrM   )rn   ÚhostrZ   ÚargsÚkwargs)rì   r]   r^   ÚresolveÝ  s    z3shutdown_server.<locals>.UnixSocketResolver.resolveN)rá   râ   rã   ró   rô   Ú	coroutinerû   r]   )rì   r]   r^   ÚUnixSocketResolverÖ  s   rý   )rò   zapi/shutdownÚPOSTó    ÚAuthorizationztoken Útoken)ÚmethodÚbodyÚheaderszPOST request to %sapi/shutdowné
   zServer PID %s is goneTgš™™™™™¹?r   FzSIGTERM to PID %szSIGKILL to PID %s)Útornadorì   Ztornado.httpclientrí   rî   rï   Útornado.netutilrð   rÂ   ÚreplaceÚdebugÚ	configureÚfetchrU   rG   ÚtimeÚsleeprÀ   Úplatformr   ÚkillÚsignalÚSIGTERMÚSIGKILL)Úserver_infoÚtimeoutrv   rí   rî   rï   rð   rÑ   rñ   rò   rý   Úreqr   r]   )rì   r^   Úshutdown_server¾  sJ    
   
  r  c                   sl   e Zd ZeZdZeedde› dZe	ddddZ
d‡ fdd	„	Zd
d„ Zdd„ Zedd„ ƒZdd„ Z‡  ZS )ÚNbserverStopAppz'Stop currently running notebook server.Tz)Port of the server to be killed. Default )r¨   ÚhelprŠ   z'UNIX socket of the server to be killed.Nc                sL   t ƒ  |¡ | jrHyt| jd ƒ| _W n  tk
rF   | jd | _Y nX d S )Nr   )rl   Úparse_command_lineÚ
extra_argsÚintrZ   Ú
ValueErrorÚsock)rn   Úargv)r}   r]   r^   r    s    z"NbserverStopApp.parse_command_linec             C   s   t || jdS )N)rv   )r  rv   )rn   Úserverr]   r]   r^   r    s    zNbserverStopApp.shutdown_serverc             C   s\   t d|› dƒ |  |¡}|sDtj d¡rDtt| jƒƒ}||krDd}|sXt d|› ¡ d S )NzShutting down server on z...r   TzCould not stop server on )	rk   r  rÀ   r  rÂ   rØ   Úlist_running_serversÚruntime_dirÚexit)rn   Ztarget_endpointr  Zserver_stoppedÚserversr]   r]   r^   Ú_shutdown_or_exit  s    
z!NbserverStopApp._shutdown_or_exitc             C   s(   yt  | ¡ W n tk
r"   Y nX d S )N)r   ÚunlinkÚOSError)Zsocket_pathr]   r]   r^   Ú_maybe_remove_unix_socket(  s    z)NbserverStopApp._maybe_remove_unix_socketc             C   s  t t| jƒƒ}|s"|  d| j ¡ xÜ|D ]l}| jrh| dd ¡}|r”|| jkr”|  ||¡ |  |¡ d S q(| jr(| dd ¡}|| jkr(|  ||¡ d S q(W | jp¢| j}t	d|› t
jd t	dt
jd x.|D ]&}t	d | d¡pæ|d ¡t
jd qÌW |  d¡ d S )	Nz%There are no running servers (per %s)r  rZ   z(There is currently no server running on )ÚfilezPorts/sockets currently in use:z  - {}r   )rØ   r   r!  r"  r  r­   r$  r'  rZ   rk   rÀ   ÚstderrÚformat)rn   r#  r  r  rZ   Zcurrent_endpointr]   r]   r^   ré   /  s.    




&zNbserverStopApp.start)N)rá   râ   rã   r   Úversionrë   r6   r   rZ   r5   r  r  r  r$  Ústaticmethodr'  ré   rä   r]   r]   )r}   r^   r    s   	r  c               @   sp   e Zd ZeZedƒZed ddiiedƒfd ddiiedƒfdZe	dded	ƒd
Z
e	ddedƒd
Zdd„ ZdS )ÚNbserverListAppz(List currently running notebook servers.ÚjsonlistTz*Produce machine-readable JSON list output.Újsonz<Produce machine-readable JSON object on each line of output.)r.  r/  FzIf True, the output will be a JSON list of objects, one per active notebook server, each with the details from the relevant server info file.)r¨   r  z«If True, each line of output will be a JSON object with the details from the server info file. For a JSON list output, see the NbserverListApp.jsonlist configuration valuec             C   s˜   t t| jƒƒ}| jr(ttj|ddƒ nl| jrLxd|D ]}tt |¡ƒ q4W nHtdƒ x>|D ]6}|d }| d¡r€|d|d   }t|d|d ƒ qZW d S )	NrT   )ÚindentzCurrently running servers:rÑ   r  z	?token=%sz::Únotebook_dir)rØ   r   r!  r.  rk   r/  Údumpsr­   )rn   Zserverinfo_listZ
serverinforÑ   r]   r]   r^   ré   a  s    


zNbserverListApp.startN)rá   râ   rã   r   r+  r   rë   rÇ   Úflagsr8   r.  r/  ré   r]   r]   r]   r^   r-  M  s   

r-  ÚNotebookAppÚopen_browserz3Don't open the notebook in a browser after startup.z
no-browserÚpylabr½   zIDISABLED: use %pylab or %matplotlib in the notebook to enable matplotlib.Ú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-mathjaxÚ
allow_rootz,Allow the notebook to be run from root user.z
allow-rootrg   z¼Autoreload the webapp

    Enable reloading of the tornado webapp and all imported Python packages
    when any changes are made to any Python src files in Notebook or
    extensions.
    ÚscriptzFileContentsManager.save_scriptzDEPRECATED, IGNOREDzNotebookApp.ipzNotebookApp.portzNotebookApp.port_retrieszNotebookApp.sockzNotebookApp.sock_modezKernelManager.transportzNotebookApp.keyfilezNotebookApp.certfilezNotebookApp.client_cazNotebookApp.notebook_dirzNotebookApp.browserzNotebookApp.pylabzGatewayClient.url)ÚiprZ   zport-retriesr  z	sock-modeÚ	transportÚkeyfileÚcertfilez	client-caznotebook-dirÚbrowserr6  zgateway-urlc                   s¨	  e Zd ZdZeZedƒZeZ	e
Z
eZeeeeeeeeeeegZerLe e¡ eeƒZee
ƒZ
eeej ¡ d feej ¡ d fe e j ¡ d fdZ!e"Z#dZ$e%ddedƒdZ&e'd	ƒd
d„ ƒZ(e)d	ƒdd„ ƒZ*e'dƒdd„ ƒZ+e'dƒdd„ ƒZ,e'dƒdd„ ƒZ-e%ddedƒdZ.e/dddZ0e/ddddZ1e/ddddZ2e%ddedƒdZ3e%ddedƒdZ4e%ddddZ5e%ddddZ6e/d ded!ƒdZ7e/d"ded#ƒdZ8e'd$ƒd%d&„ ƒZ9e)d$ƒd'd(„ ƒZ:e/dded)ƒdZ;d*Z<e=Z>e?e>ded+ƒdZ@e'd,ƒd-d.„ ƒZAd/ZBd0ZCe?eCded1ƒdZDe'd2ƒd3d4„ ƒZEe/dded5ƒdZFe/d6ded7ƒdZGe)d8ƒd9d:„ ƒZHe/dded;ƒdZIe/dded<ƒdZJe/dded=ƒdZKe/ded>ƒdZLe'd?ƒd@dA„ ƒZMeNdBddCdZOe'dDƒdEdF„ ƒZPdGdH„ ZQe/dIedJƒdKjRddZSdZTe'dLƒdMdN„ ƒZUe?dOddPdZVe?dOddQdZWe?ddRdZXe'dSƒdTdU„ ƒZYeZdLƒdVdW„ ƒZ[e/dddXdZ\e%dddYdZ]e%dddZdZ^e%ddd[dZ_e%dd\dZ`e'd]ƒd^d_„ ƒZaebe/ƒ d"gdd`dZce%dddadZde%dddbdZee/dddcdZfe?dddedeƒdZgededfƒdZheZdgƒdhdi„ ƒZiededjƒdZjekdkdedlƒdZlededmƒdZmedednƒdZnededoƒdZoededpƒdZpededqƒdZqededrƒdZre%dddsdZseZdtƒdudv„ ƒZte/dwddxdZue)dyƒdzd{„ ƒZve/dwded|ƒdZweZd}ƒd~d„ ƒZxebe/ƒ dd€dZyezdd‚„ ƒZ{ebe/ƒ edƒƒdKZ|e'd„ƒd…d†„ ƒZ}ebe/ƒ ded‡ƒdZ~ezdˆd‰„ ƒZebe/ƒ dedŠƒdZ€ebe/ƒ ded‹ƒdZezdŒd„ ƒZ‚e/dddŽdZƒe/ddddZ„e'dƒd‘d’„ ƒZ…eZdƒd“d”„ ƒZ†e/d•ded–ƒdZ‡eZd—ƒd˜d™„ ƒZˆe%dddšdZ‰eŠe‹ed›gdedœƒdZŒeZdžƒdŸd „ ƒZeŽeeded¡ƒd¢ZeŽeded£ƒd¤Z‘eŽe’ded¥ƒd¤Z“e”edd¦Z•eŽedd§d¤Z–eŽe—e˜j™ded¨ƒd¢ZšeŽe›e˜j™ded©ƒd¢Zœe%ddedªƒdZe/ƒ Zže'd«ƒd¬d­„ ƒZŸe/ƒ Z e'd®ƒd¯d°„ ƒZ¡e/d±ded²ƒdZ¢eZd³ƒd´dµ„ ƒZ£e/ded¶ƒdZ¤e'd·ƒd¸d¹„ ƒZ¥e)d·ƒdºd»„ ƒZ¦ebe/ƒ ded¼ƒdZ§eZd½ƒd¾d¿„ ƒZ¨ei dedÀƒdZ©e%ddedÁƒdZªe«dÂdedÃƒdZ¬e«dÄdedÅƒdZ­e«dÆdedÇƒdZ®e?dddÈdZ¯e%ddedÉƒdZ°e%ddÊdKjRddZ±e'dËƒdÌdÍ„ ƒZ²eZdËƒdÎdÏ„ ƒZ³dZ´d ‡ fdÐdÑ„	ZµdÒdÓ„ Z¶dÔdÕ„ Z·dÖd×„ Z¸dØdÙ„ Z¹dÚdÛ„ ZºdÜdÝ„ Z»dÞdß„ Z¼dàdá„ Z½ezdâdã„ ƒZ¾ezdädå„ ƒZ¿d!dædç„ZÀd"dèdé„ZÁdêdë„ ZÂdìdí„ ZÃdîdï„ ZÄdðdñ„ ZÅdòdó„ ZÆdôdõ„ ZÇdöd÷„ ZÈdødù„ ZÉdúdû„ ZÊdüdý„ ZËdþdÿ„ ZÌd d„ ZÍdd„ ZÎdd„ ZÏeÐd#‡ fdd„	ƒZÑdd	„ ZÒd
d„ ZÓd$dd„ZÔdd„ ZÕdd„ ZÖdd„ Z×dd„ ZØdd„ ZÙdd„ ZÚdd„ ZÛ‡ fdd„ZÜdd„ ZÝ‡  ZÞS (%  r4  zjupyter-notebookz†The Jupyter HTML Notebook.

    This launches a Tornado based HTML Notebook Server that serves up an HTML5/Javascript Notebook client.r   )rØ   Ústoprœ   FTzÐSet to True to enable JSON formatted logs. Run "pip install notebook[json-logging]" to install the required dependent packages. Can also be set using the environment variable JUPYTER_ENABLE_JSON_LOGGING=true.)r¨   r  r   c             C   s   t  dd¡ ¡ dkS )z,Get the log_json value from the environment.ZJUPYTER_ENABLE_JSON_LOGGINGÚfalseÚtrue)r   ÚgetenvÚlower)rn   r]   r]   r^   Ú_default_log_jsonÚ  s    zNotebookApp._default_log_jsonc             C   sn   |d }|rjy,dd l }| j d¡ |jdd |j| _W n0 tk
rh   | js`| j d¡ d| _d}Y nX |S )NÚvaluer   zinitializing json loggingT)Zenable_jsonzdUnable to use json logging due to missing packages. Run "pip install notebook[json-logging]" to fix.F)	Újson_loggingrv   r	  Zinit_non_webZJSONLogFormatterÚ_log_formatter_clsÚImportErrorÚ!_json_logging_import_error_loggedr»   )rn   ÚproposalrE  rF  r]   r]   r^   Ú_validate_log_jsonß  s    
zNotebookApp._validate_log_jsonÚ	log_levelc             C   s   t jS )N)ÚloggingÚINFO)rn   r]   r]   r^   Ú_default_log_levelö  s    zNotebookApp._default_log_levelZlog_datefmtc             C   s   dS )z%Exclude date from default date formatz%H:%M:%Sr]   )rn   r]   r]   r^   Ú_default_log_datefmtú  s    z NotebookApp._default_log_datefmtZ
log_formatc             C   s   dS )z+override default log format to include timezV%(color)s[%(levelname)1.1s %(asctime)s.%(msecs).03d %(name)s]%(end_color)s %(message)sr]   )rn   r]   r]   r^   Ú_default_log_formatÿ  s    zNotebookApp._default_log_formatzXDeprecated: Use minified JS file or not, mainly use during dev to avoid JS recompilationrŠ   )r¨   z Set the Access-Control-Allow-Origin header

        Use '*' to allow any origin to access your server.

        Takes precedence over allow_origin_pat.
        a,  Use a regular expression for the Access-Control-Allow-Origin header

        Requests from an origin matching the expression will get replies with:

            Access-Control-Allow-Origin: origin

        where `origin` is the origin of the request.

        Ignored if allow_origin is set.
        z5Set the Access-Control-Allow-Credentials: true headerz6Whether to allow the user to run the notebook as root.a+  Disable launching browser by redirect file

        For versions of notebook > 5.7.2, a security feature measure was added that
        prevented the authentication token used to launch the browser from being visible.
        This feature makes it difficult for other users on a multi-user system from
        running code in your Jupyter session as you.

        However, some environments (like Windows Subsystem for Linux (WSL) and Chromebooks),
        launching a browser using a redirect file can lead the browser failing to load.
        This is because of the difference in file structures/paths between the runtime and
        the browser.

        Disabling this setting to False will disable this behavior, allowing the browser
        to launch by using a URL and visible token (as before).
        z@Reload the webapp when changes are made to any Python src files.z/treez'The default URL to redirect to from `/`Ú	localhostz2The IP address the notebook server will listen on.r:  c          
   C   s\   t   ¡ }y| d¡ W n4 tk
rJ } z| j tdƒ|¡ dS d}~X Y nX | ¡  dS dS )zƒReturn localhost if available, 127.0.0.1 otherwise.

        On some (horribly broken) systems, localhost cannot be bound.
        )rR  r   z:Cannot bind to localhost, using 127.0.0.1 as default ip
%sz	127.0.0.1NrR  )rö   Úbindr&  rv   r»   r   rô   )rn   ÚsÚer]   r]   r^   Ú_default_ipJ  s    zNotebookApp._default_ipc             C   s   |d }|dkrd}|S )NrE  Ú*rŠ   r]   )rn   rJ  rE  r]   r]   r^   Ú_validate_ipZ  s    zNotebookApp._validate_ipa  Override URL shown to users.

        Replace actual URL, including protocol, address, port and base URL,
        with the given value when displaying URL to the users. Do not change
        the actual connection URL. If authentication token is enabled, the
        token is added to the custom URL automatically.

        This option is intended to be used when the URL to display to the user
        cannot be determined reliably by the Jupyter notebook server (proxified
        or containerized setups for example).ZJUPYTER_PORTz@The port the notebook server will listen on (env: JUPYTER_PORT).rZ   c             C   s   t t | j| j¡ƒS )N)r  r   rB  Úport_envÚport_default_value)rn   r]   r]   r^   Úport_defaultt  s    zNotebookApp.port_defaultZJUPYTER_PORT_RETRIESé2   ziThe number of additional ports to try if the specified port is not available (env: JUPYTER_PORT_RETRIES).Úport_retriesc             C   s   t t | j| j¡ƒS )N)r  r   rB  Úport_retries_envÚport_retries_default_value)rn   r]   r]   r^   Úport_retries_default  s    z NotebookApp.port_retries_defaultz3The UNIX socket the notebook server will listen on.Z0600z>The permissions mode for UNIX socket creation (default: 0600).Ú	sock_modec          
   C   s¨   |d }y<t | ¡ dƒ}tt|tj@ ƒt|tj@ ƒ|dkfƒsBt‚W n^ tk
rt } zt	d| ƒ|‚W d d }~X Y n0 tk
r¢ } zt	d| ƒ|‚W d d }~X Y nX |S )NrE  é   i   z<invalid --sock-mode value: %s, please specify as e.g. "0600"zAinvalid --sock-mode value: %s, must have u+rw (0600) at a minimum)
r  ÚencodeÚallÚboolÚstatÚS_IRUSRÚS_IWUSRÚAssertionErrorr  r;   )rn   rJ  rE  Zconverted_valuerU  r]   r]   r^   Ú_validate_sock_modeŒ  s     zNotebookApp._validate_sock_modez-The full path to an SSL/TLS certificate file.z;The full path to a private key file for usage with SSL/TLS.zWThe full path to a certificate authority certificate for SSL/TLS client authentication.z+The file where the cookie secret is stored.Úcookie_secret_filec             C   s   t j | jd¡S )NZnotebook_cookie_secret)r   r€   r³   r!  )rn   r]   r]   r^   Ú_default_cookie_secret_file³  s    z'NotebookApp._default_cookie_secret_filerÿ   a‡  The random bytes used to secure cookies.
        By default this is a new random number every time you start the Notebook.
        Set it to a value in a config file to enable logins to persist across server sessions.

        Note: Cookie secrets should be kept private, do not share config files with
        cookie_secret stored in plaintext (you can read the value from a file).
        r™   c          	   C   sp   t j | j¡r0t| jdƒ}| ¡ }W d Q R X ntt  d¡ƒ}|  |¡ t	j
|tjd}| | j ¡ ¡ | ¡ S )NÚrbé    )Ú	digestmod)r   r€   rµ   rk  ÚopenÚreadr   ÚurandomÚ_write_cookie_secret_fileÚhmacÚnewÚhashlibÚsha256r±   rœ   rc  Údigest)rn   ÚfÚkeyrÚ   r]   r]   r^   Ú_default_cookie_secretÁ  s    
z"NotebookApp._default_cookie_secretc          
   C   s´   | j  tdƒ| j¡ y&t| jdƒ}| |¡ W dQ R X W n8 tk
rr } z| j  tdƒ| j|¡ W dd}~X Y nX yt 	| jd¡ W n( tk
r®   | j  
tdƒ| j¡ Y nX dS )z!write my secret to my secret_filez+Writing notebook server cookie secret to %sÚwbNz'Failed to write cookie secret to %s: %si€  zCould not set permissions on %s)rv   rj   r   rk  rp  Úwriter&  Úerrorr   Úchmodr»   )rn   Úsecretry  rU  r]   r]   r^   rs  Í  s    z%NotebookApp._write_cookie_secret_filez<generated>aŸ  Token used for authenticating first-time connections to the server.

        The token can be read from the file referenced by JUPYTER_TOKEN_FILE or set directly
        with the JUPYTER_TOKEN environment variable.

        When no password is enabled,
        the default is to generate a new, random token.

        Setting to an empty string disables authentication altogether, which is NOT RECOMMENDED.
        )r  r  c          	   C   sx   t  d¡rd| _t  d¡S t  d¡rHd| _tt  d¡ƒ
}| ¡ S Q R X | jrXd| _dS d| _t t  d¡¡ 	d¡S d S )NZJUPYTER_TOKENFZJUPYTER_TOKEN_FILErŠ   Té   Úascii)
r   rB  Ú_token_generatedrp  rq  rœ   ÚbinasciiÚhexlifyrr  Údecode)rn   Z
token_filer]   r]   r^   Ú_token_defaultí  s    


zNotebookApp._token_defaulti    aD  
        Sets the maximum allowed size of the client request body, specified in
        the Content-Length request header field. If the size in a request
        exceeds the configured value, a malformed HTTP message is returned to
        the client.

        Note: max_body_size is applied even in streaming mode.
        z
        Gets or sets the maximum amount of memory, in bytes, that is allocated
        for use by the buffer manager.
        zÿ
        Gets or sets a lower bound on the open file handles process resource
        limit. This may need to be increased if you run into an
        OSError: [Errno 24] Too many open files.
        This is not applicable when running on Windows.
        Úmin_open_files_limitc             C   s@   t d krd S t  t j¡\}}d}||kr,|S | j d||¡ |S )Ni   zDDefault value for min_open_files_limit is ignored (hard=%r, soft=%r))ÚresourceÚ	getrlimitÚRLIMIT_NOFILErv   r	  )rn   ÚsoftÚhardZDEFAULT_SOFTr]   r]   r^   Ú_default_min_open_files_limit  s    z)NotebookApp._default_min_open_files_limitc             C   s
   d| _ d S )NF)rƒ  )rn   Úchanger]   r]   r^   Ú_token_changed(  s    zNotebookApp._token_changeda   Hashed password to use for web authentication.

                      To generate, type in a python/IPython shell:

                        from notebook.auth import passwd; passwd()

                      The string should be of the form type:salt:hashed-password.
                      aª  Forces users to use a password for the Notebook server.
                      This is useful in a multi user environment, for instance when
                      everybody in the LAN can access each other's machine through ssh.

                      In such a case, serving the notebook server on localhost is not secure
                      since any user can connect to the notebook server via ssh.

                      až  Allow password to be changed at login for the notebook server.

                    While logging in with a token, the notebook server UI will give the opportunity to
                    the user to enter a new password at the same time that will replace
                    the token login mechanism.

                    This can be set to false to prevent changing password from the UI/API.
                    a:  Disable cross-site-request-forgery protection

        Jupyter notebook 4.3.1 introduces protection from cross-site request forgeries,
        requiring API requests to either:

        - originate from pages served by this server (validated with XSRF cookie and token), or
        - authenticate with a token

        Some anonymous compute resources still desire the ability to run code,
        completely without authentication.
        These services can disable all authentication and security checks,
        with the full knowledge of what that implies.
        aj  Allow requests where the Host header doesn't point to a local server

       By default, requests get a 403 forbidden response if the 'Host' header
       shows that the browser thinks it's on a non-local domain.
       Setting this option to True disables this check.

       This protects against 'DNS rebinding' attacks, where a remote web server
       serves you a page and then changes its DNS to send later requests to a
       local IP, bypassing same-origin checks.

       Local IP addresses (such as 127.0.0.1 and ::1) are allowed as local,
       along with hostnames configured in local_hostnames.
       rž   c             C   sÒ   | j dkrdS yt | j ¡}W n¦ tk
rÄ   xt | j | jdtj¡D ]v}|d d }tj	sf| 
d¡}yt | d¡d ¡}W n$ tk
r¢   | j d|¡ wFY nX |jsFd|kr¸|jsFdS qFW dS X |j S d	S )
zDDisallow remote access if we're listening only on loopback addressesrŠ   Tr   é   r‚  ú%zUnrecognised IP address: %rFN)r:  Ú	ipaddressÚ
ip_addressr  rö   ÚgetaddrinforZ   ÚSOCK_STREAMrA   ÚPY3r†  Úsplitrv   r»   Úis_loopbackÚis_link_local)rn   Úaddrrj   Úparsedr]   r]   r^   Ú_default_allow_remotem  s&    

z!NotebookApp._default_allow_remotez±Hostnames to allow as local when allow_remote_access is False.

       Local IP addresses (such as 127.0.0.1 and ::1) are automatically accepted
       as local as well.
       zƒWhether the banner is displayed on the page.

                        By default, the banner is displayed.
                        ap  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
                        (NotebookApp.browser) configuration option.
                        al  Specify what command to use to invoke a web
                      browser when opening the notebook. If not specified, the
                      default browser will be determined by the `webbrowser`
                      standard library module, which allows setting of the
                      BROWSER environment variable to override it.
                      rT   až  Specify Where to open the notebook on startup. This is the
        `new` argument passed to the standard library method `webbrowser.open`.
        The behaviour is not guaranteed, but depends on browser support. Valid
        values are:

         - 2 opens a new tab,
         - 1 opens a new window,
         - 0 opens in an existing window.

        See the `webbrowser.open` documentation for details.
        z DEPRECATED, use tornado_settingsÚwebapp_settingsc             C   s   | j  tdƒ¡ |d | _d S )Nz:
    webapp_settings is deprecated, use tornado_settings.
ru  )rv   r»   r   Útornado_settings)rn   r  r]   r]   r^   Ú_update_webapp_settings¾  s    z#NotebookApp._update_webapp_settingszPSupply overrides for the tornado.web.Application that the Jupyter notebook uses.Naq  
        Set the tornado compression options for websocket connections.

        This value will be returned from :meth:`WebSocketHandler.get_compression_options`.
        None (default) will disable compression.
        A dict (even an empty one) will enable compression.

        See the tornado docs for WebSocketHandler.get_compression_options for details.
        zìSupply overrides for terminado. Currently only supports "shell_command". On Unix, if "shell_command" is not provided, a non-login shell is launched by default when the notebook server is connected to a terminal, a login shell otherwise.ziExtra keyword arguments to pass to `set_secure_cookie`. See tornado's set_secure_cookie docs for details.ziExtra keyword arguments to pass to `get_secure_cookie`. See tornado's get_secure_cookie docs for details.z\Supply SSL options for the tornado HTTPServer.
            See the tornado docs for details.z@Supply extra arguments that will be passed to Jinja environment.z<Extra variables to supply to jinja templates when rendering.ak  Whether to enable MathJax for typesetting math/TeX

        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.
        r7  c             C   s   |d sd| _ dS )z/set mathjax url to empty if mathjax is disabledru  rŠ   N)r¦   )rn   r  r]   r]   r^   Ú_update_enable_mathjax÷  s    z"NotebookApp._update_enable_mathjaxrÐ   zÒThe base URL for the notebook server.

                               Leading and trailing slashes can be omitted,
                               and will automatically be added.
                               rw   c             C   s0   |d }|  d¡sd| }| d¡s,|d }|S )NrE  rÐ   )rÂ   Úendswith)rn   rJ  rE  r]   r]   r^   Ú_update_base_url  s    

zNotebookApp._update_base_urlzDEPRECATED use base_urlÚbase_project_urlc             C   s   | j  tdƒ¡ |d | _d S )Nz,base_project_url is deprecated, use base_urlru  )rv   r»   r   rw   )rn   r  r]   r]   r^   Ú_update_base_project_url  s    z$NotebookApp._update_base_project_urlzÂExtra paths to search for serving static files.

        This allows adding javascript/css to be available from the notebook server machine,
        or overriding individual files in the IPythonc             C   s   | j tg S )z)return extra paths + the default location)Úextra_static_pathsÚDEFAULT_STATIC_FILES_PATH)rn   r]   r]   r^   rÈ     s    zNotebookApp.static_file_pathz!Path to search for custom.js, cssr‘   c             C   s   dd„ | j tfD ƒS )Nc             S   s   g | ]}t j |d ¡‘qS )r   )r   r€   r³   )r‚   Údr]   r]   r^   rƒ   '  s    z;NotebookApp._default_static_custom_path.<locals>.<listcomp>)r©   r§  )rn   r]   r]   r^   Ú_default_static_custom_path$  s    z'NotebookApp._default_static_custom_pathzvExtra paths to search for serving jinja templates.

        Can be used to override templates from notebook.templates.c             C   s
   | j t S )z*return extra paths + the default locations)Úextra_template_pathsr   )rn   r]   r]   r^   r®   2  s    zNotebookApp.template_file_pathz6extra paths to look for Javascript notebook extensionszKhandlers that should be loaded at higher priority than the default servicesc             C   sN   | j tdƒ }yddlm} W n tk
r2   Y nX | tj |ƒ d¡¡ |S )z3The path to look for Javascript notebook extensionsZnbextensionsr   )Úget_ipython_dir)	Úextra_nbextensions_pathrC   ZIPython.pathsr«  rH  rÖ   r   r€   r³   )rn   r€   r«  r]   r]   r^   r¤   ?  s    zNotebookApp.nbextensions_pathz¿The base URL for websockets,
        if it differs from the HTTP server (hint: it almost certainly doesn't).

        Should be in the form of an HTTP origin: ws[s]://hostname[:port]
        z£A custom url for MathJax.js.
        Should be in the form of a case-sensitive url to MathJax,
        for example:  /static/components/MathJax/MathJax.js
        r¦   c             C   s&   | j s
dS | j dd¡}t|dddƒS )NrŠ   r’   r   Ú
componentsZMathJaxz
MathJax.js)r7  rŸ  r­   rL   )rn   r’   r]   r]   r^   Ú_default_mathjax_url[  s    z NotebookApp._default_mathjax_urlc             C   s0   |d }|r| j sd| _n| j tdƒ|¡ d S )Nru  rŠ   zUsing MathJax: %s)r7  r¦   rv   rj   r   )rn   r  ru  r]   r]   r^   Ú_update_mathjax_urlb  s    
zNotebookApp._update_mathjax_urlzTeX-AMS-MML_HTMLorMML-full,Safez5The MathJax.js configuration file that is to be used.r§   c             C   s   | j  tdƒ|d ¡ d S )Nz$Using MathJax configuration file: %sru  )rv   rj   r   )rn   r  r]   r]   r^   Ú_update_mathjax_configo  s    z"NotebookApp._update_mathjax_configzZIf True, display a button in the dashboard to quit
        (shutdown the notebook server).z9jupyter_server.contents.services.managers.ContentsManagerz"The notebook manager class to use.)Údefault_valueZklassesr¨   r  Úcontents_manager_classc             C   s2   |d }t  |¡r|j}| d¡r.| j d¡ d S )Nru  Zjupyter_serveru=  The specified 'contents_manager_class' class inherits a manager from the 'jupyter_server' package. These (future-looking) managers are not guaranteed to work with the 'notebook' package. For longer term support consider switching to NBClassicâ€”a notebook frontend that leverages Jupyter Server as its server backend.)ÚinspectÚisclassrâ   rÂ   rv   r»   )rn   r  ru  r]   r]   r^   Ú_observe_contents_manager_classŠ  s    

z+NotebookApp._observe_contents_manager_classz The kernel manager class to use.)r±  Úklassr¨   r  z!The session manager class to use.)r±  r¨   r  zThe config manager class to use)Ú
allow_nonea  
        The kernel spec manager class to use. Should be a subclass
        of `jupyter_client.kernelspec.KernelSpecManager`.

        The Api of KernelSpecManager is provisional and might change
        without warning between this version of Jupyter and the next stable one.
        zThe login handler class to use.z The logout handler class to use.zŸWhether to trust or not X-Scheme/X-Forwarded-Proto and X-Real-Ip/X-Forwarded-For headers sent by the upstream reverse proxy. Necessary if the proxy handles SSLÚ	info_filec             C   s   dt  ¡  }t j | j|¡S )Nznbserver-%s.json)r   Úgetpidr€   r³   r!  )rn   r¸  r]   r]   r^   Ú_default_info_fileÑ  s    zNotebookApp._default_info_fileÚbrowser_open_filec             C   s   dt  ¡  }t j | j|¡S )Nznbserver-%s-open.html)r   r¹  r€   r³   r!  )rn   Úbasenamer]   r]   r^   Ú_default_browser_open_fileØ  s    z&NotebookApp._default_browser_open_fileÚdisabledz[
        DISABLED: use %pylab or %matplotlib in the notebook to enable matplotlib.
        r6  c             C   sR   |d dkrd|d  }nd}| j  tdƒ¡ | j  tdƒ |¡¡ |  d¡ dS )	z5when --pylab is specified, display a warning and exitru  r½   z %srŠ   zDSupport for specifying --pylab on the command line has been removed.zBPlease use `%pylab{0}` or `%matplotlib{0}` in the notebook itself.r   N)rv   r~  r   r*  r"  )rn   r  Úbackendr]   r]   r^   Ú_update_pylabã  s    zNotebookApp._update_pylabz/The directory to use for notebooks and kernels.r1  c             C   s(   | j rtj tj | j ¡¡S t ¡ S d S )N)Úfile_to_runr   r€   ÚdirnameÚabspathrA   Úgetcwd)rn   r]   r]   r^   Ú_default_notebook_dirô  s    z!NotebookApp._default_notebook_dirc             C   sl   |d }t j |¡\}}|t jkr&|S | t j¡}t j |¡sJt j |¡}t j |¡shtt	 
d¡| ƒ‚|S )NrE  zNo such notebook dir: '%r')r   r€   Ú
splitdriverÃ   ÚrstripÚisabsrÃ  Úisdirr;   r   r¶   )rn   rJ  rE  r   r€   r]   r]   r^   Ú_notebook_dir_validateû  s    
z"NotebookApp._notebook_dir_validatez3DEPRECATED use the nbserver_extensions dict insteadÚserver_extensionsc             C   s   | j  tdƒ¡ |d | _d S )Nz8server_extensions is deprecated, use nbserver_extensionsru  )rv   r»   r   rË  )rn   r  r]   r]   r^   Ú_update_server_extensions  s    z%NotebookApp._update_server_extensionszÀDict of Python modules to load as notebook server extensions. Entry values can be used to enable and disable the loading of the extensions. The extensions will be loaded in alphabetical order.z9Reraise exceptions encountered loading server extensions?iè  zg(msgs/sec)
        Maximum rate at which messages can be sent on iopub before they are
        limited.i@B zm(bytes/sec)
        Maximum rate at which stream output can be sent on iopub before they are
        limited.é   zI(sec) Time window used to
        check the message and data rate limits.ac  Shut down the server after N seconds with no kernels or terminals running and no activity. This can be used together with culling idle kernels (MappingKernelManager.cull_idle_timeout) to shutdown the notebook server when it's not in use. This is not precisely timed: it may shut down up to a minute later. 0 (the default) disables this automatic shutdown.a/  Set to False to disable terminals.

         This does *not* make the notebook server more secure by itself.
         Anything the user can in a terminal, they can also do in a notebook.

         Terminals may also be automatically disabled if the terminado package
         is not available.
         zG"
        Require authentication to access prometheus metrics.
        r    c             C   s0   t | jƒpt | jƒ}|dkr,| j tdƒ¡ |S )z> Authenticate Prometheus by default, unless auth is disabled. FzJAuthentication of /metrics is OFF, since other authentication is disabled.)re  rœ   r  rv   rj   r   )rn   Úauthr]   r]   r^   Ú _default_authenticate_prometheusH  s    z,NotebookApp._default_authenticate_prometheusc             C   s4   |d }| j dkr*|dkr*| j tdƒ¡ || _ d S )Nru  TFz/Authentication of /metrics is being turned OFF.)r    rv   rj   r   )rn   r  Znewauthr]   r]   r^   Ú_update_authenticate_prometheusP  s    z+NotebookApp._update_authenticate_prometheusc                sš   t ƒ  |¡ | jr–| jd }tj |¡}| j |¡ tj |¡s\| j	 
tdƒ|¡ |  d¡ tƒ }tj |¡rx||j_ntj |¡rŒ||j_|  |¡ d S )Nr   zNo such file or directory: %sr   )rl   r  r  r   r€   rÃ  r  Úremoverµ   rv   Úcriticalr   r"  r(   rÉ  r4  r1  ÚisfilerÁ  Zupdate_config)rn   r  Zarg0ry  Úc)r}   r]   r^   r  `  s    


zNotebookApp.parse_command_linec             C   sÂ   t j| d| _| jjr(d| _d| _d| _| j| d| _| j| | j| j	| jd| _
t| j
tƒr€tshtdƒ‚| j d | j
jj¡¡ | j| | jd| _| j| | j| j
| jd	| _| j| | jd| _d S )
N)Úparentz.notebook.gateway.managers.GatewayKernelManagerz/notebook.gateway.managers.GatewaySessionManagerz2notebook.gateway.managers.GatewayKernelSpecManager)rÕ  rv   Zconnection_dirrs   z”You are using `AsyncMappingKernelManager` without an appropriate jupyter_client installed!  Please upgrade jupyter_client or change kernel managers.z?Asynchronous kernel management has been configured to use '{}'.)rÕ  rv   )rÕ  rv   rp   rq   )r$   rÓ   Úgateway_configrÔ   Úkernel_manager_classÚsession_manager_classÚkernel_spec_manager_classrs   rv   r!  rp   r¯   r   Úasync_kernel_mgmt_availabler  rj   r*  r}   rá   r²  rq   rr   Úconfig_manager_classrt   )rn   r]   r]   r^   Úinit_configurablest  s8    

zNotebookApp.init_configurablesc             C   sP   d| j _xtttfD ]}| j j|_qW t d¡}d|_| j |_| 	| j j
¡ d S )NFr  T)rv   Ú	propagater   r   r   rc   rM  Ú	getLoggerrÕ  ÚsetLevelÚlevel)rn   rv   Úloggerr]   r]   r^   Úinit_logging   s    
zNotebookApp.init_loggingc          
   C   s€   t dkr| j d¡ dS t  t j¡\}}| j}|}||k r|||k rF|}| j d|› d|› d|› d|› ¡ t  t j||f¡ dS )zinitialize system resourcesNz\Ignoring min_open_files_limit because the limit cannot be adjusted (for example, on Windows)zRaising open file limit: soft z->z; hard )r‰  rv   r	  rŠ  r‹  rˆ  Z	setrlimit)rn   Zold_softZold_hardrŒ  r  r]   r]   r^   Úinit_resources¯  s    zNotebookApp.init_resourcesc             C   sV  | j | jd< | j| jd< | jr0t | j¡| jd< | j| jd< | j| jd< | j| jd< | j	| jd< | j
| jd< | j | j¡sŠt| j| jƒ| _| jrÐ| jsÐ| j td	ƒ¡ | j td
ƒ¡ | j tdƒ¡ t d¡ | jrl| jtkrþ| j tdƒ¡ t d¡ nd| _| jr| j tdƒ¡ | jr>| j tdƒ¡ t d¡ tj d¡rl| j td| j ƒ¡ t d¡ t| | j| j| j | j!| j"| j#| j| j| j| j| j$ƒ| _%| j&}| j'rº| j'|d< | j(rÌ| j(|d< | j)rÞ| j)|d< |sêd}n:ddl*}| +dt,|d|j-ƒ¡ | .dd¡r$| +d|j/¡ | j0j1| |d t2j3| j%|| j4| j5| j6d| _7dS )z(initialize tornado webapp and httpserverÚallow_originÚwebsocket_compression_optionsÚallow_origin_patÚallow_credentialsrg   Úcookie_optionsÚget_secure_cookie_kwargsr  z?Notebook servers are configured to only be run with a password.z1Hint: run the following command to set a passwordz#	$ python -m notebook.auth passwordr   z;Options --port and --sock are mutually exclusive. Aborting.r   z=Ignoring --NotebookApp.open_browser due to --sock being used.zDOptions --NotebookApp.file_to_run and --sock are mutually exclusive.r   zIOption --sock is not supported on Windows, but got value of %s. Aborting.r=  r<  Úca_certsNÚssl_versionÚPROTOCOL_TLSFÚ	cert_reqs)Ússl_options)rî  ZxheadersÚmax_body_sizeÚmax_buffer_size)8rä  rŸ  rå  ræ  ÚreÚcompilerç  rg   rè  ré  r  rx   rÂ   rw   rL   Úpassword_requiredrœ   rv   rÒ  r   rÀ   r"  r  rZ   r   r5  rj   rÁ  r  rf   rp   rq   rr   rs   rt   ru   Újinja_environment_optionsÚweb_apprî  r=  r<  Ú	client_caÚsslÚ
setdefaultÚgetattrÚPROTOCOL_SSLv23r­   ÚCERT_REQUIREDrš   Zvalidate_securityr   Z
HTTPServerÚtrust_xheadersrï  rð  Úhttp_server)rn   rî  r÷  r]   r]   r^   Úinit_webappÀ  sv    












zNotebookApp.init_webappc             C   s   | j r|  ¡ S |  ¡ S )N)r  Ú_bind_http_server_unixÚ_bind_http_server_tcp)rn   r]   r]   r^   Ú_bind_http_server  s    zNotebookApp._bind_http_serverc          
   C   sÖ   t | jƒr$| j tdƒ| j ¡ dS y*t| jt| j ¡ dƒd}| j	 
|¡ W n~ tk
rÌ } z`|jtjkr†| j tdƒ| j ¡ dS |jtjttdtjƒfkrº| j tdƒ| j ¡ dS ‚ W d d }~X Y nX dS d S )Nz The socket %s is already in use.Frb  )ÚmodeÚ	WSAEACCESz&Permission to listen on sock %s deniedT)rJ   r  rv   r»   r   r   r  ra  rc  rý  Z
add_socketr&  ÚerrnoÚ
EADDRINUSEÚEACCESrù  )rn   r  rU  r]   r]   r^   rÿ    s    
z"NotebookApp._bind_http_server_unixc             C   s4  d }xìt | j| jd ƒD ]Ö}y| j || j¡ W n° tk
rà } z’tjt	tdtjƒf}t
jdkrl|tjf7 }|jtjkr¬| jr”| j tdƒ| ¡ n| j tdƒ| ¡ wn$|j|krÎ| j tdƒ| ¡ wn‚ W d d }~X Y qX || _d}P qW |s0| jr| j tdƒ¡ n| j td	ƒ| ¡ |  d¡ |S )
Nr   r  Úcygwinz3The port %i is already in use, trying another port.zThe port %i is already in use.z'Permission to listen on port %i denied.TzYERROR: the notebook server could not be started because no available port could be found.zQERROR: the notebook server could not be started because port %i is not available.)r_   rZ   r]  rý  Úlistenr:  r&  r  r  rù  rÀ   r  ÚEPERMr  rv   rj   r   r»   rÒ  r"  )rn   ÚsuccessrZ   rU  Zeaccesr]   r]   r^   r   .  s6    


z!NotebookApp._bind_http_server_tcpc             C   s   | j r| jnd}t|d|iƒS )Nz...r  )rƒ  r  r   )rn   rÑ   r  r]   r]   r^   Ú_concat_tokenT  s    zNotebookApp._concat_tokenc             C   s   | j r | j }| d¡sX|d7 }n8| jr0|  ¡ }n(| jdkrHdt ¡  }n| j}|  |¡}| jrŒ| jsŒ|  	|¡}| j sŒ|d|  	|  d¡¡ 7 }|S )NrÐ   )rŠ   z0.0.0.0z%sz
 or %sz	127.0.0.1)
Úcustom_display_urlr¢  r  Ú_unix_sock_urlr:  rö   ÚgethostnameÚ_tcp_urlr  r  )rn   rÑ   r:  r]   r]   r^   Údisplay_urlX  s    





zNotebookApp.display_urlc             C   s,   | j r|  ¡ S | jr| jnd}|  |¡S d S )NrR  )r  r  r:  r  )rn   r:  r]   r]   r^   Úconnection_urll  s    zNotebookApp.connection_urlc             C   s   t | jƒ› | j› S )N)rN   r  rw   )rn   r  r]   r]   r^   r  t  s    zNotebookApp._unix_sock_urlc             C   s&   | j r
dnd}d|||p| j| jf S )NÚhttpsÚhttpz%s://%s:%i%s)r=  rZ   rw   )rn   r:  rZ   Úprotor]   r]   r^   r  w  s    zNotebookApp._tcp_urlc          
   C   sd   | j s
d S y ddlm} || d d| _W n4 tk
r^ } z| j tdƒ|¡ W d d }~X Y nX d S )Nr   )ró   )Znb_appTz&Terminals not available (error was %s))rË   Úterminalró   r¬   rH  rv   r»   r   )rn   ró   rU  r]   r]   r^   Úinit_terminals{  s    

zNotebookApp.init_terminalsc             C   st   t j d¡s,t jr,t j ¡ r,t tj| j¡ t tj| j	¡ t
tdƒrVt tj| j¡ t
tdƒrpt tj| j¡ d S )Nr   ÚSIGUSR1ÚSIGINFO)rÀ   r  rÂ   ÚstdinÚisattyr  ÚSIGINTÚ_handle_sigintr  Ú_signal_stopÚhasattrr  Ú_signal_infor  )rn   r]   r]   r^   Úinit_signal†  s    

zNotebookApp.init_signalc             C   s0   t   t j| j¡ tj| jd}d|_| ¡  dS )z)SIGINT handler spawns confirmation dialog)ÚtargetTN)r  r  r  Ú	threadingÚThreadÚ_confirm_exitÚdaemonré   )rn   ÚsigÚframeÚthreadr]   r]   r^   r  ‘  s    zNotebookApp._handle_sigintc             C   s   t   t j| j¡ dS )z.callback for restoring original SIGINT handlerN)r  r  r  )rn   r]   r]   r^   Ú_restore_sigint_handler›  s    z#NotebookApp._restore_sigint_handlerc             C   s  | j j}|tdƒƒ | jr>| j  tdƒ¡ | j | jj¡ dS t|  	¡ ƒ tdƒ}tdƒ}t
j tdƒ||f ¡ t
j ¡  t t
jgg g d¡\}}}|rät
j ¡ }| ¡  |¡rô|| ¡ krô| j  tdƒ¡ | j | jj¡ dS nttd	ƒd
d ttdƒƒ | j | j¡ dS )zÈconfirm shutdown on ^C

        A second ^C, or answering 'y' within 5s will cause shutdown,
        otherwise original SIGINT handler will be restored.

        This doesn't work on Windows.
        ÚinterruptedzShutting down...NÚyr[   z)Shutdown this notebook server (%s/[%s])? r   zShutdown confirmedzNo answer for 5s:ú )Úendzresuming operation...)rv   rj   r   Z
answer_yesrÒ  Úio_loopÚadd_callback_from_signalr?  rk   Únotebook_inforÀ   Ústdoutr}  ÚflushÚselectr  ÚreadlinerC  rÂ   r)  )rn   rj   ÚyesÚnoÚrÚwÚxÚliner]   r]   r^   r$  Ÿ  s*    

zNotebookApp._confirm_exitc             C   s&   | j  tdƒ|¡ | j | jj¡ d S )Nzreceived signal %s, stopping)rv   rÒ  r   r.  r/  r?  )rn   r&  r'  r]   r]   r^   r  Ç  s    zNotebookApp._signal_stopc             C   s   t |  ¡ ƒ d S )N)rk   r0  )rn   r&  r'  r]   r]   r^   r  Ë  s    zNotebookApp._signal_infoc             C   s   dS )z8Check the components submodule, and warn if it's uncleanNr]   )rn   r]   r]   r^   Úinit_componentsÎ  s    zNotebookApp.init_componentsc             C   s¸   x"| j D ]}|| jkrd| j|< qW tƒ }| j|krB| d| j¡ t|d}| | j¡}| di ¡ di ¡}xFt| 	¡ ƒD ]6\}}|| jkrz| j
jj ||i¡ | j ||i¡ qzW dS )zìConsolidate server extensions specified by all configs.

        The resulting list is stored on self.nbserver_extensions and updates config object.

        The extension API is experimental, and may change in future releases.
        Tr   )Zread_config_pathr4  Únbserver_extensionsN)rË  r<  r.   r©   Úinsertr   r­   Zconfig_file_nameÚsortedÚitemsr¨   r4  r±   )rn   Ú
modulenameZconfig_pathÚmanagerÚsectionr…   Úenabledr]   r]   r^   Úinit_server_extension_configÓ  s    



z(NotebookApp.init_server_extension_configc          	   C   s‚   x|t | j ¡ ƒD ]j\}}|ry*t |¡}t|ddƒ}|dk	rD|| ƒ W q tk
rx   | jr^‚ | jj	t
dƒ|dd Y qX qW dS )zéLoad any extensions specified by config.

        Import the module, then call the load_jupyter_server_extension function,
        if one exists.

        The extension API is experimental, and may change in future releases.
        Zload_jupyter_server_extensionNz!Error loading server extension %sT)Úexc_info)r>  r<  r?  Ú	importlibÚimport_modulerù  Ú	ExceptionÚ!reraise_server_extension_failuresrv   r»   r   )rn   r@  rC  rd   Úfuncr]   r]   r^   Úinit_server_extensionsò  s    

z"NotebookApp.init_server_extensionsc             C   s>   t jdkrtjg d t dd¡ t dd¡ t dd¡ d S )	NÚnt)Úfilesztext/cssz.csszapplication/javascriptz.jszapplication/wasmz.wasm)r   rc   Ú	mimetypesÚinitÚadd_type)rn   r]   r]   r^   Úinit_mime_overrides	  s
    
zNotebookApp.init_mime_overridesc             C   sx   | j }t|ƒdkrdS | jr2| jjd }|jr2dS tƒ | j ¡   ¡ }| j	 
d|¡ || jkrt| j	 d|¡ |  ¡  dS )zBShutdown server on timeout when there are no kernels or terminals.r   NÚterminal_managerzNo activity for %d seconds.z6No kernels or terminals for %d seconds; shutting down.)rp   rÄ   r¬   rõ  r{   Z	terminalsrE   rà   Útotal_secondsrv   r	  Úshutdown_no_activity_timeoutrj   r?  )rn   ÚkmZterm_mgrZseconds_since_activer]   r]   r^   Úshutdown_no_activity  s    
z NotebookApp.shutdown_no_activityc             C   s4   | j dkr0| j d| j ¡ t | jd¡}| ¡  d S )Nr   z=Will shut down after %d seconds with no kernels or terminals.i`ê  )rT  rv   rj   r	   ÚPeriodicCallbackrV  ré   )rn   Úpcr]   r]   r^   Úinit_shutdown_no_activity-  s
    
z%NotebookApp.init_shutdown_no_activityc             C   s’   ddl }y| ¡  W n tk
r(   Y nX tj d¡rŽtjdkrŽddl}yddlm}m	} W n t
k
rp   Y nX t| ¡ ƒ|krŽ| |ƒ ¡ dS )a  set default asyncio policy to be compatible with tornado

        Tornado 6 (at least) is not compatible with the default
        asyncio implementation on Windows

        Pick the older SelectorEventLoopPolicy on Windows
        if the known-incompatible default policy is in use.

        do this as early as possible to make it a low priority and overrideable

        ref: https://github.com/tornadoweb/tornado/issues/2608

        FIXME: if/when tornado supports the defaults in asyncio,
               remove and bump tornado requirement for py38

        With the introduction of the async kernel, the existing sync kernel
        requires the use of nested loops in order to run code synchronously.
        This is done in `jupyter_client` using the helper util `run_sync`:

        ref: https://github.com/jupyter/jupyter_client/blob/f453b51eeeff9e905c583b7da3905c0e35cfbdf0/jupyter_client/utils.py#L11

        which creates a new event loop and relies on `nest_asyncio` patching
        to allow nested loops. This requires that *all* potential tasks are
        patched before executing. When only some tasks are patched it leads to
        the following issue:

        ref: https://github.com/jupyter/notebook/issues/6164

        So we must call `nest_asyncio.apply()` method as early as possible. It
        is preferable to do this in the consuming application rather than the
        `jupyter_client` as it is a global patch and would impact all consumers
        rather than just the ones that rely on synchronous kernel behavior.
        r   Nr   )rÍ  rb  )ÚWindowsProactorEventLoopPolicyÚWindowsSelectorEventLoopPolicy)Únest_asyncioÚapplyÚRuntimeErrorrÀ   r  rÂ   Úversion_infoÚasynciorZ  r[  rH  ÚtypeÚget_event_loop_policyÚset_event_loop_policy)rn   r\  r`  rZ  r[  r]   r]   r^   Ú_init_asyncio_patch4  s    "zNotebookApp._init_asyncio_patchc                sz   |   ¡  tƒ  |¡ |  ¡  | jr&d S |  ¡  |  ¡  |  ¡  |  ¡  |  	¡  |  
¡  |  ¡  |  ¡  |  ¡  |  ¡  d S )N)rd  rl   ró   râ  Z_dispatchingrã  rÜ  rD  r;  rþ  r  r   rK  rQ  rY  )rn   r  )r}   r]   r^   ró   o  s    zNotebookApp.initializec             C   s>   t | j ¡ ƒ}t dd|¡}| j || ¡ t| j ¡ ƒ dS )zÉShutdown all kernels.

        The kernels will shutdown themselves when this process no longer exists,
        but explicit shutdown allows the KernelManagers to cleanup the connection files.
        zShutting down %d kernelzShutting down %d kernelsN)	rÄ   rp   Úlist_kernel_idsr   Úngettextrv   rj   rI   Zshutdown_all)rn   Ú	n_kernelsÚ
kernel_msgr]   r]   r^   Úcleanup_kernels‚  s    zNotebookApp.cleanup_kernelsc             C   sP   | j s
dS | jjd }t| ¡ ƒ}t dd|¡}| j || ¡ t	| 
¡ ƒ dS )z¹Shutdown all terminals.

        The terminals will shutdown themselves when this process no longer exists,
        but explicit shutdown allows the TerminalManager to cleanup.
        NrR  zShutting down %d terminalzShutting down %d terminals)r¬   rõ  r{   rÄ   rØ   r   rf  rv   rj   rI   Zterminate_all)rn   rR  Zn_terminalsZterminal_msgr]   r]   r^   Úcleanup_terminals  s    zNotebookApp.cleanup_terminalsc             C   s|   | j  ¡ d }|rBt| j ¡ ƒ}t dd|¡}||| 7 }|d7 }|tdjt	j
| jdƒ7 }| jjrx|tdƒ| jj 7 }|S )zCReturn the current working directory and the server url informationÚ
z%d active kernelz%d active kernelsz/Jupyter Notebook {version} is running at:
{url})r+  rÑ   z=
Kernels will be managed by the Gateway server running at:
%s)rq   Zinfo_stringrÄ   rp   re  r   rf  r   r*  r4  r+  r  rÖ  rÔ   rÑ   )rn   Úkernel_countrj   rg  rh  r]   r]   r^   r0  œ  s    zNotebookApp.notebook_infoc             C   sJ   | j | jr| jnd| j| jt| jƒ| j| jtj	 
| j¡t| jƒt ¡ dœ
S )z8Return a JSONable dict of information about this server.rR  )
rÑ   ÚhostnamerZ   r  Úsecurerw   r  r1  rœ   rñ   )r  r:  rZ   r  re  r=  rw   r  r   r€   rÃ  r1  rœ   r¹  )rn   r]   r]   r^   r  «  s    zNotebookApp.server_infoc          
   C   sp   y2t | jdƒ}tj|  ¡ |ddd W dQ R X W n8 tk
rj } z| j tdƒ| j|¡ W dd}~X Y nX dS )z=Write the result of server_info() to the JSON file info_file.r8  rT   T)r0  Ú	sort_keysNz%Failed to write server-info to %s: %s)	rp  r¸  r/  Údumpr  r&  rv   r~  r   )rn   ry  rU  r]   r]   r^   Úwrite_server_info_file¹  s    $z"NotebookApp.write_server_info_filec          
   C   sF   yt  | j¡ W n0 tk
r@ } z|jtjkr0‚ W dd}~X Y nX dS )zRemove the nbserver-<pid>.json file created for this server.

        Ignores the error raised when the file has already been removed.
        N)r   r%  r¸  r&  r  ÚENOENT)rn   rU  r]   r]   r^   Úremove_server_info_fileÂ  s
    z#NotebookApp.remove_server_info_filec          	   C   s@   | j t| jƒd… }t| jddd}|  ||¡ W dQ R X dS )zkWrite an nbserver-<pid>-open.html file

        This can be used to open the notebook in a browser
        Nr8  zutf-8)rŒ   )rx   rÄ   rw   rp  r»  Ú_write_browser_open_file)rn   Úopen_urlry  r]   r]   r^   Úwrite_browser_open_fileÍ  s    z#NotebookApp.write_browser_open_filec             C   sN   | j rt|d| j iƒ}t| j|ƒ}| jjd }| d¡}| |j|d¡ d S )Nr  r«   zbrowser-open.html)ru  )	r  r   rL   r  rõ  r{   Zget_templater}  Úrender)rn   rÑ   Úfhr«   Útemplater]   r]   r^   rt  Ø  s    
z$NotebookApp._write_browser_open_filec          
   C   sF   yt  | j¡ W n0 tk
r@ } z|jtjkr0‚ W dd}~X Y nX dS )z”Remove the nbserver-<pid>-open.html file created for this server.

        Ignores the error raised when the file has already been removed.
        N)r   r%  r»  r&  r  rr  )rn   rU  r]   r]   r^   Úremove_browser_open_fileá  s
    z$NotebookApp.remove_browser_open_filec          
      sp  yt  ˆjpd ¡‰W n< t jk
rP } zˆj tdƒ| ¡ d ‰W d d }~X Y nX ˆsZd S ˆjsŠˆjt	ˆj
ƒd … }ˆjrŠt|dˆjiƒ}ˆjr"tj ˆj¡sÀˆj tdƒˆj ¡ ˆ d¡ tj ˆjˆj¡}ttd| tj¡žŽ ƒ}tjdd\}}t|dd	d
}ˆ ||¡ W d Q R X nˆj}ˆjr@tdt|ƒƒ‰ ntˆj |ƒ‰ ‡ ‡‡fdd„}t!j"|d #¡  d S )NzNo web browser found: %s.r  z%s does not existr   Ú	notebooksz.html)Úsuffixr8  zutf-8)rŒ   zfile:c                  s   ˆj ˆ ˆjdS )N)ru  )rp  Úwebbrowser_open_newr]   )Úassembled_urlr>  rn   r]   r^   Ú<lambda>	  rÿ   z,NotebookApp.launch_browser.<locals>.<lambda>)r!  )r{  )$Ú
webbrowserr­   r>  ÚErrorrv   r»   r   Úuse_redirect_filerx   rÄ   rw   r  r   rÁ  r   r€   rµ   rÒ  r"  Úrelpathr1  rK   rL   r˜  rÃ   ÚtempfileÚmkstemprp  rt  r»  rO   rH   r  r"  r#  ré   )rn   rU  Úurirƒ  ÚfdÚ	open_filerx  Úbr]   )r~  r>  rn   r^   Úlaunch_browserì  s4    
zNotebookApp.launch_browserc                sF  t ƒ  ¡  | jsXyt ¡ }W n tk
r4   d}Y nX |dkrX| j tdƒ¡ |  	d¡ |  
¡ }|s~| j tdƒ¡ |  	d¡ | jj}x"| jdd d¡D ]}||ƒ qšW |td	ƒƒ d
tjkrÌ|tdƒƒ |  ¡  |  ¡  | jsè| jrö| jsö|  ¡  | jr¶| jr¶| jrH| j d dd| j dd| j|  |  dd¡¡f g¡¡ nn| js„| j d dddtdt| jƒƒ dd| j g¡¡ n2| j d dddtdt| jƒƒ dd| j g¡¡ t j! "¡ | _#t$j% &d¡rèt  'dd„ d¡}| ¡  z6y| j# ¡  W n" t(k
r   |tdƒƒ Y nX W d|  )¡  |  *¡  |  +¡  |  ,¡  X dS )z· Start the Notebook server app, after initialization

        This method takes no arguments so all configuration and initialization
        must be done prior to calling this method.éÿÿÿÿr   z?Running as root is not recommended. Use --allow-root to bypass.r   zYERROR: the notebook server could not be started because no available port could be found.F)rl  rk  zYUse Control-C to stop this server and shut down all kernels (twice to skip confirmation).ÚdevzðWelcome to Project Jupyter! Explore the various tools available and their corresponding documentation. If you are interested in contributing to the platform, please visit the communityresources section at https://jupyter.org/community.html.zNotebook is listening on %srŠ   z›UNIX sockets are not browser-connectable, but you can tunnel to the instance via e.g.`ssh -L 8888:%s -N user@this_host` and then open e.g. %s in a browser.rR  i¸"  z4To access the notebook, open this file in a browser:z    %szfile:z$Or copy and paste one of these URLs:zOr copy and paste this URL:r   c               S   s   d S )Nr]   r]   r]   r]   r^   r  _	  rÿ   z#NotebookApp.start.<locals>.<lambda>iˆ  zInterrupted...N)-rl   ré   r8  r   ÚgeteuidÚAttributeErrorrv   rÒ  r   r"  r  rj   r0  r˜  Únotebookr   rq  rv  r5  rÁ  r  rŠ  r  rƒ  r³   r  r  r  r  rO   rH   r»  r	   ZIOLoopÚcurrentr.  rÀ   r  rÂ   rW  ÚKeyboardInterruptrs  rz  ri  rj  )rn   Úuidr
  rj   r:  rX  )r}   r]   r^   ré   	  sp    





"

zNotebookApp.startc                s   ‡ fdd„}ˆ j  |¡ d S )Nc                  s   ˆ j  ¡  ˆ j ¡  d S )N)rý  r?  r.  r]   )rn   r]   r^   Ú_stopl	  s    
zNotebookApp.stop.<locals>._stop)r.  Zadd_callback)rn   r“  r]   )rn   r^   r?  k	  s    zNotebookApp.stop)N)N)N)N)T)ßrá   râ   rã   rc   r   r+  r   rë   Ú	_examplesZexamplesÚaliasesr3  r/   r1   r   r0   r   r   r2   r!   r"   r#   r$   ÚclassesrÊ   rÖ   rR   r4   rÇ   r-  Ú
splitlinesr  rå   Úsubcommandsr   rG  rI  r8   r   r?   rD  r@   rK  rO  rP  rQ  r”   r5   rÁ  rä  ræ  rç  r8  r‚  rg   rx   r:  rV  rX  r  rY  r   rZ  r6   rZ   r[  r^  r_  r]  r`  r  ra  rj  r=  r<  rö  rk  rl  r9   r™   r{  rs  Útagr  rƒ  r‡  rï  rð  rˆ  rŽ  r>   r  rœ   ró  rª   r   rž   r  r7   rŸ   r•   r5  r>  r}  rž  r   rŸ  r3   rå  Zterminado_settingsrè  ré  rî  rô  r£   r7  r¡  rw   r£  r¤  r¥  r¦  ÚpropertyrÈ   r‘   r©  rª  r®   r¬  ru   r¤   r¥   r¦   r®  r¯  r§   r°  rÉ   rP   r   r²  rµ  r<   r×  r    rØ  r   rÛ  r:   rs   rÙ  r%   r
   ZRequestHandlerrš   r&   r›   rü  r¸  rº  r»  r½  r6  rÀ  r1  rÅ  rÊ  rË  rÌ  r<  rI  r=   r–   r—   r˜   rT  rË   r    rÏ  rÐ  r¬   r  rÜ  râ  rã  rþ  r  rÿ  r   r  r  r  r  r  r  r   r  r)  r$  r  r  r;  rD  rK  rQ  rV  rY  rd  r)   ró   ri  rj  r0  r  rq  rs  rv  rt  rz  rŠ  ré   r?  rä   r]   r]   )r}   r^   r4  ³  sB  

	
	
"



	
	



	
,W&
(;		'Xc          
   c   s¸   | dkrt ƒ } tj | ¡sdS x”t | ¡D ]†}t d|¡r*ttj | |¡dd}t	 
|¡}W dQ R X d|kr‚t|d ƒr‚|V  q*yt tj | |¡¡ W q* tk
r®   Y q*X q*W dS )a  Iterate over the server info files of running notebook servers.

    Given a runtime directory, find nbserver-* files in the security directory,
    and yield dicts of their information, each one pertaining to
    a currently running notebook server instance.
    Nznbserver-(.+).jsonzutf-8)rŒ   rñ   )rB   r   r€   rÉ  Úlistdirrñ  Úmatchrp  r³   r/  ÚloadrG   r%  r&  )r!  Ú	file_namery  rj   r]   r]   r^   r   r	  s    r   )r   N)N)­rê   r  r`  r„  r¸   r  rÅ   r¶   rv  rt  rF  r³  r“  r/  rM  rN  r   rX   rñ  r3  r  rö   rf  rÀ   r„  r"  r  r¼   r€  r‰  rH  Úbase64r   Zjinja2r   r   Znotebook.transutilsr   r   r  rU  r_  rŽ  r+  r   r	   r
   Ztornado.httputilr   Ztornado.logr   r   r   r   r  rÂ   r  r   r   r   r   Z	nbclassicr€   r³   rÂ  r´   r§  Zbase.handlersr   r   rv   r   Zservices.kernels.kernelmanagerr   r   Zservices.configr   Zservices.contents.managerr   Zservices.contents.filemanagerr   Z"services.contents.largefilemanagerr   Z services.sessions.sessionmanagerr    Zgateway.managersr!   r"   r#   r$   Z
auth.loginr%   Zauth.logoutr&   r'   Ztraitlets.configr(   Ztraitlets.config.applicationr)   r*   Zjupyter_core.applicationr+   r,   r-   Zjupyter_core.pathsr.   Zjupyter_clientr/   Zjupyter_client.kernelspecr0   Zjupyter_client.sessionr1   Znbformat.signr2   Z	traitletsr3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   Zipython_genutilsrA   rB   rC   Znotebook._sysinforD   Z_tzrE   rF   ÚutilsrG   rH   rI   rJ   rK   rL   rM   rN   rO   Z
traittypesrP   rQ   rÚ  r  rR   rÊ   r”  r_   re   ÚApplicationrf   rå   r  r  r-  rÇ   r3  r±   r•  r4  r   Zlaunch_instanceÚmainZlaunch_new_instancer]   r]   r]   r^   Ú<module>   s&  
 
 
@,



  
GH'








             L
!