
2\c           @@ s  d  Z  d d l m Z 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	 Z	 d d l
 Z
 d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z y d d l m Z Wn! e k
 rd d l m  Z n Xd d l! m" Z" m# Z# d d l$ m% Z% m& Z& d d l' m( Z( e( j)   y d d l* Z* Wn# e k
 re e& d	    n Xy e* j+ Z+ Wn# e, k
 r.e e& d
    n Xe+ d d f k  r]e e& d  e* j-   n  d d l* m. Z. d d l* m/ Z/ d d l0 m1 Z1 d d l2 m3 Z3 m4 Z4 m5 Z5 m6 Z6 d d l m7 Z7 m8 Z8 m9 Z9 y
 e: Z: Wn e; k
 re< Z: n Xd d l= m> Z> m? Z? d d l@ mA ZA d d lB mC ZC d d lD mE ZE d d lF mG ZG d d lH mI ZI d d lJ mK ZK d d lL mM ZM d d lN mO ZO d d lP mQ ZQ d d l= mR ZR d d lS mT ZT d d lU mV ZV mW ZW d d  lX mY ZY mZ ZZ m[ Z[ d d! l\ m] Z] d d" l^ m_ Z_ d d# l` ma Za mb Zb mc Zc d d$ ld me Ze d d% lf mg Zg d d& lh mi Zi mj Zj mk Zk ml Zl mm Zm mn Zn mo Zo mp Zp mq Zq mr Zr ms Zs mt Zt mu Zu mv Zv d d' lw mx Zx d d( l\ my Zy mz Zz d d) l{ m| Z| d d* l} m~ Z~ m Z d d+ l m Z m Z m Z m Z m Z d, Z d-   Z d.   Z d/ e/ j f d0     YZ d1 eY f d2     YZ d3 e d4  Z d5 eY f d6     YZ d7 eY f d8     YZ e eZ  Z i i e d9 6d: 6e& d;  f e d< <i i d= d> 6d: 6e& d?  f e d> <i i e d@ 6d: 6dA f e dB <i i e dC 6d: 6e& dD  f e dE <e j eW dF dG dH dH   e e[  Z e j i
 dI dJ 6dK dL 6dM dN 6dO dP 6dQ dR 6dS dT 6dU dV 6dW dX 6dY dZ 6d[ d> 6 d: eY f d\     YZ e d]  Z e j Z Z d S(^   s(   A tornado based Jupyter notebook server.i    (   t   absolute_importt   print_functionN(   t   encodebytes(   t   encodestring(   t   Environmentt   FileSystemLoader(   t   transt   _(   t   ioloops,   The Jupyter Notebook requires tornado >= 4.0sB   The Jupyter Notebook requires tornado >= 4.0, but you have < 1.1.0i   s=   The Jupyter Notebook requires tornado >= 4.0, but you have %s(   t
   httpserver(   t   web(   t
   url_concat(   t   LogFormattert   app_logt
   access_logt   gen_log(   t   DEFAULT_STATIC_FILES_PATHt   DEFAULT_TEMPLATE_PATH_LISTt   __version__i   (   t   Template404t   RedirectWithParams(   t   log_request(   t   MappingKernelManager(   t   ConfigManager(   t   ContentsManager(   t   FileContentsManager(   t   LargeFileManager(   t   SessionManager(   t   LoginHandler(   t   LogoutHandler(   t   FileFindHandler(   t   Config(   t   catch_config_errort   boolean_flag(   t
   JupyterAppt
   base_flagst   base_aliases(   t   jupyter_config_path(   t   KernelManager(   t   KernelSpecManagert   NoSuchKernelt   NATIVE_KERNEL_NAME(   t   Session(   t   NotebookNotary(   t   Anyt   Dictt   Unicodet   Integert   Listt   Boolt   Bytest   Instancet
   TraitErrort   Typet   Floatt   observet   defaultt   validate(   t	   py3compat(   t   jupyter_runtime_dirt   jupyter_path(   t   get_sys_info(   t   utcnowt   utcfromtimestamp(   t   url_path_joint	   check_pidt
   url_escapet   urljoint   pathname2urls   
jupyter notebook                       # start the notebook
jupyter notebook --certfile=mycert.pem # use SSL/TLS certificate
jupyter notebook password              # enter a password to protect the server
c         c@ sn   x& t  t d |   D] } |  | Vq Wx> t  | d  D], } t d |  t j d | d |   Vq: Wd S(   s   Generate a list of n random ports near the given port.

    The first 5 ports will be sequential, and the remaining n-5 will be
    randomly selected in the range [port-2*n, port+2*n].
    i   i   ii   N(   t   ranget   mint   maxt   randomt   randint(   t   portt   nt   i(    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   random_ports   s    c         C@ s   t  |  d d g } | j S(   s:   Load the (URL pattern, handler) tuples for each component.t   fromlistt   default_handlers(   t
   __import__RO   (   t   namet   mod(    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   load_handlers   s    t   NotebookWebApplicationc           B@ s/   e  Z d    Z d d  Z d   Z d   Z RS(   c         C@ s\   |  j  | | | | | | | | |	 |
 | |  } |  j |  } t t |   j | |  d  S(   N(   t   init_settingst   init_handlerst   superRT   t   __init__(   t   selft   jupyter_appt   kernel_managert   contents_managert   session_managert   kernel_spec_managert   config_managert   extra_servicest   logt   base_urlt   default_urlt   settings_overridest   jinja_env_optionst   settingst   handlers(    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyRX      s    			c      W   C@ s  | j  d | j  } t | t j  r3 | f } n  g  | D] } t j j |  ^ q: } i t d 6} | j	 | rw | n i   t
 d t |  d d g |  } t   } t j j t j j t d d   } t j j t j j | d   } t j d d	 t j j | d
  d t } | j | d t | rJd d } | j |  n  | d d k rcd } n t j j   j d  } | j r| j t d   | j t d  d  t j t d  t  n  t   } | j  } t j j d  } | j! | t j j"  rd | t# |  } n  t$ d t% d |	 d |
 d | d | j& d | j' d t( d t) |	 d  d i t) |	 d  d!  g d" 6d# | d$ | j d% | j* d& | j+ d' | j, d( | j- d) t) |	 d*  d+ | j. d, | j/ d- | j0 d. t d/ | j1 d0 | j2 d1 | j3 d2 | d3 | d4 | d5 | d6 | d7 | d8 | d9 i  d: | j4 d; | j5 d< | j6 d= | j7 d> | j8 d? | j9 d@ | j: dA | j; dB | j< dC | dD | dE t  +} | j	 |  | S(F   Nt   template_patht
   autoescapet   loadert
   extensionss   jinja2.ext.i18ns   ..s   .gitt   nbuit	   localedirs   notebook/i18nt   fallbackt   newstyles  It looks like you're running the notebook from source.
    If you're working on the Javascript of the notebook, try running

    %s

    in another terminal window to have the system incrementally
    watch and build the notebook's JavaScript for you, as you make changes.s   npm run build:watcht   commit_sourcet
   repositoryt    s   %Y%m%d%H%M%Ss@   The `ignore_minified_js` flag is deprecated and no longer works.sI   Alternatively use `%s` when working on the notebook's Javascript and LESSsO   The `ignore_minified_js` flag is deprecated and will be removed in Notebook 6.0t   ~t   log_functionRb   Rc   t   static_patht   static_custom_patht   static_handler_classt   static_url_prefixs   /static/t   static_handler_argst   statict   customt   no_cache_pathst   version_hasht   ignore_minified_jst   iopub_msg_rate_limitt   iopub_data_rate_limitt   rate_limit_windowt   cookie_secrett	   login_urls   /logint   login_handler_classt   logout_handler_classt   passwordt   xsrf_cookiest   disable_check_xsrft   allow_remote_accesst   local_hostnamesR[   R\   R]   R^   R_   R`   t   startedt   last_activity_timest   jinja_template_varst   nbextensions_patht   websocket_urlt   mathjax_urlt   mathjax_configt   shutdown_buttont   configt
   config_dirt   allow_password_changet   server_root_dirt
   jinja2_envt   terminals_available(=   t   gett   template_file_patht
   isinstanceR:   t   string_typest   ost   patht
   expandusert   Truet   updateR   R   R=   t   realpatht   joint   __file__t   existst   gettextt   translationt   install_gettext_translationst   Falset   infot   datetimet   nowt   strftimeR~   t   warningR   t   warningst   warnt   DeprecationWarningR>   t   root_dirt
   startswitht   sept   lent   dictR   t   static_file_pathRv   R   R@   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t   quit_buttonR   R   R   (   RY   RZ   R[   R\   R]   R^   R_   R`   Ra   Rb   Rc   Rd   Re   t   _template_pathR   Rh   t   jenv_optt   envt   sys_infot   base_dirt   dev_modeRl   t   DEV_NOTE_NPMR}   R   R   t   homeRf   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyRU      s    %!	$!*
																											c         C@ s  g  } x% | d D] } | j  t |   q W| j  t d   | j  d | d f g  | j  d | d f g  | j  t d   | j  t d   | j  t d	   | j  t d
   | j  t d   | j  t d   | j  t d   | j  t d   | j  t d   | j  t d   | j  t d   | j  t d   | j  t d   | j  t d   | j  t d   | j  t d   | j  | d j    | j d t i | d d 6d g d 6f  | j d t i | d d 6d g d 6f  | j  t d   | j d  t i | d! d" 6t d# 6f  g  } xO | D]G } t | d$ | d%  } t | g t	 | d&   } | j |  qZW| j d' t
 f  | S((   s:   Load the (URL pattern, handler) tuples for each component.R`   s   notebook.tree.handlerss   /loginR   s   /logoutR   s   notebook.files.handlerss   notebook.view.handlerss   notebook.notebook.handlerss   notebook.nbconvert.handlerss   notebook.bundler.handlerss   notebook.kernelspecs.handlerss   notebook.edit.handlerss   notebook.services.api.handlerss!   notebook.services.config.handlerss"   notebook.services.kernels.handlerss#   notebook.services.contents.handlerss#   notebook.services.sessions.handlerss$   notebook.services.nbconvert.handlerss&   notebook.services.kernelspecs.handlerss#   notebook.services.security.handlerss   notebook.services.shutdownR\   s   /nbextensions/(.*)R   R   t   /R|   s   /custom/(.*)Rv   s   notebook.base.handlerss   /?Rc   t   urlt	   permanentRb   i    i   s   (.*)(   t   extendRS   t   get_extra_handlerst   appendR   R   R   R@   t   tuplet   listR   (   RY   Rf   Rg   t   servicet   new_handlerst   handlert   patternt   new_handler(    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyRV      sV    			c         C@ s   |  j  d |  j  d j g } y | j |  j  d  Wn t k
 rH n Xy | j |  j  d  Wn t k
 rt n X| j |  j  d j    t |  S(   s   Get a UTC timestamp for when the server last did something.

        Includes: API activity, kernel activity, kernel shutdown, and terminal
        activity.
        R   R[   t   api_last_activityt   terminal_last_activityR   (   Rf   t   last_kernel_activityR   t   KeyErrorR   t   valuesRG   (   RY   t   sources(    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   last_activity]  s    
N(   t   __name__t
   __module__RX   t   NoneRU   RV   R   (    (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyRT      s   	x	=t   NotebookPasswordAppc           B@ s&   e  Z d  Z e Z d   Z d   Z RS(   s   Set a password for the notebook server.

    Setting a password secures the notebook server
    and removes the need for token-based authentication.
    c         C@ s   t  j j |  j d  S(   Ns   jupyter_notebook_config.json(   R   R   R   R   (   RY   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _config_file_default|  s    c         C@ s;   d d l  m } | d |  j  |  j j d |  j  d  S(   Ni   (   t   set_passwordt   config_files   Wrote hashed password to %s(   t   auth.securityR   R   Ra   R   (   RY   R   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   start  s    (   R   R   t   __doc__t   descriptionR   R   (    (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR   s  s   	i   c   	      C@ s  d d l  m } m } |  d } |  d } | | d d d d d	 d
 i d |  d d 6} | rt | j d |  n  |   j |  xN t | d  D]< } t |  r | r | j d |  n  t St j	 d  q Wt
 j j d  r t S| r| j d |  n  t j | t j  xN t | d  D]< } t |  rW| rS| j d |  n  t St j	 d  q(W| r| j d |  n  t j | t j  t S(   s  Shutdown a notebook server in a separate process.

    *server_info* should be a dictionary as produced by list_running_servers().

    Will first try to request shutdown using /api/shutdown .
    On Unix, if the server is still running after *timeout* seconds, it will
    send SIGTERM. After another timeout, it escalates to SIGKILL.

    Returns True if the server was stopped by any means, False if stopping it
    failed (on Windows).
    i    (   t
   HTTPClientt   HTTPRequestR   t   pids   api/shutdownt   methodt   POSTt   bodyRr   t   headerss   token t   tokent   Authorizations   POST request to %sapi/shutdowni
   s   Server PID %s is goneg?t   wins   SIGTERM to PID %ss   SIGKILL to PID %s(   t   tornado.httpclientR   R   t   debugt   fetchRE   RA   R   t   timet   sleept   syst   platformR   R   R   t   killt   signalt   SIGTERMt   SIGKILL(	   t   server_infot   timeoutRa   R   R   R   R   t   reqR   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   shutdown_server  s:    

     t   NbserverStopAppc           B@ sJ   e  Z e Z d  Z e d d e d d Z d d  Z	 d   Z
 d   Z RS(	   s7   Stop currently running notebook server for a given porti"  R   t   helps-   Port of the server to be killed. Default 8888c         C@ s<   t  t |   j |  |  j r8 t |  j d  |  _ n  d  S(   Ni    (   RW   R   t   parse_command_linet
   extra_argst   intRJ   (   RY   t   argv(    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR     s    	c         C@ s   t  | d |  j S(   NRa   (   R   Ra   (   RY   t   server(    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR     s    c         C@ s   t  t |  j   } | s+ |  j d  n  x | D]O } | d |  j k r2 t d |  j d  |  j |  s} t j d  n  d  Sq2 Wt d j |  j  d t j	 t d d t j	 x. | D]& } t d	 j | d  d t j	 q W|  j d
  d  S(   Ns   There are no running serversRJ   s   Shutting down server on ports   ...s   Could not stop servers/   There is currently no server running on port {}t   files   Ports currently in use:s     - {}i   (
   R   t   list_running_serverst   runtime_dirt   exitRJ   t   printR   R   t   formatt   stderr(   RY   t   serversR   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR     s    $N(   R   R   R   t   versionR   R/   R   RJ   R   R   R   R   (    (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR     s   		t   NbserverListAppc           B@ s   e  Z e Z e d   Z e d i i e d 6d 6e d  f d i i e d 6d 6e d  f  Z e	 e
 d e d e d  Z e	 e
 d e d e d	  Z d
   Z RS(   s(   List currently running notebook servers.t   jsonlistR	  s*   Produce machine-readable JSON list output.t   jsons<   Produce machine-readable JSON object on each line of output.R   R   s   If True, the output will be a JSON list of objects, one per active notebook server, each with the details from the relevant server info file.s   If True, each line of output will be a JSON object with the details from the server info file. For a JSON list output, see the NbserverListApp.jsonlist configuration valuec         C@ s   t  t |  j   } |  j r: t t j | d d  n |  j rj x | D] } t t j |   qJ Wn] t d  xP | D]H } | d } | j d  r | d | d } n  t | d | d  q{ Wd  S(	   Nt   indenti   s   Currently running servers:R   R   s	   ?token=%ss   ::t   notebook_dir(   R   R  R  R
  R  R  t   dumpsR   (   RY   t   serverinfo_listt
   serverinfoR   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR     s    		

(   R   R   R   R  R   R   R   R   t   flagsR1   R   R
  R  R   (    (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR	    s   t   open_browsert   NotebookApps3   Don't open the notebook in a browser after startup.s
   no-browserR   t   pylabsI   DISABLED: use %pylab or %matplotlib in the notebook to enable matplotlib.t   enable_mathjaxs<  Disable MathJax
    
    MathJax is the javascript library Jupyter uses to render math/LaTeX. It is
    very large, so you may want to disable it if you have a slow internet
    connection, or for offline use of the notebook.
    
    When disabled, equations etc. will appear as their untransformed TeX source.
    s
   no-mathjaxt
   allow_roots,   Allow the notebook to be run from root user.s
   allow-roott   scripts   FileContentsManager.save_scripts   DEPRECATED, IGNOREDs   NotebookApp.ipt   ips   NotebookApp.portRJ   s   NotebookApp.port_retriess   port-retriess   KernelManager.transportt	   transports   NotebookApp.keyfilet   keyfiles   NotebookApp.certfilet   certfiles   NotebookApp.client_cas	   client-cas   NotebookApp.notebook_dirs   notebook-dirs   NotebookApp.browsert   browsers   NotebookApp.pylabc        
   B@ s  e  Z d  Z e Z e d  Z e Z e	 Z	 e
 Z
 e e e e e e e g Z e e
  Z
 e e	  Z	 e d e e j j   d f d e e j j   d f d e e j j   d f  Z e Z e d  d    Z e d  d	    Z e d
  d    Z e  e! d e" d e d  Z# e$ d d e" Z% e$ d d e" d d Z& e$ d d e" d d Z' e  e! d e" d e d  Z( e  e! d e" d e d  Z) e$ d d e" d e d  Z* e$ d d e" d e d  Z+ e d  d    Z, e- d  d    Z. e$ d d e" d e d  Z/ e0 d d e" d e d  Z1 e0 d d e" d e d   Z2 e$ d d e" d e d!  Z3 e$ d d e" d e d"  Z4 e$ d d e" d e d#  Z5 e$ d e" d e d$   Z6 e d%  d&    Z7 e8 d d e" d d' Z9 e d(  d)    Z: d*   Z; e$ d+ d e d,  j< d e"  Z= e" Z> e d-  d.    Z? e0 d d e" d d1 Z@ e0 d d e" d d2 ZA eB d-  d3    ZC e$ d d e" d d4 ZD e  e! d e" d d5 ZE e  e" d e" d d6 ZF e  e! d e" d d7 ZG e  d e" d d8  ZH e d9  d:    ZI eJ e$   d g d e" d d; ZK e  e" d e" d d< ZL e$ d d e" d d= ZM e0 d> d e" d e d?  ZN e d e" d e d@   ZO eB dA  dB    ZP e d e" d e dC   ZQ eR d d e" d e dD  ZT e d e" d e dE   ZU e d e" d e dF   ZV e d e" d e dG   ZW e d e" d e dH   ZX e d e" d e dI   ZY e d e" d e dJ   ZZ e  e" d e" d dK Z[ eB dL  dM    Z\ e$ dN d e" d dO Z] e- dP  dQ    Z^ e$ dN d e" d e dR  Z_ eB dS  dT    Z` eJ e$   d e" d dU Za eb dV    Zc eJ e$   d e dW  Zd e dX  dY    Ze eJ e$   d e" d e dZ  Zf eb d[    Zg eJ e$   d e" d e d\  Zh eJ e$   d e" d e d]  Zi eb d^    Zj e$ d d e" d d_ Zk e$ d d e" d d` Zl e da  db    Zm eB da  dc    Zn e$ dd d e" d e de  Zo eB df  dg    Zp e  e" d e" d dh Zq er di es dj e d e" d e dk   Zt er di e d e" d e dl   Zu er di ev d e" d e dm   Zw er di ex d e" d e dn   Zy ez e do e" Z{ er di e d e" d dp  Z| er di e} dj e~ j d e" d e dq   Z er di e dj e~ j d e" d e dr   Z e  e! d e" d e ds  Z e$   Z e dt  du    Z e$   Z e dv  dw    Z e$ dx d e" d e dy  Z eB dz  d{    Z e$ d e" d e d|   Z e d}  d~    Z e- d}  d    Z eB d}  d    Z eJ e$   d e" d e d  Z eB d  d    Z e i  d e" d e d  Z e  e! d e" d e d  Z e d d e" d e d  Z e d d e" d e d  Z e d d e" d e d  Z e0 d d e" d d Z e  e" d e" d e d  Z d d  Z d   Z d   Z d   Z eb d    Z eb d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z e d d   Z d   Z e" d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s   jupyter-notebooks   The Jupyter HTML Notebook.
    
    This launches a Tornado based HTML Notebook Server that serves up an HTML5/Javascript Notebook client.R   i    t   stopR   t	   log_levelc         C@ s   t  j S(   N(   t   loggingt   INFO(   RY   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _default_log_levelG  s    t   log_datefmtc         C@ s   d S(   s%   Exclude date from default date formats   %H:%M:%S(    (   RY   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _default_log_datefmtK  s    t
   log_formatc         C@ s   d S(   s+   override default log format to include timeuV   %(color)s[%(levelname)1.1s %(asctime)s.%(msecs).03d %(name)s]%(end_color)s %(message)s(    (   RY   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _default_log_formatP  s    R   R   sX   Deprecated: Use minified JS file or not, mainly use during dev to avoid JS recompilationRr   s   Set the Access-Control-Allow-Origin header
        
        Use '*' to allow any origin to access your server.
        
        Takes precedence over allow_origin_pat.
        sL  Use a regular expression for the Access-Control-Allow-Origin header
        
        Requests from an origin matching the expression will get replies with:
        
            Access-Control-Allow-Origin: origin
        
        where `origin` is the origin of the request.
        
        Ignored if allow_origin is set.
        s5   Set the Access-Control-Allow-Credentials: true headers6   Whether to allow the user to run the notebook as root.s   /trees'   The default URL to redirect to from `/`t	   localhosts2   The IP address the notebook server will listen on.R  c         C@ sb   t  j    } y | j d  Wn0 t  j k
 rO } |  j j t d  |  d SX| j   d Sd S(   s   Return localhost if available, 127.0.0.1 otherwise.
        
        On some (horribly broken) systems, localhost cannot be bound.
        R&  i    s:   Cannot bind to localhost, using 127.0.0.1 as default ip
%ss	   127.0.0.1N(   R&  i    (   t   sockett   bindt   errorRa   R   R   t   close(   RY   t   st   e(    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _default_ip  s    
c         C@ s#   | d } | d k r d } n  | S(   Nt   valueu   *u    (    (   RY   t   proposalR.  (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _valdate_ip  s    
	u    s  Override URL shown to users.

        Replace actual URL, including protocol, address, port and base URL,
        with the given value when displaying URL to the users. Do not change
        the actual connection URL. If authentication token is enabled, the
        token is added to the custom URL automatically.

        This option is intended to be used when the URL to display to the user
        cannot be determined reliably by the Jupyter notebook server (proxified
        or containerized setups for example).i"  s,   The port the notebook server will listen on.i2   sM   The number of additional ports to try if the specified port is not available.s-   The full path to an SSL/TLS certificate file.s;   The full path to a private key file for usage with SSL/TLS.sW   The full path to a certificate authority certificate for SSL/TLS client authentication.s+   The file where the cookie secret is stored.t   cookie_secret_filec         C@ s   t  j j |  j d  S(   Nt   notebook_cookie_secret(   R   R   R   R  (   RY   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _default_cookie_secret_file  s    s  The random bytes used to secure cookies.
        By default this is a new random number every time you start the Notebook.
        Set it to a value in a config file to enable logins to persist across server sessions.

        Note: Cookie secrets should be kept private, do not share config files with
        cookie_secret stored in plaintext (you can read the value from a file).
        R   c         C@ s   t  j j |  j  rB t j |  j d   } | j   } Wd  QXn" t t  j d   } |  j	 |  t
 j | d t j } | j |  j j    | j   S(   Nt   rbi    t	   digestmod(   R   R   R   R1  t   iot   opent   readR   t   urandomt   _write_cookie_secret_filet   hmact   newt   hashlibt   sha256R   R   t   encodet   digest(   RY   t   ft   keyt   h(    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _default_cookie_secret  s    c         C@ s   |  j  j t d  |  j  y/ t j |  j d   } | j |  Wd QXWn2 t k
 r } |  j  j t d  |  j |  n Xy t	 j
 |  j d  Wn- t k
 r |  j  j t d  |  j  n Xd S(   s!   write my secret to my secret_files+   Writing notebook server cookie secret to %st   wbNs'   Failed to write cookie secret to %s: %si  s   Could not set permissions on %s(   Ra   R   R   R1  R6  R7  t   writet   OSErrorR)  R   t   chmodR   (   RY   t   secretRA  R,  (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR:    s    		s   <generated>s  Token used for authenticating first-time connections to the server.

        When no password is enabled,
        the default is to generate a new, random token.

        Setting to an empty string disables authentication altogether, which is NOT RECOMMENDED.
        R   c         C@ sg   t  j d  r% t |  _ t  j d  S|  j r; t |  _ d St |  _ t j t  j d   j	 d  Sd  S(   Nt   JUPYTER_TOKENu    i   t   ascii(
   R   t   getenvR   t   _token_generatedR   R   t   binasciit   hexlifyR9  t   decode(   RY   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _token_default  s    				i   i   sF  
        Sets the maximum allowed size of the client request body, specified in 
        the Content-Length request header field. If the size in a request 
        exceeds the configured value, a malformed HTTP message is returned to
        the client.

        Note: max_body_size is applied even in streaming mode.
        s   
        Gets or sets the maximum amount of memory, in bytes, that is allocated 
        for use by the buffer manager.
        c         C@ s   t  |  _ d  S(   N(   R   RM  (   RY   t   change(    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _token_changed  s    s   Hashed password to use for web authentication.

                      To generate, type in a python/IPython shell:

                        from notebook.auth import passwd; passwd()

                      The string should be of the form type:salt:hashed-password.
                      s  Forces users to use a password for the Notebook server.
                      This is useful in a multi user environment, for instance when
                      everybody in the LAN can access each other's machine through ssh.

                      In such a case, server the notebook server on localhost is not secure
                      since any user can connect to the notebook server via ssh.

                      s  Allow password to be changed at login for the notebook server. 

                    While loggin in with a token, the notebook server UI will give the opportunity to
                    the user to enter a new password at the same time that will replace
                    the token login mechanism. 

                    This can be set to false to prevent changing password from the UI/API.
                    s:  Disable cross-site-request-forgery protection

        Jupyter notebook 4.3.1 introduces protection from cross-site request forgeries,
        requiring API requests to either:

        - originate from pages served by this server (validated with XSRF cookie and token), or
        - authenticate with a token

        Some anonymous compute resources still desire the ability to run code,
        completely without authentication.
        These services can disable all authentication and security checks,
        with the full knowledge of what that implies.
        sj  Allow requests where the Host header doesn't point to a local server

       By default, requests get a 403 forbidden response if the 'Host' header
       shows that the browser thinks it's on a non-local domain.
       Setting this option to True disables this check.

       This protects against 'DNS rebinding' attacks, where a remote web server
       serves you a page and then changes its DNS to send later requests to a
       local IP, bypassing same-origin checks.

       Local IP addresses (such as 127.0.0.1 and ::1) are allowed as local,
       along with hostnames configured in local_hostnames.
       R   c         C@ s   y t  j |  j  } Wn t k
 r x t j |  j |  j d t j  D] } | d d } t j	 sw | j
 d  } n  y  t  j | j d  d  } Wn' t k
 r |  j j d |  qH n X| j p d | k o | j sH t SqH Wt SX| j Sd S(   sD   Disallow remote access if we're listening only on loopback addressesi    i   RK  t   %s   Unrecognised IP address: %rN(   t	   ipaddresst
   ip_addressR  t
   ValueErrorR'  t   getaddrinfoRJ   t   SOCK_STREAMR:   t   PY3RP  t   splitRa   R   t   is_loopbackt   is_link_localR   R   (   RY   t   addrR   t   parsed(    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _default_allow_remote\  s"    (	 	s   Hostnames to allow as local when allow_remote_access is False.

       Local IP addresses (such as 127.0.0.1 and ::1) are automatically accepted
       as local as well.
       sp  Whether to open in a browser after starting.
                        The specific browser used is platform dependent and
                        determined by the python standard library `webbrowser`
                        module, unless it is overridden using the --browser
                        (NotebookApp.browser) configuration option.
                        sl  Specify what command to use to invoke a web
                      browser when opening the notebook. If not specified, the
                      default browser will be determined by the `webbrowser`
                      standard library module, which allows setting of the
                      BROWSER environment variable to override it.
                      i   s  Specify Where to open the notebook on startup. This is the
        `new` argument passed to the standard library method `webbrowser.open`.
        The behaviour is not guaranteed, but depends on browser support. Valid
        values are:

         - 2 opens a new tab,
         - 1 opens a new window,
         - 0 opens in an existing window.

        See the `webbrowser.open` documentation for details.
        s    DEPRECATED, use tornado_settingst   webapp_settingsc         C@ s'   |  j  j t d   | d |  _ d  S(   Ns:   
    webapp_settings is deprecated, use tornado_settings.
R<  (   Ra   R   R   t   tornado_settings(   RY   RR  (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _update_webapp_settings  s    sP   Supply overrides for the tornado.web.Application that the Jupyter notebook uses.sq  
        Set the tornado compression options for websocket connections.

        This value will be returned from :meth:`WebSocketHandler.get_compression_options`.
        None (default) will disable compression.
        A dict (even an empty one) will enable compression.

        See the tornado docs for WebSocketHandler.get_compression_options for details.
        sH   Supply overrides for terminado. Currently only supports "shell_command".si   Extra keyword arguments to pass to `set_secure_cookie`. See tornado's set_secure_cookie docs for details.si   Extra keyword arguments to pass to `get_secure_cookie`. See tornado's get_secure_cookie docs for details.s\   Supply SSL options for the tornado HTTPServer.
            See the tornado docs for details.s@   Supply extra arguments that will be passed to Jinja environment.s<   Extra variables to supply to jinja templates when rendering.sk  Whether to enable MathJax for typesetting math/TeX

        MathJax is the javascript library Jupyter uses to render math/LaTeX. It is
        very large, so you may want to disable it if you have a slow internet
        connection, or for offline use of the notebook.

        When disabled, equations etc. will appear as their untransformed TeX source.
        R  c         C@ s   | d s d |  _  n  d S(   s/   set mathjax url to empty if mathjax is disabledR<  u    N(   R   (   RY   RR  (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _update_enable_mathjax  s    
R   s   The base URL for the notebook server.

                               Leading and trailing slashes can be omitted,
                               and will automatically be added.
                               Rb   c         C@ sF   | d } | j  d  s& d | } n  | j d  sB | d } n  | S(   NR.  R   (   R   t   endswith(   RY   R/  R.  (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _update_base_url  s    
s   DEPRECATED use base_urlt   base_project_urlc         C@ s'   |  j  j t d   | d |  _ d  S(   Ns,   base_project_url is deprecated, use base_urlR<  (   Ra   R   R   Rb   (   RY   RR  (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _update_base_project_url  s    s   Extra paths to search for serving static files.
        
        This allows adding javascript/css to be available from the notebook server machine,
        or overriding individual files in the IPythonc         C@ s   |  j  t g S(   s)   return extra paths + the default location(   t   extra_static_pathsR   (   RY   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR     s    s!   Path to search for custom.js, cssRv   c         C@ s/   g  |  j  t f D] } t j j | d  ^ q S(   NR{   (   R   R   R   R   R   (   RY   t   d(    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _default_static_custom_path  s    sv   Extra paths to search for serving jinja templates.

        Can be used to override templates from notebook.templates.c         C@ s   |  j  t S(   s*   return extra paths + the default locations(   t   extra_template_pathsR   (   RY   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR     s    s6   extra paths to look for Javascript notebook extensionssK   handlers that should be loaded at higher priority than the default servicesc         C@ s^   |  j  t d  } y d d l m } Wn t k
 r: n  X| j t j j |   d   | S(   s3   The path to look for Javascript notebook extensionst   nbextensionsi    (   t   get_ipython_dir(	   t   extra_nbextensions_pathR<   t   IPython.pathsRn  t   ImportErrorR   R   R   R   (   RY   R   Rn  (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR     s    s   The base URL for websockets,
        if it differs from the HTTP server (hint: it almost certainly doesn't).
        
        Should be in the form of an HTTP origin: ws[s]://hostname[:port]
        s   A custom url for MathJax.js.
        Should be in the form of a case-sensitive url to MathJax,
        for example:  /static/components/MathJax/MathJax.js
        R   c         C@ s5   |  j  s d S|  j j d d  } t | d d d  S(   Nu    Rx   Rz   t
   componentst   MathJaxs
   MathJax.js(   R  Rb  R   R@   (   RY   Rx   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _default_mathjax_url;  s    	c         C@ sC   | d } | r& |  j  r& d |  _ n |  j j t d  |  d  S(   NR<  u    s   Using MathJax: %s(   R  R   Ra   R   R   (   RY   RR  R<  (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _update_mathjax_urlB  s    
s   TeX-AMS-MML_HTMLorMML-full,Safes5   The MathJax.js configuration file that is to be used.R   c         C@ s!   |  j  j t d  | d  d  S(   Ns$   Using MathJax configuration file: %sR<  (   Ra   R   R   (   RY   RR  (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _update_mathjax_configO  s    sZ   If True, display a button in the dashboard to quit
        (shutdown the notebook server).t   default_valuet   klasss"   The notebook manager class to use.s    The kernel manager class to use.s!   The session manager class to use.s   The config manager class to uset
   allow_nones  
        The kernel spec manager class to use. Should be a subclass
        of `jupyter_client.kernelspec.KernelSpecManager`.

        The Api of KernelSpecManager is provisional and might change
        without warning between this version of Jupyter and the next stable one.
        s   The login handler class to use.s    The logout handler class to use.s   Whether to trust or not X-Scheme/X-Forwarded-Proto and X-Real-Ip/X-Forwarded-For headerssent by the upstream reverse proxy. Necessary if the proxy handles SSLt	   info_filec         C@ s&   d t  j   } t  j j |  j |  S(   Ns   nbserver-%s.json(   R   t   getpidR   R   R  (   RY   Rz  (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _default_info_file  s    t   browser_open_filec         C@ s&   d t  j   } t  j j |  j |  S(   Ns   nbserver-%s-open.html(   R   R{  R   R   R  (   RY   t   basename(    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _default_browser_open_file  s    t   disableds[   
        DISABLED: use %pylab or %matplotlib in the notebook to enable matplotlib.
        R  c         C@ sm   | d d k r! d | d } n d } |  j  j t d   |  j  j t d  j |   |  j d  d S(	   s5   when --pylab is specified, display a warning and exitR<  R   s    %sRr   sD   Support for specifying --pylab on the command line has been removed.sB   Please use `%pylab{0}` or `%matplotlib{0}` in the notebook itself.i   N(   Ra   R)  R   R  R  (   RY   RR  t   backend(    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _update_pylab  s    	s/   The directory to use for notebooks and kernels.R  c         C@ s6   |  j  r( t j j t j j |  j    St j   Sd  S(   N(   t   file_to_runR   R   t   dirnamet   abspathR:   t   getcwd(   RY   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _default_notebook_dir  s    	c         C@ s   | d } t  j j |  \ } } | t  j k r5 | S| j t  j  } t  j j |  sn t  j j |  } n  t  j j |  s t t	 j
 d  |   n  | S(   NR.  s   No such notebook dir: '%r'(   R   R   t
   splitdriveR   t   rstript   isabsR  t   isdirR4   R   R   (   RY   R/  R.  R   R   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _notebook_dir_validate  s    
c         C@ s,   | d } | |  j  j _ | |  j  j _ d S(   s+   Do a bit of validation of the notebook dir.R<  N(   R   R   R   R   (   RY   RR  R<  (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _update_notebook_dir  s    
s3   DEPRECATED use the nbserver_extensions dict insteadt   server_extensionsc         C@ s'   |  j  j t d   | d |  _ d  S(   Ns8   server_extensions is deprecated, use nbserver_extensionsR<  (   Ra   R   R   R  (   RY   RR  (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _update_server_extensions  s    s   Dict of Python modules to load as notebook server extensions.Entry values can be used to enable and disable the loading ofthe extensions. The extensions will be loaded in alphabetical order.s9   Reraise exceptions encountered loading server extensions?i  sg   (msgs/sec)
        Maximum rate at which messages can be sent on iopub before they are
        limited.i@B sm   (bytes/sec)
        Maximum rate at which stream output can be sent on iopub before they are
        limited.i   sJ   (sec) Time window used to 
        check the message and data rate limits.sc  Shut down the server after N seconds with no kernels or terminals running and no activity. This can be used together with culling idle kernels (MappingKernelManager.cull_idle_timeout) to shutdown the notebook server when it's not in use. This is not precisely timed: it may shut down up to a minute later. 0 (the default) disables this automatic shutdown.s/  Set to False to disable terminals.

         This does *not* make the notebook server more secure by itself.
         Anything the user can in a terminal, they can also do in a notebook.

         Terminals may also be automatically disabled if the terminado package
         is not available.
         c         C@ s   t  t |   j |  |  j r |  j d } t j j |  } |  j j |  t j j	 |  s |  j
 j t d  |  |  j d  n  t   } t j j |  r | | j _ n! t j j |  r | | j _ n  |  j |  n  d  S(   Ni    s   No such file or directory: %si   (   RW   R  R   R   R   R   R  R   t   removeR   Ra   t   criticalR   R  R   R  R  t   isfileR  t   update_config(   RY   R   t   arg0RA  t   c(    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR     s    		c      	   C@ s   |  j  d |   |  _ |  j d |  d |  j d |  j d |  j  |  _ |  j d |  d |  j  |  _ |  j d |  d |  j d |  j d |  j  |  _	 |  j
 d |  d |  j  |  _ d  S(   Nt   parentRa   t   connection_dirR^   R[   R\   (   t   kernel_spec_manager_classR^   t   kernel_manager_classRa   R  R[   t   contents_manager_classR\   t   session_manager_classR]   t   config_manager_classR_   (   RY   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   init_configurables   s$    									c         C@ sp   t  |  j _ x& t t t f D] } |  j j | _ q Wt j d  } t	 | _ |  j | _
 | j |  j j  d  S(   Nt   tornado(   R   Ra   t	   propagateR   R   R   RQ   R  t	   getLoggerR   R  t   setLevelt   level(   RY   Ra   t   logger(    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   init_logging9  s    	c         C@ sz  |  j  |  j d <|  j |  j d <|  j rE t j |  j  |  j d <n  |  j |  j d <|  j |  j d <|  j |  j d <|  j	 |  j d <|  j
 j |  j  s t |  j |  j
  |  _
 n  |  j r|  j r|  j j t d   |  j j t d	   |  j j t d
   t j d  n  t |  |  j |  j |  j |  j |  j |  j |  j |  j |  j
 |  j |  j  |  _ |  j } |  j r|  j | d <n  |  j  r|  j  | d <n  |  j! r|  j! | d <n  | sd } nG d d l# } | j$ d | j%  | j& d t'  r| j$ d | j(  n  |  j) j* |  d | t+ j, |  j d | d |  j- d |  j. d |  j/ |  _0 d } x t1 |  j2 |  j3 d  D] } y |  j0 j4 | |  j5  Wn t6 j7 k
 r5} | j8 t8 j9 k r|  j j: t d  |  qqF| j8 t8 j; t< t8 d t8 j;  f k r/|  j j= t d  |  qqF  qX| |  _2 t> } PqW| sv|  j j t d   |  j d  n  d S(   s(   initialize tornado webapp and httpservert   allow_origint   websocket_compression_optionst   allow_origin_patt   allow_credentialst   cookie_optionst   get_secure_cookie_kwargsR   s?   Notebook servers are configured to only be run with a password.s1   Hint: run the following command to set a passwords#   	$ python -m notebook.auth passwordi   R  R  t   ca_certsi    Nt   ssl_versiont	   cert_reqst   ssl_optionst   xheaderst   max_body_sizet   max_buffer_sizes3   The port %i is already in use, trying another port.t	   WSAEACCESs&   Permission to listen on port %i deniedsY   ERROR: the notebook server could not be started because no available port could be found.(?   R  Rb  R  R  t   ret   compileR  R  R  R   Rc   R   Rb   R@   t   password_requiredR   Ra   R  R   R   R  RT   R[   R\   R]   R^   R_   R`   t   jinja_environment_optionst   web_appR  R  R  t	   client_caR   t   sslt
   setdefaultt   PROTOCOL_TLSv1R   R   t   CERT_REQUIREDR   t   validate_securityR	   t
   HTTPServert   trust_xheadersR  R  t   http_serverRM   RJ   t   port_retriest   listenR  R'  R)  t   errnot
   EADDRINUSER   t   EACCESt   getattrR   R   (   RY   R  R  t   successRJ   R,  (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   init_webappH  sr    								 '	c         C@ s   |  j  r1 |  j  } | j d  sk | d 7} qk n: |  j d k rS d t j   } n	 |  j } |  j |  } |  j r |  j r |  j n d } t | i | d 6 } n  | S(   NR   Rr   s   0.0.0.0s   (%s or 127.0.0.1)s   ...R   (   Rr   s   0.0.0.0(	   t   custom_display_urlRe  R  R'  t   gethostnamet   _urlR   RM  R   (   RY   R   R  R   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   display_url  s    				c         C@ s%   |  j  r |  j  n d } |  j |  S(   NR&  (   R  R  (   RY   R  (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   connection_url  s    c         C@ s/   |  j  r d n d } d | | |  j |  j f S(   Nt   httpst   https   %s://%s:%i%s(   R  RJ   Rb   (   RY   R  t   proto(    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR    s    c         C@ s   |  j  s d  SyC d d l m } | |  j |  j |  j |  j  t |  j j d <Wn, t	 k
 r~ } |  j
 j t d  |  n Xd  S(   Ni   (   t
   initializeR   s&   Terminals not available (error was %s)(   t   terminals_enabledt   terminalR  R  R  R  t   terminado_settingsR   Rf   Rq  Ra   R   R   (   RY   R  R,  (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   init_terminals  s    	c         C@ s   t  j j d  rD t  j rD t  j j   rD t j t j |  j  n  t j t j |  j	  t
 t d  r t j t j |  j  n  t
 t d  r t j t j |  j  n  d  S(   NR   t   SIGUSR1t   SIGINFO(   R   R   R   t   stdint   isattyR   t   SIGINTt   _handle_sigintR   t   _signal_stopt   hasattrR  t   _signal_infoR  (   RY   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   init_signal  s    +c         C@ sB   t  j  t  j |  j  t j d |  j  } t | _ | j   d S(   s)   SIGINT handler spawns confirmation dialogt   targetN(	   R   R  R  t	   threadingt   Threadt   _confirm_exitR   t   daemonR   (   RY   t   sigt   framet   thread(    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR    s    	c         C@ s   t  j  t  j |  j  d S(   s.   callback for restoring original SIGINT handlerN(   R   R  R  (   RY   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _restore_sigint_handler  s    c         C@ sD  |  j  j } | t d   t |  j    t d  } t d  } t j j t d  | | f  t j j   t	 j	 t j
 g g  g  d  \ } } } | rt j
 j   } | j   j |  r| | j   k r|  j  j t d   |  j j |  j j  d Sn t t d  d	 d
 t t d   |  j j |  j  d S(   s   confirm shutdown on ^C
        
        A second ^C, or answering 'y' within 5s will cause shutdown,
        otherwise original SIGINT handler will be restored.
        
        This doesn't work on Windows.
        t   interruptedt   yRK   s)   Shutdown this notebook server (%s/[%s])? i   s   Shutdown confirmedNs   No answer for 5s:t   endt    s   resuming operation...(   Ra   R   R   R  t   notebook_infoR   t   stdoutRF  t   flusht   selectR  t   readlinet   lowerR   R  t   io_loopt   add_callback_from_signalR  R  (   RY   R   t   yest   not   rt   wt   xt   line(    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR    s"     ''c         C@ s3   |  j  j t d  |  |  j j |  j j  d  S(   Ns   received signal %s, stopping(   Ra   R  R   R  R  R  (   RY   R  R  (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR    s    c         C@ s   t  |  j    d  S(   N(   R  R  (   RY   R  R  (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR    s    c         C@ s   d S(   s8   Check the components submodule, and warn if it's uncleanN(    (   RY   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   init_components  s    c   	      C@ s  x0 |  j  D]% } | |  j k r
 t |  j | <q
 q
 Wt   } |  j | k ra | j d |  j  n  t d |  } | j |  j  } | j d i   j d i   } x6 |  j j	   D]% \ } } | | k r | | | <q q Wx t
 | j	    D] \ } } | r y> t j |  } t | d d  } | d k	 r;| |   n  Wqt k
 r}|  j r[  n  |  j j t d  | d t qXq q Wd S(	   s   Load any extensions specified by config.

        Import the module, then call the load_jupyter_server_extension function,
        if one exists.
        
        The extension API is experimental, and may change in future releases.
        i    t   read_config_pathR  t   nbserver_extensionst   load_jupyter_server_extensions!   Error loading server extension %st   exc_infoN(   R  R  R   R%   R   t   insertR   R   t   config_file_namet   itemst   sortedt	   importlibt   import_moduleR  R   t	   Exceptiont!   reraise_server_extension_failuresRa   R   R   (	   RY   t
   modulenamet   config_patht   managert   sectionRk   t   enabledRR   t   func(    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   init_server_extensions  s0    
		c         C@ s$   t  j d d  t  j d d  d  S(   Ns   text/csss   .csss   application/javascripts   .js(   t	   mimetypest   add_type(   RY   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   init_mime_overrides.  s    c         C@ s   |  j  } t |  d k r d Sy |  j j d } Wn t k
 rF n X| j rT d St   |  j j   j   } |  j	 j
 d |  | |  j k r |  j	 j d |  |  j   n  d S(   sB   Shutdown server on timeout when there are no kernels or terminals.i    Nt   terminal_managers   No activity for %d seconds.s6   No kernels or terminals for %d seconds; shutting down.(   R[   R   R  Rf   R   t	   terminalsR>   R   t   total_secondsRa   R   t   shutdown_no_activity_timeoutR   R  (   RY   t   kmt   term_mgrt   seconds_since_active(    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   shutdown_no_activity8  s     		c         C@ sK   |  j  d k rG |  j j d |  j   t j |  j d  } | j   n  d  S(   Ni    s=   Will shut down after %d seconds with no kernels or terminals.i`  (   R  Ra   R   R   t   PeriodicCallbackR  R   (   RY   t   pc(    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   init_shutdown_no_activityO  s
    
c         C@ s   t  t |   j |  |  j   |  j r- d  S|  j   |  j   |  j   |  j   |  j	   |  j
   |  j   |  j   d  S(   N(   RW   R  R  R  t   _dispatchingR  R  R  R  R  R  R  R  (   RY   R   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR  V  s    
	






c         C@ sO   t  |  j j    } t j d d |  } |  j j | |  |  j j   d S(   s   Shutdown all kernels.
        
        The kernels will shutdown themselves when this process no longer exists,
        but explicit shutdown allows the KernelManagers to cleanup the connection files.
        s   Shutting down %d kernels   Shutting down %d kernelsN(   R   R[   t   list_kernel_idsR   t   ngettextRa   R   t   shutdown_all(   RY   t	   n_kernelst
   kernel_msg(    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   cleanup_kernelse  s    c         C@ sy   |  j  j   d } | r^ t |  j j    } t j d d |  } | | | 7} | d 7} n  | t d  |  j 7} | S(   sC   Return the current working directory and the server url informations   
s   %d active kernels   %d active kernelss&   The Jupyter Notebook is running at:
%s(	   R\   t   info_stringR   R[   R  R   R  R   R  (   RY   t   kernel_countR   R!  R"  (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR  p  s    c         C@ s   i	 |  j  d 6|  j r |  j n d d 6|  j d 6t |  j  d 6|  j d 6|  j d 6t j j	 |  j
  d 6t |  j  d	 6t j   d
 6S(   s8   Return a JSONable dict of information about this server.R   R&  t   hostnameRJ   t   secureRb   R   R  R   R   (   R  R  RJ   t   boolR  Rb   R   R   R   R  R  R   R{  (   RY   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR   |  s    


c         C@ sz   yA t  |  j d  ) } t j |  j   | d d d t Wd QXWn2 t k
 ru } |  j j t	 d  |  j |  n Xd S(   s=   Write the result of server_info() to the JSON file info_file.R  R  i   t	   sort_keysNs%   Failed to write server-info to %s: %s(
   R7  Rz  R  t   dumpR   R   RG  Ra   R)  R   (   RY   RA  R,  (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   write_server_info_file  s    ,c         C@ sF   y t  j |  j  Wn+ t k
 rA } | j t j k rB   qB n Xd S(   s   Remove the nbserver-<pid>.json file created for this server.

        Ignores the error raised when the file has already been removed.
        N(   R   t   unlinkRz  RG  R  t   ENOENT(   RY   R,  (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   remove_server_info_file  s
    c         C@ sN   |  j  t |  j  } t j |  j d d d  } |  j | |  Wd QXd S(   sk   Write an nbserver-<pid>-open.html file

        This can be used to open the notebook in a browser
        R  t   encodings   utf-8N(   Rc   R   Rb   R6  R7  R}  t   _write_browser_open_file(   RY   t   open_urlRA  (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   write_browser_open_file  s    c         C@ ss   |  j  r% t | i |  j  d 6 } n  t |  j |  } |  j j d } | j d  } | j | j d |   d  S(   NR   R   s   browser-open.htmlR1  (	   R   R   R@   R  R  Rf   t   get_templateRF  t   render(   RY   R   t   fhR   t   template(    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR0    s    	c         C@ sF   y t  j |  j  Wn+ t k
 rA } | j t j k rB   qB n Xd S(   s   Remove the nbserver-<pid>-open.html file created for this server.

        Ignores the error raised when the file has already been removed.
        N(   R   R,  R}  RG  R  R-  (   RY   R,  (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   remove_browser_open_file  s
    c         @ sj  y t  j  j p d     Wn6 t  j k
 rT }  j j t d  |  d    n X  s_ d  S j r2t	 j
 j  j  s  j j t d   j   j d  n  t	 j
 j  j  j  } t t d | j t	 j    } t j d d  \ }  t j | d d d	  }  j | |  Wd  QXn	  j      f d
   } t j d |  j   d  S(   Ns   No web browser found: %s.s   %s does not existi   t	   notebookst   suffixs   .htmlR  R/  s   utf-8c           @ s%     j  t d t    d  j S(   Ns   file:R<  (   R7  RC   RD   t   webbrowser_open_new(    (   R  t	   open_fileRY   (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   <lambda>  s   R  (   t
   webbrowserR   R  R   t   ErrorRa   R   R   R  R   R   R   R  R  t   relpathR  RB   R@   R[  R   t   tempfilet   mkstempR6  R7  R0  R}  R  R  R   (   RY   R,  R?  t   urit   fdR5  t   b(    (   R  R;  RY   s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   launch_browser  s&    
	!	c      	   C@ s  t  t |   j   |  j s{ y t j   } Wn t k
 rE d } n X| d k r{ |  j j t	 d   |  j
 d  q{ n  |  j j } x- |  j d t  j d  D] } | |  q W| t	 d   d t j k r | t	 d	   n  |  j   |  j   |  j s|  j r|  j   n  |  j rv|  j rv|  j j d j d d
 d t d t |  j   d d |  j g   n  t j j   |  _  t! j" j# d  rt j$ d   d  } | j   n  z9 y |  j  j   Wn! t% k
 r| t	 d   n XWd |  j&   |  j'   |  j(   Xd S(   s    Start the Notebook server app, after initialization
        
        This method takes no arguments so all configuration and initialization
        must be done prior to calling this method.ii    s?   Running as root is not recommended. Use --allow-root to bypass.i   R%  s   
sY   Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).t   devs   Welcome to Project Jupyter! Explore the various tools available and their corresponding documentation. If you are interested in contributing to the platform, please visit the communityresources section at https://jupyter.org/community.html.s4   To access the notebook, open this file in a browser:s       %ss   file:s$   Or copy and paste one of these URLs:R   c           S@ s   d  S(   N(   R   (    (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR<    Rr   i  s   Interrupted...N()   RW   R  R   R  R   t   geteuidt   AttributeErrorRa   R  R   R  R   R  R   R[  t   notebookR   R+  R2  R  R  RE  R   RM  R   RC   RD   R}  R  R   t   IOLoopt   currentR  R   R   R   R  t   KeyboardInterruptR.  R7  R#  (   RY   t   uidR   R  R  (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR     sL    	
"

 

c         @ s#     f d   }   j  j |  d  S(   Nc           @ s     j  j     j j   d  S(   N(   R  R  R  (    (   RY   (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   _stop  s    (   R  t   add_callback(   RY   RN  (    (   RY   s3   lib/python2.7/site-packages/notebook/notebookapp.pyR    s    i   i    i   i    N(   R   R   RQ   R   R  R   R   t	   _examplest   examplest   aliasesR  R&   R*   R   R   R   R+   R'   t   classesR-   R   R	  t
   splitlinesR   R   t   subcommandsR   t   _log_formatter_clsR8   R!  R#  R%  R1   R   R   R~   R.   R  R  R  R  R  Rc   R  R-  R9   R0  R  R/   RJ   R  R  R  R  R1  R3  R2   R   RD  R:  t   tagR   RM  RQ  R  R  R7   RS  R   R  R   R   R   R`  R0   R   R  R  R:  Ra  Rc  Rb  R,   R   R  R  R  R  R  R  R   R  Rd  Rb   Rf  Rg  Rh  Ri  t   propertyR   Rv   Rk  Rl  R   Ro  R`   R   R   R   Rt  Ru  R   Rv  R   R5   R   R  R  R   R  R   R  R3   R^   R  R   R
   t   RequestHandlerR   R   R   R  Rz  R|  R}  R  R  R  R  R  R  R  R  R  R  R  R6   R   R   R   R  R  R   R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R    R  R#  R  R   R+  R.  R2  R0  R7  RE  R   R  (    (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR  ,  s  						
																
																			J				
		!				0	
													<c         c@ s   |  d k r t   }  n  t j j |   s. d Sx t j |   D] } t j d |  r> t j	 t j j
 |  |  d d  } t j |  } Wd QXd | k r t | d  r | Vq y  t j t j j
 |  |   Wq t k
 r q Xq> q> Wd S(   s  Iterate over the server info files of running notebook servers.
    
    Given a runtime directory, find nbserver-* files in the security directory,
    and yield dicts of their information, each one pertaining to
    a currently running notebook server instance.
    Ns   nbserver-(.+).jsonR/  s   utf-8R   (   R   R;   R   R   R  t   listdirR  t   matchR6  R7  R   R  t   loadRA   R,  RG  (   R  t	   file_nameRA  R   (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyR    s    ' (   R   t
   __future__R    R   RI  RN  R   R  R   R=  R;  R  R6  RU  R  R  R  R   RH   R  R  R   R'  R   R@  R  R   R   R=  t   base64R   Rq  R   t   jinja2R   R   t   notebook.transutilsR   R   t   zmq.eventloopR   t   installR  t   version_infoRH  R  R	   R
   t   tornado.httputilR   t   tornado.logR   R   R   R   R   R   R   t	   raw_inputt	   NameErrort   inputt   base.handlersR   R   Ra   R   t   services.kernels.kernelmanagerR   t   services.configR   t   services.contents.managerR   t   services.contents.filemanagerR   t"   services.contents.largefilemanagerR   t    services.sessions.sessionmanagerR   t
   auth.loginR   t   auth.logoutR   R   t   traitlets.configR   t   traitlets.config.applicationR    R!   t   jupyter_core.applicationR"   R#   R$   t   jupyter_core.pathsR%   t   jupyter_clientR&   t   jupyter_client.kernelspecR'   R(   R)   t   jupyter_client.sessionR*   t   nbformat.signR+   t	   traitletsR,   R-   R.   R/   R0   R1   R2   R3   R4   R5   R6   R7   R8   R9   t   ipython_genutilsR:   R;   R<   t   notebook._sysinfoR=   t   _tzR>   R?   t   utilsR@   RA   RB   RC   RD   RP  RM   RS   t   ApplicationRT   R   R   R   R   R	  R   R  R   R   R   RR  R  R  t   launch_instancet   maint   launch_new_instance(    (    (    s3   lib/python2.7/site-packages/notebook/notebookapp.pyt   <module>   s   
"

^(
			.!'
	    !