
    MhW                      d Z ddlm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mZ ddl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& dd
l'm(Z(m)Z)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2m3Z3m4Z4 ddl5m6Z6 ddl7m8Z8m9Z9m:Z:m;Z; ddl<m=Z= ddl>m?Z?m@Z@ ejA        B                    d          sddl<mCZC ejA        B                    d          r 	 ddlDZD eDjE                     n# eF$ r Y nw xY wddlGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZV ddlWmXZX ddlYmZZZm[Z[ ddl\m]Z]m^Z^m_Z_m`Z`maZambZb ddlcmdZd ddlemfZf ddlgmhZhmiZi ddljmkZkmlZlmmZm ddlnmoZo ddlpmqZq ddlrmsZsmtZtmuZumvZv dd lwmxZx dd!lymzZz dd"l{m|Z| dd#l}m~Z~ dd$lmZ dd%lmZmZmZ dd&lmZ dd'lmZmZmZmZmZ dd(lmZ dd)lmZmZ dd*lmZ dd+lmZmZ dd,lmZ dd-lmZ dd.lmZmZ dd/lmZ dd0lmZmZmZmZmZmZmZ 	 ddlZn# eF$ r dZY nw xY wdd1lmZmZ dd2l+mZ dd3lmZ dd4lmZmZ dd5lmZmZ d6Z	 ddl1Z1e1j        ek    sJ n(# eFeef$ rZ eF ed7          ez            edZ[ww xY w	 ddlZn# eF$ r dZY nw xY wd8Zdd9gd:gd;gd<gd=gd>d?gd@dAgdBgdCgdDgdEgdFgdGZe^ZddMZddQZ G dR dSe4j                  ZddWZ G dX dYe(          Zdd[Z G d\ d]e(          Z G d^ d_e(          Z ee*          Zd`dadbii edc          fedd<   dedfidedfidg edh          fedi<   djdkidjdkidg edl          fedm<   d`dndbiidofedn<   eƠ                     eZdpdqdrdr                      ee)          ZeȠ                    dsdtdudvdwdxdydzd{d|d}d~ddd            G d d`e(          Z	 dddZej        xZZdS )zA tornado based Jupyter server.    )annotationsN)encodebytes)partial)Path)KernelSpecManager)KernelManager)Session)
JupyterAppbase_aliases
base_flags)jupyter_runtime_dir)EventLogger)NotebookNotary)
httpserverioloopweb)
url_concat)LogFormatter
access_logapp_loggen_log)bind_sockets)MatcherRulewin)bind_unix_socket)AnyBoolBytesDictFloatInstanceIntegerList
TraitErrorTypeUnicodeUniondefaultobservevalidate)Config)boolean_flagcatch_config_error)DEFAULT_EVENTS_SCHEMA_PATHDEFAULT_JUPYTER_SERVER_PORTDEFAULT_STATIC_FILES_PATHDEFAULT_TEMPLATE_PATH_LISTJUPYTER_SERVER_EVENTS_URI__version__)get_sys_info)utcnow)AllowAllAuthorizer
Authorizer)IdentityProviderLegacyIdentityProviderPasswordIdentityProvider)LoginHandler)LogoutHandler)FileFindHandlerMainHandlerRedirectWithParamsTemplate404)ExtensionConfigManager)ExtensionManager)ServerExtensionApp)GatewayWebSocketConnection)GatewayClient)GatewayKernelSpecManagerGatewayMappingKernelManagerGatewaySessionManager)log_request)ACTIVE_DURATIONLAST_ACTIVITYSERVER_EXTENSION_INFOSERVER_INFOSERVER_STARTED)ConfigManager)AsyncFileContentsManagerFileContentsManager)AsyncLargeFileManager)AsyncContentsManagerContentsManager)BaseKernelWebsocketConnection)ZMQChannelsWebsocketConnection)AsyncMappingKernelManagerMappingKernelManager)SessionManager)JupyterServerAuthWarning	check_pidfetchunix_socket_in_use
url_escapeurl_path_joinurlencode_unix_socket_path)EnvironmentFileSystemLoader)secure_write)ensure_async)_i18ntrans)pathname2urlurljoin)      r   z.The Jupyter Server requires tornado >=%s.%s.%sz
jupyter server                       # start the server
jupyter server  --certfile=mycert.pem # use SSL/TLS certificate
jupyter server password              # enter a password to protect the server
z$jupyter_server.services.api.handlersz'jupyter_server.services.config.handlersz)jupyter_server.services.contents.handlerszjupyter_server.files.handlersz(jupyter_server.services.kernels.handlersz#jupyter_server.kernelspecs.handlersz,jupyter_server.services.kernelspecs.handlersz!jupyter_server.nbconvert.handlersz*jupyter_server.services.nbconvert.handlersz)jupyter_server.services.security.handlersz)jupyter_server.services.sessions.handlersz jupyter_server.services.shutdownzjupyter_server.view.handlersz'jupyter_server.services.events.handlers)authapiconfigcontentsfileskernelskernelspecs	nbconvertsecuritysessionsshutdownvieweventsportintnreturnt.Generator[int, None, None]c           
   #     K   t          t          d|                    D ]	}| |z   V  
t          |dz
            D ]0}t          d| t          j        d|z  d|z            z             V  1dS )zGenerate 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].
       rk      N)rangeminmaxrandomrandint)ry   r{   i_s       X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/jupyter_server/serverapp.pyrandom_portsr      s       3q!99  Qh1q5\\ ; ;!TFN261q5999::::::; ;    namestrt.Anyc                4    t          | dg          }|j        S ):Load the (URL pattern, handler) tuples for each component.default_handlers)fromlist)
__import__r   )r   mods     r   load_handlersr      s!    
T%7$8
9
9
9Cr   c                  f     e Zd ZdZdddddd fd
Z fdZ	 ddddddddZd Zd ZddZ	 xZ
S )ServerWebApplicationzA server web application.N
authorizeridentity_provider!kernel_websocket_connection_classwebsocket_ping_intervalwebsocket_ping_timeoutc               p   |,t          j        dt          d           t          |          }|-t          j        dt          d           t          ||          }|                     ||||||||	|
|||||||||          }|                     ||          }g }|D ].^}}}|                    | 	                    ||                     /|rKd	d

                    |          z   }|j        rt          j        |t          d           nt          |           t                      j        |fi | dS )z$Initialize a server web application.Nzridentity_provider unspecified. Using default IdentityProvider. Specify an identity_provider to avoid this message.r   
stacklevelparentziauthorizer unspecified. Using permissive AllowAllAuthorizer. Specify an authorizer to avoid this message.)r   r   r   zZCore endpoints without @allow_unauthenticated, @ws_authenticated, nor @web.authenticated:

)warningswarnRuntimeWarningr9   r[   r7   init_settingsinit_handlersextend_check_handler_authjoinallow_unauthenticated_access	Exceptionsuper__init__)selfjupyter_appdefault_serviceskernel_managercontents_managersession_managerkernel_spec_managerconfig_managerevent_loggerextra_serviceslogbase_urldefault_urlsettings_overridesjinja_env_optionsr   r   r   r   r   settingshandlersundecorated_methodsmatcherhandlerr   message	__class__s                              r   r   zServerWebApplication.__init__   s   0 $MG	    !1 D D DM@(	    ,;RcdddJ%%!/.O$;#9% & 
 
( %%&6AA $, 	S 	S GWq&&t'?'?'Q'QRRRR 	)m))/001  7 ),       (((..X.....r   c                   g }|D ]T}t          |t                    r|j        }|j        }n|^}}}|                    |                     ||                     U|rA| j        d         s4dd                    |          z   }t          j	        |t          d           t                                          ||          S )Nr   z_Extension endpoints without @allow_unauthenticated, @ws_authenticated, nor @web.authenticated:
r   r   r   )
isinstancer   r   targetr   r   r   r   r   r   r[   r   add_handlers)
r   host_patternhost_handlersr   ruler   r   r   r   r   s
            r   r   z!ServerWebApplication.add_handlersF  s     ! 	S 	SD$%% ,,+'+$1&&t'?'?'Q'QRRRR 		t}5S'T 		r))/001  M(    ww##L-@@@r   c               N   |                     d|j                  }t          |t                    r|f}d |D             }ddi}|                    |r|ni            t          d>t          |          dgd|}t                      }t          j	        
                    t          j	                            t          dd                    }t          j        dt          j	                            |d	          d
          }|                    |d           |d         dk    rd}nDt           j        j        }t           j                            |                              d          }t+                      }|j        }t          j	                            d          }|                    |t          j	        j        z             rd|t5          |          d         z   }i dt7          t8          |j                  d|
d|d|d|j        d|j        dt@          dtC          |
d          ddtC          |
dd           gid!|d"|j"        d#|j#        d$|j$        d%|j%        d&|j&        d'|j'        d(tC          |
d)          i d*dd+|j(        d,|j)        d-|j*        d.|j+        d/|j,        d0|d1|d2|d3|d4|d5|d6|d7|d8|d9|d:|||i |j-        |j.        |j/        |j0        |j1        |j2        |||d;}|                    |           |
rd<|vrd=|
i|d<<   |S )?z,Initialize settings for the web application.template_pathc                L    g | ]!}t           j                            |          "S  )ospath
expanduser).0r   s     r   
<listcomp>z6ServerWebApplication.init_settings.<locals>.<listcomp>z  s(    MMMd++D11MMMr   
autoescapeTzjinja2.ext.i18n)loader
extensionsz..nbuizjupyter_server/i18n)	localedirfallbackF)newstylecommit_source
repository )tzz%Y%m%d%H%M%S~Nlog_function)record_prometheus_metricsr   r   static_pathstatic_custom_pathstatic_handler_classstatic_url_prefixz/static/static_handler_argsno_cache_pathsstaticcustomversion_hashkernel_ws_protocol
limit_rateiopub_msg_rate_limitiopub_data_rate_limitrate_limit_windowcookie_secret	login_urlz/loginxsrf_cookiesdisable_check_xsrfr   allow_remote_accesslocal_hostnamesauthenticate_prometheusr   r   r   r   r   r   r   r   r   r   r   )r   startedlast_activity_timesjinja_template_varswebsocket_urlshutdown_buttonrn   
config_dirallow_password_changeserver_root_dir
jinja2_env	serverappxsrf_cookie_kwargsr   r   )3gettemplate_file_pathr   r   updaterb   rc   r5   r   r   realpathr   __file__gettexttranslationinstall_gettext_translationsdatetimetimezoneutcnowstrftimer6   root_dirr   
startswithseplenr   rJ   record_http_request_metricsstatic_file_pathr   r>   r`   r   r   r   r   r   r   r   r   r   r   r   r   r   quit_buttonrn   r   r   ) r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   _template_pathr   jenv_optenvsys_infobase_dirr   r   r  r  r  homer   s                                    r   r   z"ServerWebApplication.init_settings]  s   . ,//*
 
 nc** 	/,.NMMnMMM&2D%9->F))BGGG 
#M22@Q?R
 
V^
 
  >>7##BGLL4$F$FGG"gll8-BCC
 
 

 	(((>>>O$44LL #'C#,00C088AA.QQLhh#,w!!#&&tbgk122 	3Xc$iikk22H=
G{7^  =

 =
 ;=
 ]=
 ;7=
 !+"@=
 #O=
  x!D!D=
 " =8X#N#N"O$=
  L!=
$ !+"@%=
( +0)=
* #K$D+=
, $[%F-=
.  !>/=
2 [63=
4 x::5=
 =
6 D7=
8 !+"@9=
: +K,T;=
< ";#B==
> {:?=
@ &{'JA=
D nE=
F  0G=
H I=
J "#6K=
L nM=
N *O=
P  !2Q=
R LS=
T 01RU=
V &'>W=
X %&<Y=
 =
\ - $&#.#B(6*6!(%0%0%F'$y=
 =
 =
@ 	*+++ 	@,H<<.4h-?H)*r   c                   g }|d         D ]$}|                     t          |                     %|D ]U}|t          v r7t          |         }|'|D ]$}|                     t          |                     %B| d}t          |          |                     |d                                                    |                     |d                                                    |                     t          d                     |d         |d         k    r'|                    d	t          |d         d
df           n|                    dt          f           g }|D ]N}	t          |d         |	d                   }
|
gt          |	dd                   R }|                    |           O|                    dt          f           |S )r   r   Nzx is not recognized as a jupyter_server service. If this is a custom service, try adding it to the `extra_services` list.r   r   zjupyter_server.base.handlersr   r   z/?F)url	permanent/r   rk   z(.*))r   r   JUPYTER_SERVICE_HANDLERSr   get_extra_handlersget_handlersappendr@   r?   r`   listrA   )r   r   r   r   service	locationslocmsgnew_handlersr   patternnew_handlers               r   r   z"ServerWebApplication.init_handlers  s     01 	4 	4GOOM'223333 ( 	% 	%G2224W=	(( < < c(:(:;;;;  - - -   nn$ 	!34GGIIJJJ!45BBDDEEE 	&DEEFFFM"hz&:::OO&'6%* 	 	 	 	 OOT;/000  	- 	-G#HZ$8'!*EEG"7T'!""+%6%677K,,,,Wk2333r   c                .   | j         d         | j         d         j        g}|                    d | j                                         D                        |                    | j         d                                                    t          |          S )zGet a UTC timestamp for when the server last did something.

        Includes: API activity, kernel activity, kernel shutdown, and terminal
        activity.
        r   r   c                B    g | ]\  }}|                     d           |S )_last_activity)endswith)r   keyvals      r   r   z6ServerWebApplication.last_activity.<locals>.<listcomp>+  s.    YYYXS##,,GW:X:XYSYYYr   r   )r   last_kernel_activityr   itemsvaluesr   )r   sourcess     r   last_activityz"ServerWebApplication.last_activity  s     M)$M*+@
 	YY!4!4!6!6YYY	
 	
 	
 	t}%:;BBDDEEE7||r   r   t.Union[str, Matcher]r   type[web.RequestHandler]c           	        g }|j         D ]}t          ||                                          }|t          j        j        k    }t          |d          }t          |          }|s'|s%|s#|                    d| d|j	         d|            |S )N__allow_unauthenticatedz- z of z registered for )
