
    Xh5                    N   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.m/Z/ ddl0m1Z1 ddl2m3Z3  ee4      jj                  jm                         Z7ejp                  ejr                  e:ejv                  e:df   f   ejv                  ejr                  ejp                  e:ejx                  f   e1f   e:f   f   Z= e e             Z>e3Z? G d deee      Z@ G d de@      ZA G d de@      ZB G d de@      ZC G d  d!e@      ZD G d" d#e@      ZE G d$ d%e@      ZF eGe      ZH G d& d'e)e       ZIeIj                  xZKZLeMd(k(  r eK        yy))zJupyter notebook application.    )annotationsN)Path)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                  *    e Zd ZdZedd       ZddZy)NotebookBaseHandlerzThe base notebook API handler.c                :    | j                   j                  dd      S )N
custom_cssT)settingsgetselfs    @/var/www/html/myenv/lib/python3.12/site-packages/notebook/app.pyr#   zNotebookBaseHandler.custom_css5   s    }}  t44    c           
        t               }| j                  }| j                  j                  dd      }| j                  j	                  di       }i |t
        | j                  | j                  j                  dd      | j                  d   t        | j                  d| j                        t        | j                  d      |j                  d}| j                  j                  d	d
      }|j                  t        j                  d      }t        j                  j                  t        |      j!                               }	 | j"                  j$                  |k7  r;dt        j                  j'                  | j"                  j$                  |      z   |d<   nd|d<   | j                  j                  dd      }| j                  j                  dd      }t+        |      s1|j-                  | j                        st        | j                  |      }|j	                  d|       |j	                  d|       |j	                  dt/                      |j1                         D ]  }	t3        ||	      |t5        |	      <    |j1                         D ]J  }	|	j7                  d      st5        d|	z         }
t3        ||	      }t9        |      st        ||      }|||
<   L |j:                  |j<                  z   }t?        |tA        || jB                               | j                  j                  dd      }|r	 || |      }|S # t(        $ r	 d|d<   Y w xY w)zGet the page config.base_url/page_config_dataterminals_availableFtokenstatic)
appVersionbaseUrlterminalsAvailabler/   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page_config_hookN)"r   extensionappr$   r%   
setdefaultversionr+   ujoinnameexpose_app_in_browserreplaceosseppathnormpathr   
expanduser	serverapppreferred_dirrelpath	Exceptionr   
startswithr   trait_namesgetattrr   endswithr   extra_labextensions_pathlabextensions_pathr   r   log)r'   configappr+   r-   page_configserver_rootr:   r;   rG   	full_namefull_urlrX   rB   s                 r(   r   z#NotebookBaseHandler.get_page_config9   s   "&"3"3==$$Z5==334FK	
	
!}}"&--"3"34I5"Q]]7+"4==(DIIF 4"%";";	
 mm''(92>!))"&&#6gg&&tK'8'C'C'EF		/~~++{:/2RWW__NN00+6 0O, 03O, **+;=UVmm''M
 {+K4J4J4==4Y{;K?/=13E3GH &&( 	?D,3C,>K
4()	? &&( 	.D==("7T>2IsD)H(# 84%-K	"	. !99C<R<RR"xx	
  ==,,-?F*4=K[  	/+.K(	/s   AL: :MMNreturnt.Any)ra   dict[str, t.Any])__name__
__module____qualname____doc__propertyr#   r    r)   r(   r!   r!   2   s    (5 5Ir)   r!   c                  8    e Zd ZdZej
                  ddd       Zy)TreeHandlerzA tree page handler.c                  K   |j                  d      }| j                  }t        |j                  |             d{   rt        |j	                  |             d{   r<|j
                  s0| j                  j                  d       t        j                  d      | j                         }||d<   | j                  d|      }| j                  |      S t        |j                  |             d{   rt        |j                  |d	
             d{   }|d   dk(  r!t        | j                   dt#        |            }n t        | j                   dt#        |            }| j                  j%                  d| j&                  j(                  |       | j+                  |       yt        j                  d      7 7 d7 7 w)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,   rL   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_hiddenrY   infor   	HTTPErrorr   render_templatewritefile_existsr%   rF   r+   r   debugrequestrL   redirect)r'   rL   cmr\   tplmodelurls          r(   r%   zTreeHandler.get   sp     zz#""bmmm6777!",,t"4555booQRmmC(( ..0K&*K
#&&{&LC::c?"bnnT2333&rvvdEv'BCCEV}
*DMM;
48HI DMM7Jt4DEHHNN14<<3D3DcJMM#mmC  - 85 4CsG   <GG!G G!BG7G8#GG	B&GGG	GNr8   )rL   strra   Nonerd   re   rf   rg   r   authenticatedr%   ri   r)   r(   rk   rk      s    !! !!r)   rk   c                  8    e Zd ZdZej
                  ddd       Zy)ConsoleHandlerzA console page handler.Nc                f    | j                  d| j                               }| j                  |      S )zGet the console page.zconsoles.htmlro   r|   r   r}   r'   rL   r   s      r(   r%   zConsoleHandler.get   s0     ""?@T@T@V"Wzz#r)   NrL   z
