summaryrefslogtreecommitdiff
path: root/sphinx/util/osutil.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/util/osutil.py')
-rw-r--r--sphinx/util/osutil.py39
1 files changed, 15 insertions, 24 deletions
diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py
index 986171293..38a986f6b 100644
--- a/sphinx/util/osutil.py
+++ b/sphinx/util/osutil.py
@@ -13,7 +13,6 @@ from __future__ import print_function
import contextlib
import errno
import filecmp
-import locale
import os
import re
import shutil
@@ -23,9 +22,9 @@ import warnings
from io import BytesIO, StringIO
from os import path
-from six import PY2, PY3, text_type
+from six import text_type
-from sphinx.deprecation import RemovedInSphinx30Warning
+from sphinx.deprecation import RemovedInSphinx30Warning, RemovedInSphinx40Warning
if False:
# For type annotation
@@ -37,9 +36,6 @@ ENOENT = getattr(errno, 'ENOENT', 0)
EPIPE = getattr(errno, 'EPIPE', 0)
EINVAL = getattr(errno, 'EINVAL', 0)
-if PY3:
- unicode = str # special alias for static typing...
-
# SEP separates path elements in the canonical file names
#
# Define SEP as a manifest constant, not so much because we expect it to change
@@ -195,19 +191,13 @@ def ustrftime(format, *args):
if source_date_epoch is not None:
time_struct = time.gmtime(float(source_date_epoch))
args = [time_struct] # type: ignore
- if PY2:
- # if a locale is set, the time strings are encoded in the encoding
- # given by LC_TIME; if that is available, use it
- enc = locale.getlocale(locale.LC_TIME)[1] or 'utf-8'
- return time.strftime(text_type(format).encode(enc), *args).decode(enc)
- else: # Py3
- # On Windows, time.strftime() and Unicode characters will raise UnicodeEncodeError.
- # https://bugs.python.org/issue8304
- try:
- return time.strftime(format, *args)
- except UnicodeEncodeError:
- r = time.strftime(format.encode('unicode-escape').decode(), *args)
- return r.encode().decode('unicode-escape')
+ # On Windows, time.strftime() and Unicode characters will raise UnicodeEncodeError.
+ # https://bugs.python.org/issue8304
+ try:
+ return time.strftime(format, *args) # type: ignore
+ except UnicodeEncodeError:
+ r = time.strftime(format.encode('unicode-escape').decode(), *args) # type: ignore
+ return r.encode().decode('unicode-escape')
def relpath(path, start=os.curdir):
@@ -235,7 +225,7 @@ def abspath(pathdir):
try:
pathdir = pathdir.decode(fs_encoding)
except UnicodeDecodeError:
- raise UnicodeDecodeError('multibyte filename not supported on '
+ raise UnicodeDecodeError('multibyte filename not supported on ' # type: ignore
'this filesystem encoding '
'(%r)' % fs_encoding)
return pathdir
@@ -243,15 +233,16 @@ def abspath(pathdir):
def getcwd():
# type: () -> unicode
- if hasattr(os, 'getcwdu'):
- return os.getcwdu()
+ warnings.warn('sphinx.util.osutil.getcwd() is deprecated. '
+ 'Please use os.getcwd() instead.',
+ RemovedInSphinx40Warning)
return os.getcwd()
@contextlib.contextmanager
def cd(target_dir):
# type: (unicode) -> Iterator[None]
- cwd = getcwd()
+ cwd = os.getcwd()
try:
os.chdir(target_dir)
yield
@@ -259,7 +250,7 @@ def cd(target_dir):
os.chdir(cwd)
-class FileAvoidWrite(object):
+class FileAvoidWrite:
"""File-like object that buffers output and only writes if content changed.
Use this class like when writing to a file to avoid touching the original