SUPPORTED_METHODSgetattrlowerr   RequestHandler_unimplemented_methodhasattr_has_tornado_web_authenticatedr%  __name__)	r   r   r   missing_authenticationmethod_namemethodis_unimplementedis_allowlistedis_blocklisteds	            r   r   z(ServerWebApplication._check_handler_auth0  s     "$"4 	 	KWk&7&7&9&9::F%);)QQ$V-FGGN;FCCN# N > &--UUU'*:UUGUU   &%r   N)r   r9  r   r:  )rD  
__module____qualname____doc__r   r   r   r   r8  r   __classcell__r   s   @r   r   r      s        ##& *. $#+R/ R/ R/ R/ R/ R/ R/hA A A A AJ D  *. $#)D D D D DL8 8 8t  && & & & & & & &r   r   rG  t.Callable[..., t.Any]boolc                ,   t          | d          sdS t          | d          sdS | j        }t          |d          r|j                            d          S t          |d          r.|j                            dd                              d	          S dS )
zCheck if given method was decorated with @web.authenticated.

    Note: it is ok if we reject on @authorized @web.authenticated
    because the correct order is @web.authenticated @authorized.
    __wrapped__F__code__co_qualnameauthenticatedco_filename\r!  ztornado/web.py)rB  rU  rV  r  rX  replacer1  )rG  codes     r   rC  rC  @  s     6=)) u6:&& u?Dt]## N**?;;;	}	%	% N''c22;;<LMMM5r   c                  .    e Zd ZU dZeZded<   d Zd ZdS )JupyterPasswordAppzSet a password for the Jupyter server.

    Setting a password secures the Jupyter server
    and removes the need for token-based authentication.
    r   descriptionc                L    t           j                            | j        d          S )zthe default config file.zjupyter_server_config.json)r   r   r   r   r   s    r   _config_file_defaultz'JupyterPasswordApp._config_file_default\  s    w||DO-IJJJr   c                x    ddl m}  || j                   | j                            d| j        z             dS )zStart the password app.r   )set_password)config_filezWrote hashed password to %sN)jupyter_server.auth.securityrc  rd  r   info)r   rc  s     r   startzJupyterPasswordApp.start`  sM    ======!122223d6FFGGGGGr   N)rD  rL  rM  rN  r^  __annotations__ra  rg  r   r   r   r]  r]  S  sY           KK K KH H H H Hr   r]  r   c           
        | d         }| d         }	 t          |d          }|r|                    d|           t          |dddd| d	         z   i
           nw# t          $ rj}t	          |          dk    s||r+|                    d           |                    d|           t          |dddd| d	         z   i
           Y d}~nd}~ww xY wt          |dz            D ]@}t          |          s|r|                    d|            dS t          j        d           At          j
                            d          rdS |r|                    d|           t          j        |t          j                   t          |dz            D ]@}t          |          s|r|                    d|            dS t          j        d           A|r|                    d|           t          j        |t          j                   dS )a  Shutdown a Jupyter 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  pidzapi/shutdownzPOST request to %sPOSTr   Authorizationztoken token)rG  bodyheaderszUnknown URL scheme.z2Was not a HTTP scheme. Treating as socket instead.N
   zServer PID %s is goneTg?r   FzSIGTERM to PID %szSIGKILL to PID %s)ri   debugr]   r   r   r   r\   timesleepsysplatformr  r   killsignalSIGTERMSIGKILL)server_infotimeoutr   r  rj  shutdown_urlexr   s           r   shutdown_serverr~  h  ss    e
C
e
C
sN33 	:II*L999$hW1E&EF		
 	
 	
 	
 	
  
 
 
2ww///H 	1IIJKKKII*C000$hW1E&EF		
 	
 	
 	
 	
 	
 	
 	
 	

 7R<    ~~ 	 8		1377744
3
|u%% u
 ,		%s+++GC    7R<    ~~ 	 8		1377744
3
 ,		%s+++GC   4s   AA 
C#A CCc                       e Zd ZU dZeZded<   dZded<    ee	dde	z            Z
 ed	dd
          Zd fd	Zd Zd Zed             Zd Z xZS )JupyterServerStopAppz(An application to stop a Jupyter server.r   versionz6Stop currently running Jupyter server for a given portr^  Tz+Port of the server to be killed. Default %srn   helpr   z'UNIX socket of the server to be killed.Nc                    t                                          |           | j        rE	 t          | j        d                   | _        dS # t
          $ r | j        d         | _        Y dS w xY wdS )zParse command line options.r   N)r   parse_command_line
extra_argsrz   ry   
ValueErrorsock)r   argvr   s     r   r  z'JupyterServerStopApp.parse_command_line  s}    ""4(((? 	// 233			 / / / OA.				/	/ 	/s   A A,+A,c                .    t          || j                  S )zShut down a server.r   )r~  r   )r   servers     r   r~  z$JupyterServerStopApp.shutdown_server  s    v484444r   c                    | j                             d|z             |                     |          st          j        d|z             dS dS )zHandle a shutdown.zShutting down server on %s...zCould not stop server on %sN)r   rf  r~  rt  exit)r   target_endpointr  s      r   _shutdown_or_exitz&JupyterServerStopApp._shutdown_or_exit  s[    5GHHH##F++ 	FH2_DEEEEE	F 	Fr   c                R    	 t          j        |            dS # t          $ r Y dS w xY w)zTry to remove a socket path.N)r   unlinkOSError)socket_paths    r   _maybe_remove_unix_socketz.JupyterServerStopApp._maybe_remove_unix_socket  s?    	Ik""""" 	 	 	DD	s    
&&c                   | j         j        }t          t          | j        | j                             }|s|                     d| j        z             |D ]}| j        rR|                    dd          }|r9|| j        k    r.|                     ||           | 	                    |            dS [| j
        r:|                    dd          }|| j
        k    r|                     ||            dS | j        p| j
        } |d|             |d           |D ];} |d                    |                    d          p|d                              <|                     d	           dS )
zStart the server stop app.r  z%There are no running servers (per %s)r  Nry   z(There is currently no server running on zPorts/sockets currently in use:z - {}rk   )r   rf  r&  list_running_serversruntime_dirr  r  r  r  r  ry   format)r   rf  serversr  r  ry   current_endpoints          r   rg  zJupyterServerStopApp.start  s   x}+D,<$(KKKLL 	RII=@PPQQQ 	 	Fy zz&$// DDI--**4888224888FF zz&$//49$$**4888FF91	J8HJJKKK./// 	G 	GFD

6 2 2 DfVnEEFFFF		!r   rK  )rD  rL  rM  rN  r4   r  rh  r^  r#   r0   ry   r'   r  r  r~  r  staticmethodr  rg  rO  rP  s   @r   r  r    s         22GOKOOOO7#:=XX  D 72d)RSSSD/ / / / / /5 5 5F F F   \      r   r  c                      e Zd ZU dZeZded<    ed          Zded<   d ddii ed          fd d	dii ed
          fdZ	 e
dd ed                    Z e
dd ed                    Zd ZdS )JupyterServerListAppz/An application to list running Jupyter servers.r   r  z'List currently running Jupyter servers.r^  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 Jupyer server, each with the details from the relevant server info file.r  zIf 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 JupyterServerListApp.jsonlist configuration valuec                   t          t          | j        | j                            }| j        r%t          t          j        |d                     d
S | j        r(|D ]#}t          t          j        |                     $d
S t          d           |D ]D}|d         }|                    d          r|d|d         z  z   }t          |d|d	                    Ed
S )z"Start the server list application.r  r   )indentzCurrently running servers:r  rm  z	?token=%s::r  N)	r&  r  r  r   r  printr  dumpsr  )r   serverinfo_list
serverinfor  s       r   rg  zJupyterServerListApp.start  s   3D4D$(SSSTT= 	9$*_Q77788888Y 		9- . .
dj,,----. . .///- 9 9
 '>>'** Bj.A AACc4J!78888	9 9r   N)rD  rL  rM  rN  r4   r  rh  rf   r^  flagsr   r  r  rg  r   r   r   r  r    s        99GuFGGKGGGG $j$%78E>??

 $fd^4EPQQ
	 	E tU)
 
  H 4UH
 
  D9 9 9 9 9r   r  	ServerApp
allow_rootTz*Allow the server to be run from root user.z
allow-rootopen_browserF)r  ExtensionAppz6Prevent the opening of the default url in the browser.z
no-browser	log_levelDEBUGzESet debug level for the extension and underlying server applications.rq  
autoreloadzAutoreload the webapp
    Enable reloading of the tornado webapp and all imported Python packages
    when any changes are made to any Python src files in server or
    extensions.
    scriptzFileContentsManager.save_scriptzDEPRECATED, IGNOREDzServerApp.ipzServerApp.portzServerApp.port_retrieszServerApp.sockzServerApp.sock_modezKernelManager.transportzServerApp.keyfilezServerApp.certfilezServerApp.client_cazServerApp.root_dirzServerApp.preferred_dirzServerApp.browserzServerApp.pylabzGatewayClient.url)ipry   zport-retriesr  z	sock-mode	transportkeyfilecertfilez	client-caznotebook-dirzpreferred-dirbrowserpylabzgateway-urlc                  n    e Zd ZU dZdZeZded<    ed          Z	ded<   e
