Georg Brandl avatar Georg Brandl committed 4aaa995

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

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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.