From 3e4971494ebb13b81805baeeff0455db3ebfc790 Mon Sep 17 00:00:00 2001 From: milde Date: Mon, 29 Nov 2010 23:11:25 +0000 Subject: [PATCH] Decode command line arguments with the locales preferred encoding. git-svn-id: https://docutils.svn.sourceforge.net/svnroot/docutils/trunk/docutils@6487 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- HISTORY.txt | 2 ++ docutils/core.py | 8 ++++++- test/test_command_line.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 test/test_command_line.py diff --git a/HISTORY.txt b/HISTORY.txt index 701cc0bfb..2c140f849 100644 --- a/HISTORY.txt +++ b/HISTORY.txt @@ -24,6 +24,8 @@ Changes Since 0.7 warn and fall back to English. - Math support: reStructuredText "math" role and directive, ``math`` and ``math_block`` doctree elements. + - Decode command line arguments with the locales preferred encoding + (to allow, e.g., ``--title=Dornröschen``. .. _BCP 47: http://www.rfc-editor.org/rfc/bcp/bcp47.txt diff --git a/docutils/core.py b/docutils/core.py index 0f66e440f..21f8d54be 100644 --- a/docutils/core.py +++ b/docutils/core.py @@ -22,6 +22,12 @@ from docutils.frontend import OptionParser from docutils.transforms import Transformer import docutils.readers.doctree +try: + import locale + argv_encoding = locale.getpreferredencoding() +except: + argv_encoding = 'ascii' + class Publisher: @@ -150,7 +156,7 @@ class Publisher: option_parser = self.setup_option_parser( usage, description, settings_spec, config_section, **defaults) if argv is None: - argv = sys.argv[1:] + argv = [a.decode(argv_encoding) for a in sys.argv[1:]] self.settings = option_parser.parse_args(argv) def set_io(self, source_path=None, destination_path=None): diff --git a/test/test_command_line.py b/test/test_command_line.py new file mode 100644 index 000000000..9abcac22e --- /dev/null +++ b/test/test_command_line.py @@ -0,0 +1,54 @@ +#! /usr/bin/env python +# .. coding: utf8 +# $Id$ +# Author: Günter Milde +# Copyright: This module has been placed in the public domain. + +""" +Test module for the command line. +""" + +import os.path +import unittest +import sys +import DocutilsTestSupport # must be imported before docutils +import docutils.core +import docutils.utils + +try: + import locale + argv_encoding = locale.getpreferredencoding() +except: + argv_encoding = None + +testoutput = """\ + + +