From 803d87c2e82de7fdf22c1507bf325937b11bd9d7 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Wed, 10 May 2017 13:31:41 +0200 Subject: [PATCH] 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 --- src/osmo_gsm_tester/util.py | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/src/osmo_gsm_tester/util.py b/src/osmo_gsm_tester/util.py index 0849ccbb..e985a0ff 100644 --- a/src/osmo_gsm_tester/util.py +++ b/src/osmo_gsm_tester/util.py @@ -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: '''