2d2a8c1
Index: docutils-0.8.1/docutils/frontend.py
2d2a8c1
===================================================================
2d2a8c1
--- docutils-0.8.1.orig/docutils/frontend.py
2d2a8c1
+++ docutils-0.8.1/docutils/frontend.py
6a55d12
@@ -33,6 +33,7 @@ import sys
6a55d12
 import warnings
6a55d12
 import ConfigParser as CP
6a55d12
 import codecs
6a55d12
+import locale
6a55d12
 import optparse
6a55d12
 from optparse import SUPPRESS_HELP
6a55d12
 import docutils
6a55d12
@@ -193,7 +194,36 @@ def make_paths_absolute(pathdict, keys,
2d2a8c1
                 value = make_one_path_absolute(base_path, value)
2d2a8c1
             pathdict[key] = value
2d2a8c1
 
2d2a8c1
+def _bytes_path_to_unicode(path):
2d2a8c1
+    '''Change a byte str path segment into unicode
2d2a8c1
+
2d2a8c1
+    Note that this is arguably wrong for Unix systems.  Unix filesystem paths
2d2a8c1
+    are bytes that programs interpret as characters.  Filesystem paths are in
2d2a8c1
+    no way guaranteed to be decodable into unicode.  So this could traceback
2d2a8c1
+    if the locale_encoding can't deal with any byte string and it could give
2d2a8c1
+    wrong values if the locale_encoding does not match the encoding of
2d2a8c1
+    a single one of the path component's values.
2d2a8c1
+
2d2a8c1
+    However, the rest of docutils is turning command line args containing
2d2a8c1
+    filenames into unicode so switching to unicode is more inline with the
2d2a8c1
+    strategy taken by the rest of docutils.
2d2a8c1
+    '''
2d2a8c1
+    # converting to Unicode (Python 3 does this automatically):
2d2a8c1
+    if sys.version_info < (3,0):
2d2a8c1
+        # TODO: make this failsafe and reversible
6a55d12
+        # locale.getpreferredencoding is not to be preferred to getlocale or
6a55d12
+        # getdefaultlocale but it is preferred to hardcoding a value.  We end
6a55d12
+        # with latin-1 because it's one of the encodings that is valid for
6a55d12
+        # every byte.
6a55d12
+        encoding = locale_encoding or locale.getpreferredencoding() or 'latin-1'
6a55d12
+        path = unicode(path, encoding)
2d2a8c1
+    return path
2d2a8c1
+
2d2a8c1
 def make_one_path_absolute(base_path, path):
2d2a8c1
+    if isinstance(base_path, unicode) and not isinstance(path, unicode):
2d2a8c1
+        path = _bytes_path_to_unicode(path)
2d2a8c1
+    elif isinstance(path, unicode) and not isinstance(base_path, unicode):
2d2a8c1
+        base_path = _bytes_path_to_unicode(base_path)
2d2a8c1
     return os.path.abspath(os.path.join(base_path, path))
2d2a8c1
 
2d2a8c1
 def filter_settings_spec(settings_spec, *exclude, **replace):