From 3ce7bae207841dab68e4ff617b429259d1a60d82 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Tue, 7 Jan 2020 14:38:55 +0000 Subject: [PATCH] dotted keys with multiline strings, fix #265 --- toml/decoder.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/toml/decoder.py b/toml/decoder.py index a24c04a..f711246 100644 --- a/toml/decoder.py +++ b/toml/decoder.py @@ -1,5 +1,6 @@ import datetime import io +from copy import deepcopy from os import linesep import re import sys @@ -360,6 +361,7 @@ def loads(s, _dict=dict, decoder=None): " Reached end of file.", original, len(s)) s = ''.join(sl) s = s.split('\n') + multilevel = None multikey = None multilinestr = "" multibackslash = False @@ -392,7 +394,8 @@ def loads(s, _dict=dict, decoder=None): value, vtype = decoder.load_value(multilinestr) except ValueError as err: raise TomlDecodeError(str(err), original, pos) - currentlevel[multikey] = value + multilevel[multikey] = value + multilevel = None multikey = None multilinestr = "" else: @@ -504,12 +507,12 @@ def loads(s, _dict=dict, decoder=None): raise TomlDecodeError(str(err), original, pos) elif "=" in line: try: - ret = decoder.load_line(line, currentlevel, multikey, + v_ = decoder.load_line(line, currentlevel, multikey, multibackslash) except ValueError as err: raise TomlDecodeError(str(err), original, pos) - if ret is not None: - multikey, multilinestr, multibackslash = ret + if v_ is not None: + multilevel, multikey, multilinestr, multibackslash = v_ return retval @@ -779,7 +782,7 @@ def load_line(self, line, currentlevel, multikey, multibackslash): raise ValueError("Duplicate keys!") except KeyError: if multikey: - return multikey, multilinestr, multibackslash + return currentlevel, multikey, multilinestr, multibackslash else: currentlevel[pair[0]] = value