util: simplify listdict

listdict came into the code base from some other python code of mine, for no
apparent reason: it is actually not used here at all. However, an upcoming
patch will use a dict of lists.

Also, the listdict implementation is convoluted/complex (to allow accessing
keys as direct object members, which we don't need). Simplify the
implementation to be used by I0939ef414bc599ee8742df48da04d8d9569d00ba.

Change-Id: I09adfd128a19c6c5ba36aae1d4cab83dbd07e0fb
This commit is contained in:
Neels Hofmeyr 2017-05-10 13:31:41 +02:00 committed by Neels Hofmeyr
parent a6278b7fd0
commit 803d87c2e8
1 changed files with 6 additions and 20 deletions

View File

@ -49,34 +49,20 @@ def ip_to_iface(ip):
pass
return None
class listdict:
class listdict(dict):
'a dict of lists { "a": [1, 2, 3], "b": [1, 2] }'
def __getattr__(ld, name):
if name == 'add':
return ld.__getattribute__(name)
return ld.__dict__.__getattribute__(name)
def add(ld, name, item):
l = ld.__dict__.get(name)
def add(self, name, item):
l = self.get(name)
if not l:
l = []
ld.__dict__[name] = l
self[name] = l
l.append(item)
return l
def add_dict(ld, d):
def add_dict(self, d):
for k,v in d.items():
ld.add(k, v)
def __setitem__(ld, name, val):
return ld.__dict__.__setitem__(name, val)
def __getitem__(ld, name):
return ld.__dict__.__getitem__(name)
def __str__(ld):
return ld.__dict__.__str__()
self.add(k, v)
class DictProxy:
'''