
    ^hvZ                       S r SSKJr  SSKrSSKrSSKrSSKrSSKJ	r	J
r
  SSKJrJr  SSKJr  SSKJr  SSKJrJrJrJrJrJrJr  SS	KJr  SS
KJr  SSKJr  SSK J!r!J"r"  SSK#J$r$  S r%S r& " S S\5      r' " S S\(5      r) " S S\5      r*g)zAn extension application.    )annotationsN)EnvironmentFileSystemLoader)
JupyterAppNoStart)LogFormatter)RedirectHandler)AnyBoolDict	HasTraitsListUnicodedefault)Config)	ServerApp)_i18n)is_namespace_packageurl_path_join   )ExtensionHandlerMixinc                   [        U5      S:X  a  gU R                  (       aj  [        U5      S:  aZ  US   USS p2[        R                  " SU5      (       a4  X R                  ;   a$  U " 5       nUR	                  X#5        UR
                  $ gggg)z.Preparse command line to look for subcommands.r   Nr   z^\w(\-?\w)*$)lensubcommandsrematchinitialize_subcommandsubapp)application_klassargvsubcsubargvapps        ^/home/james-whalen/.local/lib/python3.13/site-packages/jupyter_server/extension/application.py_preparse_for_subcommandr%      s     4yA~ $$TQQabg88OT**t7T7T/T#%C%%d4::	 0U* *7$    c                  ^  USUR                  S5       m[        U4S jS 5       5      (       a,  U " 5       nUR                  ST;   5        UR	                  S5        ST;   d  ST;   a(  U " 5       nUR                  5         UR	                  S5        S	T;   a)  U " 5       nUR                  5         UR	                  S5        gg! [         a    Um Nf = f)
a(  Looks for 'help', 'version', and 'generate-config; commands
in command line. If found, raises the help and version of
current Application.

This is useful for traitlets applications that have to parse
the command line multiple times, but want to control when
when 'help' and 'version' is raised.
Nz--c              3  ,   >#    U  H	  oT;   v   M     g 7fN ).0xinterpreted_argvs     r$   	<genexpr>/_preparse_for_stopping_flags.<locals>.<genexpr>@   s     
I*HQ  *Hs   )z-h
--help-allz--helpr0   r   z	--versionz-Vz--generate-config)index
ValueErrorany
print_helpexitprint_versionwrite_default_config)r   r    r#   r-   s      @r$   _preparse_for_stopping_flagsr8   -   s      2$**T"23
 
I*H
III!|'778 &&$2B*B! ..!  " /!    s   C CCc                  n    \ rS rSrSr\" \" S5      S9R                  SS9r\	R                  S 5       rSrg	)
ExtensionAppJinjaMixinR   zAUse Jinja templates for HTML templates on top of an ExtensionApp.z;Options to pass to the jinja2 environment for this
        helpTconfigc                   U R                  5         [        U R                  5      S:  a4  U R                  R	                  U R
                   S3U R                  05        [        S[        U R                  5      S/SS.U R                  D6U l	        U R                  R	                  U R
                   S3U R                  05        g)	z$Get templates defined in a subclass.r   _template_pathszjinja2.ext.i18nT)loader
extensions
autoescape_jinja2_envNr*   )
initialize_templatesr   template_pathssettingsupdatenamer   r   jinja2_options
jinja2_envselfs    r$   _prepare_templates)ExtensionAppJinjaMixin._prepare_templates\   s     	!!#t""#a'MM  TYYK"?ATAT!UV & 
#D$7$78)*
 !!	
 	;7IJr&   )rL   N)__name__
