
    Mh`                    6   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Z	ddl
mZmZ ddlmZ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mZ ddl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(m)Z) ddl*m+Z+ ddl,m-Z- ddl.m/Z/  G d de          Z0i Z1e12                    e           e12                    dddddddddddd           i Z3e32                    e           e32                    ddd iid!fdd"d iid#fd$d%d iid&fd$d'd(iid)fd*d+d,d-d.id/d0fd*d+d,d-d.idd id1d2fd*d+d,d-d.idd id3d4fd5d d d6id7fd5d d d d8id9fd:d;d iid<fd:d=d iid>fd5d?d*iid@fdAdBd iidCfdAdDd iidEfdF            G dG d$e          Z4 G dH dIe4          Z5e4j6        xZ7Z8e5j6        Z9dS )JzuNbConvert is a utility for conversion of .ipynb files.

Command-line interface for the NbConvert conversion utility.
    )annotationsN)dedentfill)
JupyterAppbase_aliases
base_flags)BoolDottedObjectNameInstanceListTypeUnicodedefaultobserve)Configurablecatch_config_error)import_item)__version__	exporterspostprocessorspreprocessorswriters)indent   )get_export_namesget_exporter)NbConvertBase)ConversionException)unicode_stdin_streamc                  &     e Zd ZdZdZ fdZ xZS )DottedOrNonezjA string holding a valid dotted object name in Python, such as A.b3._c
    Also allows for None type.
     c                v    |5t          |          dk    r"t                                          ||          S |S )zValidate an input.Nr   )lensupervalidate)selfobjvalue	__class__s      V/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/nbconvert/nbconvertapp.pyr&   zDottedOrNone.validate,   s6    Ua77##C///    )__name__
__module____qualname____doc__default_valuer&   __classcell__r*   s   @r+   r!   r!   %   sI          M        r,   r!   zNbConvertApp.export_formatzTemplateExporter.template_namezTemplateExporter.template_filezHTMLExporter.themezHTMLExporter.sanitize_htmlzNbConvertApp.writer_classz NbConvertApp.postprocessor_classzNbConvertApp.output_basezFilesWriter.build_directoryz SlidesExporter.reveal_url_prefixz!NotebookExporter.nbformat_version)totemplateztemplate-filethemesanitize_htmlwriterpostoutputz
output-dirzreveal-prefixnbformatExecutePreprocessorenabledTz%Execute the notebook prior to export.allow_errorszContinue 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.NbConvertApp
from_stdinzgread a single notebook file from stdin. Write the resulting notebook with default basename 'notebook.*'writer_classStdoutWriterz1Write notebook output to stdout instead of files.Fnotebook)use_output_suffixexport_formatbuild_directoryr"   )r?   FilesWriterztRun nbconvert in place, overwriting the existing notebook (only
        relevant when converting to notebook format))r?   rG   ClearOutputPreprocessorz[Clear output of current file and save in place,
        overwriting the existing notebook. )r?   rG   CoalesceStreamsPreprocessorzRCoalesce consecutive stdout and stderr outputs into one stream (within each cell).TemplateExporter)exclude_input_promptexclude_output_promptz9Exclude input and output prompts from converted document.)rL   exclude_inputrK   z|Exclude input cells and output prompts from converted document.
        This mode is ideal for generating code-free reports.WebPDFExporterallow_chromium_downloadzTWhether to allow downloading chromium if no suitable version is found on the system.disable_sandboxz:Disable chromium security sandbox when converting to PDF..rM   z<Shows code input. This flag is only useful for dejavu users.HTMLExporterembed_imageszoEmbed the images as base64 dataurls in the output. This flag is only useful for the HTML/WebPDF/Slides exports.r7   zIWhether the HTML in Markdown cells and cell outputs should be sanitized..)executezallow-errorsstdinstdoutinplacezclear-outputzcoalesce-streamsz	no-promptzno-inputzallow-chromium-downloadzdisable-chromium-sandboxz
show-inputzembed-imageszsanitize-htmlc                      e Zd 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          Z edd
                              d          Z edd
                              d          Z ed e             d          Z eddd          Z edd
                              d          ZddddZ ed          Z e d          d             Z! eddd          Z" e#d 
                              d          Z$d!d"iZ% ed#d          Z& e d$          d%             Z' ed&d' e             d()                              d          Z( e e            d*
                              d          Z) ed&d+
                              d          Z* ed&d,
                              d          Z+e,d= fd-	            Z-d. Z.d/ Z/d0 Z0d1 Z1 fd2Z2d3 Z3d4 Z4d=d5Z5d6 Z6d7 Z7d=d8Z8d9 Z9d: Z:d; Z;d< Z< xZ=S )>r?   zAApplication used to convert from notebook file type (``*.ipynb``)zjupyter-nbconvert	log_levelc                    t           j        S N)loggingINFOr'   s    r+   _log_level_defaultzNbConvertApp._log_level_default   s
    |r,   classesc                   t           g}t          t          t          t          fD ]c}t          |          D ]Q}t          ||          }t          |t                    r*t          |t                    r|                    |           Rd|S rZ   )r   r   r   r   r   dirgetattr
isinstancetype
issubclassr   append)r'   r_   pkgnameclss        r+   _classes_defaultzNbConvertApp._classes_default   s    &3_}g~F 	( 	(CC ( (c4((c4(( (Z\-J-J (NN3'''(
 r,   zThis application is used to convert notebook files (*.ipynb)
        to various other formats.

        WARNING: THE COMMANDLINE INTERFACE MAY CHANGE IN FUTURE RELEASES.{notebook_name}zsOverwrite base name use for output files.
            Supports pattern replacements '{notebook_name}'.
            )helpTconfigzWhether 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'.z{notebook_name}_fileszDirectory to copy extra files (figures) to.
               '{notebook_name}' in the string will be converted to notebook
               basename.z
        The simplest way to use nbconvert is

        > jupyter nbconvert mynotebook.ipynb --to html

        Options include aG  .

        > jupyter nbconvert --to latex mynotebook.ipynb

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

        > jupyter nbconvert --to html --template lab 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
        z!nbconvert.writers.base.WriterBasez_Instance of the writer class used to write the
                      results of the conversion.)rl   
allow_nonerG   z\Writer class used to write the
                                    results of the conversionz#nbconvert.writers.files.FilesWriterz#nbconvert.writers.debug.DebugWriterz%nbconvert.writers.stdout.StdoutWriter)fileswriterdebugwriterstdoutwriter)ro   rA   c                    |d         }|                                 | j        v r| j        |                                          }t          |          | _        d S Nnew)lowerwriter_aliasesr   writer_factoryr'   changeru   s      r+   _writer_class_changedz"NbConvertApp._writer_class_changed3  sL    Um99;;$---%ciikk2C)#..r,   z/nbconvert.postprocessors.base.PostProcessorBasezfInstance of the PostProcessor class used to write the
                      results of the conversion.zcPostProcessor class used to write the
                                    results of the conversionservez1nbconvert.postprocessors.serve.ServePostProcessorNpostprocessor_classc                    |d         }|                                 | j        v r| j        |                                          }|rt          |          | _        d S d S rt   )rv   postprocessor_aliasesr   postprocessor_factoryry   s      r+   _postprocessor_class_changedz)NbConvertApp._postprocessor_class_changedI  s^    Um99;;$444,SYY[[9C 	:)4S)9)9D&&&	: 	:r,   FzIThe export format to be used, either one of the built-in formats
        zb
        or a dotted object name that represents the import path for an
        ``Exporter`` class)ro   rl   zList of notebooks to convert.
                     Wildcards are supported.
                     Filenames passed positionally will be added to the list.
                     z"read a single notebook from stdin.z<set the 'recursive' option for glob for searching wildcards.c                   t           j        dk    rDt           j                            d          r%t	          j        t	          j                               |                                  t                      	                    |           t          | d          r|                                  |                                  |                                  |                                  dS )z<Initialize application, notebooks, writer, and postprocessor)      winload_config_environN)sysversion_infoplatform
startswithasyncioset_event_loop_policyWindowsSelectorEventLoopPolicyinit_syspathr%   
initializehasattrr   init_notebooksinit_writerinit_postprocessorr'   argvr*   s     r+   r   zNbConvertApp.initializee  s     f$$)@)@)G)G$)'*P*R*RSSS4   4.// 	'$$&&&!!!!!r,   c                h    t           j                            dt          j                               dS )z)Add the cwd to the sys.path ($PYTHONPATH)r   N)r   pathinsertosgetcwdr]   s    r+   r   zNbConvertApp.init_syspatht  s$    29;;'''''r,   c                Z   | j         r| j         n| j        }g }|D ]}t          j        || j                  }|                    t          j        |dz   | j                             |s| j                            d|           |D ]}||vr|                    |           || _        dS )zConstruct 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.
        )	recursivez.ipynbzpattern %r matched no filesN)
extra_args	notebooksglobrecursive_globextendlogwarningrf   )r'   patterns	filenamespatternglobbed_filesfilenames         r+   r   zNbConvertApp.init_notebooksx  s     '+oI4??4> 	 
	/ 
	/G !Ig9LMMMM  7X+=I\!]!]!]^^^  I  !>HHH) / /9,,$$X.../ #r,   c                    |                      d| j        i           | j        rI|                     |           | _        t	          | j        d          r| j        j        dk    rd| _        dS dS dS dS )z*Initialize the writer (which is stateless)ru   parentrF   r"   FN)r{   rA   rx   r8   r   rF   rD   r]   s    r+   r   zNbConvertApp.init_writer  s    ""E4+<#=>>> 	/--T-::DKt{$566 /4;;VZ\;\;\).&&&	/ 	// /;\;\r,   c                    |                      d| j        i           | j        r|                     |           | _        dS dS )z1Initialize the postprocessor (which is stateless)ru   r   N)r   r}   r   postprocessorr]   s    r+   r   zNbConvertApp.init_postprocessor  sU    ))5$2J*KLLL% 	I!%!;!;4!;!H!HD	I 	Ir,   c                p    t                                                       |                                  dS )z4Run start after initialization process has completedN)r%   startconvert_notebooks)r'   r*   s    r+   r   zNbConvertApp.start  s,         r,   c                    t           j                            |          }|d|                    d                   }| j                            |          }|S )z
        Returns the notebook name from the notebook filename by
        applying `output_base` pattern and stripping extension
        N.notebook_name)r   r   basenamerfindoutput_baseformat)r'   notebook_filenamer   r   s       r+   _notebook_filename_to_namez'NbConvertApp._notebook_filename_to_name  sU    
 7##$566 !68>>##6#6!67(//m/LLr,   c                    |                      |          }| j                            d|           i }| j        |d<   ||d<   | j                            |          }||d<   |S )a  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
        zNotebook name is '%s'
config_dir
unique_keyr   output_files_dir)r   r   debugr   r   r   )r'   r   r   	resourcesr   s        r+   init_single_notebook_resourcesz+NbConvertApp.init_single_notebook_resources  sw     778IJJ.>>> 	"&/	,"/	,077m7TT(8	$%r,   c                   	 | | j                             ||          \  }}n| j                             ||          \  }}nB# t          $ r5 | j                            d|d           |                     d           Y nw xY w||fS )aT  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)
        N)r   zError while converting '%s'T)exc_infor   )exporter	from_filefrom_filenamer   r   errorexit)r'   r   r   input_bufferr:   s        r+   export_single_notebookz#NbConvertApp.export_single_notebook  s    ,		'$(M$;$;LT]$;$^$^!		$(M$?$?% %@ % %!	 # 	 	 	HNN8:KVZN[[[IIaLLLLL	 y  s   AA <BBc                    d|vrd}t          |          |d         }| j        r$| j        dk    r||                    dd          z  }| j        sd}t          |          | j                            |||          S )a  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   z<unique_key MUST be specified in the resources, but it is notrk   output_suffixr"   zNo writer object defined!r   )KeyErrorrD   r   getr8   
ValueErrorwrite)r'   r:   r   msgr   s        r+   write_single_notebookz"NbConvertApp.write_single_notebook  s    & y((PC3--!,/! 	@d&6:K&K&KY]]?B???M{ 	"-CS//!{  - PPPr,   c                f    t          | d          r| j        r|                     |           dS dS dS )zStep 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'   write_resultss     r+   postprocess_single_notebookz(NbConvertApp.postprocess_single_notebook  sN     4)) 	.d.@ 	.}-----	. 	. 	. 	.r,   c                D   |"| j                             d|| j                   n | j                             d| j                   |                     |          }|                     |||          \  }}|                     ||          }|                     |           dS )a%  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.
        NzConverting notebook %s to %szConverting notebook into %sr   )r   inforE   r   r   r   r   )r'   r   r   r   r:   r   s         r+   convert_single_notebookz$NbConvertApp.convert_single_notebook  s    $ HMM8:KTM_````HMM79KLLL778IJJ	 77y| 8 
 
	 2269EE((77777r,   c                   t          | j                  dk    r/| j        s(|                                  t	          j        d           | j        s dt                       }t          |          t          | j                  } || j
                  | _        t          | j        dd          r>t          j                            | j                  \  }}|| j        j        k    r|| _        | j        s!| j        D ]}|                     |           d	S t'                      }|                     d|           |                                 d	S )
z4Convert the notebooks in the self.notebooks traitletr   z[Please specify an output format with '--to <format>'.
The following formats are available: rm   file_extensionFznotebook.ipynbr   N)r$   r   r@   
print_helpr   r   rE   r   r   r   rn   r   rb   r   r   splitextr   r   r   r   close)r'   r   ri   baseextr   r   s          r+   r   zNbConvertApp.convert_notebooks9  sn    t~!##DO#OOHRLLL! 	"O:J:L:LO O  S//! 4-..4;/// 4="2E:: 	((()9::ID#dm222#'   	!%)^ @ @!,,->????@ @ 011L(()9(UUU     r,   c           
     
   d}| j                                         D ]f\  }\  }}|| dz  }|t          t          |d                    dz   z  }|t          t          dt	          |          z   d                    dz   z  }g|S )zK
        Return a string containing descriptions of all the flags.
        z"The following flags are defined:


P   z

zLong Form: )flagsitemsr   r   str)r'   r   flagcfgfhelps        r+   document_flag_helpzNbConvertApp.document_flag_help\  s     7"&*"2"2"4"4 	I 	ID,3[[[ EVDOO,,v55EVDS!92>>??&HHEEr,   c                `    d}| j                                         D ]\  }}|d| d| dz  }|S )z-Return a string containing all of the aliasesz$The following aliases are defined:

