§
    ÁÞMhð  ã                   óV   — d Z ddlZddlmZ ddlmZmZ ddlmZ  G d„ de¦  «        Z	dS )	zF
Module that extracts attachments from notebooks into their own files
é    N)Ú	b64decode)ÚBoolÚUnicodeé   )ÚPreprocessorc                   ó¶   ‡ — e Zd ZdZ edd¬¦  «                             d¬¦  «        Z edd¬¦  «                             d¬¦  «        Zˆ fd	„Z	ˆ fd
„Z
d„ Zˆ xZS )ÚExtractAttachmentsPreprocessorzú
    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                 óV   •—  t          ¦   «         j        di |¤Ž d| _        d| _        dS )z$
        Public constructor
        Ú ÚattachmentsN© )ÚsuperÚ__init__Ú	path_nameÚresources_item_key)ÚselfÚkwÚ	__class__s     €új/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/nbconvert/preprocessors/extractattachments.pyr   z'ExtractAttachmentsPreprocessor.__init__"   s<   ø€ ð 	‰ŒÔÐÐ˜2ÐÐÐàˆŒð ð 	ÔÐÐó    c                 óZ  •— | j         r=| j                             |d         ¬¦  «        | _        | j        |d<   i |d<   d| _        n|d         | _        d| _        t          || j                 t          ¦  «        s
i || j        <   t          ¦   «                              ||¦  «        \  }}||fS )zL
        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$   z)ExtractAttachmentsPreprocessor.preprocess/   sÃ   ø€ ð Ô ð 	0Ø!Ô@×GÒGØ'¨Ô5ð Hñ ô ˆDŒNð 15´ˆIÐ,Ñ-Ø')ˆImÑ$Ø&3ˆDÔ#Ð#ð 'Ð'9Ô:ˆDŒNØ&/ˆDÔ#õ ˜) DÔ$;Ô<½dÑCÔCð 	4Ø13ˆIdÔ-Ñ.å™œ×*Ò*¨2¨yÑ9Ô9‰ˆˆIØ9ˆ}Ðr   c                 ó
  — d|v rü|j         D ]ô}| j                             d|¦  «         |j         |         D ]7}|j         |         |                              d¦  «        }t	          |¦  «        } t
          j                             | j        |¦  «        }||| j	                 |<   t
          j        j
        dk    r%|                     t
          j        j
        d¦  «        }|j                             d|z   |¦  «        |_        Œõ||fS )aB  
        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_cellz.ExtractAttachmentsPreprocessor.preprocess_cellG   s   € ð ˜DÐ Ð ØÔ)ð Wð WØ”—’Ð:¸EÑBÔBÐBð !%Ô 0°Ô 7ð ð HàÔ+¨EÔ2°8Ô<×CÒCÀGÑLÔLDÝ'¨™oœoGØõ  "œwŸ|š|¨D¬N¸EÑBÔBØCJ	˜$Ô1Ô2°<Ñ@õ ”7”; #Ò%Ð%Ø#/×#7Ò#7½¼¼ÀSÑ#IÔ#ILØ"œk×1Ò1°-À%Ñ2GÈÑVÔV”àYˆÐr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Útagr    r   r   r   r$   r9   Ú__classcell__)r   s   @r   r	   r	      sÐ   ø€ € € € € ðð ð &- WØ%ØIð&ñ &ô &÷ 
‚c€cÑÔð #ð
 tØð6ðñ ô ÷ 
‚c€cÑÔð	 ð

ð 

ð 

ð 

ð 

ðð ð ð ð ð0%ð %ð %ð %ð %ð %ð %r   r	   )
r=   r,   Úbase64r   Ú	traitletsr   r   Úbaser   r	   r   r   r   ú<module>rC      s”   ððð ð 
€	€	€	Ø Ð Ð Ð Ð Ð à #Ð #Ð #Ð #Ð #Ð #Ð #Ð #à Ð Ð Ð Ð Ð ð\ð \ð \ð \ð \ \ñ \ô \ð \ð \ð \r   