diff options
Diffstat (limited to 'sphinx/util/fileutil.py')
-rw-r--r-- | sphinx/util/fileutil.py | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/sphinx/util/fileutil.py b/sphinx/util/fileutil.py index 7670ecb0c..68dd7151f 100644 --- a/sphinx/util/fileutil.py +++ b/sphinx/util/fileutil.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ sphinx.util.fileutil ~~~~~~~~~~~~~~~~~~~~ @@ -8,15 +7,13 @@ :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ -from __future__ import absolute_import -import codecs import os import posixpath from docutils.utils import relative_path -from sphinx.util.osutil import copyfile, ensuredir, walk +from sphinx.util.osutil import copyfile, ensuredir if False: # For type annotation @@ -26,7 +23,7 @@ if False: def copy_asset_file(source, destination, context=None, renderer=None): - # type: (unicode, unicode, Dict, BaseRenderer) -> None + # type: (str, str, Dict, BaseRenderer) -> None """Copy an asset file to destination. On copying, it expands the template variables if context argument is given and @@ -40,26 +37,26 @@ def copy_asset_file(source, destination, context=None, renderer=None): if not os.path.exists(source): return - if os.path.exists(destination) and os.path.isdir(destination): + if os.path.isdir(destination): # Use source filename if destination points a directory destination = os.path.join(destination, os.path.basename(source)) - if source.lower().endswith('_t') and context: + if source.lower().endswith('_t') and context is not None: if renderer is None: from sphinx.util.template import SphinxRenderer renderer = SphinxRenderer() - with codecs.open(source, 'r', encoding='utf-8') as fsrc: # type: ignore + with open(source, encoding='utf-8') as fsrc: if destination.lower().endswith('_t'): destination = destination[:-2] - with codecs.open(destination, 'w', encoding='utf-8') as fdst: # type: ignore + with open(destination, 'w', encoding='utf-8') as fdst: fdst.write(renderer.render_string(fsrc.read(), context)) else: copyfile(source, destination) def copy_asset(source, destination, excluded=lambda path: False, context=None, renderer=None): - # type: (unicode, unicode, Union[Callable[[unicode], bool], Matcher], Dict, BaseRenderer) -> None # NOQA + # type: (str, str, Union[Callable[[str], bool], Matcher], Dict, BaseRenderer) -> None """Copy asset files to destination recursively. On copying, it expands the template variables if context argument is given and @@ -83,7 +80,7 @@ def copy_asset(source, destination, excluded=lambda path: False, context=None, r copy_asset_file(source, destination, context, renderer) return - for root, dirs, files in walk(source, followlinks=True): + for root, dirs, files in os.walk(source, followlinks=True): reldir = relative_path(source, root) for dir in dirs[:]: if excluded(posixpath.join(reldir, dir)): |