From 54e1ab93bacea78c482f5631a98f378340577528 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Tue, 4 Jan 2011 15:33:18 +0100 Subject: [PATCH] #570: Try decoding ``-D`` and ``-A`` command-line arguments with the locale's preferred encoding. --- CHANGES | 3 +++ sphinx/cmdline.py | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 7e4de2d2d..83b0bf5c1 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,9 @@ 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. diff --git a/sphinx/cmdline.py b/sphinx/cmdline.py index d2e3a4b17..af780167a 100644 --- a/sphinx/cmdline.py +++ b/sphinx/cmdline.py @@ -90,6 +90,13 @@ def main(argv): 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 @@ -129,7 +136,11 @@ def main(argv): 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: @@ -141,7 +152,11 @@ def main(argv): 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