From 584a2d20762bec179be2d2814154b340783cd9d7 Mon Sep 17 00:00:00 2001 From: Evan Goode Date: Mon, 12 Aug 2019 13:50:38 -0400 Subject: [PATCH] Add load and dump to pylorax.api.toml --- src/pylorax/api/toml.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/pylorax/api/toml.py b/src/pylorax/api/toml.py index 9af568a9..a87f233d 100644 --- a/src/pylorax/api/toml.py +++ b/src/pylorax/api/toml.py @@ -31,3 +31,12 @@ def loads(s): def dumps(o): # strip the result, because `toml.dumps` adds a lot of newlines return toml.dumps(o, encoder=toml.TomlEncoder(dict)).strip() + +def load(file): + try: + return toml.load(file) + except toml.TomlDecodeError as e: + raise TomlError(e.msg, e.doc, e.pos) + +def dump(o, file): + return toml.dump(o, file)