
    we<3                    R   d Z ddlmZ ddlZddlZddlZddlmZ	 ddl
mZ ddlmZ ddlmZ ddlmZ dd	lmZmZ dd
lmZ ddlmZmZ ddlmZ ddlmZmZmZ ddl m!Z! ddl"m#Z#m$Z$m%Z% ddl&m'Z'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z.m/Z/m0Z0 ddl1m2Z2 ddl3m4Z4 ej5        6                    e7          Z8ej9        ej:        e;ej<        e;df         f         ej<        ej:        ej9        e;ej=        f         e2f         e;f         f         Z> e            Z?e4Z@ G d deee          ZA G d deA          ZB G d deA          ZC G d deA          ZD G d  d!eA          ZE G d" d#eA          ZF G d$ d%eA          ZG eHe          ZI G d& d'e*e!          ZJeJjK        xZLZMeNd(k    r eL             dS dS ))zJupyter notebook application.    )annotationsN)join)ensure_async)base_aliases)jupyter_config_dir)JupyterHandler)ExtensionHandlerJinjaMixinExtensionHandlerMixin)flags)
url_escapeurl_is_absolute)url_path_join)get_app_dirget_user_settings_dirget_workspaces_dir)LabServerApp)	LabConfigget_page_configrecursive_update)
_camelCaseis_url)NotebookConfigShimMixin)web)BoolUnicodedefault)Config   )__version__.c                  2    e Zd ZdZedd            Zd	dZdS )
NotebookBaseHandlerzThe base notebook API handler.returnt.Anyc                8    | j                             dd          S )N
custom_cssT)settingsgetselfs    ,lib/python3.11/site-packages/notebook/app.pyr%   zNotebookBaseHandler.custom_css4   s    }  t444    dict[str, t.Any]c           
     \   t                      }| j        }| j                            dd          }| j                            di           }i |t
          | j        | j                            dd          | j        d         t          | j        d| j                  t          | j        d          |j	        d}| j                            d	d
          }|
                    t          j        d          }t          j                            t          j                            |                    }	 | j        j        |k    r1dt          j                            | j        j        |          z   |d<   nd|d<   n# t&          $ r d|d<   Y nw xY w| j                            dd          }| j                            dd          }t)          |          s/|                    | j                  st          | j        |          }|                    d|           |                    d|           |                    dt-                                 |                                D ]"}	t1          ||	          |t3          |	          <   #|                                D ]^}	|	                    d          st3          d|	z             }
t1          ||	          }t7          |          st          ||          }|||
<   _|j        |j        z   }t=          |t?          || j                              |S )zGet the page config.base_url/page_config_dataterminals_availableFtokenstatic)
appVersionbaseUrlterminalsAvailabler2   fullStaticUrlfrontendUrlexposeAppInBrowserserver_root_dir preferredPathmathjax_configzTeX-AMS_HTML-full,Safemathjax_urlz?https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.jsmathjaxConfigfullMathjaxUrljupyterConfigDir_urlfull_)logger)!r   extensionappr&   r'   
setdefaultversionr.   ujoinnameexpose_app_in_browserreplaceosseppathnormpath
expanduser	serverapppreferred_dirrelpath	Exceptionr   
startswithr   trait_namesgetattrr   endswithr   extra_labextensions_pathlabextensions_pathr   r   log)r)   configappr.   r0   page_configserver_rootr=   r>   rI   	full_namefull_urlrZ   s                r*   r   z#NotebookBaseHandler.get_page_config8   sC   "&"3=$$Z55=334FKK	
	
