
    MhM2                        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
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  G d	 d
ej                  Z G d de          Z G d de          ZdS )zeThis module defines a base Exporter class. For Jinja template-based export,
see templateexporter.py.
    )annotationsN)NotebookNode	validator)Bool	HasTraitsList
TraitErrorUnicodeConfig)LoggingConfigurable)import_itemc                      e Zd ZdZd ZdS )ResourcesDictzA default dict for resources.c                    dS )zHandle missing value.  )selfkeys     \/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/nbconvert/exporters/exporter.py__missing__zResourcesDict.__missing__   s    r    N)__name__
__module____qualname____doc__r   r   r   r   r   r      s)        ''    r   r   c                  *     e Zd ZdZdZdZ fdZ xZS )FilenameExtensionz A trait for filename extensions.r   z*a filename extension, beginning with a dotc                    t                                          ||          }|r?|                    d          s*d}t          |                    | j        |                    |S )zValidate the file name..z8FileExtension trait '{}' does not begin with a dot: {!r})supervalidate
startswithr	   formatname)r   objvaluemsg	__class__s       r   r"   zFilenameExtension.validate&   se       e,,  	;))#.. 	;LCSZZ	599:::r   )r   r   r   r   default_value	info_textr"   __classcell__r)   s   @r   r   r       sH        **M<I
 
 
 
 
 
 
 
 
r   r   c                      e Zd ZU dZ edd                              d          Z ed                              d          Z edd                              d          Z	d	Z
d
Zded<    ed                              d          Zded<    e            Zded<    eg dd                              d          Zded<   d) fd	Zed             Z	 d)d*dZ	 d)d+d!Z	 d)d,d#Zd-d$Zd% Zd& Zd' Zd( Z xZS ).Exporterz
    Class containing methods that sequentially run a list of preprocessors on a
    NotebookNode object and then return the modified NotebookNode object and
    accompanying resources dict.
    Tz<Disable this exporter (and any exporters inherited from it).)help)configz4Extension of the file that should be written to diskFz^Reduces the number of validation steps so that it only occurs after all preprocesors have run.r   Nstrexport_from_notebookz7List of preprocessors, by name or namespace, to enable.zList[t.Any]preprocessors_preprocessors)z-nbconvert.preprocessors.TagRemovePreprocessorz/nbconvert.preprocessors.RegexRemovePreprocessorz/nbconvert.preprocessors.ClearOutputPreprocessorz3nbconvert.preprocessors.CoalesceStreamsPreprocessorz+nbconvert.preprocessors.ExecutePreprocessorz+nbconvert.preprocessors.SVG2PDFPreprocessorz)nbconvert.preprocessors.LatexPreprocessorz3nbconvert.preprocessors.HighlightMagicsPreprocessorz1nbconvert.preprocessors.ExtractOutputPreprocessorz6nbconvert.preprocessors.ExtractAttachmentsPreprocessorz1nbconvert.preprocessors.ClearMetadataPreprocessorzZList of preprocessors available by default, by name, namespace,
        instance, or type.default_preprocessorsc                    | j         }|r|                    |            t                      j        dd|i| |                                  i | _        dS )z
        Public constructor

        Parameters
        ----------
        config : ``traitlets.config.Config``
            User configuration instance.
        `**kw`
            Additional keyword arguments passed to parent __init__

        r1   Nr   )default_configmerger!   __init___init_preprocessors_nb_metadata)r   r1   kwwith_default_configr)   s       r   r:   zExporter.__init__i   sm     #1 	.%%f---:: 3:r:::  """r   c                    t                      S Nr   )r   s    r   r8   zExporter.default_config~   s    xxr   nbr   	resourcest.Any | Noner=   t.Anyreturn%tuple[NotebookNode, dict[str, t.Any]]c                   t          j        |          }|                     |          }d|d         v r#|d         d                                         |d<   |                     ||          \  }}d}|t|                    di                               dd          }|                    di                               dd          }t          j                            ||          }|j	        | j
        |<   ||fS )av  
        Convert a notebook from a notebook node instance.

        Parameters
        ----------
        nb : :class:`~nbformat.NotebookNode`
            Notebook node (dict-like with attr-access)
        resources : dict
            Additional resources that can be accessed read/write by
            preprocessors and filters.
        `**kw`
            Ignored

        languagemetadatar   Nr%   path)copydeepcopy_init_resourceslower_preprocessgetosrJ   joinrI   r<   )r   rA   rB   r=   nb_copynotebook_namer%   rJ   s           r   from_notebook_nodezExporter.from_notebook_node   s    " -##((33	J''$&zN:$>$D$D$F$FIj! "--gyAA ==R0044VR@@D==R0044VR@@DGLLt44M+2+;-(	!!r   filenamedict[str, t.Any] | Nonec                   |t                      }d|vs|d         dk    rt                      |d<   t          j                            |          \  }}t          j                            |          d         }||d         d<   ||d         d<   t
          j                            t          j                            |          t
          j        j	                  }t          j        dk    rd	}nd
}|                    |          |d         d<   t          |d          5 }	 | j        |	fd|i|cddd           S # 1 swxY w Y   dS )ad  
        Convert a notebook from a notebook file.

        Parameters
        ----------
        filename : str
            Full filename of the notebook file to open and convert.
        resources : dict
            Additional resources that can be accessed read/write by
            preprocessors and filters.
        `**kw`
            Ignored

        NrI   r   r   r%   rJ   )tzwin32z	%B %d, %Yz
