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 <[email protected]>
---
 ryu/lib/stringify.py | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/ryu/lib/stringify.py b/ryu/lib/stringify.py
index 81eb617..94ffbbc 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)
 
-- 
2.7.4


------------------------------------------------------------------------------
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to