Z ee          Z ee          Zeeeeeeeeeeeeeeeeee gZ!e"e"j	        #                                d         fe$e$j	        #                                d         fe%e%j	        #                                d         fe&e&j	        #                                d         fdZ'd	ed
<   dZ(e)Z* e+dd          Z, e-d          d-d            Z. e-d          d.d            Z/ e0dd          1                    d          Z2 e0dd          1                    d          Z3 e0ddd          Z4 e0ddd          Z5 e+dd ed                    Z6 e+dd ed                    Z7 e+dd ed                     Z8 e0d!d ed"                    Z9 e0d#d ed$                    Z: e-d%          d.d&            Z; e<d%          d/d)            Z= e0dd ed*                    Z>d+Z?e@ZA eBd ed,                    ZC e-d-          d-d.            ZDd/ZEd0ZF eBeFd ed1                    ZG e-d2          d-d3            ZH e0ddd4          ZI e0d5dd6          ZJ e<d7          d0d8            ZK e0dd ed9                    ZL e0dd ed:                    ZM e0dd ed;                    ZN e0d ed<                    ZO e-d=          d.d>            ZP eQd?dd@          ZR e-dA          d1dC            ZSd2dFZTdZU e0dG edH                    1                    d          ZV eWdI          d3dK            ZX e-dI          d.dL            ZY eBddMdN          ZZ e-dO          d4dQ            Z[ eBdRddS          Z\ eBdRddT          Z] e0dddU          Z^ e+dddV          Z_ e+dddW          Z`	 d5d6d\Za eWd]          d3d^            Zb eWd_d`          d3da            Zc e+dddb          ZddcZe e+ddddee de          Zf e-df          dg             Zg e+ddh          Zh e-di          d7dk            Zi e+dddl          Zj ek e0            d#gddm          Zl e+dddn          Zm e0dddo          Zn eBdpd edq                    Zo ed edr                    Zp eqdXd eds                    Zr e es ek             e0            g          d edt                    Zt ed edu                    Zu ed edv                    Zv eWdwdx          d3dy            Zw edd edz          {          Zx ed ed|                    Zy ed ed}                    Zz e0d!dd~          Z{ e<d          d/d            Z| ek e0            dd          Z}e~d8d            Z ek e0             ed                    Z e-d          d8d            Z ek e0            d ed                    Ze~d8d            Z ek e0            d ed                    Z e0ddd          Z e+ddd          Z eeed ed                    Z eed ed                    Z e-d          d9d            Z ed ed                    Z e-d          d:d            Z eed ed                    Z e-d          d;d            Z eBdd          Z eBdd          Z eed ed                    Z eed          Z edd          Z e-d          d<d            Z eeej        dd ed                    Z eeej        dd ed                    Z eeed ed                    Z eeed ed                    Z e+dd ed                    Z eedd          Z e0            Z e-d          d.d            Z e+dd          Z e0            Z e-d          d.d            Z e0            Z e-d          d.d            Z e0dd ed                    Z eWd          d3d            Z e0d ed                    Z eWd          d3d            Z e0dXdd ed          {          Z e+dd ed                    Z e0d ed                    ZdZ e-d          d.d            Zd=dZ e<d          d/d            Z eWd          d3d            Z e0d ej        dæ                    Z e-dĦ          d.dń            Z e<dĦ          d/dƄ            Z eWdǦ          d3dȄ            Z ei  e+            d edɦ          ʦ          Z e+dd ed˦                    Z e0dd ed̦          {          Z eWdͦ          d3d΄            Z e+dd edϦ          {          Z eWdЦ          d3dф            Z edd edҦ          {          Z eWdӦ          d3dԄ            Z edd edզ          {          Z eWd֦          d3dׄ            Z edd edئ          {          Z eWd٦          d3dڄ            Z eBddd۬          Z e+d edܦ                    Z e-dݦ          d7dބ            Z e+ddd          Z e+dd          Z ek e0            dd          Z edXdd          Ze~d>d            ZӐd5d? fdZԐd@dZՐd@dZ֐d@dZאd@dZؐd@dZ	 dAdBdZe~d.d            Ze~d.d            Ze~d.d            Ze~d.d            Zސd@dZߐdCdZd@dZd@dZdCdZdCdZd@dZd@dZd@d Zd@dZd@dZd@dZd@dZe~dDd            Zd@dZd@dZd7d	Zd7d
Zd@dZed@d            Zd@dZe	 	 	 	 dEdF fd            Zd@dZd@dZdGdHdZdIdZd@dZd@dZd.dZdJdZd@dZd@dZ d@dZd@d ZdKd"Zd@d#Zd@ fd$Zd@d%Zd@d&Zd@d'Zd( Z	d@d)Z
d@d*ZdLdMd,Z xZS (N  r  z%The Jupyter Server application class.zjupyter-serverr   r  zFThe Jupyter Server.

    This launches a Tornado-based Jupyter Server.r^  r   )r&  stoppassword	extensiondict[str, t.Any]subcommands)rm   rl   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   Fz!Signal that we've begun stopping.)r  r  r|   rz   c                    t           j        S rK  )loggingINFOr`  s    r   _default_log_levelzServerApp._default_log_level  s
    |r   
log_formatc                    	 dS )z2override default log format to include date & timezV%(color)s[%(levelname)1.1s %(asctime)s.%(msecs).03d %(name)s]%(end_color)s %(message)sr   r`  s    r   _default_log_formatzServerApp._default_log_format  s     e	
 	
r   r   z5Open the named file when the application is launched.T)rn   	notebooksz/The URL prefix where files are opened directly.zSet the Access-Control-Allow-Origin header

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

        Takes precedence over allow_origin_pat.
        r  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 headerz4Whether to allow the user to run the server as root.z@Reload the webapp when changes are made to any Python src files.r!  z'The default URL to redirect to from `/`	localhostz1The IP address the Jupyter server will listen on.r  c                    t          j                     }	 |                    d           |                                 dS # t          $ r3}| j                            t          d          |           Y d}~dS d}~ww xY w)zReturn localhost if available, 127.0.0.1 otherwise.

        On some (horribly broken) systems, localhost cannot be bound.
        )r  r   r  z:Cannot bind to localhost, using 127.0.0.1 as default ip
%sN	127.0.0.1)socketbindcloser  r   warningrf   )r   ses      r   _default_ipzServerApp._default_ip  s     MOO		FF#$$$ GGIII;  	 	 	HSTTVW   ;;;;;		s   A   
A=
(A88A=proposalr   c                V    t          j        t          |d                   }|dk    rd}|S )Nvalue*r   )tcastr   r   r  r  s      r   _validate_ipzServerApp._validate_ip  s+    sHW-..C<<Er   a  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 server (proxified
        or containerized setups for example).JUPYTER_PORTz7The port the server will listen on (env: JUPYTER_PORT).ry   c                Z    t          t          j        | j        | j                            S rK  )rz   r   getenvport_envport_default_valuer`  s    r   _port_defaultzServerApp._port_default-  s!    29T]D,CDDEEEr   JUPYTER_PORT_RETRIES2   ziThe number of additional ports to try if the specified port is not available (env: JUPYTER_PORT_RETRIES).port_retriesc                Z    t          t          j        | j        | j                            S rK  )rz   r   r  port_retries_envport_retries_default_valuer`  s    r   _port_retries_defaultzServerApp._port_retries_default<  s"    29T2D4STTUUUr   z2The UNIX socket the Jupyter server will listen on.0600z>The permissions mode for UNIX socket creation (default: 0600).	sock_modec                   |d         }	 t          |                                d          }t          t          |t          j        z            t          |t          j        z            |dk    f          sJ nE# t          $ r}t          d|z            |d }~wt          $ r}t          d|z            |d }~ww xY w|S )Nr        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)
rz   encodeallrR  statS_IRUSRS_IWUSRr  r%   AssertionError)r   r  r  converted_valuer  s        r   _validate_sock_modezServerApp._validate_sock_modeH  s    !	!%,,..!44O 4<7884<788#u,       	 	 	NQVV   	 	 	SV[[ 	 s$   A.A9 9
B;BB;#B66B;z-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                L    t           j                            | j        d          S )Njupyter_cookie_secret)r   r   r   r  r`  s    r   _default_cookie_secret_filez%ServerApp._default_cookie_secret_filex  s    w||D,.EFFFr   r   a  The random bytes used to secure cookies.
        By default this is generated on first start of the server and persisted across server
        sessions by writing the cookie secret into the `cookie_secret_file` file.
        When using an executable config file you can override this to be random at each server restart.

        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   bytesc                   t           j                            | j                  rBt	          | j        d          5 }|                                }d d d            n# 1 swxY w Y   n6t          t          j        d                    }|                     |           t          j
        |t          j                  }|                    | j                                                   |                                S )Nrb    )	digestmod)r   r   existsr  openreadr   urandom_write_cookie_secret_filehmacnewhashlibsha256r  r  r  digest)r   fr2  hs       r   _default_cookie_secretz ServerApp._default_cookie_secret  s    7>>$122 	0d-t44 ffhh               bjnn--C**3///HSGN333	%%''(((xxzzs   AA"AsecretNonec                t   | j                             t          d          | j                   	 t	          | j        d          5 }|                    |           ddd           dS # 1 swxY w Y   dS # t          $ r9}| j                             t          d          | j        |           Y d}~dS d}~ww xY w)z!write my secret to my secret_filez*Writing Jupyter server cookie secret to %sTNz'Failed to write cookie secret to %s: %s)r   rf  rf   r  rd   writer  error)r   r  r  r  s       r   r  z#ServerApp._write_cookie_secret_file  s   eHII4Kbccc	d5t<<                                      	 	 	HNN?@@'        	s;   A4 A'A4 'A++A4 .A+/A4 4
