bundlewrap/libs/ini.py
2021-11-13 15:17:03 +01:00

26 lines
548 B
Python

from configparser import ConfigParser
import json
def parse(text):
config = ConfigParser()
config.read_string(text)
return {
section: dict(config.items(section))
for section in config.sections()
}
class Writable():
data = ''
def write(self, line):
self.data += line
def dumps(dict):
config = ConfigParser()
sorted_dict = json.loads(json.dumps(dict, sort_keys=True))
config.read_dict(sorted_dict)
writable = Writable()
config.write(writable)
return writable.data