Commits

Georg Brandl committed 4aaa995

#570: Try decoding ``-D`` and ``-A`` command-line arguments with the locale's preferred encoding.

  • Participants
  • Parent commits c497e81

Comments (0)

Files changed (2)

 Release 1.0.6 (in development)
 ==============================
 
+* #570: Try decoding ``-D`` and ``-A`` command-line arguments with
+  the locale's preferred encoding.
+
 * #528: Observe :confval:`locale_dirs` when looking for the JS
   translations file.
 

sphinx/cmdline.py

     if err:
         return 1
 
+    # likely encoding used for command-line arguments
+    try:
+        locale = __import__('locale')  # due to submodule of the same name
+        likely_encoding = locale.getpreferredencoding()
+    except Exception:
+        likely_encoding = None
+
     buildername = None
     force_all = freshenv = warningiserror = use_pdb = False
     status = sys.stdout
             try:
                 val = int(val)
             except ValueError:
-                pass
+                if likely_encoding:
+                    try:
+                        val = val.decode(likely_encoding)
+                    except UnicodeError:
+                        pass
             confoverrides[key] = val
         elif opt == '-A':
             try:
             try:
                 val = int(val)
             except ValueError:
-                pass
+                if likely_encoding:
+                    try:
+                        val = val.decode(likely_encoding)
+                    except UnicodeError:
+                        pass
             confoverrides['html_context.%s' % key] = val
         elif opt == '-n':
             confoverrides['nitpicky'] = True