From 3eadd6705e9ad5ee39042a130d7b3fdd74200d68 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Simen=20Heggest=C3=B8yl?= Date: Sat, 14 Oct 2017 23:46:17 +0200 Subject: [PATCH] Support Unicode characters in configuration values Prior to this commit, using a Unicode character in a configuration string would result in a `UnicodeDecodeError` being raised. Supporting Unicode characters is especially useful in user-facing configuration strings, such as `html_title`. --- mediagoblin/init/config.py | 1 + mediagoblin/tests/fake_carrot_conf_good.ini | 2 +- mediagoblin/tests/test_config.py | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/mediagoblin/init/config.py b/mediagoblin/init/config.py index a9189e8d..fe469156 100644 --- a/mediagoblin/init/config.py +++ b/mediagoblin/init/config.py @@ -123,6 +123,7 @@ def read_mediagoblin_config(config_path, config_spec_path=CONFIG_SPEC_PATH): config = ConfigObj( config_path, configspec=config_spec, + encoding="UTF8", interpolation="ConfigParser") _setup_defaults(config, config_path, mainconfig_defaults) diff --git a/mediagoblin/tests/fake_carrot_conf_good.ini b/mediagoblin/tests/fake_carrot_conf_good.ini index 1377907b..8dc32525 100644 --- a/mediagoblin/tests/fake_carrot_conf_good.ini +++ b/mediagoblin/tests/fake_carrot_conf_good.ini @@ -7,7 +7,7 @@ num_carrots = 88 encouragement_phrase = "I'd love it if you eat your carrots!" # Something extra! -blah_blah = "blah!" +blah_blah = "blæh!" [celery] EAT_CELERY_WITH_CARROTS = False diff --git a/mediagoblin/tests/test_config.py b/mediagoblin/tests/test_config.py index b13adae6..c3527418 100644 --- a/mediagoblin/tests/test_config.py +++ b/mediagoblin/tests/test_config.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # GNU MediaGoblin -- federated, autonomous media hosting # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. # @@ -47,7 +49,7 @@ def test_read_mediagoblin_config(): assert this_conf['carrotapp']['num_carrots'] == 88 assert this_conf['carrotapp']['encouragement_phrase'] == \ "I'd love it if you eat your carrots!" - assert this_conf['carrotapp']['blah_blah'] == "blah!" + assert this_conf['carrotapp']['blah_blah'] == u"blæh!" assert this_conf['celery']['EAT_CELERY_WITH_CARROTS'] == False # A bad file -- 2.25.1