
    -Ph                        d Z ddlm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 ddlmZmZmZ erdd	lmZ dd
lmZ ddlmZ ddlmZ  ej        e          Zd%dZ	 	 d&ddd'dZd dddfddd(d$ZdS ))z"File utility functions for Sphinx.    )annotationsN)Path)TYPE_CHECKING)__)logging)_relative_pathcopyfile	ensuredir)Callable)Any)BaseRenderer)PathMatcherfilenamer   returnPath | Nonec                   | j                                         }|                    d          r"|                     | j         dd                   S |                    d          r"|                     | j         dd                   S dS )zGiven an input filename:
    If the input looks like a template, then return the filename output should
    be written to.  Otherwise, return no result (None).
    _tNz.jinjai)namelowerendswith	with_name)r   basenames     T/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinx/util/fileutil.py_template_basenamer      s    
 }""$$H 6!!(-"4555			8	$	$ 6!!(-"45554    Fforcesourcestr | os.PathLike[str]destinationcontextdict[str, Any] | NonerendererBaseRenderer | Noner   boolNonec               "   t          |           } |                                 sdS t          |          }|                                r
|| j        z  }t	          |           r||ddlm}  |            }|                     d          }|                    ||          }|sn|                                rZ||k    rTt          d          }t                              |t          j        |           t          j        |          dd	           dS t	          |          p|}t          d
          }t                              |t          j        |          dd	           |                    |d           dS t!          | ||           dS )a  Copy an asset file to destination.

    On copying, it expands the template variables if context argument is given and
    the asset is a template file.

    :param source: The path to source file
    :param destination: The path to destination file or directory
    :param context: The template variables.  If not given, template files are simply copied
    :param renderer: The template engine.  If not given, SphinxRenderer is used by default
    :param bool force: Overwrite the destination file even if it exists.
    Nr   SphinxRendererzutf-8)encodingz`Aborted attempted copy from rendered template %s to %s (the destination path has existing data).misccopy_overwrite)typesubtypez'Writing evaluated template result to %stemplate_evaluationr   )r   existsis_dirr   r   sphinx.util.templater*   	read_textrender_stringr   loggerwarningosfsdecodeinfo
write_textr	   )	r   r!   r"   r$   r   r*   template_contentrendered_templatemsgs	            r   copy_asset_filer?   %   s   & &\\F==?? {##K #v{"&!! !3g&9;;;;;;%~''H!++W+==$223CWMM 	++-- 	2BFW2W2W< C NNF##K(((     F(55D:;;K$$)	 	 	
 	
 	
 	07CCCCCE222222r   c                    dS )NF )paths    r   <lambda>rC   h   s     r   excludedr   onerror'Callable[[str, Exception], None] | Nonec          	        t          |           } |                                 sdS |ddlm}  |            }t	          |           |                                 rt          | ||||           dS t          j        | d          D ]?\  }}	}
t          |          }t          ||           
                                }|	                                D ]Y} |t          j        ||                    r|	                    |           6t	          t          j        |||                     Z|
D ]} |t          j        ||                    sv	 t          t          j        ||          t          j        ||          |||           \# t          $ r-}|r  |t          j        ||          |           n Y d}~d}~ww xY wAdS )a  Copy asset files to destination recursively.

    On copying, it expands the template variables if context argument is given and
    the asset is a template file.

    Use ``copy_asset_file`` instead to copy a single file.

    :param source: The path to source file or directory
    :param destination: The path to destination directory
    :param excluded: The matcher to determine the given path should be copied or not
    :param context: The template variables.  If not given, template files are simply copied
    :param renderer: The template engine.  If not given, SphinxRenderer is used by default
    :param onerror: The error handler.
    :param bool force: Overwrite the destination file even if it exists.
    Nr   r)   )r"   r$   r   T)followlinks)r   r1   r3   r*   r
   is_filer?   r8   walkr   as_posixcopy	posixpathjoinremove	Exception)r   r!   rD   r"   r$   rE   r   r*   rootdirsfilesroot_preldirdirr   excs                   r   
copy_assetrX   e   s1   2 &\\F==?? 777777!>##k~~ K85	
 	
 	
 	
 	WV>>>  dEd//88::99;; 	D 	DCx	vs3344 DC    ).fcBBCCCC 	 	H8IN68<<== #!tX66!{F;; '!)#     !    	tX > >DDDD EDDDD	 s   :F
G#F==G)r   r   r   r   )NN)r   r    r!   r    r"   r#   r$   r%   r   r&   r   r'   )r   r    r!   r    rD   r   r"   r#   r$   r%   rE   rF   r   r&   r   r'   )__doc__
__future__r   r8   rM   pathlibr   typingr   sphinx.localer   sphinx.utilr   sphinx.util.osutilr   r	   r
   collections.abcr   r   r3   r   sphinx.util.typingr   	getLogger__name__r6   r   r?   rX   rA   r   r   <module>rd      s   ( ( " " " " " " 				                                   B B B B B B B B B B /((((((111111......		8	$	$
 
 
 
  &*$(	=3 =3 =3 =3 =3 =3 =3F /.%)$(7;@ @ @ @ @ @ @ @ @r   