B7>.B22B7z<DEPRECATED>z&DEPRECATED. Use IdentityProvider.tokenrm  changec                2    |                      |d           d S Nr9   _warn_deprecated_configr   r  s     r   _deprecated_tokenzServerApp._deprecated_token      $$V-?@@@@@r   c                R    t          j        dt          d           | j        j        S )NVServerApp.token config is deprecated in jupyter-server 2.0. Use IdentityProvider.token   r   )r   r   DeprecationWarningr   rm  r`  s    r   _deprecated_token_accessz"ServerApp._deprecated_token_access  s2    d	
 	
 	
 	

 %++r   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.
        )rn   r  
allow_nonemin_open_files_limitt.Optional[int]c                    t           d S t          j        t           j                  \  }}d}||k    r|S | j                            d||           |S )Nr  zDDefault value for min_open_files_limit is ignored (hard=%r, soft=%r))resource	getrlimitRLIMIT_NOFILEr   rq  )r   softharddefault_softs       r   _default_min_open_files_limitz'ServerApp._default_min_open_files_limit  sb    4'(>??
d<R	
 	
 	
 r   i    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?DEPRECATED in 2.0. Use PasswordIdentityProvider.hashed_passwordzADEPRECATED in 2.0. Use PasswordIdentityProvider.password_requiredzEDEPRECATED in 2.0. Use PasswordIdentityProvider.allow_password_changeNclsnamenew_namet.Optional[str]c           	     V   ||j         }|| j        vs|| j        |         vr@| j                            d|j          d| d| d           |j        | j        |         |<   dS | j        |         |         |j        k    r+| j                            d|j          d| d| d           dS dS )zWarn on deprecated config.Nz
ServerApp.z" config is deprecated in 2.0. Use .zIgnoring deprecated ServerApp.z config. Using )r   rn   r   r  r   )r   r  r$  r%  s       r   r  z!ServerApp._warn_deprecated_config  s     {H$+%%W9M)M)M HaV[aaGaaV^aaa   .4ZDK *** [!(+vz99HbbbWbbW_bbb     :9r   r  c                6    |                      |dd           d S )Nr;   hashed_password)r%  r  r  s     r   _deprecated_passwordzServerApp._deprecated_password  s%    $$V-GRc$dddddr   password_requiredr   c                2    |                      |d           d S )Nr;   r  r  s     r   _deprecated_password_configz%ServerApp._deprecated_password_config  s    $$V-GHHHHHr   a0  Disable cross-site-request-forgery protection

        Jupyter server includes 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.
        +JUPYTER_SERVER_ALLOW_UNAUTHENTICATED_ACCESSaS  Allow unauthenticated access to endpoints without authentication rule.

        When set to `True` (default in jupyter-server 2.0, subject to change
        in the future), any request to an endpoint without an authentication rule
        (either `@tornado.web.authenticated`, or `@allow_unauthenticated`)
        will be permitted, regardless of whether user has logged in or not.

        When set to `False`, logging in will be required for access to each endpoint,
        excluding the endpoints marked with `@allow_unauthenticated` decorator.

        This option can be configured using `z`
        environment variable: any non-empty value other than "true" and "yes" will
        prevent unauthenticated access to endpoints without `@allow_unauthenticated`.
        r   c                    t          j        | j                  r+t           j        | j                                                 dv S dS )N)trueyesT)r   r  !_allow_unauthenticated_access_envenvironr?  r`  s    r   %_allow_unauthenticated_access_defaultz/ServerApp._allow_unauthenticated_access_default@  s?    9T;<< 	a:dDEKKMMQ```tr   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   rR  c                   | j         dk    rdS 	 t          j        | j                   }|j         S # t          $ r t          j        | j         | j        dt
          j                  D ]}|d         d         }	 t          j        |	                    d          d                   }n+# t          $ r | j
                            d|           Y fw xY w|j        sd|v r|j        s Y dS Y dS w xY w)zDDisallow remote access if we're listening only on loopback addressesr   Tr      %zUnrecognised IP address: %rF)r  	ipaddress
ip_addressis_loopbackr  r  getaddrinfory   SOCK_STREAMsplitr   r  is_link_local)r   addrrf  parseds       r   _default_allow_remotezServerApp._default_allow_remoteW  s    7b==4	('00D* ''')  	 	 	*47DIq&BTUU    Awqz&1$**S//!2DEEFF!   H$$%BDIIIH & ,/4KKV=QK44455%	s:   0 AC*6-B$#C*$%C	C*CC*%C*)C*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).
     zHostnames 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.
       an  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.
                        ak  Specify what command to use to invoke a web
                      browser when starting the server. 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.
                      r   a  Specify where to open the server 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.
        zNSupply overrides for the tornado.web.Application that the Jupyter server uses.aq  
        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.
        zHSupply overrides for terminado. Currently only supports "shell_command".z/DEPRECATED. Use IdentityProvider.cookie_optionsz9DEPRECATED. Use IdentityProvider.get_secure_cookie_kwargscookie_optionsget_secure_cookie_kwargsc                2    |                      |d           d S r  r  r  s     r   _deprecated_cookie_configz#ServerApp._deprecated_cookie_config  r  r   z\Supply SSL options for the tornado HTTPServer.
            See the tornado docs for details.)r  rn   r  z@Supply extra arguments that will be passed to Jinja environment.z<Extra variables to supply to jinja templates when rendering.zThe base URL for the Jupyter server.

                       Leading and trailing slashes can be omitted,
                       and will automatically be added.
                       r   c                    t          j        t          |d                   }|                    d          sd|z   }|                    d          s|dz   }|S )Nr  r!  )r  r  r   r  r1  r  s      r   _update_base_urlzServerApp._update_base_url  sY    sHW-..$$ 	 %KE~~c"" 	 CKEr   zExtra paths to search for serving static files.

        This allows adding javascript/css to be available from the Jupyter server machine,
        or overriding individual files in the IPython	list[str]c                "    g | j         t          S )z)return extra paths + the default location)extra_static_pathsr1   r`  s    r   r  zServerApp.static_file_path  s     E(D*CDDr   z!Path to search for custom.js, cssr   c                2    d | j         t          fD             S )Nc                N    g | ]"}t           j                            |d           #S )r   )r   r   r   )r   ds     r   r   z9ServerApp._default_static_custom_path.<locals>.<listcomp>  s(    ```aQ))```r   )r   r1   r`  s    r   _default_static_custom_pathz%ServerApp._default_static_custom_path  s    ``DOE^3_````r   z|Extra paths to search for serving jinja templates.

        Can be used to override templates from jupyter_server.templates.c                     | j         t          z   S )z*return extra paths + the default locations)extra_template_pathsr2   r`  s    r   r  zServerApp.template_file_path*  s     (+EEEr   zKhandlers that should be loaded at higher priority than the default serviceszThe 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]
        zYIf True, display controls to shut down the Jupyter server, such as menu items or buttons.z!The content manager class to use.)default_valueklassrn   r  z The kernel manager class to use.)rS  rn   r  kernel_manager_class-t.Union[str, type[AsyncMappingKernelManager]]c                ,    | j         j        rdS t          S )Nz;jupyter_server.gateway.managers.GatewayMappingKernelManager)gateway_configgateway_enabledrX   r`  s    r   _default_kernel_manager_classz'ServerApp._default_kernel_manager_classT  s    . 	QPP((r   z!The session manager class to use.session_manager_class"t.Union[str, type[SessionManager]]c                ,    | j         j        rdS t          S )Nz5jupyter_server.gateway.managers.GatewaySessionManager)rW  rX  rZ   r`  s    r   _default_session_manager_classz(ServerApp._default_session_manager_class_  s    . 	KJJr   z-The kernel websocket connection class to use.r   2t.Union[str, type[ZMQChannelsWebsocketConnection]]c                ,    | j         j        rdS t          S )Nz=jupyter_server.gateway.connections.GatewayWebSocketConnection)rW  rX  rW   r`  s    r   *_default_kernel_websocket_connection_classz4ServerApp._default_kernel_websocket_connection_classk  s     . 	SRR--r   aC  
            Configure the websocket ping interval in seconds.

            Websockets are long-lived connections that are used by some Jupyter
            Server extensions.

            Periodic pings help to detect disconnected clients and keep the
            connection active. If this is set to None, then no pings will be
            performed.

            When a ping is sent, the client has ``websocket_ping_timeout``
            seconds to respond. If no response is received within this period,
            the connection will be closed from the server side.
        z
            Configure the websocket ping timeout in seconds.

            See ``websocket_ping_interval`` for details.
        zThe config manager class to use)rR  rn   r  )r  a  
        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.
        kernel_spec_manager_class%t.Union[str, type[KernelSpecManager]]c                ,    | j         j        rdS t          S )Nz8jupyter_server.gateway.managers.GatewayKernelSpecManager)rW  rX  r   r`  s    r   "_default_kernel_spec_manager_classz,ServerApp._default_kernel_spec_manager_class  s    . 	NMM  r   zThe login handler class to use.)rR  rS  r  rn   r  z The logout handler class to use.zThe authorizer class to use.z#The identity provider class to use.zWhether to trust or not X-Scheme/X-Forwarded-Proto and X-Real-Ip/X-Forwarded-For headerssent by the upstream reverse proxy. Necessary if the proxy handles SSLzUAn EventLogger for emitting structured event data from Jupyter Server and extensions.)r  r  	info_filec                x    dt          j                    z  }t           j                            | j        |          S )Nzjpserver-%s.jsonr   getpidr   r   r  )r   re  s     r   _default_info_filezServerApp._default_info_file  s+    &4	w||D,i888r   zCIf True, do not write redirect HTML file disk, or show in messages.browser_open_filec                x    dt          j                    z  }t           j                            | j        |          S )Nzjpserver-%s-open.htmlrg  r   basenames     r   _default_browser_open_filez$ServerApp._default_browser_open_file  s+    *RY[[8w||D,h777r   browser_open_file_to_runc                x    dt          j                    z  }t           j                            | j        |          S )Nz!jpserver-file-to-run-%s-open.htmlrg  rl  s     r   !_default_browser_open_file_to_runz+ServerApp._default_browser_open_file_to_run  s+    6Dw||D,h777r   disabledz[
        DISABLED: use %pylab or %matplotlib in the notebook to enable matplotlib.
        r  c                $   |d         dk    rd|d         z  nd}| j                             t          d                     | j                             t          d                              |                     |                     d           dS )	z5when --pylab is specified, display a warning and exitr   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.rk   N)r   r  rf   r  r  )r   r  backends      r   _update_pylabzServerApp._update_pylab  s     ,2%=F+B+B%&-''XYY	
 	
 	
 	VWW^^ 	
 	
 	

 			!r   zDEPRECATED, use root_dir.notebook_dirc                    | j         rd S | j                            t          d                     |d         | _        d S )Nz(notebook_dir is deprecated, use root_dirr   )_root_dir_setr   r  rf   r  r  s     r   _update_notebook_dirzServerApp._update_notebook_dir	  s@     	FIJJKKKur   a  The directory to look at for external kernel connection files, if allow_external_kernels is True. Defaults to Jupyter runtime_dir/external_kernels. Make sure that this directory is not filled with left-over connection files, that could result in unnecessary kernel manager creations.zgWhether or not to allow external kernels, whose connection files are placed in external_connection_dir.z/The directory to use for notebooks and kernels.r  c                    | j         rHd| _        t          j                            t          j                            | j                             S t          j                    S NT)file_to_runrx  r   r   dirnameabspathgetcwdr`  s    r   _default_root_dirzServerApp._default_root_dir(  sF     	!%D7??27??43C#D#DEEE9;;r   r  c                (   t           j                            |          \  }}|t           j        k    r|S |                    t           j                  }t           j                            |          st           j                            |          }|S )zNormalize a directory.)r   r   
splitdriver  rstripisabsr~  )r   r  r   r   s       r   _normalize_dirzServerApp._normalize_dir0  sn     '$$U++426>>LRV$$w}}U## 	+GOOE**Er   c                    |                      |d                   }t          j                            |          s$t	          t          j        d          |z            |S )Nr  zNo such directory: '%r'r  r   r   isdirr%   rg   r	  r  s      r   _root_dir_validatezServerApp._root_dir_validate=  sT    ##HW$566w}}U## 	OU]+DEEMNNNr   c                    d| _         d S r{  )rx  r  s     r   _root_dir_changedzServerApp._root_dir_changedD  s     "r   zPreferred starting directory to use for notebooks and kernels. ServerApp.preferred_dir is deprecated in jupyter-server 2.0. Use FileContentsManager.preferred_dir insteadpreferred_dirc                    | j         S rK  )r  r`  s    r   _default_prefered_dirzServerApp._default_prefered_dirQ  s
    }r   c                    |                      |d                   }t          j                            |          s$t	          t          j        d          |z            |S )Nr  zNo such preferred dir: '%r'r  r  s      r   _preferred_dir_validatez!ServerApp._preferred_dir_validateU  sT    ##HW$566w}}U## 	SU]+HIIEQRRRr   server_extensionsc                n    | j                             t          d                     |d         | _        d S )Nz8server_extensions is deprecated, use jpserver_extensionsr   )r   r  rf   r  r  s     r   _update_server_extensionsz#ServerApp._update_server_extensions\  s3    YZZ[[[!'r   zDict of Python modules to load as Jupyter server extensions.Entry values can be used to enable and disable the loading ofthe extensions. The extensions will be loaded in alphabetical order.)rR  value_traitrn   r  z9Reraise exceptions encountered loading server extensions?zADEPRECATED. Use ZMQChannelsWebsocketConnection.kernel_ws_protocolr   c                2    |                      |d           d S NrW   r  r  s     r   _deprecated_kernel_ws_protocolz(ServerApp._deprecated_kernel_ws_protocol{      $$V-MNNNNNr   z9DEPRECATED. Use ZMQChannelsWebsocketConnection.limit_rater   c                2    |                      |d           d S r  r  r  s     r   _deprecated_limit_ratez ServerApp._deprecated_limit_rate  r  r   zCDEPRECATED. Use ZMQChannelsWebsocketConnection.iopub_msg_rate_limitr   c                2    |                      |d           d S r  r  r  s     r    _deprecated_iopub_msg_rate_limitz*ServerApp._deprecated_iopub_msg_rate_limit  r  r   zDDEPRECATED. Use ZMQChannelsWebsocketConnection.iopub_data_rate_limitr   c                2    |                      |d           d S r  r  r  s     r   !_deprecated_iopub_data_rate_limitz+ServerApp._deprecated_iopub_data_rate_limit  r  r   z@DEPRECATED. Use ZMQChannelsWebsocketConnection.rate_limit_windowr   c                2    |                      |d           d S r  r  r  s     r   _deprecated_rate_limit_windowz'ServerApp._deprecated_rate_limit_window  r  r   aT  Shut down the server after N seconds with no kernelsrunning and no activity. This can be used together with culling idle kernels (MappingKernelManager.cull_idle_timeout) to shutdown the Jupyter 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 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.
         terminals_enabledc                    dS r{  r   r`  s    r   _default_terminals_enabledz$ServerApp._default_terminals_enabled  s    tr   zG"
        Require authentication to access prometheus metrics.
        )r  rn   aT  
        Record http_request_duration_seconds metric in the metrics endpoint.

        Since a histogram is exposed for each request handler, this can create a
        *lot* of metrics, creating operational challenges for multitenant deployments.

        Set to False to disable recording the http_request_duration_seconds metric.
        z
        Paths to set up static files as immutable.

        This allow setting up the cache control of static files as immutable.
        It should be used for static file named with a hash for instance.
        z1jupyter_server.extension.application.ExtensionApp)rR  r  rS  c                    | j         S )z+Get the Extension that started this server.)_starter_appr`  s    r   starter_appzServerApp.starter_app  s       r   r  t.Optional[list[str]]c                   t                                          |           | j        r| j        d         }t          j                            |          }| j                            |           t          j                            |          s=| j	        
                    t          d          |           |                     d           t                      }t          j                            |          r||j        _        n+t          j                            |          r||j        _        |                     |           dS dS )zParse the command line options.r   zNo such file or directory: %srk   N)r   r  r  r   r   r~  r  remover  r   criticalrf   r  r,   r  r  r  isfiler|  update_config)r   r  arg0r  cr   s        r   r  zServerApp.parse_command_line  s   ""4(((? 	"?1%D%%AIT"""7>>!$$ !!%(G"H"H!LLL		! Aw}}Q ,'($$"" ,*+'q!!!!!	" 	"r   c                P   t          j        |           | _        t          | j        t
                    st          j        dt          d           t          | j	        t                    st          j        dt          d           |                     |           | _        | | j        | j        | j        d}t          j        dk    r:| j        r2| j        }|$t'          t)          | j                  d	z            }||d
