
    ^hR              	          S r SSKrSSKrSSKrSSKrSSKrSSKJr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  SSKJr  SSKJrJr  SS	KJr  S
SKJr  S
SKJr  SSK J!r!  \"" 5       r#/ SQr$SAS jr%SSSSSS\#SS4	S jr&  SBS jr'  SCS jr(SDS jr)  SES jr* SFS jr+ SDS jr,  SFS jr-  SFS jr.SDS jr/  SFS jr0  SFS jr1SDS jr2SDS jr3S
S K4J5r5J6r6J7r7J8r8J9r9J:r:J;r;J<r<J=r=  SS!K>J?r?J@r@  0 rA\AR                  \=5        \AR                  S"S#S00S$4S"S%S00S&4S'.5        \AS%   \AS('   0 rC\CR                  \<5        \CR                  S)S*S+S,.5         " S- S"\55      rD " S. S/\55      rE " S0 S1\55      rF " S2 S3\F5      rG " S4 S5\F5      rH " S6 S7\55      rIS8rJ " S9 S:\55      rK\KR                  rMSDS; jrNSDS< jrOS= rPSGS> jrQS? rR\SS@:X  a  \M" 5         gg)Hz?Utilities for installing Javascript extensions for the notebook    N)basenamejoinnormpath)urlparse)urlretrieve)jupyter_data_dirjupyter_config_pathjupyter_pathSYSTEM_JUPYTER_PATHENV_JUPYTER_PATH)ensure_dir_exists)string_typescast_unicode_py2)TemporaryDirectory   )__version__)BaseJSONConfigManager)import_item)commonnotebooktreeeditterminalFc                    ^ [        XX#S9m[        R                  R                  T5      (       d  g[	        U [
        5      (       a  U /n [        U4S jU  5       5      $ )a  Check whether nbextension files have been installed

Returns True if all files are found, False if any are missing.

Parameters
----------

files : list(paths)
    a list of relative paths within nbextensions.
user : bool [default: False]
    Whether to check the user's .jupyter/nbextensions directory.
    Otherwise check a system-wide install (e.g. /usr/local/share/jupyter/nbextensions).
prefix : str [optional]
    Specify install prefix, if it should differ from default (e.g. /usr/local).
    Will check prefix/share/jupyter/nbextensions
nbextensions_dir : str [optional]
    Specify absolute path of nbextensions directory explicitly.
sys_prefix : bool [default: False]
    Install into the sys.prefix, i.e. environment
user
sys_prefixprefixnbextensions_dirFc              3   v   >#    U  H.  n[         R                  R                  [        TU5      5      v   M0     g 7fN)ospathexistspjoin).0fnbexts     P/home/james-whalen/.local/lib/python3.13/site-packages/nbclassic/nbextensions.py	<genexpr>$check_nbextension.<locals>.<genexpr>B   s'     >1rww~~eE1o..s   69)_get_nbextension_dirr"   r#   r$   
isinstancer   all)filesr   r   r   r   r(   s        @r)   check_nbextensionr0   $   sL    * !d&tE77>>%  %&&>>>>    c
           
      t	   U[         :w  a  SSKn
U
R                  S[        5        Sn[	        X9XES9n[        U5        [        [        S5      (       d  Sn[        U [        [        45      (       a  [        S5      e[        U 5      n U R                  S5      (       a  U(       a  [        S	5      e[        5        n[!        U 5      R"                  R%                  S
5      S   n[        R"                  R'                  X5      nU(       a  UR)                  SU  SU 35        [+        X5        [-        XUXUS9nSSS5        U$ U R/                  S5      (       d  [1        U 5      (       a  U(       a  [        S5      eU(       a  [        S5      eU(       a  UR)                  SU  SU 35        U R/                  S5      (       a  [2        R4                  " U 5      nO&[1        U 5      (       a  [6        R8                  " U 5      nWR;                  U5        UR=                  5         SnU$ U(       d  [?        [A        U 5      5      n[        U5      n[A        [C        X5      5      nU(       a  [        R"                  RE                  U5      (       a  U(       a  UR)                  SU 35        [        R"                  RG                  U5      (       a;  [        R"                  RI                  U5      (       d  [J        RL                  " U5        O[        RN                  " U5        U(       ay  [        R"                  RQ                  U 5      n [        R"                  RS                  U5      (       d4  U(       a  UR)                  SU SU  35        [        RT                  " X5        U$ [        R"                  RG                  U 5      (       a  [C        [        R"                  RQ                  U 5      S5      n [        RV                  " U 5       H  u  nnn[C        UU[Y        U 5      S 5      n[        R"                  RS                  U5      (       d1  U(       a  UR)                  SU 35        [        RZ                  " U5        U H&  n[C        UU5      n[C        UU5      n[]        UUUS9  M(     M     U$ U n[]        UXS9  U$ ! , (       d  f       U$ = f)a  Install a Javascript extension for the notebook

Stages files and/or directories into the nbextensions directory.
By default, this compares modification time, and only stages files that need updating.
If `overwrite` is specified, matching files are purged before proceeding.

Parameters
----------

path : path to file, directory, zip or tarball archive, or URL to install
    By default, the file will be installed with its base name, so '/path/to/foo'
    will install to 'nbextensions/foo'. See the destination argument below to change this.
    Archives (zip or tarballs) will be extracted into the nbextensions directory.
overwrite : bool [default: False]
    If True, always install the files, regardless of what may already be installed.
symlink : bool [default: False]
    If True, create a symlink in nbextensions, rather than copying files.
    Not allowed with URLs or archives. Windows support for symlinks requires
    Vista or above, Python 3, and a permission bit which only admin users
    have by default, so don't rely on it.
user : bool [default: False]
    Whether to install to the user's nbextensions directory.
    Otherwise do a system-wide install (e.g. /usr/local/share/jupyter/nbextensions).
prefix : str [optional]
    Specify install prefix, if it should differ from default (e.g. /usr/local).
    Will install to ``<prefix>/share/jupyter/nbextensions``
nbextensions_dir : str [optional]
    Specify absolute path of nbextensions directory explicitly.
destination : str [optional]
    name the nbextension is installed to.  For example, if destination is 'foo', then
    the source file will be installed to 'nbextensions/foo', regardless of the source name.
    This cannot be specified if an archive is given as the source.
logger : Jupyter logger [optional]
    Logger instance to use
r   Nzv`install_nbextension`'s `verbose` parameter is deprecated, it will have no effects and will be removed in Notebook 5.0r   symlinkFzpath must be a string pointing to a single extension to install; call this function multiple times to install multiple extensions)zhttps://zhttp://zCannot symlink from URLs/zDownloading:  -> )	overwriter3   r   destinationloggerz.zipzCannot symlink from archivesz$Cannot give destination for archiveszExtracting: 
Removing: zSymlinking:  zMaking directory: r9   )/DEPRECATED_ARGUMENTwarningswarnDeprecationWarningr,   r   hasattrr"   r-   listtuple	TypeErrorr   
startswith
ValueErrorr   r   r#   splitr   infor   install_nbextensionendswith_safe_is_tarfilezipfileZipFiletarfileopen
extractallcloser   r   r%   lexistsisdirislinkshutilrmtreeremoveabspathr$   r3   walklenmakedirs_maybe_copy)r#   r7   r3   r   r   r   r8   verboser9   r   r>   	full_destr(   tdfilename
local_patharchiveparentdirsr/   dest_dir	file_namesrc	dest_files                           r)   rI   rI   E   s   P %%  O  Qc  	d I d&tEe 2y!!$u&&  \  ]  	]D!D.//788!R~**005b9Hb3JmD6j\BC)+JU\!&PI "x g 
v		"24"8"8;<<CDDKK,tfD89==  ood+Gd##ll4(G5!	H E "8D>2K&{3U567	33j45ww}}Y''y0I0Ii(		)$77??4(D77>>),,KK,ykdV DE

4+" ! WW]]4  .3D')wwt}#e F3t9:,>?ww~~h//&8
$CDKK)!&I	2C %h	 :IYv> "' (5  CY6y "!x s   6A<R((
R7c                 l   [        U 5      u  p[        R                  R                  UR                  5      S   n
/ nU	 Hr  n[        R                  R                  XS   5      nUS   nU(       a  UR                  SU SU 35        [        XUX4XVXS9	n[        XU5        UR                  U5        Mt     U$ )zInstall an nbextension bundled in a Python package.

Returns a list of installed/updated directories.

See install_nbextension for parameter information.r   rg   destzInstalling r6   )r7   r3   r   r   r   r   r8   r9   )
_get_nbextension_metadatar"   r#   rG   __file__r   rH   rI   validate_nbextension_pythonappend)moduler7   r3   r   r   r   r   r9   mnbexts	base_path
full_destsr(   rg   rj   r^   s                   r)   install_nbextension_pythonrt      s     *&1IAajj)!,IJggll9El3V}KK+cU$tf56'gV	
 	$Ef=)$  r1   c                 b   [        X#XES9n[        U 5      n [        Xp5      n[        R                  R                  U5      (       a  U(       a  UR                  SU 35        [        R                  R                  U5      (       a;  [        R                  R                  U5      (       d  [        R                  " U5        O[        R                  " U5        [        R                  R                  [        X#S9S5      n	[        U	S9n
U(       a$  [         H  nU
R!                  USUS005        M     gg)a  Uninstall a Javascript extension of the notebook

Removes staged files and/or directories in the nbextensions directory and
removes the extension from the frontend config.

Parameters
----------

dest : str
    path to file, directory, zip or tarball archive, or URL to install
    name the nbextension is installed to.  For example, if destination is 'foo', then
    the source file will be installed to 'nbextensions/foo', regardless of the source name.
    This cannot be specified if an archive is given as the source.
require : str [optional]
    require.js path used to load the extension.
    If specified, frontend config loading extension will be removed.
user : bool [default: False]
    Whether to install to the user's nbextensions directory.
    Otherwise do a system-wide install (e.g. /usr/local/share/jupyter/nbextensions).
prefix : str [optional]
    Specify install prefix, if it should differ from default (e.g. /usr/local).
    Will install to ``<prefix>/share/jupyter/nbextensions``
nbextensions_dir : str [optional]
    Specify absolute path of nbextensions directory explicitly.
logger : Jupyter logger [optional]
    Logger instance to use
r   r:   r   r   nbconfig
config_dirload_extensionsN)r,   r   r%   r"   r#   rR   rH   rS   rT   rU   rV   rW   r   _get_config_dirr   NBCONFIG_SECTIONSupdate)rj   requirer   r   r   r   r9   r(   r^   ry   cmsections               r)   uninstall_nbextensionr      s    : !d&tED!De"I	wwy!!KK*YK0177==##BGGNN9,E,EMM)$IIi  o4OQ[\J	*	5B(GIIg 1GT?CD ) r1   c                    [        U 5      n [        S5       H  n[        X 5      n[        R                  R                  U5      (       d  M4  U(       a  UR                  SU 35        [        R                  R                  U5      (       a<  [        R                  R                  U5      (       d  [        R                  " U5          g[        R                  " U5          g   g)zwRemove nbextension files from the first location they are found.

Returns True if files were removed, False otherwise.
nbextensionsr:   TF)r   r
   r%   r"   r#   rR   rH   rS   rT   rU   rV   rW   )r`   r9   r(   r#   s       r)   _find_uninstall_nbextensionr     s    
  )Hn-U%77??4  j/0ww}}T""277>>$+?+?d#  		$ . r1   c                     [        U 5      u  pgU H7  nUS   n	US   n
U(       a  UR                  SU	 SU
 35        [        XXX4US9  M9     g)zfUninstall an nbextension bundled in a Python package.

See parameters of `install_nbextension_python`
rj   r~   zUninstalling  r   r   r   r   r9   N)rk   rH   r   )ro   r   r   r   r   r9   rp   rq   r(   rj   r~   s              r)   uninstall_nbextension_pythonr   &  s[     *&1IAV}	"KK-vQwi89d$V	M r1   Tc                 N   U(       a  SOUn[         R                  R                  [        X4S9S5      n[	        US9nU(       a#  UR                  U(       a  SOS SU  SU S	35        UR                  U S
X005        [        XS9  UR                  U 5      R                  U5      U:H  $ )a  Set whether the section's frontend should require the named nbextension

Returns True if the final state is the one requested.

Parameters
----------
section : string
    The section of the server to change, one of NBCONFIG_SECTIONS
require : string
    An importable AMD module inside the nbextensions static path
state : bool
    The state in which to leave the extension
user : bool [default: True]
    Whether to update the user's .jupyter/nbextensions directory
sys_prefix : bool [default: False]
    Whether to update the sys.prefix, i.e. environment. Will override
    `user`.
logger : Jupyter logger [optional]
    Logger instance to use
Frv   rw   rx   Enabling	Disablingr   z extension z...rz   r<   )	r"   r#   r   r{   r   rH   r}   validate_nbextensionget)r   r~   stater   r   r9   ry   r   s           r)   _set_nbextension_stater   7  s    , 5DDT9:GJ	*	5BUz<AgYkRYQZZ]^_IIg)G+;<=066'?w'500r1   c                 n    [        U5      u  pVU Vs/ s H  n[        US   US   U X#US9PM     sn$ s  snf )a$  Enable or disable some nbextensions stored in a Python package

Returns a list of whether the state was achieved (i.e. changed, or was
already right)

Parameters
----------

state : Bool
    Whether the extensions should be enabled
module : str
    Importable Python module exposing the
    magic-named `_jupyter_nbextension_paths` function
user : bool
    Whether to enable in the user's nbextensions directory.
sys_prefix : bool
    Enable/disable in the sys.prefix, i.e. environment
logger : Jupyter logger [optional]
    Logger instance to use
r   r~   r   r~   r   r   r   r9   )rk   r   )r   ro   r   r   r9   rp   rq   r(   s           r)   _set_nbextension_state_pythonr   Z  sX    , *&1IA  !
   #5+;+0+;).(,*0	2
  ! ! !s   2c           	          [        XSX#US9$ )a  Enable a named nbextension

Returns True if the final state is the one requested.

Parameters
----------

section : string
    The section of the server to change, one of NBCONFIG_SECTIONS
require : string
    An importable AMD module inside the nbextensions static path
user : bool [default: True]
    Whether to enable in the user's nbextensions directory.
sys_prefix : bool [default: False]
    Whether to enable in the sys.prefix, i.e. environment. Will override
    `user`
logger : Jupyter logger [optional]
    Logger instance to use
Tr   r   r   r~   r   r   r9   s        r)   enable_nbextensionr   y  s    * "'(,'+)/1 1r1   c           	          [        XSX#US9$ )a  Disable a named nbextension

Returns True if the final state is the one requested.

Parameters
----------

section : string
    The section of the server to change, one of NBCONFIG_SECTIONS
require : string
    An importable AMD module inside the nbextensions static path
user : bool [default: True]
    Whether to enable in the user's nbextensions directory.
sys_prefix : bool [default: False]
    Whether to enable in the sys.prefix, i.e. environment. Will override
    `user`.
logger : Jupyter logger [optional]
    Logger instance to use
Fr   r   r   s        r)   disable_nbextensionr     s    * "'(-'+)/1 1r1   c                 F   [        5        H  n[        [        R                  R	                  US5      S9nUR                  U 5      nUR                  S0 5      R                  US5      (       d  Md  U(       a  UR                  SX5        UR                  U SUS005          g   g)zDisable an nbextension from the first config location where it is enabled.

Returns True if it changed any config, False otherwise.
rw   rx   rz   NzDisabling %s extension in %sTF)r	   r   r"   r#   r   r   rH   r}   )r   r~   r9   ry   r   ds         r)   _find_disable_nbextensionr     s    
 *+
"ww||J
;=FF7O55"B'++GT:::GPIIg 1GT?CD , r1   c                     [        SXUUS9$ )a#  Enable some nbextensions associated with a Python module.

Returns a list of whether the state was achieved (i.e. changed, or was
already right)

Parameters
----------

module : str
    Importable Python module exposing the
    magic-named `_jupyter_nbextension_paths` function
user : bool [default: True]
    Whether to enable in the user's nbextensions directory.
sys_prefix : bool [default: False]
    Whether to enable in the sys.prefix, i.e. environment. Will override
    `user`
logger : Jupyter logger [optional]
    Logger instance to use
Tr<   r   ro   r   r   r9   s       r)   enable_nbextension_pythonr     s    * )vZ068 8r1   c                     [        SXUUS9$ )a  Disable some nbextensions associated with a Python module.

Returns True if the final state is the one requested.

Parameters
----------

module : str
    Importable Python module exposing the
    magic-named `_jupyter_nbextension_paths` function
user : bool [default: True]
    Whether to enable in the user's nbextensions directory.
sys_prefix : bool [default: False]
    Whether to enable in the sys.prefix, i.e. environment
logger : Jupyter logger [optional]
    Logger instance to use
Fr<   r   r   s       r)   disable_nbextension_pythonr     s    & )j068 8r1   c                 n   / n/ nSn[        S5       H^  n[        R                  R                  " U/U R	                  S5      Q76  S3n[        R                  R                  U5      nU(       d  M^    O   SnU(       a&  UR                  UR                  [        U 5      5        O%UR                  UR                  [        U 5      5        U(       af  U(       aG  UR                  S5        U H  nUR                  U5        M     U H  nUR                  U5        M     U$ UR                  S[         35        U$ )zValidate a named nbextension.

Looks across all of the nbextension directories.

Returns a list of warnings.

require : str
    require.js path used to load the extension
logger : Jupyter logger [optional]
    Logger instance to use
Fr   r4   .jsz        - require? {} {}z#      - Validating: problems found:z      - Validating: )r
   r"   r#   r   rG   r$   rn   formatGREEN_OKRED_XwarningrH   )	r~   r9   r>   infos	js_existsextsjsrequire_tmplmsgs	            r)   r   r     s    HEI^,T7GMM#$678<GGNN2&	9 - .L\((7;<++E7;<NN@As#  C  
 O KK.xj9:Or1   c                    / n/ nU R                  SS5      nU[        ;   a  UR                  S[         SU 35        OUR                  S[         SU 35        U R                  SS5      nUb  [
        R                  R                  US[        U S   5      *  U S	35      n[
        R                  R                  U5      (       a  UR                  S[         S
U 35        OUR                  S[         SU 35        U(       az  U(       a[  UR                  S5        U H  nUR                  U5        M     U H  nUR                  U5        M     UR                  SU  35        U$ UR                  S[         35        U$ )a  Assess the health of an installed nbextension

Returns a list of warnings.

Parameters
----------

spec : dict
    A single entry of _jupyter_nbextension_paths():
        [{
            'section': 'notebook',
            'src': 'mockextension',
            'dest': '_mockdestination',
            'require': '_mockdestination/index'
        }]
full_dest : str
    The on-disk location of the installed nbextension: this should end
    with `nbextensions/<dest>`
logger : Jupyter logger [optional]
    Logger instance to use
r   Nz  z
 section: z  section: r~   r   rj   r   z
 require: z  require: z- Validating: problems found:zFull spec: z- Validating: )r   r|   rn   r   r   r"   r#   r   rZ   r$   r   rH   )	specr^   r9   r   r>   r   r~   require_pathr   s	            r)   rm   rm     sZ   , EHhhy$'G##r(:gY78"UG;wi89hhy$'Gww||aT&\**+isO 77>>,''LL2hZz,@AOOb{<.ABNN:;s#  C  NN[/0 O KK.
34Or1   )	BaseExtensionAppr{   GREEN_ENABLEDRED_DISABLEDr   r   ArgumentConflict_base_aliases_base_flags)BoolUnicodeInstallNBExtensionAppr7   !Force overwrite of existing filesr3   z'Create symlink instead of copying files)r7   r3   szInstallNBExtensionApp.prefixz&InstallNBExtensionApp.nbextensions_dirz!InstallNBExtensionApp.destination)r   r   r8   c                       \ rS rSrSrSrSr\r\r\	" SSSS9r
\	" SSS	S9r\" S
SSS9r\" S
SSS9r\" S
SSS9rS rS rS rSrg)r   iu  z.Entry point for installing notebook extensionsa  Install Jupyter notebook extensions

    Usage

        jupyter nbclassic-extension install path|url [--user|--sys-prefix]

    This copies a file or a folder into the jupyter nbclassic-extensions directory.
    If a URL is given, it will be downloaded.
    If an archive is given, it will be extracted into nbextensions.
    If the requested files are already up to date, no action is taken
    unless --overwrite is specified.
    zB
    jupyter nbclassic-extension install /path/to/myextension
    FTr   confighelpz(Create symlinks instead of copying filesr;   zInstallation prefix;Full path to nbextensions dir (probably use prefix or user)z#Destination for the copy or symlinkc                     gzThe default config file name.jupyter_notebook_config selfs    r)   _config_file_name_default/InstallNBExtensionApp._config_file_name_default      (r1   c                 |   [        U R                  5      S:  a  [        S5      eU R                  (       a	  [        n0 nO[
        nSU R                  0nU" U R                  S   4U R                  U R                  U R                  U R                  U R                  U R                  U R                  S.UD6nU(       a  U R                  R                  SU R                  (       a  U R                  S   OS U R                  (       a  SOS	 U R                  (       a  S
OS	 U R                  (       a  SOS	 S35        gg)z*Perform the installation of nbextension(s)r   z[Only one nbextension allowed at a time. Call multiple times to install multiple extensions.r8   r   )r7   r3   r   r   r   r   r9   z
To initialize this nbextension in the browser every time the notebook (or other app) loads:

      jupyter nbclassic-extension enable z<the entry point>z --userr;   z --pyz --sys-prefix
N)rZ   
extra_argsrF   pythonrt   rI   r8   r7   r3   r   r   r   r   logrH   )r   installkwargsrs   s       r)   install_extensions(InstallNBExtensionApp.install_extensions  s   t! O P P ;;0GF)G#T%5%56FT__Q/ 	'+~~%)\\"&))(,$(KK.2.C.C$(HH	  &	
 HHMM<RVR]R]DOOA<Ncv;w $		9r2"kk7r2&*oo?2>bB r1   c                     U R                   (       d  [        R                  " S5        g U R                  5         g! [         a)  n[        R                  " [        U5      5         SnAgSnAff = f)z(Perform the App's function as configuredz(Please specify an nbextension to installN)r   sysexitr   r   strr   es     r)   startInstallNBExtensionApp.start  sJ    HH?@!'')# !Q  !s   ; 
A.A))A.r   N)__name__
__module____qualname____firstlineno____doc__descriptionexamplesaliasesflagsr   r7   r3   r   r   r   r8   r   r   r   __static_attributes__r   r1   r)   r   r   u  s~    8KH GEU4.QRI5,VWGR+@AFr$MO"T0UVK) D!r1   c                       \ rS rSrSr\rSrSrSSSS.r	\
R                  R                  5       rS S	S
00S4\S	'   \" SS
SS9r\" SS
SS9r\" SS
SS9r\" SS
SS9rS rS rS rS rSrg)UninstallNBExtensionAppi  z0Entry point for uninstalling notebook extensionsab  Uninstall Jupyter notebook extensions

    Usage

        jupyter nbclassic-extension uninstall path/url path/url/entrypoint
        jupyter nbclassic-extension uninstall --py pythonPackageName

    This uninstalls an nbextension. By default, it uninstalls from the
    first directory on the search path where it finds the extension, but you can
    uninstall from a specific location using the --user, --sys-prefix or
    --system flags, or the --prefix option.

    If you specify the --require option, the named extension will be disabled,
    e.g.::

        jupyter nbclassic-extension uninstall myext --require myext/main

    If you use the --py or --python flag, the name should be a Python module.
    It will uninstall nbextensions listed in that module, but not the module
    itself (which you should uninstall using a package manager such as pip).
    z
    jupyter nbclassic-extension uninstall dest/dir dest/dir/extensionjs
    jupyter nbclassic-extension uninstall --py extensionPyPackage
    zUninstallNBExtensionApp.prefixz(UninstallNBExtensionApp.nbextensions_dirzUninstallNBExtensionApp.require)r   r   r~   systemTz=Uninstall specifically from systemwide installation directoryr;   z@Installation prefix. Overrides --user, --sys-prefix and --systemr   r   z$require.js module to disable loadingFc                     gr   r   r   s    r)   r   1UninstallNBExtensionApp._config_file_name_default  r   r1   c                 @   U R                   U R                  U R                  U R                  U R                  S.nU R
                  (       a  [        U R                  S   40 UD6  gU R                  (       a  U R                  US'   [        U R                  S   40 UD6  g)z1Uninstall an nbextension from a specific locationr   r   r~   N)
r   r   r   r   r   r   r   r   r~   r   )r   r   s     r)   uninstall_extension+UninstallNBExtensionApp.uninstall_extension  sz     II//kk $ 5 5hh
 ;;();FvF||$(LLy!!$//!"4??r1   c                    U R                   S   nU R                  (       a[  [        U5      u  p#SnU HE  n[        US   U R                  S9(       a  Sn[
         H  n[        XeS   U R                  S9  M     MG     O[        XR                  S9nU(       d  [        SU< S35        U R                  (       a,  [
         H!  n[        X`R                  U R                  S9  M#     g	g	)
z5Uninstall an nbextension from an unspecified locationr   Frj   r<   Tr~   zNo installed extension z found.N)	r   r   rk   r   r   r|   r   printr~   )r   name_rq   changedr(   r   s          r)   find_uninstall_extension0UninstallNBExtensionApp.find_uninstall_extension
  s    q!;;1$7IAG.uV}TXXN"G  1G-gY7G59XX?  1   2$xxHG+D87;<<<,)'<<15; - r1   c                    U R                   (       d  [        R                  " S5        g [        U R                   5      S:  a  [        R                  " S5        g U R                  (       dD  U R
                  (       d3  U R                  (       d"  U R                  (       d  U R                  (       a   U R                  5         g U R                  5         g ! [         a)  n[        R                  " [        U5      5         S nAg S nAff = f)Nz*Please specify an nbextension to uninstallr   z]Only one nbextension allowed at a time. Call multiple times to uninstall multiple extensions.)r   r   r   rZ   r   r   r   r   r   r   r   r   r   r   s     r)   r   UninstallNBExtensionApp.start$  s    HHAB!A%HH M Nii4??dkkT[[&&!((*
 ))+	 $ !Q  !s   /C 
DC??Dr   N)r   r   r   r   r   r   versionr   r   r   r   r   copyr   r   r   r~   r   r   r   r   r   r   r   r   r1   r)   r   r     s    :GK,H 4C4G
 ""'')E1Hd3CDGIE(O ROF r$J b,RSG%LF)@";4,r1   r   c                   h    \ rS rSrSrSr\rSr\	" SSSS9r
\" SSS	S9rS
S0rSrS rS rS rS rSrg)ToggleNBExtensionAppi6  z4A base class for apps that enable/disable extensionsz*jupyter nbclassic-extension enable/disablez/Enable/disable an nbextension in configuration.r   TzMWhich config section to add the extension to, 'common' will affect all pages.r   z;Apply the configuration only for the current user (default)r   zToggleNBExtensionApp.sectionNc                     gr   r   r   s    r)   r   .ToggleNBExtensionApp._config_file_name_defaultE  r   r1   c                     U R                   (       a  [        O[        nU" UU R                  U R                  U R
                  S9$ )a  Toggle some extensions in an importable Python module.

Returns a list of booleans indicating whether the state was changed as
requested.

Parameters
----------
module : str
    Importable Python module exposing the
    magic-named `_jupyter_nbextension_paths` function
r   r   r9   )_toggle_valuer   r   r   r   r   )r   ro   toggles      r)   toggle_nbextension_python.ToggleNBExtensionApp.toggle_nbextension_pythonI  s<     04/A/A+1 	f99!%!XX' 	'r1   c                     U R                   (       a  [        O[        nU" U R                  UU R                  U R
                  U R                  S9$ )zToggle some a named nbextension by require-able AMD module.

Returns whether the state was changed as requested.

Parameters
----------
require : str
    require.js path used to load the nbextension
r   )r   r   r   r   r   r   r   )r   r~   r   s      r)   toggle_nbextension'ToggleNBExtensionApp.toggle_nbextension\  sA     )-(:(:$* 	dllG99!XX' 	'r1   c                 N   U R                   (       d  [        R                  " S5        O/[        U R                   5      S:  a  [        R                  " S5        U R                  (       a  U R                  U R                   S   5        g U R                  U R                   S   5        g )Nz:Please specify an nbextension/package to enable or disabler   z0Please specify one nbextension/package at a timer   )r   r   r   rZ   r   r   r  r   s    r)   r   ToggleNBExtensionApp.startl  si    HHQR!A%HHGH;;**4??1+=>##DOOA$67r1   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r1   r)   r   r   6  sZ    >7DGCKjbG T(efD89GM)'&' 8r1   r   c                   $    \ rS rSrSrSrSrSrSrg)EnableNBExtensionAppiw  z An App that enables nbextensionsz"jupyter nbclassic-extension enablez
    Enable an nbextension in frontend configuration.

    Usage
        jupyter nbclassic-extension enable [--system|--sys-prefix]
    Tr   N	r   r   r   r   r   r   r   r   r   r   r1   r)   r  r  w  s    */DK Mr1   r  c                   $    \ rS rSrSrSrSrSrSrg)DisableNBExtensionAppi  z!An App that disables nbextensionsz#jupyter nbclassic-extension disablez
    Disable an nbextension in frontend configuration.

    Usage
        jupyter nbclassic-extension disable [--system|--sys-prefix]
    Nr   r	  r   r1   r)   r  r    s    +0DK Mr1   r  c                   0    \ rS rSrSrSr\rSrS r	S r
Srg)	ListNBExtensionsAppi  z,An App that lists and validates nbextensionsz jupyter nbclassic-extension listz7List all nbextensions known by the configuration systemc           	         [        5        Vs/ s H#  n[        R                  R                  US5      PM%     nn[	        S5        U H  nSU 3nSn[        XS9n[         H  nUR                  U5      nSU;   d  M  U(       d  [	        U5        Sn[	        SU S	35        US   R                  5        HC  u  p[	        S
U	 SU
(       a  [        O[         35        U
(       d  M0  [        XR                  S9  ME     M     M     gs  snf )zList all the nbextensionsrw   zKnown nbextensions:z  config dir: F)rc   ry   rz   Tz    z sectionz      r   r<   N)r	   r"   r#   r   r   r   r|   r   itemsr   r   r   r   )r   pconfig_dirsry   head
head_shownr   r   datar~   enableds              r)   list_nbextensions%ListNBExtensionsApp.list_nbextensions  s    <O<QR<Qqrww||Az2<QR#$%J#J<0DJ&dJB,vvg$,%d%)
D	23,01B,C,I,I,K(wiq'|0\]^"70J -L - &	 Ss   *Dc                 $    U R                  5         g))Perform the App's functions as configuredN)r  r   s    r)   r   ListNBExtensionsApp.start  s     r1   r   N)r   r   r   r   r   r   r   r   r   r  r   r   r   r1   r)   r  r    s    6-DGKKK2!r1   r  a  
jupyter nbclassic-extension list                          # list all configured nbextensions
jupyter nbclassic-extension install --py <packagename>    # install an nbextension from a Python package
jupyter nbclassic-extension enable --py <packagename>     # enable all nbextensions in a Python package
jupyter nbclassic-extension disable --py <packagename>    # disable all nbextensions in a Python package
jupyter nbclassic-extension uninstall --py <packagename>  # uninstall an nbextension in a Python package
c                   d   ^  \ rS rSrSrSr\rSr\	r
\" \S4\S4\S4\S4\S	4S
9rU 4S jrSrU =r$ )NBExtensionAppi  z4Base jupyter nbclassic-extension command entry pointzjupyter nbclassic-extensionz%Work with Jupyter notebook extensionszInstall an nbextensionzEnable an nbextensionzDisable an nbextensionzUninstall an nbextensionzList nbextensions)r   enabledisable	uninstallrB   c                    > [         TU ]  5         SR                  [        U R                  5      5      n[
        R                  " SU 35        g)r  , z'Please supply at least one subcommand: N)superr   r   sortedsubcommandsr   r   )r   subcmds	__class__s     r)   r   NBExtensionApp.start  s;     ))F4#3#345:7)DEr1   r   )r   r   r   r   r   r   r   r   r   	_examplesr   dictr   r  r  r   r  r$  r   r   __classcell__)r&  s   @r)   r  r    s]    >(DG9KH&'?@$&=>&(@A*,FG!#67KF Fr1   r  c                 F   [         R                  R                  U5      (       d  g[         R                  " U 5      R                  [         R                  " U5      R                  -
  S:  a  U(       a  UR                  SU 35        gU(       a  UR                  SU 35        g)aE  Should a file be copied, if it doesn't exist, or is newer?

Returns whether the file needs to be updated.

Parameters
----------

src : string
    A path that should exist from which to copy a file
src : string
    A path that might exist to which to copy a file
logger : Jupyter logger [optional]
    Logger instance to use
Tgư>zOut of date: zUp to date: F)r"   r#   r$   statst_mtimer?   rH   rg   rj   r9   s      r)   _should_copyr/    sw     77>>$	wws|rwwt}555< KK-v./l4&)*r1   c                     [        XUS9(       a5  U(       a  UR                  SU  SU 35        [        R                  " X5        gg)zCopy a file if it needs updating.

Parameters
----------

src : string
    A path that should exist from which to copy a file
src : string
    A path that might exist to which to copy a file
logger : Jupyter logger [optional]
    Logger instance to use
r<   z	Copying: r6   N)r/  rH   rU   copy2r.  s      r)   r\   r\     s;     Cf-KK)C5TF34S .r1   c                 P     [         R                  " U 5      $ ! [         a     gf = f)zSafe version of is_tarfile, return False on IOError.

Returns whether the file exists and is a tarfile.

Parameters
----------

path : string
    A path that might not exist and or be a tarfile
F)rN   
is_tarfileOSError)r#   s    r)   rK   rK   	  s*    !!$'' s    
%%c                    SU 4SU4SU4SU4/nU VVs/ s H  u  pVU(       d  M  U SU< 3PM     nnn[        U5      S:  a  [        SSR                  U5       35      eU (       a  [        [	        5       S	5      nU$ U(       a  [        [
        S
   S	5      nU$ U(       a  [        USSS	5      nU$ U(       a  UnU$ [        [        S
   S	5      nU$ s  snnf )aa  Return the nbextension directory specified

Parameters
----------

user : bool [default: False]
    Get the user's .jupyter/nbextensions directory
sys_prefix : bool [default: False]
    Get sys.prefix, i.e. ~/.envs/my-env/share/jupyter/nbextensions
prefix : str [optional]
    Get custom prefix
nbextensions_dir : str [optional]
    Get what you put in
r   r   r   r   =r   zXcannot specify more than one of user, sys_prefix, prefix, or nbextensions_dir, but got: r!  r   r   sharejupyter)rZ   r   r   r%   r   r   r   )	r   r   r   r   conflictingnvconflicting_setr(   s	            r)   r,   r,     s
     
	6	-.	z"	K 1<Aq|!AaU|OA
?a		/235
 	
 &(.9 L 
&q)>: L 
fgy.A
 L	 
  L )!,n=L! Bs
   CCc                 ~    [        U 5      n[        US5      (       d  [        SU  S35      eUR                  5       nX4$ )a{  Get the list of nbextension paths associated with a Python module.

Returns a tuple of (the module,             [{
    'section': 'notebook',
    'src': 'mockextension',
    'dest': '_mockdestination',
    'require': '_mockdestination/index'
}])

Parameters
----------

module : str
    Importable Python module exposing the
    magic-named `_jupyter_nbextension_paths` function
_jupyter_nbextension_pathszThe Python module zU is not a valid nbextension, it is missing the `_jupyter_nbextension_paths()` method.)r   rA   KeyErrorr>  )ro   rp   rq   s      r)   rk   rk   B  sT    " 	FA1233  )G H
 	
 ))+F9r1   __main__)FNNF)FFFFNNN)NFFNNNr!   )FFNNN)TFN)FFNN)Tr   r"   rU   r   rN   rL   os.pathr   r   r%   r   urllib.parser   urllib.requestr   jupyter_core.pathsr   r	   r
   r   r   jupyter_core.utilsr   ipython_genutils.py3compatr   r   ipython_genutils.tempdirr   _versionr   config_managerr   traitlets.utils.importstringr   objectr=   r|   r0   rI   rt   r   r   r   r   r   r   r   r   r   r   r   rm   
extensionsr   r{   r   r   r   r   r   r   r   	traitletsr   r   r   r}   r   r   r   r   r  r  r  r(  r  launch_instancemainr/  r\   rK   r,   rk   r   r   r1   r)   <module>rP     s`   E
 
  
   5 5 ! &  1 E 7 ! 1 4h F ?B ).u"4$$(2E#|~ AFae: TX8<.Eb* UY#M$ @D 1H *.!> @E"16 AF#16$ =B%)82 >C&*8.'T4v   $
 [  $#
 0 	 #
 6  9c

 }  -=7 K!, K!\p,. p,f>8+ >8B	/ 		0 	!!* !!H	F% F0 %%8 &"%P8 zF r1   