
    :Mcx                     n    d Z ddlZddlZddlmZ ddlmZmZ ddlm	Z	m
Z
 ddlmZ  G d d	e          ZdS )
z;Contains writer for writing nbconvert output to filesystem.    N)Path)Unicodeobserve)ensure_dir_existslink_or_copy   )
WriterBasec                        e Zd ZdZ edd                              d          Z ed                              d          Z ed          d	             Z	 fd
Z
d ZddZ xZS )FilesWriterz-Consumes nbconvert output and produces files. a  Directory to write output(s) to. Defaults
                              to output to the directory of each notebook. To recover
                              previous default behaviour (outputting to the current
                              working directory) use . as the flag value.)helpT)configaU  When copying files that the notebook depends on, copy them in
        relation to this path, such that the destination filename will be
        os.path.relpath(filename, relpath). If FilesWriter is operating on a
        notebook that already exists elsewhere on disk, then the default will be
        the directory containing that notebook.build_directoryc                 <    |d         }|rt          |           d S d S )Nnew)r   )selfchanger   s      7lib/python3.11/site-packages/nbconvert/writers/files.py_build_directory_changedz$FilesWriter._build_directory_changed%   s1    Um 	#c"""""	# 	#    c                 r     t                      j        di | |                     d| j        i           d S )Nr    )super__init__r   r   )r   kw	__class__s     r   r   zFilesWriter.__init__+   sB    2%%ud.B&CDDDDDr   c                 b    |r,| j                             d|           t          |           dS dS )z,Make a directory if it doesn't already existzMaking directory %sN)loginfor   )r   paths     r   _makedirzFilesWriter._makedir/   s?     	$HMM/666d#####	$ 	$r   Nc           	      
   |t          d          |                    dd          }|                    di                               dd          }| j        p|}| j        p|}|                    di                                           }	|	rM| j                            dt          j        	                    |                    d	d          d                     |	D ]\  }
}t          j        	                    ||
          }t          j        
                    |          }|                     |           | j                            d
t          |          |           t          |d          5 }|                    |           ddd           n# 1 swxY w Y   |r| j        D ]}
t#          j        |
          D ]}|dk    r!t          j                            ||          }n|}t          j        	                    ||          }t          j        
                    |          }|                     |           t          j                            |          t          j                            |          k    s,| j                            d||           t'          ||           |||z   }n|}t)          |          |z  }| j                            dt          |          |           t+          |t,                    r@t          |dd          5 }|                    |           ddd           n# 1 swxY w Y   n=t          |d          5 }|                    |           ddd           n# 1 swxY w Y   |S )z
        Consume and write Jinja output to the file system.  Output directory
        is set via the 'build_directory' variable of this instance (a
        configurable).

        See base for more...
        Nnotebook_nameoutput_extensionmetadatar    r   outputszSupport files will be in %soutput_files_dirz#Writing %i bytes to support file %swbzCopying %s -> %szWriting %i bytes to %swzutf-8)encoding)	TypeErrorgetrelpathr   itemsr   r   osr    joindirnamer!   debuglenopenwritefilesglobnormpathr   r   
isinstancestr)r   output	resourcesr#   r   r$   resource_pathr-   r   r.   filenamedatadestr    fmatching_filenamedest_filenames                    r   r5   zFilesWriter.write5   s
     	-O,,, %==);TBB "j"5599&"EE,/-.?- i,,2244 	HMM-Y]]+=rBBBGG   $ 
	 
	NHd 7<<::D7??4((DMM$ HNN@#d))TRRRdD!! Q                	> J > > *.8)<)< > >% "} :(*8I7(S(S(9 7<<GGD7??400DMM$''' 7++D11RW5E5EFW5X5XX >&8:KTRRR$%6===!>&  	! #33DD DO$$t+ 	.FTBBBfc"" 	 dC'222  a                              dD!!  Q                              s6   /FF	F	L::L>L>M88M<?M<)N)__name__
__module____qualname____doc__r   tagr   r-   r   r   r   r!   r5   __classcell__)r   s   @r   r   r      s        77g
M   
cc  g3   
cc  W# #  #
E E E E E$ $ $R R R R R R R Rr   r   )rG   r7   r/   pathlibr   	traitletsr   r   nbconvert.utils.ior   r   baser	   r   r   r   r   <module>rN      s    A A
  				       & & & & & & & & > > > > > > > >      v v v v v* v v v v vr   