예제 #1
0
파일: codec.py 프로젝트: acg/lwpb
  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
예제 #2
0
    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
예제 #3
0
def test_unflatten():
    assert unflatten({
        'a': 1,
        'data.a': 2,
        'data.data.a': 3,
    }) == {
        'a': 1,
        'data': {
            'a': 2,
            'data': {
                'a': 3,
            }
        }
    }
예제 #4
0
def test_unflatten():
    assert unflatten({
        'a': 1,
        'data.a': 2,
        'data.data.a': 3,
    }) == {
        'a': 1,
        'data': {
            'a': 2,
            'data': {
                'a': 3,
            }
        }
    }
예제 #5
0
def test_roundtrip():
    data = {
        'a.b.c': 3,
    }
    assert data == flatten(unflatten(data))
예제 #6
0
def test_roundtrip():
    data = {
        'a.b.c': 3,
    }
    assert data == flatten(unflatten(data))