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`.
This commit is contained in:
Simen Heggestøyl 2017-10-14 23:46:17 +02:00 committed by Boris Bobrov
parent ceab88e3bd
commit 3eadd6705e
3 changed files with 5 additions and 2 deletions

View File

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

View File

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

View File

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