
    RiK                    *   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j0                  e      ZddZ	 	 ddd	 	 	 	 	 	 	 	 	 	 	 ddZd dddfdd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy)z"File utility functions for Sphinx.    )annotationsN)Path)TYPE_CHECKING)__)logging)_relative_pathcopyfile	ensuredir)Callable)Any)BaseRenderer)PathMatcherc                    | j                   j                         }|j                  d      r| j                  | j                   dd       S |j                  d      r| j                  | j                   dd       S y)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)filenamebasenames     L/home/agent/.friday_env/lib/python3.12/site-packages/sphinx/util/fileutil.py_template_basenamer      sm    
 }}""$H!!(--"455			8	$!!(--"455    Fforcec                  t        |       } | j                         syt        |      }|j                         r|| j                  z  }t	        |       r||ddlm}  |       }| j                  d      }|j                  ||      }|sa|j                         rQ||k7  rLt        d      }t        j                  |t        j                  |       t        j                  |      dd	       yt	        |      xs |}t        d
      }t        j                  |t        j                  |      dd	       |j                  |d       yt!        | ||       y)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	   )	sourcedestinationcontextrendererr   r   template_contentrendered_templatemsgs	            r   copy_asset_filer8   %   sD   & &\F==?{#Kv{{"&!g&9;%'H!++W+=$223CWM++-2BFW2W<C NNF#K((   (5D:;KK$)	 	 	
 	07CE2r   c                     y)NF )paths    r   <lambda>r<   h   s    r   c          	     *   t        |       } | j                         sy|ddlm}  |       }t	        |       | j                         rt        | ||||       yt        j                  | d      D ]  \  }}	}
t        |      }t        ||       j                         }|	j                         D ]P  } |t        j                  ||            r|	j                  |       1t	        t        j                  |||             R |
D ]X  } |t        j                  ||            r 	 t        t        j                  ||      t        j                  ||      |||       Z  y# t        $ r+}|r |t        j                  ||      |       n Y d}~d}~ww xY w)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.

    Use ``app.add_static_dir()`` instead to copy static files to
    the output directory.

    :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   )r3   r4   r   T)followlinks)r   r&   r(   r   r
   is_filer8   r-   walkr   as_posixcopy	posixpathjoinremove	Exception)r1   r2   excludedr3   r4   onerrorr   r   rootdirsfilesroot_preldirdirr   excs                   r   
copy_assetrP   e   sg   8 &\F==?7!#k~~K85	
 	WWV> dEd/88:99; 	DC	vs34C )..fcBC		D  	HINN68<=#!tX6!{F; '!)#	& ! 	tX >D Es   !8E	F'!FF)r   r   returnzPath | None)NN)r1   str | os.PathLike[str]r2   rR   r3   dict[str, Any] | Noner4   BaseRenderer | Noner   boolrQ   None)r1   rR   r2   rR   rG   r   r3   rS   r4   rT   rH   z'Callable[[str, Exception], None] | Noner   rU   rQ   rV   )__doc__
__future__r   r-   rC   pathlibr   typingr   sphinx.localer   sphinx.utilr   sphinx.util.osutilr   r	   r
   collections.abcr   r   r(   r   sphinx.util.typingr   	getLogger__name__r+   r   r8   rP   r:   r   r   <module>rb      s   ( " 	       B B(1.			8	$
  &*$(	=3 =3"=3'=3 #=3 "	=3 =3 
=3F /%)$(7;C C"C'C C #	C
 "C 5C C 
Cr   