
    FeF                        d Z ddlmZ ddlZddlZddlmZmZ ddlm	Z	 ddl
mZmZ erddlmZ ddlmZ 	 	 d	 	 	 	 	 dd	Zd
 dddf	 	 	 	 	 	 	 	 	 ddZy)z"File utility functions for Sphinx.    )annotationsN)TYPE_CHECKINGCallable)relative_path)copyfile	ensuredir)BaseRenderer)PathMatcherc                   t         j                  j                  |       syt         j                  j                  |      r>t         j                  j	                  |t         j                  j                  |             }nt        |      }t         j                  j                  |       j                  d      r||ddlm	}  |       }t        | d      5 }|j                  d      r|dd }t        |dd      5 }|j                  |j                  |j                         |             ddd       ddd       yt        | |       y# 1 sw Y   xY w# 1 sw Y   yxY w)	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
    N)_t_Tr   SphinxRendererzutf-8)encodingw)ospathexistsisdirjoinbasenamestrendswithsphinx.util.templater   openwriterender_stringreadr   )sourcedestinationcontextrendererr   fsrcfdsts          6/usr/lib/python3/dist-packages/sphinx/util/fileutil.pycopy_asset_filer'      s    77>>&!	ww}}[!ggll;0@0@0HI+&	ww((67;N;%'H&7+ 	It##L1)#2.k39 IT

811$))+wGHI	I 	I 	%I I	I 	Is$   %E:0E*EE	EEc                     y)NF )r   s    r&   <lambda>r*   7   s        c           	         t         j                  j                  |       sy|ddlm}  |       }t        |       t         j                  j                  |       rt        | |||       yt        j                  | d      D ]  \  }}}	t        | |      }
|dd D ]P  } |t        j                  |
|            r|j                  |       1t        t        j                  ||
|             R |	D ]V  } |t        j                  |
|            r 	 t        t        j                  ||      t        j                  ||
      ||       X  y# t        $ r+}|r |t        j                  ||      |       n Y d}~d}~ww xY w)aM  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.

    :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.
    Nr   r   T)followlinks)r   r   r   r   r   r   isfiler'   walkr   	posixpathr   remove	Exception)r    r!   excludedr"   r#   onerrorr   rootdirsfilesreldirdirfilenameexcs                 r&   
copy_assetr<   6   sK     77>>&!7!#k	ww~~fWh?WWV> dEvt,7 	DC	vs34C )..fcBC		D  
	HINN68<=#INN4$B$-NN;$G$+X7
	 ! 	tX >D Es   6E			E=!E88E=)NN)
r    str | os.PathLike[str]r!   r=   r"   dict | Noner#   BaseRenderer | NonereturnNone)r    r=   r!   r=   r3   r
   r"   r>   r#   r?   r4   z'Callable[[str, Exception], None] | Noner@   rA   )__doc__
__future__r   r   r0   typingr   r   docutils.utilsr   sphinx.util.osutilr   r   r   r	   sphinx.util.typingr
   r'   r<   r)   r+   r&   <module>rH      s    ( " 	  * ( 21. ,048!&(!&1!&=A!&J (:&*DBF.$.#.6I. @. LP.r+   