
    Mh-                         d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	 ddl
mZmZ ddlmZ d	 Zd
 Z G d de          ZdS )zA preprocessor that extracts all of the outputs from the
notebook file.  The extracted outputs are returned in the 'resources' dictionary.
    N)
a2b_base64guess_extension)dedent)SetUnicode   )Preprocessorc                 4    t          |           }|dk    rd}|S )z
    This function fixes a problem with '.jpe' extensions
    of jpeg images which are then not recognised by latex.
    For any other case, the function works in the same way
    as mimetypes.guess_extension
    z.jpez.jpegr   )mimetypeexts     e/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/nbconvert/preprocessors/extractoutput.pyguess_extension_without_jper      s$     (
#
#C
f}}J    c                     t          | t                    r;t          j        dk    r|                     dd          } |                     d          } | S )zEncode data based on platform.win32
z
utf-8)
isinstancestrsysplatformreplaceencode)datas    r   platform_utf_8_encoder   !   sJ    $ $<7""<<f--D{{7##Kr   c                       e Zd ZdZ ed                              d          Z eh d                              d          Zd Z	dS )ExtractOutputPreprocessorz
    Extracts all of the outputs from the notebook file.  The extracted
    outputs are returned in the 'resources' dictionary.
    z,{unique_key}_{cell_index}_{index}{extension}T)config>   image/svg+xml	image/png
image/jpegapplication/pdfc                    |                     dd          }|                     dd          }t          |d         t                    si |d<   t          |                     dg                     D ]\  }}|j        dvrd|j        v r$t          |d         d                   |d         d<   | j        D ]}||j        v r|j        |         }	|d	v rt          |	          }	nv|d
k    st          |	t                    sLt          |	t                    r|	                    d          }	t          t          j        |	                    }	nt          |	          }	t          |          }
|
d|                    d          d         z   }
|j                             dd          r(|j        d         }|                    |
          s||
z  }n| j                            ||||
          }| t*          j                            ||          }|j                            di            ||j        d         |<   ||d         v rd| d| d}t3          |          |	|d         |<   ||fS )a  
        Apply a transformation on each cell,

        Parameters
        ----------
        cell : NotebookNode cell
            Notebook cell being processed
        resources : dictionary
            Additional resources used in the conversion process.  Allows
            preprocessors to pass variables into the Jinja engine.
        cell_index : int
            Index of the cell being processed (see base.py)
        
unique_keyoutputoutput_files_dirNoutputs>   display_dataexecute_resultz	text/htmlr   >   r!   r"   r#   zapplication/jsonr   ./filename )r%   
cell_indexindex	extension	filenameszYour outputs have filename metadata associated with them. Nbconvert saves these outputs to external files using this filename metadata. Filenames need to be unique across the notebook, or images will be overwritten. The filename ze is associated with more than one output. The second output associated with this filename is in cell )getr   dict	enumerateoutput_typer   r   extract_output_typesr   r   bytesdecoder   jsondumpsr   rsplitmetadataendswithoutput_filename_templateformatospathjoin
setdefault
ValueError)selfcell	resourcesr0   r%   r'   r1   out	mime_typer   r   r.   msgs                r   preprocess_cellz)ExtractOutputPreprocessor.preprocess_cell8   s   $ ]]<::
$==);TBB )I.55 	&#%Ii  $DHHY$;$;<< B	: B	:JE3&HHHch&&+1#f+k2J+K+KFK(!6 <: <:	((8I.D !$RRR  *$//"&888
4QT@U@U8 &dE22 8 $(;;w#7#7D4TZ5E5EFF  5T::5i@@C{!I$4$4S$9$9"$==|''
B77 #&<
#;'0055 ,$OH#'#@#G#G'1jPUad $H $ $ (3#%7<<0@(#K#KL++K<<<;CCL-i89Y#777- LT	- -  *- - -  )oo- 6:Ii(2y<:| Yr   N)
__name__
__module____qualname____doc__r   tagr@   r   r8   rM    r   r   r   r   *   s         
  'w'UVVZZ  [     3^^^__cc d  ^ ^ ^ ^ ^r   r   )rQ   r;   rB   r   binasciir   	mimetypesr   textwrapr   	traitletsr   r   baser
   r   r   r   rS   r   r   <module>rY      s      				 



       % % % % % %       " " " " " " " "      
 
 
  l l l l l l l l l lr   