<   n!| j        r| j                            d            | j        di || _        | 	                    | | j                  | _        | j        j         |                     | | j        | j        | j                  | _        |                     | | j                  | _        | | j        d}| j        t<          urY| j        t@          u rKtB          | _        | j                            d| j         d           | j        |d<   | j"        r
| j"        |d<   n1| j        t<          ur#| j                            d| j         d            | j        di || _#        | j        tB          u r(| j#        j$        | j%        d<   | j#        j&        | j%        d<   | j'        r^| j                            d           | j#        j(        rd| j#        _(        | j&        | j#        _&        n| j                            d           | )                    | | j        | j#                  | _*        dS )zInitialize configurables.r   zhThe synchronous MappingKernelManager class is deprecated and will not be supported in Jupyter Server 3.0r   r   zfThe synchronous ContentsManager classes are deprecated and will not be supported in Jupyter Server 3.0)r   r   connection_dirr   )r  r  r   Nexternal_kernelsexternal_connection_dirzAlthough allow_external_kernels=True, external kernels are not supported because jupyter-client's version does not allow them (should be >8.3.0).)r   r   )r   r   r   r   z=Customizing authentication via ServerApp.login_handler_class=zs is deprecated in Jupyter Server 2.0. Use ServerApp.identity_provider_class. Falling back on legacy authentication.login_handler_classlogout_handler_classz9Ignoring deprecated config ServerApp.login_handler_class=zQ. Superseded by ServerApp.identity_provider_class={self.identity_provider_class}.r  rm  r  Fz*Ignoring deprecated ServerApp.token config)r   r   r   r   )+rF   instancerW  
issubclassrT  rX   r   r   r  contents_manager_classrT   ra  r   r   r  jupyter_clientversion_infoallow_external_kernelsr  r   r   r  r   r   r  rZ  r   config_manager_classr   r  r<   identity_provider_classr;   r:   r  r   r*  tornado_settingsrm  
_token_settoken_generatedauthorizer_classr   )r   kwargsr  identity_provider_kwargss       r   init_configurableszServerApp.init_configurables  s    ,4DAAA%%
 
 	 Mz"    ' 
 
 	 Mx"    $(#A#A $B $
 $
 
 8".#'#;	
 
 &22* L*.*F'*2.1$t7G2H2HK]2].^.^+4K01( 	H[  
 8d7AA&AA $ ; ; !< !
 !
 	++#99.!2	  :  
  
 #77 8 
 
 /348#D#D  $L88,0HHH
 ,BD(H:PTPh : : :   ?C>V$%:;( ]CGC\()?@%\99HcDLd c c c   ">!=!Y!Y@X!Y!Y'+AAA040F0VD!*--1-C-ID!'*? 	OHh   %5 O :?&6/3z&,,   !MNNN//TX9O 0 
 
r   c                    d| j         _        t          t          t          fD ]}| j         j        |_        t          j        d          }d|_        | j         |_        |	                    | j         j
                   dS )zInitialize logging.FtornadoTN)r   	propagater   r   r   r   r  	getLoggerr   setLevellevel)r   r   loggers      r   init_loggingzServerApp.init_loggingz  sn    
 #J/ 	% 	%Cx}CHH"9--'''''r   c                    t          |           | _        g d}|D ]G}|                    t          dz   d          dz   }t          |z  }| j                            |           HdS )zInitialize the Event Bus.r   )z=https://events.jupyter.org/jupyter_server/contents_service/v1z;https://events.jupyter.org/jupyter_server/gateway_client/v1z;https://events.jupyter.org/jupyter_server/kernel_actions/v1r!  r   z.yamlN)r   r   rZ  r3   r/   register_event_schema)r   
schema_ids	schema_idrel_schema_pathschema_paths        r   init_event_loggerzServerApp.init_event_logger  s    't444
 
 


 $ 	A 	AI'//0IC0OQSTTW^^O4FK33K@@@@	A 	Ar   c                   | j         | j        d<   | j        | j        d<   | j        r!t	          j        | j                  | j        d<   | j        | j        d<   | j        | j        d<   | j        j	        | j        d<   | j        j
        | j        d<   | j        j        | j        d<   | j        r| j        | j        d	<   | j                            | j                  st!          | j        | j                  | _        | j        r| j        t&          k    r/| j                            d
           t-          j        d           nd| _        | j        r| j                            d           | j        r.| j                            d           t-          j        d           t,          j                            d          r6| j                            d| j        z             t-          j        d           t9          | | j        | j        | j        | j         | j!        | j"        | j#        | j$        | j        | j        | j        | j        | j%        | j&        | j        | j'        | j(        | j)                  | _*        | j+        r| j+        | j,        d<   | j-        r| j-        | j,        d<   | j.        r| j.        | j,        d<   | j,        sd| _,        nnddl/}| j,        0                    dtc          |d|j2                             | j,        3                    dd          r | j,        0                    d|j4                   | j        5                    | | j,                   tm          | j        tn                    r| j*        j8        | j        _8        dS dS )zinitialize tornado webappallow_originwebsocket_compression_optionsallow_origin_patallow_credentialsr  rC  rD  rm  static_immutable_cachez;Options --port and --sock are mutually exclusive. Aborting.rk   r   z;Ignoring --ServerApp.open_browser due to --sock being used.zBOptions --ServerApp.file_to_run and --sock are mutually exclusive.r   zIOption --sock is not supported on Windows, but got value of %s. Aborting.r   r  r  ca_certsNssl_versionPROTOCOL_TLSF	cert_reqs)ssl_options)9r  r  r  r  recompiler  r  r   rC  rD  rm  r  r   r  r   r`   r  ry   r0   r   r  rt  r  r  rf  r|  ru  r   r   r   r   r   r   r   r   r   jinja_environment_optionsr   r   r   r   web_appr  r  r  	client_cassl
setdefaultr>  PROTOCOL_SSLv23r  CERT_REQUIREDvalidate_securityr   r:   r   )r   r  s     r   init_webappzServerApp.init_webapp  s   040An-AEAc=>  	Z8:
4CX8Y8YD!"45595K12.2ol+ 372H2W./"; 	89 *.)?)Eg&& 	Z>B>YD!":; **4=99 	N,T]D<LMMD 9 	y777!!R    	  R    !!Y   |&&u-- !!c)$   +!! $HM!*"4.2.T$($@#'#>'
 
 
* = 	9+/=DZ(< 	7*.,DY'> 	:+/>DZ( 	L  $D JJJ ''wsNC<OPP   ##J66 L ++K9JKKK004CS0TTTd,.DEE 	D.2l.CD"+++	D 	Dr   c           
     V   t           | j                            d           dS t          j        t           j                  \  }}| j        }|}|W||k     rS||k     r|}| j                            d| d| d| d|            t          j        t           j        ||f           dS dS 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  r   rq  r  r  r  	setrlimit)r   old_softold_hardr   r!  s        r   init_resourceszServerApp.init_resources	  s    HNNn   F%/0FGG((4d{{HNN\\\T\\(\\VZ\\   x5d|DDDDD r   r   include_tokenurllib.parse.ParseResultc                   | j         rd}t          | j                   }n\| j        sd}n;| j        dv rdt          j                    z  }nd| j        v rd| j         dn| j        }| d| j         }| j        rdnd	}|s| j        }d
}|rG| j        j	        r;| j        j
        r| j        j	        nd}t          j                            d|i          }t          j                            ||||pddd          }|S )zConstructs a urllib named tuple, ParseResult,
        with default values set by server config.
        The returned tuple can be manipulated using the `_replace` method.
        z	http+unixr  )z0.0.0.0r  z%s:[]httpshttpNz...rm  r   )schemenetlocr   queryparamsfragment)r  ra   r  r  gethostnamery   r  r   r   rm  r  urllibparse	urlencodeParseResult)	r   r   r  r  r  r  r  rm  urlpartss	            r   _get_urlpartszServerApp._get_urlparts	  s7    9 	: F/	::FF7 C ---F.000'*dg~~^^^^^47((TY((F $9WW6F 	$#D 	=T39 	=040F0Va&,,\a  L**GU+;<<E<++&t5;Br\^ , 
 
 r   c                &   |                      d          }| j        rat          j                            | j                                                  }d |                                D             } |j        di |}|                                S )NTr  c                    i | ]
\  }}|||S r   r   )r   r2  items      r   
<dictcomp>z(ServerApp.public_url.<locals>.<dictcomp>B	  s#    PPPIC4Pc4PPPr   r   )	r  custom_display_urlr  r  urlparse_asdictr5  _replacegeturl)r   partsr   custom_updatess       r   
public_urlzServerApp.public_url:	  s    """66" 	5\**4+BCCKKMMFPPPPPN"EN44^44E||~~r   c                    |                      d          }| j        s-d| j        v rdnd}|                    | d| j                   }|                                S )NTr  r  z[::1]r  )r  )r  r  r  r
  ry   r  )r   r  r  s      r   	local_urlzServerApp.local_urlG	  sg    """66y 	F#&$'>>{INNY*D*D*D*DNEEE||~~r   c                L    | j         }| j         | j        k    r| d| j         }|S )z`Human readable string with URLs for interacting
        with the running Jupyter Server
        z
    )r  r  )r   r  s     r   display_urlzServerApp.display_urlP	  s4    
 o?dn,,0000C
r   c                `    |                      | j                  }|                                S )N)r   )r  r   r  )r   r   s     r   connection_urlzServerApp.connection_urlZ	  s*    %%4=%99   r   c                   t           j                            d          sNt           j        rBt           j                                        r$t          j        t
          j        | j                   t          j        t
          j        | j	                   t          t
          d          r$t          j        t
          j        | j                   t          t
          d          r&t          j        t
          j        | j                   dS dS )zInitialize signal handlers.r   SIGUSR1SIGINFON)rt  ru  r  stdinisattyrw  SIGINT_handle_sigintrx  _signal_stoprB  r  _signal_infor  r`  s    r   init_signalzServerApp.init_signal_	  s     ''..	>		> 	  ""	>
 M&-)<===fnd&788869%% 	=M&.$*;<<<69%% 	=M&.$*;<<<<<	= 	=r   sigframec                    t          j         t           j        | j                   t          j        | j                  }d|_        |                                 dS )zSIGINT handler spawns confirmation dialog

        Note:
            JupyterHub replaces this method with _signal_stop
            in order to bypass the interactive prompt.
            https://github.com/jupyterhub/jupyterhub/pull/4864

        r   TN)rw  r  r  	threadingThread_confirm_exitdaemonrg  )r   r  r   threads       r   r  zServerApp._handle_siginto	  sK     	fmT%6777 !);<<<r   c                N    t          j         t           j        | j                   dS )z.callback for restoring original SIGINT handlerN)rw  r  r  r`  s    r   _restore_sigint_handlerz!ServerApp._restore_sigint_handler	  s    fmT%899999r   c                $   | j         j        } |t          d                     | j        r?| j                             t          d                     |                     d           dS  ||                                            t          d          }t          d          }t          j        	                    t          d          ||fz             t          j        
                                 t          j        t          j        gg g d	          \  }}}|rt          j                                        }|                                                    |          rU||                                vr?| j                             t          d
                     |                     d           dS n!| j        rdS  |t          d                      |t          d                     | j                            | j                   dS )zconfirm 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...Tfrom_signalNyr{   z)Shut down this Jupyter server (%s/[%s])? r   zShutdown confirmedzNo answer for 5s:zresuming operation...)r   rf  rf   
answer_yesr  r  running_server_infort  stdoutr
  flushselectr  readliner?  r  	_stoppingio_loopadd_callback_from_signalr)  )r   rf  r2  norwxlines           r   r%  zServerApp._confirm_exit	  s    x}U=!!"""? 	He$677888 II$I'''FT%%''(((Cjj3ZZ
JKKsTViWXXX
-RQ771a 	-9%%''Dzz||&&s++ $**,,0F0F!!%(<"="=>>> 		d	+++~  D*++,,,U*++,,,
 	--d.JKKKKKr   c                    | j                             t          d          |           |                     d           dS )zHandle a stop signal.

        Note:
            JupyterHub configures this method to be called for SIGINT.
            https://github.com/jupyterhub/jupyterhub/pull/4864

        zreceived signal %s, stoppingTr,  N)r   r  rf   r  r   r  r   s      r   r  zServerApp._signal_stop	  s?     	% >??EEE		d	#####r   c                ^    | j                             |                                            dS )zHandle an info signal.N)r   rf  r0  r>  s      r   r  zServerApp._signal_info	  s(    d..0011111r   c                    dS )z8Check the components submodule, and warn if it's uncleanNr   r`  s    r   init_componentszServerApp.init_components	  s      r   c                <   t          | j                  }|                                }t          |                                          D ]P\  }}|| j        vrB| j        j        j                            ||i           | j                            ||i           QdS )zA
        Searches Jupyter paths for jpserver_extensions.
        )read_config_pathN)	rB   config_file_pathsget_jpserver_extensionssortedr5  jpserver_extensionsrn   r  r  )r   managerr   
