diff options
author | Georg Brandl <georg@python.org> | 2013-03-30 17:53:04 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2013-03-30 17:53:04 +0100 |
commit | 77d2a90f36a22f5e12f14dc2ef0589f122318d8d (patch) | |
tree | f46e43865e4bed7d75fbe1c74078dad7a706dc78 /sphinx/util/osutil.py | |
parent | b9696a9d9d7462bc8ee50057254854d6d9223646 (diff) | |
download | sphinx-git-77d2a90f36a22f5e12f14dc2ef0589f122318d8d.tar.gz |
Closes #1128: Fix Unicode errors when trying to format time strings with a non-standard locale.
Diffstat (limited to 'sphinx/util/osutil.py')
-rw-r--r-- | sphinx/util/osutil.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py index 7322289ef..6cb310eb0 100644 --- a/sphinx/util/osutil.py +++ b/sphinx/util/osutil.py @@ -14,6 +14,7 @@ import re import sys import time import errno +import locale import shutil from os import path @@ -135,10 +136,12 @@ def make_filename(string): return no_fn_re.sub('', string) if sys.version_info < (3, 0): + # strftime for unicode strings def ustrftime(format, *args): - # strftime for unicode strings - return time.strftime(unicode(format).encode('utf-8'), *args) \ - .decode('utf-8') + # 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(unicode(format).encode(enc), *args).decode(enc) else: ustrftime = time.strftime @@ -159,4 +162,3 @@ def find_catalog(docname, compaction): return ret fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding() - |