z	**z** (z)

)aliasesr   )r'   r   aliaslongnames       r+   document_alias_helpz NbConvertApp.document_alias_helpg  sO     ;#|1133 	9 	9OE88e888888GGr,   c                     fddD             }d |                                 D             fd                                 D             |d<   t          d          }d}|D ]b}||                    |                                          z  }|d	v r	|d
| dz  }|d                    d ||         D                       z  }c|                    dd          S )z
        Provides a much improves version of the configuration documentation by
        breaking the configuration options into app, exporter, writer,
        preprocessor, postprocessor, and other sections.
        c                T    i | ]#fd                                  D             $S )c                J    g | ]}|j                                         v | S  )r-   rv   ).0ccategorys     r+   
<listcomp>zCNbConvertApp.document_config_options.<locals>.<dictcomp>.<listcomp>v  s1    ```QQZM]M]M_M_A_A_qA_A_A_r,   )_classes_inc_parents)r   r   r'   s    @r+   
<dictcomp>z8NbConvertApp.document_config_options.<locals>.<dictcomp>u  sM     
 
 
 ````$";";"="=```
 
 
r,   )appr   r8   preprocessorr   c                    h | ]	}|D ]}|
S r   r   )r   r   r   s      r+   	<setcomp>z7NbConvertApp.document_config_options.<locals>.<setcomp>y  s%    QQQxQQ1QQQQr,   c                    g | ]}|v|	S r   r   )r   r   accounted_fors     r+   r   z8NbConvertApp.document_config_options.<locals>.<listcomp>z  s$    ```QR_I_I_qI_I_I_r,   otherzt
                        {section} Options
                        -----------------------

                        r"   )section)r   r   r8   z.. image:: _static/z_inheritance.png

r   c              3  >   K   | ]}|                                 V  d S rZ   )class_config_rst_doc)r   r   s     r+   	<genexpr>z7NbConvertApp.document_config_options.<locals>.<genexpr>  s.      !Y!Yq!"8"8":":!Y!Y!Y!Y!Y!Yr,   z : z \: )valuesr   r   r   titlejoinreplace)r'   
categoriesheadersectionsr   r   s   `    @r+   document_config_optionsz$NbConvertApp.document_config_optionso  s*   
 
 
 