!}"&-"3"34I5"Q"Q]7+"4=(DIFF 44"%";	
 	
 	
 m''(92>>!))"&#66g&&rw'9'9+'F'FGG		/~+{::/2RW__N0+6 6 0O,, 03O, 	/ 	/ 	/+.K(((	/ **+;=UVVm''M
 
 {++ 	<K4J4J4=4Y4Y 	<{;;K???/===13E3G3GHHH &&(( 	? 	?D,3C,>,>K
4(()) &&(( 	. 	.D==(( "7T>22IsD))H(## 5 844%-K	"" 9C<RR"x  	
 	
 	
 s   1AE8 8F
	F
Nr"   r#   )r"   r,   )__name__
__module____qualname____doc__propertyr%   r    r+   r*   r!   r!   1   sR        ((5 5 5 X5C C C C C Cr+   r!   c                  6    e Zd ZdZej        d	d
d            ZdS )TreeHandlerzA tree page handler.r;   rN   strr"   Nonec                  K   |                     d          }| j        }t          |                    |                     d{V rt          |                    |                     d{V r5|j        s.| j                            d           t          j	        d          | 
                                }||d<   |                     d|          }|                     |          S t          |                    |                     d{V rt          |                    |d	
                     d{V }|d         dk    r$t          | j        dt#          |                    }n#t          | j        dt#          |                    }| j                            d| j        j        |           |                     |           dS t          j	        d          )z
        Display appropriate page for given path.

        - A directory listing is shown if path is a directory
        - Redirected to notebook page if path is a notebook
        - Render the raw file if path is any other file
        r/   )rN   Nz1Refusing to serve hidden directory, via 404 Errori  treePathz	tree.htmlr^   F)contenttypenotebook	notebooksfileszRedirecting %s to %s)stripcontents_managerr   
dir_exists	is_hiddenallow_hiddenr[   infor   	HTTPErrorr   render_templatewritefile_existsr'   rH   r.   r   debugrequestrN   redirect)r)   rN   cmr^   tplmodelurls          r*   r'   zTreeHandler.get   s      zz#"bmmm6677777777 	%!",,t"4"455555555 )bo )QRRRmC((( ..00K&*K
#&&{&LLC::c??"t 4 455555555 	%&rvvdEv'B'BCCCCCCCCEV}
**DM;
48H8HII DM7Jt4D4DEEHNN14<3DcJJJMM#-$$$r+   N)r;   )rN   rk   r"   rl   rc   rd   re   rf   r   authenticatedr'   rh   r+   r*   rj   rj   ~   sA        !% !% !% !% !% !% !%r+   rj   c                  6    e Zd ZdZej        dd	d            ZdS )
ConsoleHandlerzA console page handler.NrN   
str | Noner"   r#   c                ~    |                      d|                                           }|                     |          S )zGet the console page.zconsoles.htmlro   r|   r   r}   r)   rN   r   s      r*   r'   zConsoleHandler.get   s8     ""?@T@T@V@V"WWzz#r+   NrN   r   r"   r#   r   rh   r+   r*   r   r      sA        !!      r+   r   c                  6    e Zd ZdZej        dd	d            ZdS )
TerminalHandlerzA terminal page handler.NrN   r   r"   r#   c                ~    |                      d|                                           }|                     |          S )zGet the terminal page.zterminals.htmlro   r   r   s      r*   r'   zTerminalHandler.get   9     ""#3AUAUAWAW"XXzz#r+   r   r   r   rh   r+   r*   r   r      A        ""      r+   r   c                  6    e Zd ZdZej        dd	d            ZdS )
FileHandlerzA file page handler.NrN   r   r"   r#   c                ~    |                      d|                                           }|                     |          S )zGet the file page.z	edit.htmlro   r   r   s      r*   r'   zFileHandler.get   s8     "";D<P<P<R<R"SSzz#r+   r   r   r   rh   r+   r*   r   r      sA              r+   r   c                  6    e Zd ZdZej        dd	d            ZdS )
NotebookHandlerzA notebook page handler.NrN   r   r"   r#   c                ~    |                      d|                                           }|                     |          S )zGet the notebook page.znotebooks.htmlro   r   r   s      r*   r'   zNotebookHandler.get   r   r+   r   r   r   rh   r+   r*   r   r      r   r+   r   c                  4    e Zd ZdZej        dd            ZdS )CustomCssHandlerzA custom CSS handler.r"   r#   c                   |                      dd           |                                 }|d          d}t          j                            |          s<t          j        d|d                   }||                                d         }| d	}t          |          5 }| 	                    |
                                          cddd           S # 1 swxY w Y   dS )
zGet the custom css file.zContent-Typeztext/cssrA   /custom/custom.cssz^(.*?)static	staticDirNr   zcustom/custom.css)
set_headerr   rL   rN   isfilerematchgroupsopenr}   read)r)   r^   custom_css_filestatic_path_root
custom_dircss_fs         r*   r'   zCustomCssHandler.get   s    	
333**,,();<PPPw~~o.. 	C!xK8PQQ+-4466q9
%/"B"B"B/"" 	,e::ejjll++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s    'CCCNrb   r   rh   r+   r*   r   r      s<        , , , , , ,r+   r   c                  D    e Zd ZU dZdZdZdZeZ eed          Z	dZ
 edd	d
          ZdZd	ZeZi Zded<    edd	d          Z ed	d	d          ZeZded<   d dd	iidfed<   d dd	iidfed<    ed          d3d            Z ed          d3d            Z ed          d3d             Z ed!          d3d"            Z ed#          d3d$            Z ed%          d3d&            Z ed'          d3d(            Zd4 fd*Zd5d-Zd4 fd.Zd6d7 fd2Z  xZ!S )8JupyterNotebookAppz"The notebook server extension app.rr   zJupyter NotebookzMJupyter Notebook - A web-based notebook environment for interactive computingzThe version of the application.)helpr/   z/treeTz'The default URL to redirect to from `/`)r\   r   r,   subcommandsFzJWhether to expose the global app instance to browser via window.jupyterappzeWhether custom CSS is loaded on the page.
        Defaults to True and custom CSS is loaded.
        Flagsr   rJ   z@Expose the global app instance to browser via window.jupyterapp.zexpose-app-in-browserr%   z7Load custom CSS in template html files. Default is Truez