modulenameenableds        r   find_server_extensionsz ServerApp.find_server_extensions	  s     )$:PQQQ4466
#)**:*:*<*<#=#= 	G 	GJ!999%9@@*gAVWWW(//W0EFFF	G 	Gr   c                    t          | j        |           | _        | j                            | j                   | j                                         dS )a)  
        If an extension's metadata includes an 'app' key,
        the value must be a subclass of ExtensionApp. An instance
        of the class will be created at this step. The config for
        this instance will inherit the ServerApp's config object
        and load its own config.
        )r   r  N)rC   r   extension_managerfrom_jpserver_extensionsrG  link_all_extensionsr`  s    r   init_server_extensionsz ServerApp.init_server_extensions	  sP     "2dh$!O!O!O778PQQQ2244444r   c                8    | j                                          dS )zLoad 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.
        N)rM  load_all_extensionsr`  s    r   load_server_extensionsz ServerApp.load_server_extensions	  s     	2244444r   c                    t           j        dk    rt          j        g            t          j        dd           t          j        dd           d S )Nnt)rp   ztext/cssz.csszapplication/javascriptz.js)r   r   	mimetypesinitadd_typer`  s    r   init_mime_overrideszServerApp.init_mime_overrides	  sO     7d??N$$$$:v...3U;;;;;r   c                   | j         }t          |          dk    rdS | j                                        rdS t	                      | j                                        z
                                  }| j        	                    d|           || j
        k    r1| j                            d|           |                                  dS dS )zBShutdown server on timeout when there are no kernels or terminals.r   NzNo activity for %d seconds.z)No kernels for %d seconds; shutting down.)r   r  rM  any_activityr6   r  r8  total_secondsr   rq  shutdown_no_activity_timeoutrf  r  )r   kmseconds_since_actives      r   shutdown_no_activityzServerApp.shutdown_no_activity	  s     r77a<<F!..00 	F &4<+E+E+G+G GVVXX46JKKK$"CCCHMM;$   IIKKKKK DCr   c                    | j         dk    rP| j                            d| j                    t          j        | j        d          }|                                 dS dS )z%Initialize a shutdown on no activity.r   z0Will shut down after %d seconds with no kernels.i`  N)r]  r   rf  r   PeriodicCallbackr`  rg  r   pcs     r   init_shutdown_no_activityz#ServerApp.init_shutdown_no_activity
  sa    ,q00HMMB1   ()BEJJBHHJJJJJ 10r   httpserver.HTTPServerc                R    	 | j         S # t          $ r d}t          |          dw xY w)zIAn instance of Tornado's HTTPServer class for the Server Web Application.zAn HTTPServer instance has not been created for the Server Web Application. To create an HTTPServer for this application, call `.init_httpserver()`.N)_http_serverAttributeErrorr   r*  s     r   http_serverzServerApp.http_server
  sG    	0$$ 	0 	0 	0: 
 !%%4/	0s   	 &c                *   t          | d          sd}t          |          t          j        | j        | j        | j        | j        | j                  | _	        | j
        s|                                  | j                            | j                   dS )zCreates an instance of a Tornado HTTPServer for the Server Web Application
        and sets the http_server attribute.
        r  zUA tornado web application has not be initialized. Try calling `.init_webapp()` first.)r  xheadersmax_body_sizemax_buffer_sizeN)rB  ri  r   
HTTPServerr  r  trust_xheadersrn  ro  rh  r  _find_http_portr6  add_callback_bind_http_serverrj  s     r   init_httpserverzServerApp.init_httpserver(
  s    
 tY'' 	&6  !%%% '1L((, 0
 
 
 y 	#  """!!$"899999r   c                    | j         r|                                 n|                                 }|s>| j                            t          d                     |                     d           dS dS )zBind our http server.XERROR: the Jupyter server could not be started because no available port could be found.rk   N)r  _bind_http_server_unix_bind_http_server_tcpr   r  rf   r  )r   successs     r   rt  zServerApp._bind_http_serverB
  s~    379^$--///$B\B\B^B^ 	H8    IIaLLLLL	 	r   c                   t          | j                  r1| j                            t	          d          | j        z             dS 	 t          | j        t          | j                                        d                    }| j	        
                    |           dS # t          $ r}|j        t          j        k    r5| j                            t	          d          | j        z             Y d}~dS |j        t          j        t          t          dt          j                  fv r5| j                            t	          d          | j        z             Y d}~dS  d}~ww xY w)	zBind an http server on unix.z The socket %s is already in use.Fr  )modeTN	WSAEACCESz&Permission to listen on sock %s denied)r^   r  r   r  rf   r   rz   r  r  rk  
add_socketr  errno
EADDRINUSEEACCESr>  )r   r  r  s      r   rx  z ServerApp._bind_http_server_unixN
  sM   di(( 	HU#EFFRSSS5	#DIC8M8M8O8OQR4S4STTTD''--- 4  	 	 	w%***  'I!J!JTY!VWWWuuuuuU\75+u|+T+TUUU  'O!P!PSWS\!\]]]uuuuu	s'   AB 
E (AE2A"EEE c                P    | j                             | j        | j                   dS )zBind a tcp server.T)rk  listenry   r  r`  s    r   ry  zServerApp._bind_http_server_tcpc
  s$    	47333tr   c           	        d}| j         }t          | j         | j        dz             D ](}	 t          || j                  }|d                                          d}|| _          n# t          $ r}|j        t          j        k    ra| j        r+| j	        
                    t          d          |z             n*| j	        
                    t          d          |z             Y d}~|j        t          j        t          t          dt          j                  fv r0| j	                            t          d	          |z             Y d}~! d}~ww xY w|sp| j        r(| j	                            t          d
                     n*| j	                            t          d          |z             |                     d           dS dS )zFind an available http port.Frk   r   Tz3The port %i is already in use, trying another port.zThe port %i is already in use.Nr}  z'Permission to listen on port %i denied.rw  zPERROR: the Jupyter server could not be started because port %i is not available.)ry   r   r  r   r  r  r  r  r  r   rf  rf   r  r>  r  r  r  )r   rz  ry   socketsr  s        r   rr  zServerApp._find_http_porth
  s   y D,=,ABB 	 	D&tTW55
  """$  	'    7e...( V!"WXX[__    e,L&M&MPT&TUUUHHHH7LE;==   H$$U+T%U%UX\%\]]]HHHH(  	  !!<     !!4  	   IIaLLLLL!	 	s%   /A%%
E/A1E	%AE	E		Ec                    t           j                            d          rbddl} 	 ddlm}m} t          |                                           |u r|                      |                       dS dS # t          $ r Y dS w xY wdS )a  set default asyncio policy to be compatible with tornado

        Tornado 6.0 is not compatible with default asyncio
        ProactorEventLoop, which lacks basic *_reader methods.
        Tornado 6.1 adds a workaround to add these methods in a thread,
        but SelectorEventLoop should still be preferred
        to avoid the extra thread for ~all of our events,
        at least until asyncio adds *_reader methods
        to proactor.
        r   r   N)WindowsProactorEventLoopPolicyWindowsSelectorEventLoopPolicy)
rt  ru  r  asyncior  r  typeget_event_loop_policyset_event_loop_policyImportError)r  r  r  s      r   _init_asyncio_patchzServerApp._init_asyncio_patch
  s     <""5)) 	TNNNTbbbbbbbb
 557788<ZZZ112P2P2R2RSSSSS [Z	    	T 	Ts   A1 1
A?>A?c                    t          j        dt          i            j        j                                        D ]G}t          j        |j        |j	        t          |j                                                             H j        j        d         }t          j        |                                           t%          j         fd           t)          j         fd           dS )z\
        Initialize any prometheus metrics that need to be set up on server startup
        r  )r   r  rJ  r   c                 Z     j                                                                         S rK  )r  r8  	timestampr`  s   r   <lambda>z(ServerApp.init_metrics.<locals>.<lambda>
  s!    4<+E+E+G+G+Q+Q+S+S r   c                      j                                          j         j        d         z
                                  S )Nr   )r  r8  r   r\  r`  s   r   r  z(ServerApp.init_metrics.<locals>.<lambda>
  s1    **,,t|/DY/OOmoo r   N)rN   rf  r4   rM  r   r6  rM   labelsr   r  r   rJ  r?  r  r   rO   setr  rL   set_functionrK   )r   extr   s   `  r   init_metricszServerApp.init_metrics
  s     	)[1222)4;;== 	 	C!(Xs{C<L<L<R<R<T<T     ,'	27,,..///"#S#S#S#STTT$   	
 	
 	
 	
 	
r   find_extensionsnew_httpserverstarter_extensionc                   |                                   | j                                        }t                                          |           | j                            |           | j        rdS |                                  |r|                                  | 	                                 | 
                                 |                                  |rL| j        j        |         }|j        r|j        | _        |                     t#          |j                             |                                  |                                  |                                  |                                  |                                  |                                  |                                  |                                  |                                  |r|                                  dS dS )ag  Initialize the Server application class, configurables, web application, and http server.

        Parameters
        ----------
        argv : list or None
            CLI arguments to parse.
        find_extensions : bool
            If True, find and load extensions listed in Jupyter config paths. If False,
            only load extensions that are passed to ServerApp directly through
            the `argv`, `config`, or `jpserver_extensions` arguments.
        new_httpserver : bool
            If True, a tornado HTTPServer instance will be created and configured for the Server Web
            Application. This will set the http_server attribute of this class.
        starter_extension : str
            If given, it references the name of an extension point that started the Server.
            We will try to load configuration from extension point
        )r  N)r  rG  copyr   
initializer  _dispatchinginit_iolooprK  r  r  rP  rM  extension_pointsappr  r  r,   rn   r  r  rA  r  r  rS  rY  re  r  ru  )r   r  r  r  r  rG  pointr   s          r   r  zServerApp.initialize
  s   2 	  """
 #6;;==%%% ''(;<<< 	F 	  	*'')))   ##%%%  	5*;<MNEy .$)I!vel33444 	!!!##%%%  """&&((( 	#  """""	# 	#r   c                :  K   t          | dd          sdS t          | j                                                  }t	          j        dd|          }| j                            ||z             t          | j        	                                           d{V  dS )zShutdown all kernels.

        The kernels will shutdown themselves when this process no longer exists,
        but explicit shutdown allows the KernelManagers to cleanup the connection files.
        r   NzShutting down %d kernelzShutting down %d kernels)
r>  r  r   list_kernel_idsrg   ngettextr   rf  re   shutdown_all)r   	n_kernels
kernel_msgs      r   cleanup_kernelszServerApp.cleanup_kernels  s       t-t44 	F+;;==>>	^%'A9
 

 	j9,---4.;;==>>>>>>>>>>>r   c                   K   t          | dd          sdS t          | j        j                  }t	          j        dd|          }| j                            ||z             t          | j        	                                           d{V  dS )z&Call shutdown hooks in all extensions.rM  NzShutting down %d extensionzShutting down %d extensions)
