aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2017-08-27 13:11:26 +0800
committerAaron LI <aly@aaronly.me>2017-08-27 13:11:26 +0800
commit1381532dcd81d1f376c9395fd6b3f6eb4f3279ae (patch)
treefbc70858cac0b6737890881864ee6e4ddbed9d8e
parent3ab87a73ff91fcc0cc33fb9dc43c77589b212498 (diff)
downloadfg21sim-1381532dcd81d1f376c9395fd6b3f6eb4f3279ae.tar.bz2
configs: Use "utf-8" encoding to allow unicode in config files
-rw-r--r--fg21sim/configs/manager.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/fg21sim/configs/manager.py b/fg21sim/configs/manager.py
index 59e364f..3582437 100644
--- a/fg21sim/configs/manager.py
+++ b/fg21sim/configs/manager.py
@@ -148,9 +148,11 @@ class ConfigManager:
"""
configspec = _get_configspec()
self._configspec = ConfigObj(configspec, interpolation=False,
- list_values=False, _inspec=True)
+ list_values=False, _inspec=True,
+ encoding="utf-8")
configs_default = ConfigObj(interpolation=False,
- configspec=self._configspec)
+ configspec=self._configspec,
+ encoding="utf-8")
# Keep a copy of the default configurations
self._config_default = self._validate(configs_default)
# NOTE: use ``copy.deepcopy``; see ``self.reset()`` for more details
@@ -164,12 +166,13 @@ class ConfigManager:
Parameters
----------
- config : `~ConfigObj`, dict, str, or list[str]
+ config : `~configobj.ConfigObj`, dict, str, or list[str]
Supplied configurations to be merged.
"""
if not isinstance(config, ConfigObj):
try:
- config = ConfigObj(config, interpolation=False)
+ config = ConfigObj(config, interpolation=False,
+ encoding="utf-8")
except ConfigObjError as e:
logger.exception(e)
raise ConfigError(e)
@@ -188,7 +191,8 @@ class ConfigManager:
"""
try:
newconfig = ConfigObj(config, interpolation=False,
- configspec=self._configspec)
+ configspec=self._configspec,
+ encoding="utf-8")
except ConfigObjError as e:
raise ConfigError(e)
newconfig = self._validate(newconfig)
@@ -404,7 +408,8 @@ class ConfigManager:
d = reduce(lambda x, y: {y: x}, reversed(key), value)
# Create the temporary ``ConfigObj`` instance and validate it
config_new = ConfigObj(d, interpolation=False,
- configspec=self._configspec)
+ configspec=self._configspec,
+ encoding="utf-8")
# NOTE:
# May raise ``ConfigError`` if fails to pass the validation
config_new = self._validate(config_new)