__module____qualname____firstlineno____doc__r   r   tagrK   tno_type_checkrO   __static_attributes__r*   r&   r$   r:   r:   R   sG    K

 
cc  __K Kr&   r:   c                      \ rS rSrSrSrg)JupyterServerExtensionExceptionu   z9Exception class for raising for Server extensions errors.r*   N)rQ   rR   rS   rT   rU   rY   r*   r&   r$   r[   r[   u   s    Cr&   r[   c                  |  ^  \ rS rSr% SrSr0 rS\S'   \" SS9R                  SS9r
\" S	5      S
 5       r\S 5       rS rS\S'   \S 5       r\S 5       rSr\" 5       R                  SS9r\" S5      S 5       r\" S5      r\" S5      r\/r\" 5       rS\S'   \" S5      S 5       r\r\" S5      S 5       r \" S5      S 5       r!\" SS9R                  SS9r"\" S5      S 5       r#\$" \" 5       SS9R                  SS9r%\$" \" 5       \&" S 5      S9R                  SS9r'\(" \&" S!5      S9R                  SS9r)\$" \&" S"5      S9R                  SS9r*S#\S$'   S% r+S& r,S' r-S( r.S) r/S* r0S+ r1S, r2S- r3S;S. jr4S/ r5U 4S0 jr6S1 r7S2 r8S3 r9\S4 5       r:S5 r;\S6 5       r<\r=\S<S7 j5       r>\S=S8 j5       r?\S>S9 j5       r@S:rAU =rB$ )?ExtensionApp~   a  Base class for configurable Jupyter Server Extension Applications.

ExtensionApp subclasses can be initialized two ways:

- Extension is listed as a jpserver_extension, and ServerApp calls
  its load_jupyter_server_extension classmethod. This is the
  classic way of loading a server extension.

- Extension is launched directly by calling its `launch_instance`
  class method. This method can be set as a entry_point in
  the extensions setup.py.
Tzdict[str, t.Any]serverapp_configa  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.
        r<   r>   open_browserc                r    U R                   c   eU R                   R                  S   R                  SS5      $ )Nr   ra   T)	serverappr?   getrM   s    r$   _default_open_browser"ExtensionApp._default_open_browser   s4    ~~)))~~$$[155ndKKr&   c                L    U R                   c   eU R                   R                  $ )z4Look on the same path as our parent for config files)rc   config_file_pathsrM   s    r$   rh   ExtensionApp.config_file_paths   s$     ~~)))~~///r&   zstr | Unicode[str, str]rJ   c                    U R                   R                  S5      n[        US   5      (       a  SR                  USS 5      $ US   $ )zGet an extension package..r      )rR   splitr   join)clspartss     r$   get_extension_package"ExtensionApp.get_extension_package   sE     $$S)a))88E!AJ''Qxr&   c                    U R                   $ )zGet an extension point.)rR   )ro   s    r$   get_extension_point ExtensionApp.get_extension_point   s     ~~r&   /default_urlc                    U R                   $ r)   )extension_urlrM   s    r$   _default_urlExtensionApp._default_url   s    !!!r&   	notebooksFzServerApp | Nonerc   c                    [         R                  " 5       (       a   [         R                  " 5       $ [        5       $ ! [         a     [        5       $ f = fr)   )r   initializedinstance	ExceptionrM   s    r$   _default_serverappExtensionApp._default_serverapp   sO       "" ))++ {   {s   ; 
AA	log_levelc                "    [         R                  $ r)   )loggingINFOrM   s    r$   _default_log_levelExtensionApp._default_log_level   s    ||r&   
log_formatc                     g)z2override default log format to include date & timezV%(color)s[%(levelname)1.1s %(asctime)s.%(msecs).03d %(name)s]%(end_color)s %(message)sr*   rM   s    r$   _default_log_format ExtensionApp._default_log_format   s     e	
r&   z9Url where the static assets for the extension are served.static_url_prefixc                    SU R                    S3nU R                  c   e[        U R                  R                  U5      $ )Nzstatic/rv   )rJ   rc   r   base_url)rN   
static_urls     r$   _default_static_url_prefix'ExtensionApp._default_static_url_prefix   s;    tyyk+
~~)))T^^44jAAr&   zpaths to search for serving static files.

        This allows adding javascript/css to be available from the notebook server machine,
        or overriding individual files in the IPython
        zpPaths to search for serving jinja templates.

        Can be used to override templates from notebook.templates.z(Settings that will passed to the server.z Handlers appended to the server.zList[tuple[t.Any, ...]]handlersc                |    U R                   (       d  gSR                  U R                   R                  SS5      5      $ )zThe default config file name. zjupyter_{}_config-_)rJ   formatreplacerM   s    r$   _config_file_name_default&ExtensionApp._config_file_name_default  s.    yy"))$))*;*;C*EFFr&   c                    g)z1Override this method to add handling of settings.Nr*   rM   s    r$   initialize_settings ExtensionApp.initialize_settings      r&   c                    g)z<Override this method to append handlers to a Jupyter Server.Nr*   rM   s    r$   initialize_handlers ExtensionApp.initialize_handlers  r   r&   c                    g)z7Override this method to add handling of template files.Nr*   rM   s    r$   rF   !ExtensionApp.initialize_templates!  r   r&   c           
         U R                  5       R                  5       n[        U Vs0 s H  o"[        X5      _M     sn5      U l        U R                  U R
                  U R                   S3'   gs  snf )zvBuilds a Config object from the extension's traits and passes
the object to the webapp's settings as `<name>_config`.
_configN)class_own_traitskeysr   getattrextension_configrH   rJ   )rN   traitsrW   s      r$   _prepare_configExtensionApp._prepare_config$  sd     &&(--/ &V'LV74+;(;V'L M/3/D/D7+, (Ms   A0c                   U R                   c   eU R                   R                  nU R                  R                  " S0 UR                  D6  U R                  R                  U R                   S3U R
                  U R                   U 05        U R                  5         UR                  R                  " S0 U R                  D6  g)zPrepare the settings.N_static_pathsr*   )rc   web_apprH   rI   rJ   static_pathsr   )rN   webapps     r$   _prepare_settingsExtensionApp._prepare_settings,  s     ~~)))''/v/ 	99+]+T->->99+	
 	  " 	//r&   c                z   U R                   c   eU R                   R                  nU R                  5         / nU R                   Ht  n[	        UR
                  S   US   5      nUS   n0 n[        U[        5      (       a  U R                  US'    UR                  US   5        XEU4nUR                  U5        Mv     [        U R                  5      S:  aE  [	        U R                  S5      nUUR
                  S   S	U R                  04nUR                  U5        UR                  S
U5        g! [         a     Nf = f)zPrepare the handlers.Nr   r   r   rJ   rl   z(.*)static_handler_classpathz.*$)rc   r   r   r   r   rH   
issubclassr   rJ   rI   
IndexErrorappendr   r   r   add_handlers)	rN   r   new_handlershandler_itemspatternhandlerkwargsnew_handlerr   s	            r$   _prepare_handlersExtensionApp._prepare_handlersA  s<   ~~)))'' 	  " !]]M#FOOJ$?qAQRG#A&G (*F'#899!%vmA./ #V4K,! +& t  !A%&t'='=vFJ  67**+G
 (E<0'  s   D--
D:9D:c                    [        U R                  5      S:  a4  U R                  R                  U R                   S3U R                  05        U R                  5         g)z=Add templates to web app settings if extension has templates.r   rA   N)r   rG   rH   rI   rJ   rF   rM   s    r$   rO   ExtensionApp._prepare_templatesl  sI    t""#a'MM  TYYK"?ATAT!UV!!#r&   c                    SU R                   U R                  U R                  S.0nUS   R                  U R                  5        U$ )zThe jupyter server config.r   )rw   ra   file_url_prefix)rw   ra   r   rI   r`   )rN   base_configs     r$   _jupyter_server_config#ExtensionApp._jupyter_server_configr  sO     #// $ 1 1#'#7#7
 	K ''(=(=>r&   c                   Xl         U R                  5         U R                  U R                   R                  5        U R	                  U R                   R
                  5        U R                   R                  U R                  5        SU l        g)a  Link the ExtensionApp to an initialized ServerApp.

The ServerApp is stored as an attribute and config
is exchanged between ServerApp and `self` in case
the command line contains traits for the ExtensionApp
or the ExtensionApp's config files have server
settings.

Note, the ServerApp has not initialized the Tornado
Web Application yet, so do not try to affect the
`web_app` attribute.
TN)rc   load_config_fileupdate_configr?   parse_command_line
extra_args_linkedrN   rc   s     r$   _link_jupyter_server_extension+ExtensionApp._link_jupyter_server_extension~  sh     # 	4>>001 	 9 9: 	$$T[[1r&   c                    U R                   (       d  Sn[        U5      eU R                  5         U R                  5         U R	                  5         U R                  5         g)a   Initialize the extension app. The
corresponding server app and webapp should already
be initialized by this step.

