3

T'íc9ã	@s°dZddlZddlZddlmZmZmZddlmZddl	m
Z
mZddlm
Z
er`ddlmZdeeeddd	œd
d„Zdd
„dddfeee
edeeegdfddœdd„ZdS)z"File utility functions for Sphinx.éN)Ú
TYPE_CHECKINGÚCallableÚDict)Ú
relative_path)ÚcopyfileÚ	ensuredir)ÚPathMatcher)ÚBaseRendererr	)ÚsourceÚdestinationÚcontextÚrendererÚreturncCsÔtjj|ƒsdStjj|ƒr2tjj|tjj|ƒƒ}|jƒjdƒrÆ|dk	rÆ|dkrbddlm	}|ƒ}t
|ddP}|jƒjdƒrŠ|dd	…}t
|ddd}|j|j|j
ƒ|ƒƒWdQRXWdQRXn
t||ƒdS)
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
    NZ_tr)ÚSphinxRendererzutf-8)ÚencodingéÚwéþÿÿÿ)ÚosÚpathÚexistsÚisdirÚjoinÚbasenameÚlowerÚendswithÚsphinx.util.templaterÚopenÚwriteZ
render_stringÚreadr)r
rrr
rÚfsrcÚfdst©r"ú6/tmp/pip-build-gk9425m9/sphinx/sphinx/util/fileutil.pyÚcopy_asset_files,r$cCsdS)NFr")rr"r"r#Ú<lambda>1sr%)r
rÚexcludedrr
ÚonerrorrcCsBtjj|ƒsdS|dkr*ddlm}|ƒ}t|ƒtjj|ƒrPt||||ƒdSxìtj|ddD]Ú\}}}	t	||ƒ}
xB|dd…D]2}|t
j|
|ƒƒr¢|j|ƒq‚tt
j||
|ƒƒq‚Wx€|	D]x}|t
j|
|ƒƒs¾y"tt
j||ƒt
j||
ƒ||ƒWq¾t
k
r4}
z"|r"|t
j||ƒ|
ƒn‚WYdd}
~
Xq¾Xq¾Wq`WdS)aMCopy 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)rT)Úfollowlinks)rrrrrrÚisfiler$ÚwalkrÚ	posixpathrÚremoveÚ	Exception)r
rr&rr
r'rÚrootÚdirsÚfilesZreldirÚdirÚfilenameÚexcr"r"r#Ú
copy_asset1s2


r4)NN)Ú__doc__rr+ÚtypingrrrZdocutils.utilsrZsphinx.util.osutilrrZsphinx.util.typingrrr	Ústrr$r-r4r"r"r"r#Ú<module>s