Z
 
 

 RQ:+<+<+>+>QQQ````$*C*C*E*E```
7
 
 " 	Z 	ZHhnn.>.>???HAAAP(PPPP		!Y!YJxDX!Y!Y!YYYYHHw///r,   rZ   )>r-   r.   r/   r0   r   versionrh   nbconvert_aliasesr   nbconvert_flagsr   r   r^   r   r_   rj   r   descriptiontagr   r	   rD   r   r   examplesr   r8   r
   rA   rw   r   rx   r   r{   r   r!   r}   r   r   r   rE   r   r@   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r2   r3   s   @r+   r?   r?      s       KKGDGEW[   dffGWY   '	M K '  
 
cc  :  
 
cc  w  
 
cc  w&	
 *)++&	 &	 &	( (HV X+4	  F $#A   
cc	  =<? N
 TT***NW^/ / / H94	  M ',A   
cc  %&YZ D$777W"##: : $#: G				     
cc  		   
cc  e"FGGGKKSWKXXJTR  	cc  " " " " " "( ( (# # #6/ / /I I I! ! ! ! !
	 	 	  8!! !! !! !!FQ Q Q@	. 	. 	.8 8 8 8<!! !! !!F	 	 	  0 0 0 0 0 0 0r,   c                  L     e Zd ZdZd fd	Z ed          d             Z xZS )	DejavuAppzA deja vu app.Nc                b   d| j         j        _        d| j         j        _        d| j         j        _        d| j         j        _        d| j         j        _        d| j         j	        _        t                                          |           t          | d          r|                                  dS dS )zInitialize the app.TFr   N)rn   rJ   rM   rL   rK   r<   r=   rN   paginateQtPDFExporterr%   r   r   r   r   s     r+   r   zDejavuApp.initialize  s    59$2=A$:<@$926'/.3"+-2!*4   4.// 	'$$&&&&&	' 	'r,   rE   c                    dS )Nhtmlr   r]   s    r+   _default_export_formatz DejavuApp._default_export_format  s    vr,   rZ   )r-   r.   r/   r0   r   r   r  r2   r3   s   @r+   r  r    si        ' ' ' ' ' ' W_      r,   r  ):r0   
__future__r   r   r   r[   r   r   typingttextwrapr   r   jupyter_core.applicationr   r   r   	traitletsr	   r
   r   r   r   r   r   r   traitlets.configr   r   traitlets.utils.importstringr   	nbconvertr   r   r   r   r   nbconvert.utils.textr   exporters.baser   r   
utils.baser   utils.exceptionsr   utils.ior   r!   r  updater  r?   r  launch_instancemainlaunch_new_instancedejavu_mainr   r,   r+   <module>r/     s    # " " " " "    				 



     ! ! ! ! ! ! ! ! I I I I I I I I I I ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] = = = = = = = = 4 4 4 4 4 4 T T T T T T T T T T T T T T ' ' ' ' ' ' : : : : : : : : % % % % % % 1 1 1 1 1 1 * * * * * *    #         & & &   *49%5-2,3;7        z " " "    #Y$563

 #^T$:;F
  $!
 v
 nn=>?
 */%/! ! !226 8

 */%/! ! !226,5t+< /
 7<j Y Y 126094/@ 
 e
 #,0-1% % H
 #-1%),0% %@

 !-t#
 g$
 !%t#
 M%
 ##U%
 O
 "D!
 B
 #T!
 \
[u uw w wtI0 I0 I0 I0 I0: I0 I0 I0X       2 *9 9'r,   