diff options
-rw-r--r-- | cliapp/settings.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/cliapp/settings.py b/cliapp/settings.py index de058c9..298cd6a 100644 --- a/cliapp/settings.py +++ b/cliapp/settings.py @@ -301,7 +301,20 @@ class Settings(object): self._add_default_settings() self._config_files = None - self._cp = configparser.ConfigParser() + + self._cp = self._create_configparser() + + def _create_configparser(self): + if sys.version_info[0] == 2: + cp = configparser.ConfigParser() + else: + # The default interpolation in Python 3 is + # configparser.BasicInterpolation. This class parses % symbols in + # the strings, which can break existing cliapp.settings users. The + # LegacyInterpolation class preserves the Python 2 behaviour. + cp = configparser.RawConfigParser( + interpolation=configparser.LegacyInterpolation()) + return cp def _add_default_settings(self): self.string(['output'], @@ -751,7 +764,7 @@ class Settings(object): ''' - cp = configparser.ConfigParser() + cp = self._create_configparser() cp.add_section('config') for pathname in self.config_files: @@ -787,7 +800,7 @@ class Settings(object): meanings it desires to the section names. ''' - cp = configparser.ConfigParser() + cp = self._create_configparser() cp.add_section('config') for name in self._canonical_names: cp.set('config', name, self._settingses[name].format()) |