o $a@sdZddlZddlZddlmZmZmZddlmZddl m Z m Z ddl m Z er0ddlmZ dded ed ed d d df ddZdddddfded ede d ed d deeegdfd dfddZdS)z sphinx.util.fileutil ~~~~~~~~~~~~~~~~~~~~ File utility functions for Sphinx. :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. N) TYPE_CHECKINGCallableDict) relative_path)copyfile ensuredir) PathMatcher) BaseRenderersource destinationcontextrendererr returnc Cstj|sdStj|rtj|tj|}|dr|dur|dur1ddlm }|}t |dd@}|drE|dd}t |ddd}| | | |Wdn1sbwYWddSWddS1szwYdSt||dS) aCopy 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_trSphinxRendererzutf-8)encodingw)ospathexistsisdirjoinbasenamelowerendswithsphinx.util.templateropenwrite render_stringreadr)r r r r rfsrcfdstr$6/usr/lib/python3/dist-packages/sphinx/util/fileutil.pycopy_asset_files$    "r&cCsdS)NFr$)rr$r$r%9sr'excludedonerrorc Cs4tj|sdS|durddlm}|}t|tj|r(t||||dStj|ddD]h\}}} t ||} |ddD]} |t | | rO| | q?tt || | q?| D];} |t | | sztt || t || ||Wq[t y} z|r|t || | nWYd} ~ q[d} ~ wwq[q/dS)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. NrrT) followlinks)rrrrrrisfiler&walkr posixpathrremove Exception)r r r(r r r)rrootdirsfilesreldirdirfilenameexcr$r$r% copy_asset9s@        r7)NN)__doc__rr-typingrrrdocutils.utilsrsphinx.util.osutilrrsphinx.util.typingrrr strr&r/r7r$r$r$r%s:      !