
    ^h-                         S r SSKrSSKrSSKrSSKJr  SSKJr  SSKJ	r	  SSK
JrJr  SSKJr  S	 rS
 r " S S\5      rg)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                 ,    [        U 5      nUS:X  a  SnU$ )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     _/home/james-whalen/.local/lib/python3.13/site-packages/nbconvert/preprocessors/extractoutput.pyguess_extension_without_jper      s     (
#C
f}J    c                     [        U [        5      (       a7  [        R                  S:X  a  U R	                  SS5      n U R                  S5      n U $ )zEncode data based on platform.win32
z
utf-8)
isinstancestrsysplatformreplaceencode)datas    r   platform_utf_8_encoder   !   s>    $<<7"<<f-D{{7#Kr   c                   v    \ rS rSrSr\" S5      R                  SS9r\" 1 Sk5      R                  SS9r	S r
Srg	)
ExtractOutputPreprocessor*   zx
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/png
image/jpegimage/svg+xmlapplication/pdfc           	         UR                  SS5      nUR                  SS5      n[        US   [        5      (       d  0 US'   [        UR                  S/ 5      5       GH  u  pgUR                  S;  a  M  SUR
                  ;   a  [        US   S   5      US   S'   U R                   GH  nXR
                  ;   d  M  UR
                  U   n	US	;   a  [        U	5      n	OlUS
:X  d  [        U	[        5      (       dF  [        U	[        5      (       a  U	R                  S5      n	[        [        R                  " U	5      5      n	O[        U	5      n	[        U5      n
U
c  SUR!                  S5      S   -   n
UR"                  R                  SS5      (       a*  UR"                  S   nUR%                  U
5      (       d  X-  nOU R&                  R)                  XCXjS9nUb  [*        R,                  R/                  X[5      nUR"                  R1                  S0 5        XR"                  S   U'   XS   ;   a  SU SU S3n[3        U5      eXS   U'   GM     GM     X4$ )aP  
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	resourcesr1   r&   r(   r2   out	mime_typer   r   r/   msgs                r   preprocess_cell)ExtractOutputPreprocessor.preprocess_cell8   sQ   $ ]]<:
$==);TB )I.55#%Ii  $DHHY$;<JE&HHchh&+1#f+k2J+KFK(!66	(88I.D !$RR  *$/"&88
4QT@U@U &dE22 $(;;w#7D4TZZ5EF  5T:5i@C{!I$4$4S$9"$==||''
B77#&<<
#;'0055$OH#'#@#@#G#G'1PU $H $ (3#%77<<0@#KLL++K<;CLL-i8Y#77K LT* UO  *l!-  )o- 6:i(2y 7 =H r    N)__name__
__module____qualname____firstlineno____doc__r   tagrA   r   r9   rN   __static_attributes__rP   r   r   r   r   *   sQ    
  ''UVZZ  [   ^_cc d ^r   r   )rU   r<   rC   r   binasciir   	mimetypesr   textwrapr   	traitletsr   r   baser
   r   r   r   rP   r   r   <module>r]      s<     	 
  %  " 
l lr   