1
0
Fork 0
forked from github/pelican

force argparse output to be unicode in Py2

This commit is contained in:
Deniz Turgut 2013-04-18 02:26:01 -04:00
commit a07052ff86

View file

@ -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