def decode(self, data): maxsplit = len(self.fields)-1 if maxsplit < 0: maxsplit = 0 values = data.rstrip('\r\n').split(self.delim, maxsplit) flat = {} for i in range(0, len(values)): k = self.fields[i] flat[k] = self.unescape(values[i]) record = unflatten(flat) return record
def decode(self, data): maxsplit = len(self.fields) - 1 if maxsplit < 0: maxsplit = 0 values = data.rstrip('\r\n').split(self.delim, maxsplit) flat = {} for i in range(0, len(values)): k = self.fields[i] flat[k] = self.unescape(values[i]) record = unflatten(flat) return record
def test_unflatten(): assert unflatten({ 'a': 1, 'data.a': 2, 'data.data.a': 3, }) == { 'a': 1, 'data': { 'a': 2, 'data': { 'a': 3, } } }
def test_roundtrip(): data = { 'a.b.c': 3, } assert data == flatten(unflatten(data))