str | Nonera   rb   r   ri   r)   r(   r   r      s    ! r)   r   c                  8    e Zd ZdZej
                  ddd       Zy)TerminalHandlerzA terminal page handler.Nc                f    | j                  d| j                               }| j                  |      S )zGet the terminal page.zterminals.htmlro   r   r   s      r(   r%   zTerminalHandler.get   s1     ""#3AUAUAW"Xzz#r)   r   r   r   ri   r)   r(   r   r      s    " r)   r   c                  8    e Zd ZdZej
                  ddd       Zy)FileHandlerzA file page handler.Nc                f    | j                  d| j                               }| j                  |      S )zGet the file page.z	edit.htmlro   r   r   s      r(   r%   zFileHandler.get   s0     "";D<P<P<R"Szz#r)   r   r   r   ri   r)   r(   r   r      s     r)   r   c                  8    e Zd ZdZej
                  ddd       Zy)NotebookHandlerzA notebook page handler.c                  K   |j                  d      }| j                  }t        |j                  |             d{   rct	        | j
                  dt        |            }| j                  j                  d| j                  j                  |       | j                  |       y| j                  d| j                               }| j                  |      S 7 w)z4Get the notebook page. Redirect if it's a directory.r,   rm   Ntreez.Redirecting %s to %s since path is a directoryznotebooks.htmlro   )ru   rv   r   rw   rF   r+   r   rY   r   r   rL   r   r|   r   r}   )r'   rL   r   r   r   s        r(   r%   zNotebookHandler.get   s      zz#""bmmm6777vz$/?@CHHNNKT\\M^M^`cdMM#""#3AUAUAW"Xzz# 8s   <CCBCNr   )rL   r   ra   rb   r   ri   r)   r(   r   r      s    " r)   r   c                  6    e Zd ZdZej
                  dd       Zy)CustomCssHandlerzA custom CSS handler.c                   | j                  dd       | j                         }|d    d}t        |      j                         s3t	        j
                  d|d         }||j                         d   }| d	}t        |      j                         5 }| j                  |j                               cddd       S # 1 sw Y   yxY w)
zGet the custom css file.zContent-Typeztext/cssr>   /custom/custom.cssz^(.*?)static	staticDirNr   zcustom/custom.css)

