mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Merge pull request #47151 from zer0def/configparser-defaultsect
Allow interaction with default section in ConfigParser serializer
This commit is contained in:
commit
a2ed8cbb7f
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user