%B %-d, %Ymodified_datezutf-8)encodingrB   )r   rQ   rJ   splitsplitextdatetimefromtimestampgetmtimetimezoneutcsysplatformstrftimeopen	from_file)
r   rV   rB   r=   rJ   basenamerT   r[   date_formatfs
             r   from_filenamezExporter.from_filename   s   $ %IY&&)J*?2*E*E$1OOIj!x00h((2215(5	*f%(,	*f% )77GX&&8+<+@ 8 
 
 <7""%KK&K1>1G1G1T1T	*o.(W--- 	@!4>!??y?B??	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@s    D==EEfile_streamc                J     | j         t          j        |d          fd|i|S )ab  
        Convert a notebook from a notebook file.

        Parameters
        ----------
        file_stream : file-like object
            Notebook file-like object to convert.
        resources : dict
            Additional resources that can be accessed read/write by
            preprocessors and filters.
        `**kw`
            Ignored

           )
as_versionrB   )rU   nbformatread)r   rm   rB   r=   s       r   rh   zExporter.from_file   sB    " 't&M+!444
 
@I
MO
 
 	
r   c                   |d}t          |          t          |t                    }| }|r:t          |t                    r%t	          |          }|                     ||          S |r4t          |          r%|rd|_        | j        	                    |           |S |r7t          |t                    r"|                      ||           |           dS |r |                      |            |           dS t          d|z            )a  
        Register a preprocessor.
        Preprocessors are classes that act upon the notebook before it is
        passed into the Jinja templating engine. Preprocessors are also
        capable of passing additional information to the Jinja
        templating engine.

        Parameters
        ----------
        preprocessor : `nbconvert.preprocessors.Preprocessor`
            A dotted module name, a type, or an instance
        enabled : bool
            Mark the preprocessor as enabled

        Nzpreprocessor must not be NoneT)parentzBpreprocessor must be callable or an importable constructor, got %r)	TypeError
isinstancetyper2   r   register_preprocessorcallableenabledr5   append
issubclassr   )r   preprocessorrz   r(   isclassconstructedpreprocessor_clss          r   rx   zExporter.register_preprocessor   sJ     1CC.. \400!k  	I:
 
 	I  +<88--.>HHH 	 8L11 	   ,'+$&&|444 	z,	:: 	 &&||4'@'@'@'JJJ4 	&&||~~w???4 PS__
 
 	
r   c                    g | _         | j        D ]}|                     |           | j        D ]}|                     |d           dS )z{
        Register all of the preprocessors needed for this exporter, disabled
        unless specified explicitly.
        T)rz   N)r5   r6   rx   r4   )r   r}   s     r   r;   zExporter._init_preprocessors  su    
 ! !6 	5 	5L&&|4444 !. 	C 	CL&&|T&BBBB	C 	Cr   c                   |t                      }t          |t                     s%t                      }|                    |           |}d|v rJt          |d         t                     s.t                      }|                    |d                    ||d<   n*t                      |d<   |d         d         sd|d         d<   | j        |d<   |S )NrI   r%   Notebookoutput_extension)r   rv   updatefile_extension)r   rB   new_resourcesnew_metadatas       r   rM   zExporter._init_resources(  s    %I)]33 	&)OOM  +++%I ""i
3]CC 5,##Ij$9:::(4	*%$1OOIj!Z(0 ;0:	*%f- )-(;	$%r   c                    	 t          j        |d           d S # t           j        $ r | j                            d|            w xY w)NT)relax_add_propsz)Notebook is invalid after preprocessor %s)rq   r"   ValidationErrorlogerror)r   nbcr}   s      r   _validate_preprocessorzExporter._validate_preprocessor@  s[    	c4888888' 	 	 	HNNFUUU	s	    ,Ac                X   t          j        |          }t          j        |          }t          t          d          rt          j        |          \  }}| j        D ].} |||          \  }}| j        s|                     ||           /| j        r|                     ||           ||fS )a  
        Preprocess the notebook before passing it into the Jinja engine.
        To preprocess the notebook is to successively apply all the
        enabled preprocessors. Output from each preprocessor is passed
        along to the next one.

        Parameters
        ----------
        nb : notebook node
            notebook that is being exported.
        resources : a dict of additional resources that
            can be accessed read/write by preprocessors
        	normalize)rK   rL   hasattrr   r   r5   optimistic_validationr   )r   rA   rB   r   resc_r}   s          r   rO   zExporter._preprocessG  s    " mB}Y''9k** 	.(--FAs !/ 	? 	?L$S$//IC- ?++C>>>% 	;''\:::Dyr   r@   )rA   r   rB   rC   r=   rD   rE   rF   )rV   r2   rB   rW   r=   rD   rE   rF   )rm   rD   rB   rW   r=   rD   rE   rF   )F)r   r   r   r   r   tagrz   r   r   r   output_mimetyper3   __annotations__r   r4   r5   r6   r:   propertyr8   rU   rl   rh   rx   r;   rM   r   rO   r,   r-   s   @r   r/   r/   3   st          d4\]]]aa b  G '&C  	cc  !Dm   
cc  O !%$$$$ "&J" " "	cc      #'$&&N(((()-	
 	
 	
* * *  
cc!     $     *   X ;?" " " " "D CG&@ &@ &@ &@ &@R HL
 
 
 
 
*7
 7
 7
 7
rC C C  0  ! ! ! ! ! ! !r   r/   )r   
__future__r   collectionsrK   r_   rQ   rd   typingtrq   r   r   	traitletsr   r   r   r	   r
   traitlets.configr   traitlets.config.configurabler   traitlets.utils.importstringr   defaultdictr   r   r/   r   r   r   <module>r      sv    # " " " " "       				 



      , , , , , , , , @ @ @ @ @ @ @ @ @ @ @ @ @ @ # # # # # # = = = = = = 4 4 4 4 4 4    K+          &u u u u u" u u u u ur   