- Appends Handlers to the ServerApp,
- Passes config and settings from ExtensionApp
  to the Tornado web application
- Points Tornado Webapp to templates and static assets.
zoThis extension has no attribute `serverapp`. Try calling `.link_to_serverapp()` before calling `.initialize()`.N)rc   r[   r   rO   r   r   )rN   msgs     r$   
initializeExtensionApp.initialize  sR     ~~# 
 2#66!  r&   c                t   > [         TU ]  5         U R                  c   eU R                  R                  5         g)z_Start the underlying Jupyter server.

Server should be started after extension is initialized.
N)superstartrc   )rN   	__class__s    r$   r   ExtensionApp.start  s.    
 	~~)))r&   c                    g)z6Return a list of activity happening in this extension.Nr*   rM   s    r$   current_activityExtensionApp.current_activity  s    r&   c                   #    g7f)z0Cleanup any resources managed by this extension.Nr*   rM   s    r$   stop_extensionExtensionApp.stop_extension          c                    U R                   c   eU R                   R                  5         U R                   R                  5         g)z#Stop the underlying Jupyter server.N)rc   stopclear_instancerM   s    r$   r   ExtensionApp.stop  s2    ~~)))%%'r&   c                    UR                   n UR                  U R                     nUR                  nUR                  5         U$ ! [         a    U " 5       nUR                  U5         N6f = f)zyInitialize and configure this extension, then add the extension's