set_headerr   r   is_filerematchgroupsopenr}   read)r'   r\   custom_css_filestatic_path_root
custom_dircss_fs         r(   r%   zCustomCssHandler.get   s     	
3**,();<==OPO$,,.!xxK8PQ+-446q9
%/L0A"B/"'') 	,U::ejjl+	, 	, 	,s   B99CNr`   r   ri   r)   r(   r   r      s    , ,r)   r   c                      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      d+d       Z ed      d+d       Z ed      d+d       Z ed      d+d        Z ed!      d+d"       Z ed#      d+d$       Z ed%      d+d&       Zd, fd'Zd-d(Zd, fd)Zd.d/ fd*Z  xZ!S )0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 `/`)rZ   r   rc   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   rH   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_dirc                &    t        t        dz        S )Nr0   r   HEREr&   s    r(   _default_static_dirz&JupyterNotebookApp._default_static_dir  s    4(?##r)   templates_dirc                &    t        t        dz        S )N	templatesr   r&   s    r(   _default_templates_dirz)JupyterNotebookApp._default_templates_dir!  s    4+%&&r)   app_settings_dirc                &    t        t        dz        S )Nr$   r   app_dirr&   s    r(   _default_app_settings_dirz,JupyterNotebookApp._default_app_settings_dir%  s    7Z'((r)   schemas_dirc                &    t        t        dz        S )Nschemasr   r&   s    r(   _default_schemas_dirz'JupyterNotebookApp._default_schemas_dir)  s    7Y&''r)   
themes_dirc                &    t        t        dz        S )Nthemesr   r&   s    r(   _default_themes_dirz&JupyterNotebookApp._default_themes_dir-  s    7X%&&r)   user_settings_dirc                F    t        j                  t        t                     S r   )tcastr   r   r&   s    r(   _default_user_settings_dirz-JupyterNotebookApp._default_user_settings_dir1  s    vvc0233r)   workspaces_dirc                F    t        j                  t        t                     S r   )r   r   r   r   r&   s    r(   _default_workspaces_dirz*JupyterNotebookApp._default_workspaces_dir5  s    vvc-/00r)   c                    t         t        |           | j                  j                  j                  | j                         y )N)r#   )superr   _prepare_templates
jinja2_envglobalsupdater#   )r'   	__class__s    r(   r   z%JupyterNotebookApp._prepare_templates9  s/    lD46&&$//&Br)   c                    | j                   y	 | j                   j                  j                  |   j                  du }|S # t        t
        t        f$ r d}Y |S w xY w)z%Check if server extension is enabled.FT)rO   extension_manager
extensionsenabledAttributeErrorKeyError	TypeError)r'   	extensionextension_enableds      r(   server_extension_is_enabledz.JupyterNotebookApp.server_extension_is_enabled=  si    >>!	&00;;IFNNRVV 
 !  )4 	& %  	&s   /A   AAc                l   | j                   J | j                   j                  j                  j                  di       }| j	                  d      }||d<   d| j                   j
                  v rs| j                   j
                  }|d   }||d<   |d   |d<   |d	   |d
<   t        |d      |d<   t        | j                   d      r| j                   j                  |d<   d|d<   | j                  j                  dt        f       | j                  j                  dt        f       | j                  j                  dt        f       | j                  j                  dt        f       | j                  j                  dt        f       | j                  j                  dt         f       t"        | I          y)zInitialize handlers.Nr-   	nbclassicnbclassic_enabled
hub_prefix	hubPrefixhub_hosthubHostuserhubUserzuser-redirectshareUrlserver_namehubServerNamer8   r/   z	/tree(.*)z/notebooks(.*)z	/edit(.*)z/consoles/(.*)z/terminals/(.*)r   )rO   web_appr$   rD   r   tornado_settingsrF   hasattrr   handlersappendrk   r   r   r   r   r   r   initialize_handlers)r'   r\   r   r   r   r   s        r(   r   z&JupyterNotebookApp.initialize_handlersI  s   ~~)))nn,,55@@ASUWX <<[I+<'( 4>>:::#~~>>),7J'1K$%5j%AK	"%5f%=K	"&+J&HK
#t~~}5/3~~/I/IO,
 $&K k;78.@Ak;78.?@/AB24DEF#%r)   c                "    t         |           y)zMSubclass because the ExtensionApp.initialize() method does not take argumentsN)r   
initialize)r'   argvr   s     r(   r   zJupyterNotebookApp.initializei  s    r)   )ra   r   )ra   r   )r   r   ra   boolr   )r   zlist[str] | Nonera   r   )"rd   re   rf   rg   rG   app_namedescriptionrE   r   app_versionextension_urldefault_urlfile_url_prefixload_other_extensionsr   r   __annotations__r   rH   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JKM'$5^_KO G$&K!& Y J E5	 7>?J&E
!" 
d34AE,
 \$ $ _' '  ) !) ]( ( \' '  !4 "4 1 1C
!&@ r)   r   __main__)Nrg   
__future__r   rJ   r   typingr   pathlibr   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   rF   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   __file__parentresolver   DictUnionr   TupleAnyr   r   rE   r!   rk   r   r   r   r   r   dictaliasesr   launch_instancemainlaunch_new_instancerd   ri   r)   r(   <module>r     s   # " 	 	   - 1 1 7 + < 7 
 + 
 : 6  , , * !H~$$&	qwwsAGGCH--.sAEEz@RTZ@Z8[]`8`0aab
{}


P46K^ Pf%!% %!P( ) % ) $,* ,* |
v0, vr 0?? ?zF r)   