From cca2a806c999cbf4ad299c137ae5e728e0b45dd5 Mon Sep 17 00:00:00 2001 From: zer0def Date: Mon, 16 Apr 2018 21:41:35 +0200 Subject: [PATCH] Made interaction with [DEFAULT] section in ConfigParser as sane as upstream permits. --- salt/serializers/configparser.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/salt/serializers/configparser.py b/salt/serializers/configparser.py index 3df65e93f1..14be3fdc1e 100644 --- a/salt/serializers/configparser.py +++ b/salt/serializers/configparser.py @@ -85,15 +85,28 @@ def serialize(obj, **options): raise SerializationError(error) -def _read_dict(configparser, dictionary): +def _is_defaultsect(section_name): + if six.PY3: + return section_name == configparser.DEFAULTSECT + else: # in py2 the check is done against lowercased section name + return section_name.upper() == configparser.DEFAULTSECT + + +def _read_dict(cp, dictionary): ''' Cribbed from python3's ConfigParser.read_dict function. ''' for section, keys in dictionary.items(): section = str(section) - configparser.add_section(section) + + if _is_defaultsect(section): + if six.PY2: + section = configparser.DEFAULTSECT + else: + cp.add_section(section) + for key, value in keys.items(): - key = configparser.optionxform(str(key)) + key = cp.optionxform(str(key)) if value is not None: value = str(value) - configparser.set(section, key, value) + cp.set(section, key, value)