From 1301ffcdc102ad41ab061301665594e099c5a6df Mon Sep 17 00:00:00 2001 From: Anders Blomdell <anders.blomdell@control.lth.se> Date: Mon, 13 May 2013 19:39:56 +0200 Subject: [PATCH] Simplified anonymous_object by inheriting dict. --- lib/python/labcomm/LabComm.py | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/lib/python/labcomm/LabComm.py b/lib/python/labcomm/LabComm.py index a6ede79..b137925 100644 --- a/lib/python/labcomm/LabComm.py +++ b/lib/python/labcomm/LabComm.py @@ -468,34 +468,19 @@ TYPEDEF = typedef(None, None) ARRAY = array(None, None) STRUCT = struct({}) -class anonymous_object(object): - def __init__(self): - self._attr = {} - +class anonymous_object(dict): def __setattr__(self, name, value): if name.startswith("_"): super(anonymous_object, self).__setattr__(name, value) else: - self._attr[name] = value + self[name] = value def __getattr__(self, name): if name.startswith("_"): return super(anonymous_object, self).__getattr__(name) else: - return self._attr[name] - - def __getattribute__(self, name): - if name.startswith("_"): - return super(anonymous_object, self).__getattribute__(name) - else: - return self._attr[name] - - def __iter__(self): - return self._attr.iteritems() + return self[name] - def __repr__(self): - return self._attr.__repr__() - class Codec(object): def __init__(self): self.type_to_name = {} -- GitLab