From 3445066b11ef1123f3a32bb6b87fac5bfe3be293 Mon Sep 17 00:00:00 2001 From: Russ Webber Date: Thu, 18 Jul 2013 09:44:46 +0800 Subject: [PATCH 1/3] fix an exception not correctly reporting if the locale is not set --- pelican/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pelican/__init__.py b/pelican/__init__.py index 53216421..a9aa916c 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -390,7 +390,7 @@ def main(): # so convert the message to unicode with the correct encoding msg = str(e) if not six.PY3: - msg = msg.decode(locale.getpreferredencoding(False)) + msg = msg.decode(locale.getpreferredencoding()) logger.critical(msg) From 2ace30cdb0a80e481c9acc749c9afa0f403d7443 Mon Sep 17 00:00:00 2001 From: Russ Webber Date: Sun, 21 Jul 2013 13:31:11 +0800 Subject: [PATCH 2/3] fix it not setting the default locale If LOCALE was not specified in the settings file it would default to [] insted of [''], where '' is used by locale.setlocale to mean the user's default locale. --- pelican/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pelican/settings.py b/pelican/settings.py index 01203504..5c1bd8f3 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -90,7 +90,7 @@ DEFAULT_CONFIG = { 'MD_EXTENSIONS': ['codehilite(css_class=highlight)', 'extra'], 'JINJA_EXTENSIONS': [], 'JINJA_FILTERS': {}, - 'LOCALE': [], # defaults to user locale + 'LOCALE': [''], # defaults to user locale 'DEFAULT_PAGINATION': False, 'DEFAULT_ORPHANS': 0, 'DEFAULT_METADATA': (), From b527fd594db86bf68ec01b1d6ae6dd4c518f9b04 Mon Sep 17 00:00:00 2001 From: Russ Webber Date: Sun, 21 Jul 2013 14:12:21 +0800 Subject: [PATCH 3/3] added testing for default locale setting removed LOCALE="" from default conf as it looks weird and you shouldn't need to set a blank LOCALE for the system to work. --- pelican/tests/default_conf.py | 1 - pelican/tests/test_settings.py | 12 ++++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pelican/tests/default_conf.py b/pelican/tests/default_conf.py index 80a990b5..62594894 100644 --- a/pelican/tests/default_conf.py +++ b/pelican/tests/default_conf.py @@ -9,7 +9,6 @@ GITHUB_URL = 'http://github.com/ametaireau/' DISQUS_SITENAME = "blog-notmyidea" PDF_GENERATOR = False REVERSE_CATEGORY_ORDER = True -LOCALE = "" DEFAULT_PAGINATION = 2 FEED_RSS = 'feeds/all.rss.xml' diff --git a/pelican/tests/test_settings.py b/pelican/tests/test_settings.py index b1e813e1..7907a551 100644 --- a/pelican/tests/test_settings.py +++ b/pelican/tests/test_settings.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals, print_function import copy import os +import locale from os.path import dirname, abspath, join from pelican.settings import (read_settings, configure_settings, @@ -92,3 +93,14 @@ class TestSettingsConfiguration(unittest.TestCase): settings['FEED_DOMAIN'] = 'http://feeds.example.com' configure_settings(settings) self.assertEqual(settings['FEED_DOMAIN'], 'http://feeds.example.com') + + def test_default_encoding(self): + # test that the default locale is set if + # locale is not specified in the settings + + #reset locale to python default + locale.setlocale(locale.LC_ALL, str('C')) + self.assertEqual(self.settings['LOCALE'], DEFAULT_CONFIG['LOCALE']) + + configure_settings(self.settings) + self.assertEqual(locale.getlocale(), locale.getdefaultlocale())