summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2016-11-22 11:20:20 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-12-10 14:57:37 +0900
commit430424aac0e407748e1241b7a610fff5dace5a99 (patch)
tree92637be8b831abca360329feb1c404a797a1dd48
parent197a6c49a68f55b445b4c31316eb022e30fee300 (diff)
stringify: Add optional attributes list to be displayed
Currently, propery type attributes are ignored in the str and json representations. If we want to include them, it is required to override to_jsondict() and from_jsondict() methods. This patch adds the optional attributes list to specify the addtional attributes included in the str and json representations. Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/lib/stringify.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/ryu/lib/stringify.py b/ryu/lib/stringify.py
index 81eb6178..94ffbbcb 100644
--- a/ryu/lib/stringify.py
+++ b/ryu/lib/stringify.py
@@ -144,6 +144,15 @@ class StringifyMixin(object):
_class_prefixes = []
_class_suffixes = []
+ # List of attributes ignored in the str and json representations.
+ _base_attributes = []
+
+ # Optional attributes included in the str and json representations.
+ # e.g.) In case of attributes are property, the attributes will be
+ # skipped in the str and json representations.
+ # Then, please specify the attributes into this list.
+ _opt_attributes = []
+
def stringify_attrs(self):
"""an override point for sub classes"""
return obj_python_attrs(self)
@@ -368,14 +377,17 @@ def obj_python_attrs(msg_):
yield(k, getattr(msg_, k))
return
base = getattr(msg_, '_base_attributes', [])
+ opt = getattr(msg_, '_opt_attributes', [])
for k, v in inspect.getmembers(msg_):
- if k.startswith('_'):
+ if k in opt:
+ pass
+ elif k.startswith('_'):
continue
- if callable(v):
+ elif callable(v):
continue
- if k in base:
+ elif k in base:
continue
- if hasattr(msg_.__class__, k):
+ elif hasattr(msg_.__class__, k):
continue
yield (k, v)