From 1e70503fef51aa419558ea767f56018642307010 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= <simen@e5r.no>
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
|
b
|
def read_mediagoblin_config(config_path, config_spec_path=CONFIG_SPEC_PATH):
|
123 | 123 | config = ConfigObj( |
124 | 124 | config_path, |
125 | 125 | configspec=config_spec, |
| 126 | encoding="UTF8", |
126 | 127 | interpolation="ConfigParser") |
127 | 128 | |
128 | 129 | _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
|
b
|
num_carrots = 88
|
7 | 7 | encouragement_phrase = "I'd love it if you eat your carrots!" |
8 | 8 | |
9 | 9 | # Something extra! |
10 | | blah_blah = "blah!" |
| 10 | blah_blah = "blÊh!" |
11 | 11 | |
12 | 12 | [celery] |
13 | 13 | EAT_CELERY_WITH_CARROTS = False |
diff --git a/mediagoblin/tests/test_config.py b/mediagoblin/tests/test_config.py
index b13adae6..c3527418 100644
a
|
b
|
|
| 1 | # -*- coding: utf-8 -*- |
| 2 | # |
1 | 3 | # GNU MediaGoblin -- federated, autonomous media hosting |
2 | 4 | # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. |
3 | 5 | # |
… |
… |
def test_read_mediagoblin_config():
|
47 | 49 | assert this_conf['carrotapp']['num_carrots'] == 88 |
48 | 50 | assert this_conf['carrotapp']['encouragement_phrase'] == \ |
49 | 51 | "I'd love it if you eat your carrots!" |
50 | | assert this_conf['carrotapp']['blah_blah'] == "blah!" |
| 52 | assert this_conf['carrotapp']['blah_blah'] == u"blÊh!" |
51 | 53 | assert this_conf['celery']['EAT_CELERY_WITH_CARROTS'] == False |
52 | 54 | |
53 | 55 | # A bad file |