custom-css
static_dirr"   rk   c                L    t           j                            t          d          S )Nr3   rL   rN   r   HEREr(   s    r*   _default_static_dirz&JupyterNotebookApp._default_static_dir  s    w||D(+++r+   templates_dirc                L    t           j                            t          d          S )N	templatesr   r(   s    r*   _default_templates_dirz)JupyterNotebookApp._default_templates_dir  s    w||D+...r+   app_settings_dirc                ,    t          t          d          S )Nr&   pjoinapp_dirr(   s    r*   _default_app_settings_dirz,JupyterNotebookApp._default_app_settings_dir  s    Wj)))r+   schemas_dirc                ,    t          t          d          S )Nschemasr   r(   s    r*   _default_schemas_dirz'JupyterNotebookApp._default_schemas_dir  s    Wi(((r+   
themes_dirc                ,    t          t          d          S )Nthemesr   r(   s    r*   _default_themes_dirz&JupyterNotebookApp._default_themes_dir  s    Wh'''r+   user_settings_dirc                N    t          j        t          t                                S r   )tcastrk   r   r(   s    r*   _default_user_settings_dirz-JupyterNotebookApp._default_user_settings_dir"  s    vc022333r+   workspaces_dirc                N    t          j        t          t                                S r   )r   r   rk   r   r(   s    r*   _default_workspaces_dirz*JupyterNotebookApp._default_workspaces_dir&  s    vc-//000r+   rl   c                    t          t          |                                            | j        j                            | j                   d S )N)r%   )superr   _prepare_templates
jinja2_envglobalsupdater%   )r)   	__class__s    r*   r   z%JupyterNotebookApp._prepare_templates*  sC    lD!!44666&&$/&BBBBBr+   	extensionboolc                    | j         dS 	 | j         j        j        |         j        du }n# t          t
          t          f$ r d}Y nw xY w|S )z%Check if server extension is enabled.NFT)rQ   extension_manager
extensionsenabledAttributeErrorKeyError	TypeError)r)   r   extension_enableds      r*   server_extension_is_enabledz.JupyterNotebookApp.server_extension_is_enabled.  sk    >!5	&0;IFNRVV  )4 	& 	& 	& %	&  s   * AAc                V   | j         J | j         j        j                            di           }|                     d          }||d<   d| j         j        v rk| j         j        }|d         }||d<   |d         |d<   |d	         |d
<   t          |d          |d<   t          | j         d          r| j         j        |d<   d|d<   | j	        
                    dt          f           | j	        
                    dt          f           | j	        
                    dt          f           | j	        
                    dt          f           | j	        
                    dt          f           | j	        
                    dt           f           t#                                                       dS )zInitialize handlers.Nr0   	nbclassicnbclassic_enabled
hub_prefix	hubPrefixhub_hosthubHostuserhubUserzuser-redirectshareUrlserver_namehubServerNamer;   r2   z	/tree(.*)z/notebooks(.*)z	/edit(.*)z/consoles/(.*)z/terminals/(.*)r   )rQ   web_appr&   rF   r   tornado_settingsrH   hasattrr   handlersappendrj   r   r   r   r   r   r   initialize_handlers)r)   r^   r   r   r   r   s        r*   r   z&JupyterNotebookApp.initialize_handlers:  s   ~)))n,5@@ASUWXX <<[II+<'( 4>:::#~>),7J'1K$%5j%AK	"%5f%=K	"&+J&H&HK
#t~}55 J/3~/IO,
 $&K k;7888.@AAAk;7888.?@@@/ABBB24DEFFF##%%%%%r+   Nargvlist[str] | Nonec                H    t                                                       dS )zMSubclass because the ExtensionApp.initialize() method does not take argumentsN)r   
initialize)r)   r   r   s     r*   r   zJupyterNotebookApp.initializeZ  s    r+   )r"   rk   )r"   rl   )r   rk   r"   r   r   )r   r   r"   rl   )"rc   rd   re   rf   rI   app_namedescriptionrG   r   app_versionextension_urldefault_urlfile_url_prefixload_other_extensionsr   r   __annotations__r   rJ   r%   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__)r   s   @r*   r   r      s        ,,D!HaKG''(IJJJKM''$5^___KO G$&K&&&& DY     J E	 7>?J&E
!" 
d34AE,
 W\, , , , W_/ / / / W  * * * ! * W]) ) ) ) W\( ( ( ( W !!4 4 4 "!4 W1 1 1 1C C C C C C
! 
! 
! 
!& & & & & &@          r+   r   __main__)Orf   
__future__r   rL   r   typingr   os.pathr   r   jupyter_client.utilsr   jupyter_core.applicationr   jupyter_core.pathsr   jupyter_server.base.handlersr    jupyter_server.extension.handlerr	   r
   jupyter_server.serverappr   jupyter_server.utilsr   r   r   rH   jupyterlab.commandsr   r   r   jupyterlab_serverr   jupyterlab_server.configr   r   r   jupyterlab_server.handlersr   r   notebook_shim.shimr   tornador   	traitletsr   r   r   traitlets.config.loaderr   _versionr   rN   dirname__file__r   DictUnionrk   TupleAnyr   r   rG   r!   rj   r   r   r   r   r   dictaliasesr   launch_instancemainlaunch_new_instancerc   rh   r+   r*   <module>r     s   # # " " " " " " 				 				     ! ! ! ! ! ! - - - - - - 1 1 1 1 1 1 1 1 1 1 1 1 7 7 7 7 7 7        + * * * * * < < < < < < < < 7 7 7 7 7 7         
 + * * * * *         
 : 9 9 9 9 9 9 9 6 6 6 6 6 6       , , , , , , , , , , * * * * * * ! ! ! ! ! !	wx  	qwsAGCH--.sAEz@RTZ@Z8[]`8`0aab
+--

J J J J J46K^ J J JZ%% %% %% %% %%% %% %% %%P    (       )       %       )   , , , , ,* , , ,* $|

v v v v v0, v v vr 0? ?zDFFFFF r+   