r>  r  rM  extension_appsrg   r  r   rf  re   stop_all_extensions)r   n_extensionsextension_msgs      r   cleanup_extensionszServerApp.cleanup_extensions  s      t0$77 	F41@AA(*G
 
 	ml233341EEGGHHHHHHHHHHHr   kernel_countc                   t          j        t          | j                                                  dz   }|rIt          | j                                                  }t          j	        dd|          }|||z  z  }|dz  }|t          d                              t          j        | j                  z  }| j        j        r|t          d          | j        j        z  z  }|S )zCReturn the current working directory and the server url informationr   z%d active kernelz%d active kernelsz-Jupyter Server {version} is running at:
{url})r  r  z=
Kernels will be managed by the Gateway server running at:
%s)r  r  r   r   info_stringr  r   r  rg   r  rf   r  r  r  r  rW  rX  r  )r   r  rf  r  r  s        r   r0  zServerApp.running_server_info%  s    vc40<<>>??$F 	D/??AABBI(:<OQZ[[JJ**DDLDFGGNN%4+; O 
 
 	
 . 	WXX%)*D r   c                8   | j         | j        r| j        nd| j        | j        t	          | j                  | j        | j        j        t          j
                            | j                  t	          | j                  t          j                    t          j        dS )z8Return a JSONable dict of information about this server.r  )r  hostnamery   r  securer   rm  r  r  rj  r  )r  r  ry   r  rR  r  r   r   rm  r   r   r~  r  r  rh  r  r  r`  s    r   rz  zServerApp.server_info8  s}     &#'7;II4=))+166T]++9;; (
 
 	
r   c                B   	 t          | j                  5 }t          j        |                                 |dd           ddd           dS # 1 swxY w Y   dS # t
          $ r9}| j                            t          d          | j        |           Y d}~dS d}~ww xY w)z=Write the result of server_info() to the JSON file info_file.r   T)r  	sort_keysNz%Failed to write server-info to %s: %r)	rd   re  r  dumprz  r  r   r  rf   )r   r  r  s      r   write_server_info_filez ServerApp.write_server_info_fileH  s
   	^dn-- K	$**,,aTJJJJK K K K K K K K K K K K K K K K K K 	^ 	^ 	^HNN5!HII4>[\]]]]]]]]]	^s:   A +AA AA AA 
B%.BBc                    	 t          j        | j                   dS # t          $ r!}|j        t          j        k    r Y d}~dS d}~ww xY w)zRemove the jpserver-<pid>.json file created for this server.

        Ignores the error raised when the file has already been removed.
        N)r   r  re  r  r  ENOENTr   r  s     r   remove_server_info_filez!ServerApp.remove_server_info_fileP  sd    
	Idn%%%%% 	 	 	w%,&& '&&&&&	    
AAAc                
   t          j        | j                                                  }t          j        | j                  }||z                                  }t          |                              t          |                    }|rG|j        |k    r| j        	                    d           t          |
                    |                    S | j                            d           |                     d           dS )af  Returns a relative path from file_to_run
        to root_dir. If root_dir and file_to_run
        are incompatible, i.e. on different subtrees,
        crash the app and log a critical message. Note
        that if root_dir is not configured and file_to_run
        is configured, root_dir will be set to the parent
        directory of file_to_run.
        zThe `root_dir` trait is set to a directory that's not the immediate parent directory of `file_to_run`. Note that the server will start at `root_dir` and open the the file from the relative path to the `root_dir`.z`root_dir` and `file_to_run` are incompatible. They don't share the same subtrees. Make sure `file_to_run` is on the same path as `root_dir`.rk   r   )pathlibr   r  absoluter|  r   r  r   r   rq  relative_tor  r  )r   rootdir_abspathfile_rawpathcombined_pathis_childs        r   !_resolve_file_to_run_and_root_dirz+ServerApp._resolve_file_to_run_and_root_dir[  s     ",t}55>>@@|D$455(<7AACC}%%00_1E1EFF 	C#66I   }00AABBB1	
 	
 	

 			!rr   r  fhc                ,   | j         j        rt          |d| j         j        i          }t          | j        |          }| j        j        d         }|                    d          }|                    |	                    || j
                             dS )zWrite the browser open file.rm  r  zbrowser-open.html)open_urlr   N)r   rm  r   r`   r  r  r   get_templater
  renderr   )r   r  r  r  templates        r   _write_browser_open_filez"ServerApp._write_browser_open_file{  s    !' 	KS7D,B,H"IJJCD/55\*<8
**+>??
#FFGGGGGr   c                l   |                                   | j        r|                                 }t          t	          | j        g|                    t          j                  R            }t          | j
        dd          5 }|                     ||           ddd           dS # 1 swxY w Y   dS dS )zWrite an `browser_open_file` and `browser_open_file_to_run` files

        This can be used to open a file directly in a browser.
        r:  utf-8encodingN)write_browser_open_filer|  r  r_   r`   file_url_prefixr>  r   r  r  ro  r  )r   file_to_run_relpathfile_open_urlr  s       r   write_browser_open_filesz"ServerApp.write_browser_open_files  s    	$$&&&  		@"&"H"H"J"J&d2W5H5N5Nrv5V5VWWW M d3S7KKK @q--mQ???@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @		@ 		@s   B''B+.B+c                    | j         t          | j                  d         }t          | j        dd          5 }|                     ||           ddd           dS # 1 swxY w Y   dS )zkWrite an jpserver-<pid>-open.html file

        This can be used to open the notebook in a browser
        Nr:  r  r  )r   r  r   r  rj  r  )r   r  r  s      r   r  z!ServerApp.write_browser_open_file  s     #C$6$6$8$89$(#@@@ 	7A))(A666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s   AA!$A!c                    |                                   	 t          j        | j                   dS # t          $ r!}|j        t
          j        k    r Y d}~dS d}~ww xY w)zRemove the `browser_open_file` and `browser_open_file_to_run` files
        created for this server.

        Ignores the error raised when the file has already been removed.
        N)remove_browser_open_filer   r  ro  r  r  r  r  s     r   remove_browser_open_filesz#ServerApp.remove_browser_open_files  sy     	%%'''	Id344444 	 	 	w%,&& '&&&&&	s   1 
AAAc                    	 t          j        | j                   dS # t          $ r!}|j        t          j        k    r Y d}~dS d}~ww xY w)zRemove the jpserver-<pid>-open.html file created for this server.

        Ignores the error raised when the file has already been removed.
        N)r   r  rj  r  r  r  r  s     r   r  z"ServerApp.remove_browser_open_file  se    
	Id,----- 	 	 	w%,&& '&&&&&	r  tuple[str, t.Optional[str]]c                J   | j         sI| j        t          | j                  d         }| j        j        rt          |d| j        j        i          }| j        r| j        }n| j	        }| j         rt          dt          |                    }nt          | j        |          }||fS )zPrepare to open the browser.Nrm  file:)use_redirect_filer   r  r   r   rm  r   r|  ro  rj  ri   rh   r`   r  )r   uri	open_fileassembled_urls       r   _prepare_browser_openzServerApp._prepare_browser_open  s    % 	O"3t}#5#5#7#78C%+ O w0F0L&MNN 	/ 5II .I! 	D#G\)-D-DEEMM)$*=sCCMi''r   c                h    ddl }	 |                     j        pd          nC# |j        $ r6} j                            t          d          |z             dY d}~nd}~ww xY wsdS                                  \  } fd}t          j	        |          
                                 dS )zLaunch the browser.r   NzNo web browser found: %r.c                 H    J                       j                   d S )N)r   )r  webbrowser_open_new)r  r  r   s   r   r   z(ServerApp.launch_browser.<locals>.target  s.    &&&LLD,DLEEEEEr   r"  )
webbrowserr  r  Errorr   r  rf   r  r#  r$  rg  )r   r  r  r   r   r  r  s   `    @@r   launch_browserzServerApp.launch_browser  s     		 nnT\%9T::GG 	 	 	HU#>??!CDDDGGGGGG	  	F5577q	F 	F 	F 	F 	F 	F 	F 	'''--/////s   & 
A&,A!!A&c                   t                                                       | j        si	 t          j                    }n# t
          $ r d}Y nw xY w|dk    r<| j                            t          d                     | 	                    d           | j        j
        }|                     d                              d          D ]} ||            |t          d                     d	t          v r |t          d
                     |                                  | j        s|                                  | j        r| j        s|                                  | j        j        r| j        j        r| j        rL| j                            d                    dd| j        z  dd| j         d| j         dg                     dS | j        rdt          d          d| j        z  g}nLdt          d          dt5          dt7          | j                            z  t          d          d| j        z  g}| j                            d                    |                     dS dS dS )z%Start the Jupyter Server application.r   z?Running as root is not recommended. Use --allow-root to bypass.rk   F)r  r   zYUse Control-C to stop this server and shut down all kernels (twice to skip confirmation).devzWelcome to Project Jupyter! Explore the various tools available and their corresponding documentation. If you are interested in contributing to the platform, please visit the community resources section at https://jupyter.org/community.html.z!Jupyter Server is listening on %sr   zbUNIX sockets are not browser-connectable, but you can tunnel to the instance via e.g.`ssh -L 8888:z' -N user@this_host` and then open e.g. z in a browser.z7To access the server, copy and paste one of these URLs:z    %sz2To access the server, open this file in a browser:r  z$Or copy and paste one of these URLs:N)r   rg  r  r   geteuidri  r   r  rf   r  rf  r0  r>  r4   r  no_browser_open_filer  r  r  r  r   rm  r  r   r  r  ri   rh   rj  )r   uidrf  r<  r   r   s        r   	start_appzServerApp.start_app  s    
	jll!   axx!![\\   		!x},,%,@@FFtLL 	 	DDJJJJk 	
 	
 	

 KDP    	##%%%( 	,))+++  	"TY 	"!!!!' &	6D,B,R &	6 y #6!!II ?$BRR!QEIY!Q !Q-1-@!Q !Q !Q	      , WXX 4#33GG P  !77LAW4X4X#Y#YYB  !4#33
G !!$))G"4"455555M&	6 &	6 &	6 &	6s   > AAc                "  K   |                                   |                                  |                                  d{V  |                                  d{V  	 | j                                         d{V  n# t          $ r Y nw xY wt          | dd          r| j        	                                 t          | dd          r| j
                                         t          | d          r| j                                         dS dS )zeGeneral cleanup of files, extensions and kernels created
        by this instance ServerApp.
        Nr   r   rk  )r  r  r  r  r   	close_allri  r>  r   __del__r   r  rB  rk  r  r`  s    r   _cleanupzServerApp._cleanup>  sR      	$$&&&&&(((%%'''''''''""$$$$$$$$$	8BBDDDDDDDDDD 
	 
	 
	 D
	 4)400 	*'')))4*D11 	) &&(((4'' 	$!!#####	$ 	$s    B   
BBc                z   t           j                            d          r*t          j        d d          }|                                 	 | j                            | j                   | j                                         dS # t          $ r+ | j
                            t          d                     Y dS w xY w)zStart the IO Loop.r   c                     d S rK  r   r   r   r   r  z(ServerApp.start_ioloop.<locals>.<lambda>`  s     r   i  zInterrupted...N)rt  ru  r  r   rb  rg  r6  rs  _post_startKeyboardInterruptr   rf  rf   rc  s     r   start_ioloopzServerApp.start_ioloop[  s    <""5)) 	 (t<<BHHJJJ	3L%%d&6777L       	3 	3 	3HMM% 011222222	3s   8B 1B:9B:c                L    t           j                                        | _        dS )zdinit self.io_loop so that an extension can use it by io_loop.call_later() to create background tasksN)r   IOLoopcurrentr6  r`  s    r   r  zServerApp.init_iolooph  s    },,..r   c                   K   	 | j                                          d{V  dS # t          $ r%}| j                            |           Y d}~dS d}~ww xY w)zAdd an async hook to start tasks after the event loop is running.

        This will also attempt to start all tasks found in
        the `start_extension` method in Extension Apps.
        N)rM  start_all_extensionsr   r   r  )r   errs     r   r  zServerApp._post_startl  s}      	 (==??????????? 	  	  	 HNN3	 s   % 
AAAc                V    |                                   |                                  dS )zStart the Jupyter server app, after initialization

        This method takes no arguments so all configuration and initialization
        must be done prior to calling this method.N)r  r  r`  s    r   rg  zServerApp.startw  s,    
 	r   c                   K   |                                   d{V  t          | dd          r| j                                         dS dS )z'Cleanup resources and stop the IO Loop.Nr6  )r  r>  r6  r  r`  s    r   _stopzServerApp._stop  s^      mmoo4D)) 	 L	  	 r   r-  c                   d| _         t          | d          r| j                                         t	          | dd          rD|r!| j                            | j                   dS | j                            | j                   dS dS )z&Cleanup resources and stop the server.Trk  r6  N)	r5  rB  rk  r  r>  r6  r7  r  rs  )r   r-  s     r   r  zServerApp.stop  s     4'' 	$!!###4D)) 	6  655djAAAAA))$*55555	6 	6r   )r|   rz   )r|   r   )r  r   r|   r   )r  r   r|   r   )r|   r  )r  r  r|   r  )r  r   r|   r  )r|   r  rK  )r  r   r$  r   r%  r&  r|   r  )r|   rR  )r|   rI  )r|   rU  )r|   r[  )r|   r^  )r|   rb  )r  r   r|   r   )r|   r   )r  r  r|   r  )r|   r  )NF)r   r&  r  rR  r|   r  )r  r   r   r   r|   r  )r|   rf  )NTTN)
