bundlewrap/libs/toml.py

20 lines
640 B
Python
Raw Normal View History

from tomlkit import document as toml_document
from bundlewrap.utils import Fault
# Copied from bw core, because bw core doesn't support faults
def dict_to_toml(dict_obj):
toml_doc = toml_document()
for key, value in sorted(dict_obj.items()):
if isinstance(value, tuple):
toml_doc[key] = list(value)
elif isinstance(value, set):
toml_doc[key] = sorted(value)
elif isinstance(value, dict):
toml_doc[key] = dict_to_toml(value)
elif isinstance(value, Fault):
toml_doc[key] = str(value)
else:
toml_doc[key] = value
return toml_doc