settings and handlers to the server's web application.
)extension_managerextension_pointsrJ   r#   KeyErrorr   r   )ro   rc   r   point	extensions        r$   _load_jupyter_server_extension+ExtensionApp._load_jupyter_server_extension  so    
 &77	@%66sxx@E		I 		  	@I44Y?	@s   %A "A*)A*c                   #    g7f)a  
An async hook to start e.g. tasks from the extension after
the server's event loop is running.

Override this method (no need to call `super()`) to
start (async) tasks from an extension.

This is useful for starting e.g. background tasks from
an extension.
Nr*   r   s     r$   _start_jupyter_server_extension,ExtensionApp._start_jupyter_server_extension  r   r   c                   U " 5       nXl         UR                  5         UR                  UR                  5        UR	                  UR
                  5        UR                  R                  S[        S[        UR                  S5      04S[        S[        UR                  S5      04S[        S[        UR                  S5      04S[        S[        UR                  S	5      04S
[        S[        UR                  S5      04S[        S[        UR                  S5      04S[        S[        UR                  S5      04S[        S[        UR                  S5      04/5        UR                  5         g)zPEnables extension to be loaded as classic Notebook (jupyter/notebook) extension.z/static/favicons/favicon.icourlzstatic/base/images/favicon.icoz#/static/favicons/favicon-busy-1.icoz%static/base/images/favicon-busy-1.icoz#/static/favicons/favicon-busy-2.icoz%static/base/images/favicon-busy-2.icoz#/static/favicons/favicon-busy-3.icoz%static/base/images/favicon-busy-3.icoz!/static/favicons/favicon-file.icoz#static/base/images/favicon-file.icoz%/static/favicons/favicon-notebook.icoz'static/base/images/favicon-notebook.icoz%/static/favicons/favicon-terminal.icoz'static/base/images/favicon-terminal.icoz/static/logo/logo.pngzstatic/base/images/logo.pngN)rc   r   r   r?   r   r   r   extendr	   r   r   r   )ro   rc   r   s      r$   load_classic_server_extension*ExtensionApp.load_classic_server_extension  s    E	'""$	 0 01$$Y%9%9:!! 4#M)*<*<>^_` ;#}%..0W  ;#}%..0W  ;#}%..0W  9#}%..0U  =#}%..E 	 =#}%..E 	 -#M)*<*<>[\]}CE	
L 	r&   c                :    U R                   R                  " S0 UD6$ )zaInstantiate the ServerApp

Override to customize the ServerApp before it loads any configuration
r*   )serverapp_classr   )ro   r   s     r$   make_serverappExtensionApp.make_serverapp=  s     ""++5f55r&   c                x   U R                  5       S0nU R                  nSU R                  ;   a.  UR                  U R                  S   5        X@R                  S'   SnU R                  " SSU0UD6nUR
                  R                  U R
                  5        UR                  U=(       d    / U R                  US9  U$ )zCreates an instance of ServerApp and explicitly sets
this extension to enabled=True (i.e. superseding disabling
found in other config from files).

The `launch_instance` method uses this method to initialize
and start a server.
Tjpserver_extensionsF)r    starter_extensionfind_extensionsr*   )rq   load_other_extensionsr`   rI   r   aliasesr   rJ   )ro   r    r  r   r   r   rc   s          r$   initialize_serverExtensionApp.initialize_serverE  s      #88:DA33 C$8$88&&s';';<Q'RS:M  !67#O&&Y;NYRXY	  -!hh+ 	 	

 r&   c                d   Uc  [         R                  SS nOUn[        X5      nU(       a  UR                  5         g[	        X5        U R                  US9nU R                  (       d(  UR                  R                  U R                   S35         UR                  5         g! [         a     gf = f)zLaunch the extension like an application. Initializes+configs a stock server
and appends the extension to the server. Then starts the server and routes to
extension's landing page.
Nr   )r    z- is running without loading other extensions.)sysr    r%   r   r8   r  r  loginforJ   r   )ro   r    r   argsr   rc   s         r$   launch_instanceExtensionApp.launch_instance]  s     <88AB<DD *#4LLN
 	%S/))t)4	 ((MM#((+XYZ	OO 		s   B" "
B/.B/)r   r   rc   )rc   r   returnNone)r   zt.Anyr  r   )NTr)   )CrQ   rR   rS   rT   rU   r  r`   __annotations__r   rV   ra   r   re   propertyrh   rJ   classmethodrq   rt   ry   r   rw   rz   r   r   r   classesr
   rc   r   r   _log_formatter_clsr   r   r   r   r   r   r   rG   r   rH   r   r   r   r   rF   r   r   r   rO   r   r   r   r   r   r   r   r   r   r   r   r   r  r
  rY   __classcell__)r   s   @r$   r^   r^   ~   s     !
 *,&+
  
cc  ^L L 0 0 %3D
!2   
 M)--t-,K]" " k*O 5kG 	G
 #&%I'[  &[  \
 
  L	cc   !B "B
 	 
cc  	F
 
cc  MNOSS[_S`H(,9:)	cc % G@KFE0*)1V$
 D!.?(  
 N N`  O6 6  .  r&   r^   )+rU   
__future__r   r   r   r  typingrW   jinja2r   r   jupyter_core.applicationr   r   tornado.logr   tornado.webr	   	traitletsr
   r   r   r   r   r   r   traitlets.configr   jupyter_server.serverappr   jupyter_server.transutilsr   jupyter_server.utilsr   r   r   r   r%   r8   r:   r   r[   r^   r*   r&   r$   <module>r     sq     "  	 
  0 8 $ ' H H H # . + D *""JKY KFDi D: r&   