summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYAMAMOTO Takashi <yamamoto@valinux.co.jp>2013-12-19 16:18:00 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2013-12-25 12:13:01 +0900
commitac94864869c8d54e62aa505a9fb11bc262d3d5ac (patch)
treea31462dbd461832ad9494cb4f67492bcff5b53e3
parentf3060bff7dae5279f6abb8f9d676fc39a3d1b29f (diff)
of_config: allows both of of-config element names and python style names
for convenience of api consumers, allows both of of-config style element names (eg. logical-switches) and python style attribute names (eg. logical_switches). Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/lib/of_config/base.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/ryu/lib/of_config/base.py b/ryu/lib/of_config/base.py
index bb467f77..6495924b 100644
--- a/ryu/lib/of_config/base.py
+++ b/ryu/lib/of_config/base.py
@@ -60,11 +60,16 @@ class _Base(stringify.StringifyMixin):
k = _pythonify(e.name)
try:
v = kwargs.pop(k)
+ assert not e.name in kwargs
except KeyError:
- if e.is_list:
- v = []
- else:
- v = None
+ k = e.name
+ try:
+ v = kwargs.pop(k)
+ except KeyError:
+ if e.is_list:
+ v = []
+ else:
+ v = None
setattr(self, k, v)
if kwargs:
raise TypeError('unknown kwargs %s' % kwargs)
@@ -129,6 +134,12 @@ class _Base(stringify.StringifyMixin):
kwargs[k] = v
return cls(**kwargs)
+ def __getattribute__(self, k):
+ return stringify.StringifyMixin.__getattribute__(self, _pythonify(k))
+
+ def __setattr__(self, k, v):
+ stringify.StringifyMixin.__setattr__(self, _pythonify(k), v)
+
class _Unimpl(_Base):
_ELEMENTS = [