
2\c        
   @  s  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l m	 Z	 m
 Z m Z y$ d d l m Z d d l m Z Wn1 e k
 r d d l m Z d d l m Z n Xd d l m Z m Z m Z 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! d d l" m# Z# d d l$ m% Z% e&   Z' d d d d d g Z( e) d d e) d  Z+ e) e) e) d d d e' d e) d 	 Z, e) e) e) e) d d d d  Z- d e) e) d d d d  Z. d d  Z/ e) e) d d d d  Z0 e1 e) d d  Z2 d d  Z3 e1 e) d d  Z4 e1 e) d d  Z5 d d  Z6 e1 e) d d  Z7 e1 e) d d   Z8 d d!  Z9 d d"  Z: d d# l; m< Z< m= Z= m> Z> m? Z? m@ Z@ mA ZA mB ZB mC ZC mD ZD d d$ lE mF ZF mG ZG i  ZH eH jI eD  eH jI i i i e1 d% 6d& 6d' f d% 6i i e1 d( 6d& 6d) f d( 6 eH d( eH d* <i  ZJ eJ jI eC  eJ jI i d+ d, 6d- d. 6d/ d0 6 d& e< f d1     YZK d2 e< f d3     YZL d4 e< f d5     YZM d6 eM f d7     YZN d8 eM f d9     YZO d: e< f d;     YZP d< ZQ d= e< f d>     YZR eR jS ZT d d?  ZU d d@  ZV dA   ZW e) e) d d dB  ZX dC   ZY eZ dD k reT   n  d S(E   s?   Utilities for installing Javascript extensions for the notebooki(   t   print_functionN(   t   basenamet   joint   normpath(   t   urlparse(   t   urlretrieve(   t   jupyter_data_dirt   jupyter_config_patht   jupyter_patht   SYSTEM_JUPYTER_PATHt   ENV_JUPYTER_PATH(   t   ensure_dir_exists(   t   string_typest   cast_unicode_py2(   t   TemporaryDirectoryi   (   t   __version__(   t   BaseJSONConfigManager(   t   import_itemt   commont   notebookt   treet   editt   terminalc      	     sl   t  d | d | d | d |    t j j    s7 t St |  t  rR |  g }  n  t   f d   |  D  S(   s  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
    t   usert
   sys_prefixt   prefixt   nbextensions_dirc         3  s*   |  ]  } t  j j t   |   Vq d  S(   N(   t   ost   patht   existst   pjoin(   t   .0t   f(   t   nbext(    s4   lib/python2.7/site-packages/notebook/nbextensions.pys	   <genexpr>J   s    (   t   _get_nbextension_dirR   R   R   t   Falset
   isinstanceR   t   all(   t   filesR   R   R   R   (    (   R!   s4   lib/python2.7/site-packages/notebook/nbextensions.pyt   check_nbextension,   s    !c
         C  sC  | t  k r+ d d l }
 |
 j d t  n  d } t d | d |	 d | d |  } t |  t t d  st t	 } n  t
 |  t t f  r t d	   n  t |   }  |  j d  re| r t d   n  t    } t |   j j d  d } t j j | |  } | r%| j d |  | f  n  t |  |  t | d | d | d | d | d | } Wd QXn|  j d  st |   r)| rt d   n  | rt d   n  | r| j d |  | f  n  |  j d  rt j |   } n t |   r	t j |   } n  | j |  | j    d } n| sDt! t" |    } n  t |  } t" t# | |   } | rt j j$ |  r| r| j d |  n  t j j% |  rt j j& |  rt' j( |  qt j) |  n  | r<t j j* |   }  t j j+ |  s?| r&| j d | |  f  n  t j, |  |  q?nt j j% |   r&t# t j j* |   d  }  x t j- |   D] \ } } } t# | | t. |    } t j j+ |  s| r| j d |  n  t j/ |  n  x? | D]7 } t# | |  } t# | |  } t0 | | d | qWqyWn |  } t0 | | d | | S(   s  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
    iNsv   `install_nbextension`'s `verbose` parameter is deprecated, it will have no effects and will be removed in Notebook 5.0R   R   R   R   t   symlinks   path must be a string pointing to a single extension to install; call this function multiple times to install multiple extensionss   https://s   http://s   Cannot symlink from URLst   /s   Downloading: %s -> %st	   overwritet   destinationt   loggers   .zips   Cannot symlink from archivess$   Cannot give destination for archivess   Extracting: %s -> %ss   Removing: %ss   Symlinking: %s -> %st    s   Making directory: %s(   s   https://s   http://(1   t   DEPRECATED_ARGUMENTt   warningst   warnt   DeprecationWarningt   NoneR"   R   t   hasattrR   R#   R$   t   listt   tuplet	   TypeErrorR   t
   startswitht
   ValueErrorR   R   R   t   splitR   t   infoR   t   install_nbextensiont   endswitht   _safe_is_tarfilet   zipfilet   ZipFilet   tarfilet   opent
   extractallt   closeR   R   R   t   lexistst   isdirt   islinkt   shutilt   rmtreet   removet   abspathR   R(   t   walkt   lent   makedirst   _maybe_copy(   R   R*   R(   R   R   R   R+   t   verboseR,   R   R/   t	   full_destR!   t   tdt   filenamet
   local_patht   archivet   parentt   dirsR&   t   dest_dirt	   file_namet   srct	   dest_file(    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyR;   M   s    (!
	
	%c         C  s   t  |   \ } }	 t j j | j  d }
 g  } x |	 D] } t j j |
 | d  } | d } | r | j d | | f  n  t | d | d | d | d | d	 | d
 | d | d | } t | | |  | j	 |  q8 W| S(   s   Install an nbextension bundled in a Python package.

    Returns a list of installed/updated directories.

    See install_nbextension for parameter information.i    RY   t   dests   Installing %s -> %sR*   R(   R   R   R   R   R+   R,   (
   t   _get_nbextension_metadataR   R   R9   t   __file__R   R:   R;   t   validate_nbextension_pythont   append(   t   moduleR*   R(   R   R   R   R   R,   t   mt   nbextst	   base_patht
   full_destsR!   RY   R[   RP   (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyt   install_nbextension_python   s    
c      	   C  s  t  d | d | d | d |  } t |   }  t | |   } t j j |  r | rh | j d |  n  t j j |  r t j j |  r t	 j
 |  q t j |  n  t j j t d | d |  d  }	 t d |	  }
 | rx/ t D]$ } |
 j | i i d	 | 6d 6 q Wn  d	 S(
   s  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   s   Removing: %st   nbconfigt
   config_dirt   load_extensionsN(   R"   R   R   R   R   RD   R:   RE   RF   RG   RH   RI   R   t   _get_config_dirR   t   NBCONFIG_SECTIONSt   updateR2   (   R[   t   requireR   R   R   R   R,   R!   RP   Rg   t   cmt   section(    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyt   uninstall_nbextension   s    !%$c         C  s   t  |   }  x t d  D] } t | |   } t j j |  r | rZ | j d |  n  t j j |  r t j j |  r t	 j
 |  n t j |  t Sq Wt S(   s   Remove nbextension files from the first location they are found.

    Returns True if files were removed, False otherwise.
    t   nbextensionss   Removing: %s(   R   R   R   R   R   RD   R:   RE   RF   RG   RH   RI   t   TrueR#   (   RR   R,   R!   R   (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyt   _find_uninstall_nbextension  s    %c         C  s   t  |   \ } } xo | D]g } | d }	 | d }
 | rU | j d j |	 |
   n  t |	 |
 d | d | d | d | d | q Wd	 S(
   sr   Uninstall an nbextension bundled in a Python package.
    
    See parameters of `install_nbextension_python`
    R[   Rl   s   Uninstalling {} {}R   R   R   R   R,   N(   R\   R:   t   formatRo   (   R`   R   R   R   R   R,   Ra   Rb   R!   R[   Rl   (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyt   uninstall_nbextension_python.  s    

c         C  s   | r t  n | } t j j t d | d |  d  } t d |  } | rv | j d j | rc d n d |  |   n  | j |  i i | | 6d 6 t	 | d	 | | j
 |   j
 |  | k S(
   s  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
    R   R   Rf   Rg   s   {} {} extension {}...t   Enablingt	   DisablingRh   R,   (   R#   R   R   R   Ri   R   R:   Rs   Rk   t   validate_nbextensiont   get(   Rn   Rl   t   stateR   R   R,   Rg   Rm   (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyt   _set_nbextension_state?  s    	c         C  sX   t  |  \ } } g  | D]; } t d | d d | d d |  d | d | d |  ^ q S(   sd  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
    Rn   Rl   Ry   R   R   R,   (   R\   Rz   (   Ry   R`   R   R   R,   Ra   Rb   R!   (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyt   _set_nbextension_state_pythonf  s    c         C  s+   t  d |  d | d t d | d | d |  S(   sX  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
    Rn   Rl   Ry   R   R   R,   (   Rz   Rq   (   Rn   Rl   R   R   R,   (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyt   enable_nbextension  s    c         C  s+   t  d |  d | d t d | d | d |  S(   s^  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
    Rn   Rl   Ry   R   R   R,   (   Rz   R#   (   Rn   Rl   R   R   R,   (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyt   disable_nbextension  s    c         C  s   x t    D] } t d t j j | d   } | j |   } | j d i   j | d  r
 | rw | j d | |  n  | j |  i i d | 6d 6 t	 Sq
 Wt
 S(   s   Disable an nbextension from the first config location where it is enabled.

    Returns True if it changed any config, False otherwise.
    Rg   Rf   Rh   s   Disabling %s extension in %sN(   R   R   R   R   R   Rx   R2   R:   Rk   Rq   R#   (   Rn   Rl   R,   Rg   Rm   t   d(    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyt   _find_disable_nbextension  s    c         C  s   t  t |  | | d | S(   s_  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
    R,   (   R{   Rq   (   R`   R   R   R,   (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyt   enable_nbextension_python  s    c         C  s   t  t |  | | d | S(   s"  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
    R,   (   R{   R#   (   R`   R   R   R,   (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyt   disable_nbextension_python  s    c   	      C  s"  g  } g  } t  } xW t d  D]I } d j t j j | |  j d    } t j j |  } | r Pq q Wd } | r | j | j t	 |    n | j | j t
 |    | r| r| j d  x | D] } | j |  q Wx4 | D] } | j |  q Wq| j d j t	   n  | S(   s  Validate 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
    Rp   u   {}.jsR)   u           - require? {} {}u#         - Validating: problems found:u         - Validating: {}(   R#   R   Rs   R   R   R   R9   R   R_   t   GREEN_OKt   RED_Xt   warningR:   (	   Rl   R,   R/   t   infost	   js_existst   extst   jst   require_tmplt   msg(    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyRw     s*    'c   	      C  s  g  } g  } |  j  d d  } | t k rF | j d j t |   n | j d j t |   |  j  d d  } | d k	 r t j j	 | d t
 |  d  !d j |   } t j j |  r | j d j t |   q | j d	 j t |   n  | r~| re| j d
  x | D] } | j |  qWx | D] } | j |  q5W| j d j |    q~| j d j t   n  | S(   sP  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
    Rn   u     {} section: {}u     {}  section: {}Rl   i    R[   u   {}.jsu     {} require: {}u     {}  require: {}s   - Validating: problems found:u   Full spec: {}u   - Validating: {}N(   Rx   R2   Rj   R_   Rs   R   R   R   R   R   RL   R   R   R:   (	   t   specRP   R,   R   R/   Rn   Rl   t   require_pathR   (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyR^   '  s0    	(	   t   BaseExtensionAppRi   t   GREEN_ENABLEDt   RED_DISABLEDR   R   t   ArgumentConflictt   _base_aliasest   _base_flags(   t   Boolt   UnicodeR*   t   InstallNBExtensionApps!   Force overwrite of existing filesR(   s'   Create symlink instead of copying filest   ss   InstallNBExtensionApp.prefixR   s&   InstallNBExtensionApp.nbextensions_dirRp   s!   InstallNBExtensionApp.destinationR+   c           B  s   e  Z d  Z d Z d Z e Z e Z e e d e	 d d Z
 e e d e	 d d Z e d d e	 d d Z e d d e	 d d	 Z e d d e	 d d
 Z d   Z d   Z d   Z RS(   s.   Entry point for installing notebook extensionss  Install Jupyter notebook extensions
    
    Usage
    
        jupyter nbextension install path|url [--user|--sys-prefix]
    
    This copies a file or a folder into the Jupyter nbextensions 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.
    s:   
    jupyter nbextension install /path/to/myextension
    t   configt   helps!   Force overwrite of existing filess(   Create symlinks instead of copying filesR-   s   Installation prefixs;   Full path to nbextensions dir (probably use prefix or user)s#   Destination for the copy or symlinkc         C  s   d S(   s   The default config file name.t   jupyter_notebook_config(    (   t   self(    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyt   _config_file_name_default  s    c         C  s  t  |  j  d k r$ t d   n  |  j r< t } i  } n t } i |  j d 6} | |  j d d |  j d |  j d |  j	 d |  j
 d	 |  j d
 |  j d |  j | } | r|  j j d j |  j r |  j d n d |  j	 r d n d |  j r d n d |  j
 rd n d   n  d S(   s*   Perform the installation of nbextension(s)i   s[   Only one nbextension allowed at a time. Call multiple times to install multiple extensions.R+   i    R*   R(   R   R   R   R   R,   u   
To initialize this nbextension in the browser every time the notebook (or other app) loads:

      jupyter nbextension enable {}{}{}{}
s   <the entry point>s    --userR-   s    --pys    --sys-prefixN(   RL   t
   extra_argsR8   t   pythonRe   R;   R+   R*   R(   R   R   R   R   t   logR:   Rs   (   R   t   installt   kwargsRd   (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyt   install_extensions  s.    										c         C  sT   |  j  s t j d  n7 y |  j   Wn& t k
 rO } t j t |   n Xd S(   s(   Perform the App's function as configureds(   Please specify an nbextension to installN(   R   t   syst   exitR   R   t   str(   R   t   e(    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyt   start  s    	(   t   __name__t
   __module__t   __doc__t   descriptiont   examplest   aliasest   flagsR   R#   Rq   R*   R(   R   R   R   R+   R   R   R   (    (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyR     s   			$t   UninstallNBExtensionAppc           B  s   e  Z d  Z e Z d Z d Z i d d 6d d 6d d 6Z e j	 j
   Z	 i i e d	 6d
 6d f e	 d	 <e d d e d d Z e d d e d d Z e d d e d d Z e e d e d d Z d   Z d   Z d   Z d   Z RS(   s0   Entry point for uninstalling notebook extensionssR  Uninstall Jupyter notebook extensions
    
    Usage
    
        jupyter nbextension uninstall path/url path/url/entrypoint
        jupyter nbextension 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 nbextension 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).
    s   
    jupyter nbextension uninstall dest/dir dest/dir/extensionjs
    jupyter nbextension uninstall --py extensionPyPackage
    s   UninstallNBExtensionApp.prefixR   s(   UninstallNBExtensionApp.nbextensions_dirRp   s   UninstallNBExtensionApp.requireRl   t   systemR   s=   Uninstall specifically from systemwide installation directoryR-   R   R   s@   Installation prefix. Overrides --user, --sys-prefix and --systems;   Full path to nbextensions dir (probably use prefix or user)s$   require.js module to disable loadingc         C  s   d S(   s   The default config file name.R   (    (   R   (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyR     s    c         C  s   i |  j  d 6|  j d 6|  j d 6|  j d 6|  j d 6} |  j rX t |  j d |  n- |  j rq |  j | d <n  t	 |  j d |  d S(	   s1   Uninstall an nbextension from a specific locationR   R   R   R   R,   i    Rl   N(
   R   R   R   R   R   R   Rt   R   Rl   Ro   (   R   R   (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyt   uninstall_extension  s    



		c         C  s   |  j  d } |  j r t |  \ } } t } xs | D]S } t | d d |  j r] t } n  x( t D]  } t | | d d |  j qd Wq5 Wn t | d |  j } | s t	 d |  n  |  j
 r x* t D] } t | |  j
 d |  j q Wn  d S(   s5   Uninstall an nbextension from an unspecified locationi    R[   R,   Rl   s    No installed extension %r found.N(   R   R   R\   R#   Rr   R   Rq   Rj   R   t   printRl   (   R   t   namet   _Rb   t   changedR!   Rn   (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyt   find_uninstall_extension  s"    			c         C  s   |  j  s t j d  n t |  j   d k r> t j d  nq |  j sk |  j sk |  j sk |  j sk |  j r y |  j	   Wq t
 k
 r } t j t |   q Xn
 |  j   d  S(   Ns*   Please specify an nbextension to uninstalli   s]   Only one nbextension allowed at a time. Call multiple times to uninstall multiple extensions.(   R   R   R   RL   R   R   R   R   R   R   R   R   R   (   R   R   (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyR   2  s    	$	(   R   R   R   R   t   versionR   R   R   R   R   t   copyRq   R   R   R   Rl   R   R#   R   R   R   R   R   (    (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyR     s,   
						t   ToggleNBExtensionAppc           B  s   e  Z d  Z d Z e Z d Z e d d e d d Z	 e
 e d e d d Z i d d	 6Z d Z d
   Z d   Z d   Z d   Z RS(   s4   A base class for apps that enable/disable extensionss"   jupyter nbextension enable/disables/   Enable/disable an nbextension in configuration.R   R   R   sM   Which config section to add the extension to, 'common' will affect all pages.s;   Apply the configuration only for the current user (default)s   ToggleNBExtensionApp.sectionRn   c         C  s   d S(   s   The default config file name.R   (    (   R   (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyR   S  s    c         C  s:   |  j  r t n t } | | d |  j d |  j d |  j S(   sN  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   R,   (   t   _toggle_valueR   R   R   R   R   (   R   R`   t   toggle(    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyt   toggle_nbextension_pythonW  s    			c      	   C  s@   |  j  r t n t } | |  j | d |  j d |  j d |  j S(   s   Toggle 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}   Rn   R   R   R   (   R   Rl   R   (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyt   toggle_nbextensionj  s
    
c         C  sv   |  j  s t j d  n% t |  j   d k r> t j d  n  |  j r^ |  j |  j  d  n |  j |  j  d  d  S(   Ns:   Please specify an nbextension/package to enable or disablei   s0   Please specify one nbextension/package at a timei    (   R   R   R   RL   R   R   R   (   R   (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyR   z  s    		N(   R   R   R   R   R   R   R   R   Rq   Rn   R   R   R   R2   R   R   R   R   R   (    (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyR   D  s   				t   EnableNBExtensionAppc           B  s    e  Z d  Z d Z d Z e Z RS(   s    An App that enables nbextensionss   jupyter nbextension enables   
    Enable an nbextension in frontend configuration.
    
    Usage
        jupyter nbextension enable [--system|--sys-prefix]
    (   R   R   R   R   R   Rq   R   (    (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyR     s   t   DisableNBExtensionAppc           B  s    e  Z d  Z d Z d Z d Z RS(   s!   An App that disables nbextensionss   jupyter nbextension disables   
    Disable an nbextension in frontend configuration.
    
    Usage
        jupyter nbextension disable [--system|--sys-prefix]
    N(   R   R   R   R   R   R2   R   (    (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyR     s   t   ListNBExtensionsAppc           B  s2   e  Z d  Z d Z e Z d Z d   Z d   Z RS(   s,   An App that lists and validates nbextensionss   jupyter nbextension lists7   List all nbextensions known by the configuration systemc         C  s.  g  t    D] } t j j | d  ^ q
 } t d  x | D] } d j |  } t } t d |  d |  } x t D] } | j	 |  } d | k rs | s t |  t
 } n  t d j |   x_ | d j   D]J \ }	 }
 t d j |	 |
 r t n t   |
 r t |	 d	 |  j q q Wqs qs Wq< Wd
 S(   s   List all the nbextensionsRf   s   Known nbextensions:u     config dir: {}RU   Rg   Rh   u       {} sectionu         {} {}R,   N(   R   R   R   R   R   Rs   R#   R   Rj   Rx   Rq   t   itemsR   R   Rw   R   (   R   t   pt   config_dirsRg   t   headt
   head_shownRm   Rn   t   dataRl   t   enabled(    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyt   list_nbextensions  s&    +

		c         C  s   |  j    d S(   s)   Perform the App's functions as configuredN(   R   (   R   (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyR     s    (	   R   R   R   R   R   R   R   R   R   (    (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyR     s   	s  
jupyter nbextension list                          # list all configured nbextensions
jupyter nbextension install --py <packagename>    # install an nbextension from a Python package
jupyter nbextension enable --py <packagename>     # enable all nbextensions in a Python package
jupyter nbextension disable --py <packagename>    # disable all nbextensions in a Python package
jupyter nbextension uninstall --py <packagename>  # uninstall an nbextension in a Python package
t   NBExtensionAppc           B  st   e  Z d  Z d Z e Z d Z e Z e	 d e
 d f d e d f d e d f d	 e d
 f d e d f  Z d   Z RS(   s,   Base jupyter nbextension command entry points   jupyter nbextensions%   Work with Jupyter notebook extensionsR   s   Install an nbextensiont   enables   Enable an nbextensiont   disables   Disable an nbextensiont	   uninstalls   Uninstall an nbextensionR4   s   List nbextensionsc         C  s@   t  t |   j   d j t |  j   } t j d |  d S(   s)   Perform the App's functions as configureds   , s)   Please supply at least one subcommand: %sN(   t   superR   R   R   t   sortedt   subcommandsR   R   (   R   t   subcmds(    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyR     s    (   R   R   R   R   R   R   R   t	   _examplesR   t   dictR   R   R   R   R   R   R   (    (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyR     s   c         C  sz   t  j j |  s t St  j |   j t  j |  j d k r\ | rX | j d |  n  t S| rv | j d |  n  t S(   sm  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
    gư>s   Out of date: %ss   Up to date: %s(	   R   R   R   Rq   t   statt   st_mtimeR0   R:   R#   (   RY   R[   R,   (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyt   _should_copy  s    (c         C  sL   t  |  | d | rH | r5 | j d |  | f  n  t j |  |  n  d S(   s!  Copy 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,   s   Copying: %s -> %sN(   R   R:   RG   t   copy2(   RY   R[   R,   (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyRN     s    c         C  s*   y t  j |   SWn t k
 r% t SXd S(   s   Safe 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
    N(   R@   t
   is_tarfilet   IOErrorR#   (   R   (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyR=     s    c   	      C  s	  d |  f d | f d | f d | f g } g  | D]$ \ } } | r1 d j  | |  ^ q1 } t |  d k r t d j  d j |     n  |  r t t   d	  } n\ | r t t d
 d	  } n@ | r t | d d d  } n" | r | } n t t d
 d  } | S(   s  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   s   {}={!r}i   sZ   cannot specify more than one of user, sys_prefix, prefix, or nbextensions_dir, but got: {}s   , u   nbextensionsi    t   sharet   jupyterRp   (   Rs   RL   R   R   R   R   R
   R	   (	   R   R   R   R   t   conflictingt   nt   vt   conflicting_setR!   (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyR"   *  s&    			1	c         C  sI   t  |   } t | d  s3 t d j |     n  | j   } | | f S(   s  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
    t   _jupyter_nbextension_pathssi   The Python module {} is not a valid nbextension, it is missing the `_jupyter_nbextension_paths()` method.(   R   R3   t   KeyErrorRs   R   (   R`   Ra   Rb   (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyR\   Q  s    	t   __main__([   R   t
   __future__R    R   RG   R   R@   R>   t   os.pathR   R   R   R   t   urllib.parseR   t   urllib.requestR   t   ImportErrort   urllibt   jupyter_core.pathsR   R   R   R	   R
   t   jupyter_core.utilsR   t   ipython_genutils.py3compatR   R   t   ipython_genutils.tempdirR   t   _versionR   t   config_managerR   t   traitlets.utils.importstringR   t   objectR.   Rj   R#   R2   R'   R;   Re   Ro   Rr   Rt   Rq   Rz   R{   R|   R}   R   R   R   Rw   R^   t
   extensionsR   Ri   R   R   R   R   R   R   R   t	   traitletsR   R   R   Rk   R   R   R   R   R   R   R   R   R   t   launch_instancet   mainR   RN   R=   R"   R\   R   (    (    (    s4   lib/python2.7/site-packages/notebook/nbextensions.pyt   <module>   s   (	!	|0'*;@	
	PsA,		'	