r  r  r  rR  r  rR  r  r   r|   r  )T)r  rR  r|   r   )r|   r  )r  r   r  r   r|   r  )r|   r  )F)r-  rR  r|   r  (  rD  rL  rM  rN  r   r4   r  rh  rf   r^  	_examplesexamplesr    r  aliasesr   r	   rY   r   rX   rU   rR   rT   rQ   r   rH   rG   rI   rE   rF   r8   r   rW   classesr  
splitlinesr  r]  rD   r  r   r   _log_formatter_clsr   r5  r)   r  r  r'   tagr|  r  r  r  r  r  r  r   r  r  r+   r  r  r  r0   r  r#   ry   r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r  r  r  rm  r*   r  r  r  r#  rn  ro  r  r,  r   r  r+  r.  r   r3  r   r5  r   rB  r  r$   r   r  r  r  r  r   r  r(   terminado_settingsrC  rD  rF  r  r  r   r   rH  rK  propertyr  r   rO  rQ  r  r   r   r  r&   rS   r  rT  rY  rZ  r]  rV   r   r`  r   r   rP   r  r"   r   ra  rd  r<   r   r@  r  r=   r  r7   r  r;   r9   r  rq  r   re  ri  r  rj  rn  ro  rq  r  ru  rv  ry  r  r  r  rx  r  r  r  r  rg   r	  r  r  r  r  rG  !reraise_server_extension_failuresr   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  r  r  r  r  r  r)  r%  r  r  rA  rK  rP  rS  rY  r`  re  rk  ru  rt  rx  ry  rr  r  r  r  r.   r  r  r  r0  rz  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rg  r  r  rO  rP  s   @r   r  r  e  s        //DGu	5 K    
 HDKKEd7mmG 	! # "&%G. ! ,7799!<

 ! ,7799!<

 *5577:

 *5577:
% %K    ,  &U!DEEEIW[    W\
 
 
 
 '"#Z[[[__ `  K gK  	cc 
 7
	 	 	L w
	   UJKK   UIJJ  J UUVV  J '#d7`1a1abbbK	UFGG
 
 
B WT]]   ]" Xd^^   ^ !
U	1
 
  " H47ULMM  D
 WV__F F F _F .!#7"U5
 
  L W^V V V V 72d)]^^^DM  I Xk   . w
UFGG  H g
UTUU  G 
Ui
 
  I !%% QRR   W!""G G G #"G E  M W_	 	 	 	    JGN/[)\)\]]]aa b  E WWA A A A WW, , , , #7 	 	 	 W#$$   %$& G  M g  O w
R  H T   !DX   HL    * WZe e e e W "9::I I I ;:I   $ )V%#'4 /P  $ $ $ & W+,,  -,
 $  " W"##( ( ( $#(@ 	  $ d					 	 	O 4	 	 	L g
	 	 	G "'	U

 
  $ tU\
 
   %(CU

 

% % %! ttvvwwyy!""U]^^   TUDEE  N  $tUNOO     
 W9::A A A ;:A $U1
 
  K !%UUVV! ! !
 $UQRR  
 w  H Xj    		9   E E E XE ggiiee4[.\.\]]]W!""a a a #"a  4		UL
 
   F F F XF T		U]
 
  N G
  M $l  K "T+U677	    4"U566   W#$$) ) ) %$)
 !DU677  
 W$%%   &%
 )-+UBCC) ) )% W011. . . 21. &g  " %W    4#U455   #(#4FFF $	! 	! 	! W())! ! ! *)!
 $" U455    4# U566   t(U122	   #d.U899	   TEY 		 	 	N 8d  L 		IW[9 9 9 9  4Y    		W !!8 8 8 "!8  'wyyW'((8 8 8 )(8 GU
 
  E WW    7$UU3N-O-OPPPLW^& & & & &gUI
 
	
 
 
 "TUu
 
   wd/`)a)abbbHMWZ       Xj    WZ" " " "
 GU] x
 
  M W_    Xo    W !!/ / / "!/ $DFFE    )-UNOO) ) )% !UVWW   W!""O O O #"O UNOO  J W\O O O O !5UXYY   W#$$O O O %$O "EUYZZ   W$%%O O O &%O UUVV   W !!O O O "!O $+7	@	$ $ $  U	
 	
   W !!   "! #d    #'$
# 
# 
# "T		 	 	 	 8A  L ! ! ! X!" " " " " " "*r
 r
 r
 r
h( ( ( ( A A A A$fD fD fD fDPE E E E( CH! ! ! ! !F 
 
 
 X
    X    X ! ! ! X!= = = =    ": : : :*L *L *L *LX	$ 	$ 	$ 	$2 2 2 2G G G GG G G G.5 5 5 55 5 5 5< < < <   $    
0 
0 
0 X
0: : : :4
 
 
 
   *   
, , , ,\ T T T \T0
 
 
 
*  '+ $##'D# D# D# D# D# D# D#L? ? ? ?	I 	I 	I 	I    &
 
 
 
 ^ ^ ^ ^	 	 	 	   @H H H H@ @ @ @*	7 	7 	7 	7   	 	 	 	( ( ( (.0 0 0 0.Q6 Q6 Q6 Q6 Q6 Q6f$ $ $ $:3 3 3 3/ / / /	  	  	           6 6 6 6 6 6 6 6 6r   r  r&  r   t.Optional[logging.Logger]t.Generator[t.Any, None, None]c              #    K   | t                      } t          j                            |           sdS t          j        |           D ](}t          j        d|          rt          t          j                            | |          d          5 }	 t          j
        |          }n # t          j        $ r Y ddd           {w xY w	 ddd           n# 1 swxY w Y   d|v rt          |d                   r|V  	 t          j        t          j                            | |                     # t          $ r2}|r%|                    t!          d          |z             Y d}~ d}~ww xY w*dS )a  Iterate over the server info files of running Jupyter servers.

    Given a runtime directory, find jpserver-* files in the security directory,
    and yield dicts of their information, each one pertaining to
    a currently running Jupyter server instance.
    Nzjpserver-(.+).jsonr  r  rj  z%Deleting server info file failed: %s.)r   r   r   r  listdirr  matchr  r   r  loadJSONDecodeErrorr\   r  r  r  rf   )r  r   	file_namer  rf  r  s         r   r  r    s      )++ 7==%% Z,, X X	8()44 	Xbgll;	::WMMM QR9Q<<DD+                         9T%[#9#9



XIbgll;	BBCCCC X X X XE*Q$R$RUV$VWWWX!	XX XsN   CB'&C'C6CCCC	C	>2D11
E-;'E((E-)ry   rz   r{   rz   r|   r}   )r   r   r|   r   )rG  rQ  r|   rR  )r   N)NN)r  r&  r   r  r|   r  )rN  
__future__r   r  r  r	  r  r  r9  r  r  rV  r   r  r   r  r3  rw  r  r  rt  r#  rr  typingr  r  r   base64r   	functoolsr   r   r  jupyter_client.kernelspecr   jupyter_client.managerr   jupyter_client.sessionr	   jupyter_core.applicationr
   r   r   jupyter_core.pathsr   jupyter_events.loggerr   nbformat.signr   r  r   r   r   tornado.httputilr   tornado.logr   r   r   r   tornado.netutilr   tornado.routingr   r   ru  r  r   coloramarW  r  	traitletsr   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   traitlets.configr,   traitlets.config.applicationr-   r.   jupyter_serverr/   r0   r1   r2   r3   r4   jupyter_server._sysinfor5   jupyter_server._tzr6   jupyter_server.auth.authorizerr7   r8   jupyter_server.auth.identityr9   r:   r;   jupyter_server.auth.loginr<   jupyter_server.auth.logoutr=   jupyter_server.base.handlersr>   r?   r@   rA   jupyter_server.extension.configrB    jupyter_server.extension.managerrC   (jupyter_server.extension.serverextensionrD   "jupyter_server.gateway.connectionsrE   %jupyter_server.gateway.gateway_clientrF   jupyter_server.gateway.managersrG   rH   rI   jupyter_server.logrJ   !jupyter_server.prometheus.metricsrK   rL   rM   rN   rO   jupyter_server.services.configrP   ,jupyter_server.services.contents.filemanagerrQ   rR   1jupyter_server.services.contents.largefilemanagerrS   (jupyter_server.services.contents.managerrT   rU   /jupyter_server.services.kernels.connection.baserV   3jupyter_server.services.kernels.connection.channelsrW   -jupyter_server.services.kernels.kernelmanagerrX   rY   /jupyter_server.services.sessions.sessionmanagerrZ   jupyter_server.utilsr[   r\   r]   r^   r_   r`   ra   r  jinja2rb   rc   rd   jupyter_core.utilsre   jupyter_server.transutilsrf   rg   rh   ri   MIN_TORNADOr  ri  r  r  r  r"  DEFAULT_SERVER_PORTr   r   Applicationr   rC  r]  r~  r  r  dictr  r  r  r  r  launch_instancemainlaunch_new_instancer   r   r   <module>rN     sg   % % # " " " " "                				   				     



                                  7 7 7 7 7 7 0 0 0 0 0 0 * * * * * * I I I I I I I I I I 2 2 2 2 2 2 - - - - - - ( ( ( ( ( ( + + + + + + + + + + ' ' ' ' ' ' B B B B B B B B B B B B ( ( ( ( ( ( ) ) ) ) ) ) ) )
|u%% 1000000<5!!                                     " $ # # # # # I I I I I I I I                1 0 0 0 0 0 % % % % % % I I I I I I I I         
 3 2 2 2 2 2 4 4 4 4 4 4            C B B B B B = = = = = = G G G G G G I I I I I I ? ? ? ? ? ?         
 + * * * * *              9 8 8 8 8 8        T S S S S S Z Z Z Z Z Z Z Z Y Y Y Y Y Y ^ ^ ^ ^ ^ ^        K J J J J J                 OOOO   HHH 1 0 0 0 0 0 0 0 + + + + + + + + + + + + 2 2 2 2 2 2 2 2 6 6 6 6 6 6 6 6 dNNN;.....^^4 d d d
+eeLMMP[[
\
\bccdOOOO   HHH	 2389<=-.2 	.6
 	,4 ==<=34+,89+  2 2 	; 	; 	; 	;       N& N& N& N& N&3? N& N& N&b
   &H H H H H H H H*@ @ @ @FB B B B B: B B BJ29 29 29 29 29: 29 29 29r 	Z <&'	E
677l 
 "5)NE;RSS	E
BCCl 
 (;:PQQ	E
QRRg
 <&'l  L)	    $|

  0 *.&(*,2&"*   0m$6 m$6 m$6 m$6 m$6
 m$6 m$6 m$6bI LP#X #X #X #X #XT '6 6sN   D" "D*)D*(H- -H76H7!I3 3J;JJJ! !J+*J+