From a07052ff861d0a18f0657dc2b05a46ebf8b89516 Mon Sep 17 00:00:00 2001 From: Deniz Turgut Date: Thu, 18 Apr 2013 02:26:01 -0400 Subject: [PATCH] force argparse output to be unicode in Py2 --- pelican/__init__.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pelican/__init__.py b/pelican/__init__.py index 707fa8f0..c377a04e 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -8,6 +8,7 @@ import sys import time import logging import argparse +import locale from pelican import signals @@ -274,6 +275,18 @@ def get_config(args): config['THEME'] = abstheme if os.path.exists(abstheme) else args.theme if args.delete_outputdir is not None: config['DELETE_OUTPUT_DIRECTORY'] = args.delete_outputdir + + # argparse returns bytes in Py2. There is no definite answer as to which + # encoding argparse (or sys.argv) uses. + # "Best" option seems to be locale.getpreferredencoding() + # ref: http://mail.python.org/pipermail/python-list/2006-October/405766.html + if not six.PY3: + enc = locale.getpreferredencoding() + for key in config: + if key in ('PATH', 'OUTPUT_PATH', 'THEME'): + config[key] = config[key].decode(enc) + if key == "MARKUP": + config[key] = [a.decode(enc) for a in config[key]] return config