diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2018-09-08 10:52:24 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2018-09-22 21:27:59 +0900 |
commit | 3a2418a82728a138a3c08b084877f76984714254 (patch) | |
tree | a30e94b17f3657b627344f0d0b23f4c238c82c01 /sphinx/util/osutil.py | |
parent | 5ffce30d7527166e444d79e10a88e795d6a0b9c0 (diff) | |
download | sphinx-git-3a2418a82728a138a3c08b084877f76984714254.tar.gz |
refactoring: Drop PY2 and PY3 flags
Diffstat (limited to 'sphinx/util/osutil.py')
-rw-r--r-- | sphinx/util/osutil.py | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py index ffc918557..84d773b7e 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,7 +22,7 @@ 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, RemovedInSphinx40Warning @@ -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): |