ó
öÀ„\c           @@  sÓ   d  Z  d d l m Z d d l Z d d l Z d d l Z d d l m Z d d l m	 Z	 m
 Z
 m Z e r« d d l m Z m Z m Z d d l m Z d d l m Z n  d d d	 „ Z d
 „  d d d „ Z d S(   sÍ   
    sphinx.util.fileutil
    ~~~~~~~~~~~~~~~~~~~~

    File utility functions for Sphinx.

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
i    (   t   absolute_importN(   t   relative_path(   t   copyfilet	   ensuredirt   walk(   t   Callablet   Dictt   Union(   t   Matcher(   t   BaseRendererc         C@  s8  t  j j |  ƒ s d St  j j | ƒ r^ t  j j | ƒ r^ t  j j | t  j j |  ƒ ƒ } n  |  j ƒ  j d ƒ r'| r'| d k r¡ d d l	 m
 } | ƒ  } n  t j |  d d d ƒi } | j ƒ  j d ƒ rÞ | d  } n  t j | d	 d d ƒ& } | j | j | j ƒ  | ƒ ƒ Wd QXWd QXn t |  | ƒ d S(
   sÂ  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
    Nt   _ti    (   t   SphinxRenderert   rt   encodings   utf-8iþÿÿÿt   w(   t   ost   patht   existst   isdirt   joint   basenamet   lowert   endswitht   Nonet   sphinx.util.templateR   t   codecst   opent   writet   render_stringt   readR   (   t   sourcet   destinationt   contextt   rendererR   t   fsrct   fdst(    (    s3   lib/python2.7/site-packages/sphinx/util/fileutil.pyt   copy_asset_file   s    $$.c         C@  s   t  S(   N(   t   False(   R   (    (    s3   lib/python2.7/site-packages/sphinx/util/fileutil.pyt   <lambda>=   s    c         C@  sT  t  j j |  ƒ s d S| d k r> d d l m } | ƒ  } n  t | ƒ t  j j |  ƒ rq t |  | | | ƒ d SxÜ t	 |  d t
 ƒD]È \ } } } t |  | ƒ }	 xP | D]G }
 | t j |	 |
 ƒ ƒ rØ | j |
 ƒ qª t t j | |	 |
 ƒ ƒ qª WxT | D]L } | t j |	 | ƒ ƒ sü t t j | | ƒ t j | |	 ƒ | | ƒ qü qü Wq„ Wd S(   s&  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
    Ni    (   R   t   followlinks(   R   R   R   R   R   R   R   t   isfileR$   R   t   TrueR   t	   posixpathR   t   remove(   R   R   t   excludedR    R!   R   t   roott   dirst   filest   reldirt   dirt   filename(    (    s3   lib/python2.7/site-packages/sphinx/util/fileutil.pyt
   copy_asset=   s(    
"(   t   __doc__t
   __future__R    R   R   R*   t   docutils.utilsR   t   sphinx.util.osutilR   R   R   R%   t   typingR   R   R   t   sphinx.util.matchingR   R   R	   R   R$   R3   (    (    (    s3   lib/python2.7/site-packages/sphinx/util/fileutil.pyt   <module>
   s   !