diff options
author | shimizukawa <shimizukawa@gmail.com> | 2015-10-27 00:16:18 +0900 |
---|---|---|
committer | shimizukawa <shimizukawa@gmail.com> | 2015-10-27 00:16:18 +0900 |
commit | df3643722f0116176388604f676d89104ea39800 (patch) | |
tree | b4a115262b7de11a34838d0c961fb99dbc49e859 /sphinx/util/osutil.py | |
parent | f26f716d597ed82dfb77a4774f35a5cb787ef74a (diff) | |
download | sphinx-git-df3643722f0116176388604f676d89104ea39800.tar.gz |
Fixed #2102: On Windows + Py3, using ``|today|`` and non-ASCII date format will raise UnicodeEncodeError.
Diffstat (limited to 'sphinx/util/osutil.py')
-rw-r--r-- | sphinx/util/osutil.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py index 20c6a90cc..b4488b5c6 100644 --- a/sphinx/util/osutil.py +++ b/sphinx/util/osutil.py @@ -158,8 +158,15 @@ if PY2: # 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: - ustrftime = time.strftime +else: # Py3 + def ustrftime(format, *args): + # On Windows, time.strftime() and Unicode characters will raise UnicodeEncodeError. + # http://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') def safe_relpath(path, start=None): |