If the string for a key is repeated, key_value_to_tree() produces strange results, up to and including exceptions:
In [1]: import collections
In [2]: import pepa
In [3]: data = collections.OrderedDict([('foo..bar..foo', True), ('foo..bar..baz', True)])
In [4]: pepa.key_value_to_tree(data, '..')
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-4-f64c7011dc9a> in <module>()
----> 1 pepa.key_value_to_tree(data, '..')
/mnt/c/Users/bewing/PycharmProjects/pepa/pepa/__init__.pyc in key_value_to_tree(data, delimiter)
28 t[key] = value
29 else:
---> 30 t = t.setdefault(key, {})
31 return tree
32
AttributeError: 'bool' object has no attribute 'setdefault'
In order to avoid this, we will probably have to track the number of times a key appears in the hierarchy, and only set once we really are on the last key.
If the string for a key is repeated, key_value_to_tree() produces strange results, up to and including exceptions:
In order to avoid this, we will probably have to track the number of times a key appears in the hierarchy, and only set once we really are on the last key.