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.py32
1 files changed, 26 insertions, 6 deletions
diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py
index 20c6a90cc..585dc6104 100644
--- a/sphinx/util/osutil.py
+++ b/sphinx/util/osutil.py
@@ -5,7 +5,7 @@
Operating system-related utility functions for Sphinx.
- :copyright: Copyright 2007-2015 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from __future__ import print_function
@@ -40,6 +40,11 @@ def os_path(canonicalpath):
return canonicalpath.replace(SEP, path.sep)
+def canon_path(nativepath):
+ """Return path in OS-independent form"""
+ return nativepath.replace(path.sep, SEP)
+
+
def relative_uri(base, to):
"""Return a relative URL from ``base`` to ``to``."""
if to.startswith(SEP):
@@ -151,15 +156,30 @@ no_fn_re = re.compile(r'[^a-zA-Z0-9_-]')
def make_filename(string):
return no_fn_re.sub('', string) or 'sphinx'
-if PY2:
- # strftime for unicode strings
- def ustrftime(format, *args):
+
+def ustrftime(format, *args):
+ # [DEPRECATED] strftime for unicode strings
+ # It will be removed at Sphinx-1.5
+ if not args:
+ # If time is not specified, try to use $SOURCE_DATE_EPOCH variable
+ # See https://wiki.debian.org/ReproducibleBuilds/TimestampsProposal
+ source_date_epoch = os.getenv('SOURCE_DATE_EPOCH')
+ if source_date_epoch is not None:
+ time_struct = time.gmtime(float(source_date_epoch))
+ args = [time_struct]
+ 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:
- ustrftime = time.strftime
+ else: # Py3
+ # 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):