
]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 m Z m	 Z	 d d l
 m Z d d l m Z m Z m Z d d l m Z m Z d d l m Z m Z m Z 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" m# Z# m$ Z$ m% Z% m& Z& d
 d l' m( Z( d
 d l) m* Z* d
 d l+ m, Z, d e f d     YZ- i  Z. e. j/ e  e. j/ i d d 6d d 6d d 6d d 6d d 6d d 6d d 6d  d! 6 i  Z0 e0 j/ e  e0 j/ i i i e1 d" 6d# 6d$ f d% 6i i e1 d& 6d# 6d' f d( 6i i e1 d) 6d* 6d+ f d, 6i i d- d. 6d* 6d/ f d0 6i i e2 d1 6d2 d3 6d* 6i d4 d5 6d6 6d7 f d8 6i i e2 d1 6d2 d3 6d* 6i d4 d5 6d6 6i e1 d" 6d9 6d: f d; 6i i e1 d< 6e1 d= 6d> 6d? f d@ 6i i e1 d= 6e1 dA 6d> 6dB f dC 6 d* e f dD     YZ3 e3 j4 Z5 Z6 d S(E   su   NbConvert is a utility for conversion of .ipynb files.

Command-line interface for the NbConvert conversion utility.
i(   t   print_functionN(   t   fillt   dedent(   t   indent(   t
   JupyterAppt   base_aliasest
   base_flags(   t   catch_config_errort   Configurable(   t   Unicodet   Listt   Instancet   DottedObjectNamet   Typet   Boolt   defaultt   observe(   t   import_itemi   (   t   get_export_namest   get_exporter(   t	   exporterst   preprocessorst   writerst   postprocessorst   __version__(   t   NbConvertBase(   t   ConversionException(   t   unicode_stdin_streamt   DottedOrNonec           B  s   e  Z d  Z d Z d   Z RS(   sj   A string holding a valid dotted object name in Python, such as A.b3._c
    Also allows for None type.
    u    c         C  s?   | d  k	 r7 t |  d k r7 t t |   j | |  S| Sd  S(   Ni    (   t   Nonet   lent   superR   t   validate(   t   selft   objt   value(    (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pyR    ,   s    (   t   __name__t
   __module__t   __doc__t   default_valueR    (    (    (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pyR   &   s   s   NbConvertApp.export_formatt   tos   TemplateExporter.template_filet   templates   NbConvertApp.writer_classt   writers    NbConvertApp.postprocessor_classt   posts   NbConvertApp.output_baset   outputs   FilesWriter.build_directorys
   output-dirs    SlidesExporter.reveal_url_prefixs   reveal-prefixs!   NotebookExporter.nbformat_versiont   nbformatt   enabledt   ExecutePreprocessors%   Execute the notebook prior to export.t   executet   allow_errorss   Continue notebook execution even if one of the cells throws an error and include the error message in the cell output (the default behaviour is to abort conversion). This flag is only relevant if '--execute' was specified, too.s   allow-errorst
   from_stdint   NbConvertAppsg   read a single notebook file from stdin. Write the resulting notebook with default basename 'notebook.*'t   stdint   StdoutWritert   writer_classs1   Write notebook output to stdout instead of files.t   stdoutt   use_output_suffixt   notebookt   export_formatt    t   build_directoryt   FilesWritersu   Run nbconvert in place, overwriting the existing notebook (only 
        relevant when converting to notebook format)t   inplacet   ClearOutputPreprocessors\   Clear output of current file and save in place, 
        overwriting the existing notebook. s   clear-outputt   exclude_input_promptt   exclude_output_promptt   TemplateExporters9   Exclude input and output prompts from converted document.s	   no-promptt   exclude_inputs}   Exclude input cells and output prompts from converted document. 
        This mode is ideal for generating code-free reports.s   no-inputc           B  s  e  Z d  Z e Z d Z e Z e Z	 e
 d  d    Z e   Z e
 d  d    Z e d  Z e d d d	 j d
 e  Z e e d d j d
 e  Z e d d d j d
 e  Z e d j d e     Z e d d d d e Z e d d d j d
 e  Z i d d 6d d 6d d 6Z e d e  Z  e! d  d    Z" e d d d d e Z# e$ d d  j d
 e  Z% i d  d! 6Z& e d9 d e Z( e! d"  d#    Z) e d$ d d% j d
 e  Z* e d& d e+ d d' j d e    j d
 e  Z, e g  d d( j d
 e  Z- e e+ d d) j d
 e  Z. e/ d9 d*   Z0 d+   Z1 d,   Z2 d-   Z3 d.   Z4 d/   Z5 d0   Z6 d9 d1  Z7 d2   Z8 d3   Z9 d9 d4  Z: d5   Z; d6   Z< d7   Z= d8   Z> RS(:   sA   Application used to convert from notebook file type (``*.ipynb``)s   jupyter-nbconvertt	   log_levelc         C  s   t  j S(   N(   t   loggingt   INFO(   R!   (    (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pyt   _log_level_default   s    t   classesc         C  s~   t  g } xn t t t t f D]Z } xQ t |  D]C } t | |  } t | t  r/ t	 | t
  r/ | j |  q/ q/ Wq W| S(   N(   R   R   R   R   R   t   dirt   getattrt
   isinstancet   typet
   issubclassR   t   append(   R!   RH   t   pkgt   namet   cls(    (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pyt   _classes_default   s    	u   This application is used to convert notebook files (*.ipynb)
        to various other formats.

        WARNING: THE COMMANDLINE INTERFACE MAY CHANGE IN FUTURE RELEASES.R;   t   helps{   overwrite base name use for output files.
            can only be used when converting one notebook at a time.
            t   configs   Whether to apply a suffix prior to the extension (only relevant
            when converting to notebook format). The suffix is determined by
            the exporter, and is usually '.nbconvert'.s   {notebook_name}_filess   Directory to copy extra files (figures) to.
               '{notebook_name}' in the string will be converted to notebook
               basename.u  
        The simplest way to use nbconvert is
        
        > jupyter nbconvert mynotebook.ipynb
        
        which will convert mynotebook.ipynb to the default format (probably HTML).
        
        You can specify the export format with `--to`.
        Options include {formats}.
        
        > jupyter nbconvert --to latex mynotebook.ipynb

        Both HTML and LaTeX support multiple output templates. LaTeX includes
        'base', 'article' and 'report'.  HTML includes 'basic' and 'full'. You
        can specify the flavor of the format used.

        > jupyter nbconvert --to html --template basic mynotebook.ipynb
        
        You can also pipe the output to stdout, rather than a file
        
        > jupyter nbconvert mynotebook.ipynb --stdout

        PDF is generated via latex

        > jupyter nbconvert mynotebook.ipynb --to pdf
        
        You can get (and serve) a Reveal.js-powered slideshow
        
        > jupyter nbconvert myslides.ipynb --to slides --post serve
        
        Multiple notebooks can be given at the command line in a couple of 
        different ways:
  
        > jupyter nbconvert notebook*.ipynb
        > jupyter nbconvert notebook1.ipynb notebook2.ipynb
        
        or you can specify the notebooks list in a config file, containing::
        
            c.NbConvertApp.notebooks = ["my_notebook.ipynb"]
        
        > jupyter nbconvert --config mycfg.py
        t   formatss!   nbconvert.writers.base.WriterBases`   Instance of the writer class used to write the 
                      results of the conversion.t
   allow_noneR=   s]   Writer class used to write the 
                                    results of the conversions#   nbconvert.writers.files.FilesWritert   fileswriters#   nbconvert.writers.debug.DebugWritert   debugwriters%   nbconvert.writers.stdout.StdoutWritert   stdoutwriterR6   c         C  sH   | d } | j    |  j k r5 |  j | j    } n  t |  |  _ d  S(   Nt   new(   t   lowert   writer_aliasesR   t   writer_factory(   R!   t   changeRZ   (    (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pyt   _writer_class_changed   s    
s/   nbconvert.postprocessors.base.PostProcessorBasesf   Instance of the PostProcessor class used to write the
                      results of the conversion.sc   PostProcessor class used to write the
                                    results of the conversions1   nbconvert.postprocessors.serve.ServePostProcessort   servet   postprocessor_classc         C  sQ   | d } | j    |  j k r5 |  j | j    } n  | rM t |  |  _ n  d  S(   NRZ   (   R[   t   postprocessor_aliasesR   t   postprocessor_factory(   R!   R^   RZ   (    (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pyt   _postprocessor_class_changed   s
    
s   https://unpkg.com/s   URL base for ipywidgets packaget   htmls   The export format to be used, either one of the built-in formats
        {formats}
        or a dotted object name that represents the import path for an
        `Exporter` classs   List of notebooks to convert.
                     Wildcards are supported.
                     Filenames passed positionally will be added to the list.
                     s"   read a single notebook from stdin.c         C  sB   |  j    t t |   j |  |  j   |  j   |  j   d S(   s<   Initialize application, notebooks, writer, and postprocessorN(   t   init_syspathR   R3   t
   initializet   init_notebookst   init_writert   init_postprocessor(   R!   t   argv(    (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pyRg     s
    


c         C  s   t  j j d t j    d S(   s)   Add the cwd to the sys.path ($PYTHONPATH)i    N(   t   syst   patht   insertt   ost   getcwd(   R!   (    (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pyRf   !  s    c         C  s   |  j  r |  j  } n	 |  j } g  } x | D]x } t j |  } | j t j | d   | sv |  j j d |  n  x* | D]" } | | k r} | j |  q} q} Wq+ W| |  _ d S(   s   Construct the list of notebooks.

        If notebooks are passed on the command-line,
        they override (rather than add) notebooks specified in config files.
        Glob each notebook to replace notebook patterns with filenames.
        s   .ipynbs   pattern %r matched no filesN(   t
   extra_argst	   notebookst   globt   extendt   logt   warningRN   (   R!   t   patternst	   filenamest   patternt   globbed_filest   filename(    (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pyRh   %  s    
		c         C  s`   |  j  i |  j d 6 |  j d |   |  _ t |  j d  r\ |  j j d k r\ t |  _ n  d S(   s*   Initialize the writer (which is stateless)RZ   t   parentR<   R;   N(   R_   R6   R]   R*   t   hasattrR<   t   FalseR8   (   R!   (    (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pyRi   D  s    $c         C  s<   |  j  i |  j d 6 |  j r8 |  j d |   |  _ n  d S(   s1   Initialize the postprocessor (which is stateless)RZ   R|   N(   Rd   Ra   Rc   t   postprocessor(   R!   (    (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pyRj   K  s    	c         C  s!   t  t |   j   |  j   d S(   s4   Run start after initialization process has completedN(   R   R3   t   startt   convert_notebooks(   R!   (    (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pyR   Q  s    c         C  s   t  j j |  } | | j d   } |  j r t |  j d t  r t  j j |  j  \ } } | |  j j	 k r | |  _ q n  |  j } n  |  j
 j d |  i  } |  j | d <| | d <|  j j d |  } | | d <|  j | d <| S(	   s  Step 1: Initialize resources

        This initializes the resources dictionary for a single notebook.

        Returns
        -------

        dict
            resources dictionary for a single notebook that MUST include the following keys:
                - config_dir: the location of the Jupyter config directory
                - unique_key: the notebook name
                - output_files_dir: a directory where output files (not
                  including the notebook itself) should be saved
        t   .t   file_extensions   Notebook name is '%s't
   config_dirt
   unique_keyt   notebook_namet   output_files_dirt   ipywidgets_base_url(   Ro   Rm   t   basenamet   rfindt   output_baseRJ   t   exporterR~   t   splitextR   Ru   t   debugR   R   t   formatR   (   R!   t   notebook_filenameR   R   t   baset   extt	   resourcesR   (    (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pyt   init_single_notebook_resourcesV  s"    	
	
c         C  s   yO | d k	 r0 |  j j | d | \ } } n |  j j | d | \ } } Wn7 t k
 r |  j j d | d t |  j d  n X| | f S(   sU  Step 2: Export the notebook

        Exports the notebook to a particular format according to the specified
        exporter. This function returns the output and (possibly modified)
        resources from the exporter.

        Parameters
        ----------
        notebook_filename : str
            name of notebook file.
        resources : dict
        input_buffer :
            readable file-like object returning unicode.
            if not None, notebook_filename is ignored

        Returns
        -------
        output

        dict
            resources (possibly modified)
        R   s   Error while converting '%s't   exc_infoi   N(	   R   R   t	   from_filet   from_filenameR   Ru   t   errort   Truet   exit(   R!   R   R   t   input_bufferR,   (    (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pyt   export_single_notebook  s    !"c         C  sp   d | k r t  d   n  | d } |  j rQ |  j rQ | | j d d  7} n  |  j j | | d | } | S(   s  Step 3: Write the notebook to file

        This writes output from the exporter to file using the specified writer.
        It returns the results from the writer.

        Parameters
        ----------
        output :
        resources : dict
            resources for a single notebook including name, config directory
            and directory to save output

        Returns
        -------
        file
            results from the specified writer output of exporter
        R   s<   unique_key MUST be specified in the resources, but it is nott   output_suffixR;   R   (   t   KeyErrorR8   R   t   getR*   t   write(   R!   R,   R   R   t   write_results(    (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pyt   write_single_notebook  s    
	c         C  s,   t  |  d  r( |  j r( |  j |  n  d S(   s   Step 4: Post-process the written file

        Only used if a postprocessor has been specified. After the
        converted notebook is written to a file in Step 3, this post-processes
        the notebook.
        R   N(   R}   R   (   R!   R   (    (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pyt   postprocess_single_notebook  s    c         C  s   | d k r( |  j j d | |  j  n |  j j d |  j  |  j |  } |  j | | d | \ } } |  j | |  } |  j |  d S(   s%  Convert a single notebook.

        Performs the following steps:

            1. Initialize notebook resources
            2. Export the notebook to a particular format
            3. Write the exported notebook to file
            4. (Maybe) postprocess the written file

        Parameters
        ----------
        notebook_filename : str
        input_buffer :
            If input_buffer is not None, conversion is done and the buffer is
            used as source into a file basenamed by the notebook_filename
            argument.
        s   Converting notebook %s to %ss   Converting notebook into %sR   N(   R   Ru   t   infoR:   R   R   R   R   (   R!   R   R   R   R,   R   (    (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pyt   convert_single_notebook  s    c         C  s   |  j  d k rD t |  j  d k rD |  j j d  |  j d  n  t |  j  } | d |  j  |  _	 t |  j  d k r |  j
 r |  j   t j d  n  |  j
 s x= |  j D] } |  j |  q Wn t   } |  j d d | d	 S(
   s4   Convert the notebooks in the self.notebook traitlet R;   i   s   
                UsageError: --output flag or `NbConvertApp.output_base` config option
                cannot be used when converting multiple notebooks.
                RT   i    is   notebook.ipynbR   N(   R   R   Rr   Ru   R   R   R   R:   RT   R   R2   t
   print_helpRl   R   R   (   R!   RQ   R   R   (    (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pyR     s    $	
		c         C  s   d } xz |  j  j   D]i \ } \ } } | d j |  7} | t t | d   d 7} | t t d t |  d   d 7} q W| S(   sK   
        Return a string containing descriptions of all the flags.
        s"   The following flags are defined:

s   {}
iP   s   

s   Long Form: (   t   flagst   itemsR   R   R   t   str(   R!   R   t   flagt   cfgt   fhelp(    (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pyt   document_flag_help  s    "+c         C  s@   d } x3 |  j  j   D]" \ } } | d j | |  7} q W| S(   s-   Return a string containing all of the aliasess#   The folowing aliases are defined:

s   	**{}** ({})

(   t   aliasesR   R   (   R!   R   t   aliast   longname(    (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pyt   document_alias_help  s    c           s     f d   d d d d d g D } d   | j    D } g    j   D] } | | k rH | ^ qH | d <t d	  } d
 } xp | D]h } | | j d | j    7} | d k r | d j d |  7} n  | d j d   | | D  7} q W| j d d  S(   s   
        Provides a much improves version of the configuration documentation by
        breaking the configuration options into app, exporter, writer,
        preprocessor, postprocessor, and other sections.
        c           sG   i  |  ]= } g    j    D]! } | | j j   k r | ^ q |  q S(    (   t   _classes_inc_parentsR$   R[   (   t   .0t   categoryt   c(   R!   (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pys
   <dictcomp>  s   	t   appR   R*   t   preprocessorR   c         S  s#   h  |  ] } | D] } |  q q S(    (    (   R   R   R   (    (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pys	   <setcomp>  s   	 t   otherst   
                        {section} Options
                        -----------------------

                        R;   t   sections,   .. image:: _static/{image}_inheritance.png

t   images   
c         s  s   |  ] } | j    Vq d  S(   N(   t   class_config_rst_doc(   R   R   (    (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pys	   <genexpr>,  s    s    : s    \: (   R   R   R*   (   t   valuesR   R   R   t   titlet   joint   replace(   R!   t
   categoriest   accounted_forR   t   headert   sectionsR   (    (   R!   s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pyt   document_config_options  s    /	%N(?   R$   R%   R&   R   t   versionRP   t   nbconvert_aliasesR   t   nbconvert_flagsR   R   RG   R
   RH   RR   R	   t   descriptiont   tagR   R   R   R8   R   R   R   t   examplesR   R*   R   R6   R\   R   R]   R   R_   R   R   Ra   Rb   R   Rc   Rd   R   R~   R:   Rr   R2   R   Rg   Rf   Rh   Ri   Rj   R   R   R   R   R   R   R   R   R   R   (    (    (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pyR3      s   						)		

												)"					(7   R&   t
   __future__R    RE   Rl   Ro   Rs   t   textwrapR   R   t   ipython_genutils.textR   t   jupyter_core.applicationR   R   R   t   traitlets.configR   R   t	   traitletsR	   R
   R   R   R   R   R   R   t   traitlets.utils.importstringR   t   exporters.baseR   R   t	   nbconvertR   R   R   R   R   t
   utils.baseR   t   utils.exceptionsR   t   utils.ioR   R   R   t   updateR   R   R~   R3   t   launch_instancet   maint   launch_new_instance(    (    (    s5   lib/python2.7/site-packages/nbconvert/nbconvertapp.pyt   <module>   s   :(		






 