ó
    Ú^íhð  ã                   óN   • S r SSKrSSKJr  SSKJrJr  SSKJr   " S S\5      r	g)	zF
Module that extracts attachments from notebooks into their own files
é    N)Ú	b64decode)ÚBoolÚUnicodeé   )ÚPreprocessorc                   óŽ   ^ • \ rS rSrSr\" SSS9R                  SS9r\" SS	S9R                  SS9r	U 4S
 jr
U 4S jrS rSrU =r$ )ÚExtractAttachmentsPreprocessoré   zê
Extracts attachments from all (markdown and raw) cells in a notebook.
The extracted attachments are stored in a directory ('attachments' by default).
https://nbformat.readthedocs.io/en/latest/format_description.html#cell-attachments
z{notebook_name}_attachmentsz:Directory to place attachments if use_separate_dir is True)ÚhelpT)ÚconfigFznWhether to use output_files_dir (which ExtractOutput also uses) or create a separate directory for attachmentsc                 óB   >• [         TU ]  " S0 UD6  SU l        SU l        g)z
Public constructor
Ú ÚattachmentsN© )ÚsuperÚ__init__Ú	path_nameÚresources_item_key)ÚselfÚkwÚ	__class__s     €Úd/home/james-whalen/.local/lib/python3.13/site-packages/nbconvert/preprocessors/extractattachments.pyr   Ú'ExtractAttachmentsPreprocessor.__init__"   s)   ø€ ô 	‰ÒÑ˜2ÒàˆŒð ð 	Õó    c                 óH  >• U R                   (       a=  U R                  R                  US   S9U l        U R                  US'   0 US'   SU l        OUS   U l        SU l        [        X R                     [        5      (       d  0 X R                  '   [        TU ]!  X5      u  pX4$ )z<
Determine some settings and apply preprocessor to notebook
Ú
unique_key)Únotebook_nameÚattachment_files_dirr   Úoutput_files_dirÚoutputs)	Úuse_separate_dirÚattachments_directory_templateÚformatr   r   Ú
isinstanceÚdictr   Ú
preprocess)r   ÚnbÚ	resourcesr   s      €r   r&   Ú)ExtractAttachmentsPreprocessor.preprocess/   s­   ø€ ð × × Ø!×@Ñ@×GÑGØ'¨Ñ5ð Hð ˆDŒNð 15·±ˆIÐ,Ñ-Ø')ˆImÑ$Ø&3ˆDÕ#ð 'Ð'9Ñ:ˆDŒNØ&/ˆDÔ#ô ˜)×$;Ñ$;Ñ<¼d×CÑCØ13ˆI×-Ñ-Ñ.ä™Ñ*¨2Ó9‰ˆØˆ}Ðr   c                 óJ  • SU;   Ga  UR                    GH	  nU R                  R                  SU5        UR                   U    H/  nUR                   U   U   R                  S5      n[	        U5      n  O   [
        R                  R                  U R                  U5      nWX R                     U'   [
        R                  R                  S:w  a*  UR                  [
        R                  R                  S5      nUR                  R                  SU-   U5      Ul        GM     X4$ )a  
Extract attachments to individual files and
change references to them.
E.g.
'![image.png](attachment:021fdd80.png)'
becomes
'![image.png]({path_name}/021fdd80.png)'
Assumes self.path_name and self.resources_item_key is set properly (usually in preprocess).
r   zEncountered attachment %szutf-8Ú/zattachment:)r   ÚlogÚdebugÚencoder   ÚosÚpathÚjoinr   r   ÚsepÚreplaceÚsource)	r   Úcellr(   ÚindexÚfnameÚmimetypeÚdataÚdecodedÚnew_filenames	            r   Úpreprocess_cellÚ.ExtractAttachmentsPreprocessor.preprocess_cellG   sò   € ð ˜DÔ Ø×)Õ)Ø—‘—‘Ð:¸EÔBð !%× 0Ñ 0°Ô 7Hà×+Ñ+¨EÑ2°8Ñ<×CÑCÀGÓLDÜ'¨›oGÙñ	 !8ô  "Ÿw™wŸ|™|¨D¯N©N¸EÓBØCJ	×1Ñ1Ñ2°<Ñ@ô —7‘7—;‘; #Ó%Ø#/×#7Ñ#7¼¿¹¿¹ÀSÓ#ILØ"Ÿk™k×1Ñ1°-À%Ñ2GÈÓV—ñ1 *ð4 ˆÐr   )r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Útagr"   r   r!   r   r&   r<   Ú__static_attributes__Ú__classcell__)r   s   @r   r	   r	      sd   ø† ññ &-Ø%ØIñ&÷ 
c€cÐð #ñ
 Øð6ñ÷ 
c€cÐð	 õ

õ÷0%ð %r   r	   )
rB   r/   Úbase64r   Ú	traitletsr   r   Úbaser   r	   r   r   r   Ú<module>rI      s&   ðñó 
Ý ç #å ô\ \õ \r   