summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docutils/core.py10
-rw-r--r--test/test_command_line.py7
2 files changed, 12 insertions, 5 deletions
diff --git a/docutils/core.py b/docutils/core.py
index 620c01ac4..19d57bb17 100644
--- a/docutils/core.py
+++ b/docutils/core.py
@@ -152,11 +152,13 @@ class Publisher:
option_parser = self.setup_option_parser(
usage, description, settings_spec, config_section, **defaults)
if argv is None:
+ argv = sys.argv[1:]
# converting to Unicode (Python 3 does this automatically):
- # TODO: make this failsafe and reversible
- argv_encoding = (sys.stdin.encoding or frontend.locale_encoding
- or 'ascii')
- argv = [a.decode(argv_encoding) for a in sys.argv[1:]]
+ if sys.version_info < (3,0):
+ # TODO: make this failsafe and reversible
+ argv_encoding = (sys.stdin.encoding or
+ frontend.locale_encoding or 'ascii')
+ argv = [a.decode(argv_encoding) for a in argv]
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
index a73249183..d5eab5928 100644
--- a/test/test_command_line.py
+++ b/test/test_command_line.py
@@ -24,9 +24,14 @@ class CommandLineEncodingTests(unittest.TestCase):
def test_sys_argv_decoding(self):
if locale_encoding in (None, 'ascii'): # cannot test
return
- sys.argv.append(u'--title=Dornröschen'.encode(locale_encoding))
+ sys.argv.append('--source-url=test.txt') # pure ASCII argument
+ if sys.version_info < (3,0):
+ sys.argv.append(u'--title=Dornröschen'.encode(locale_encoding))
+ else:
+ sys.argv.append(u'--title=Dornröschen')
publisher = docutils.core.Publisher()
publisher.process_command_line()
+ self.assertEqual(publisher.settings.source_url, 'test.txt')
self.assertEqual(publisher.settings.title, u'Dornröschen')
sys.argv.pop()