[Spice-devel] [PATCH v5 24/41] dissector: Introduce a class to handle wireshark attributes
Frediano Ziglio
fziglio at redhat.com
Fri Aug 7 08:00:53 PDT 2015
This class will allow to handle wireshark attributes in a simpler way.
This as different elements handle attributes in a slightly different
way so handle the logic in a single class.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
python_modules/dissector.py | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/python_modules/dissector.py b/python_modules/dissector.py
index db5d364..5ccdbbe 100644
--- a/python_modules/dissector.py
+++ b/python_modules/dissector.py
@@ -26,6 +26,43 @@ hf_writer = None
hf_defs = None
+# handle wireshark attributes
+# is quite complex as attributes ca come from
+# member or array
+# - pointers, have their attributes
+# - array, get from member
+# - primitive or structure from array, specific attributes or type
+# - primitive or structure not in array, member or type
+class WSAttributes:
+ def __init__(self, t, other=None):
+ self.add_attrs = other
+ self.attrs = t.attributes
+
+ def _getattr(self, name, default=[None,None]):
+ if self.add_attrs and name in self.add_attrs:
+ return self.add_attrs[name]
+ return self.attrs.get(name, default)
+
+ def __getattr__(self, name):
+ if name == 'name':
+ val = self._getattr('ws')[1]
+ elif name == 'desc':
+ val = self._getattr('ws_desc')[0]
+ if val is None:
+ val = self._getattr('ws')[0]
+ elif name in {'type', 'base'}:
+ val = self._getattr('ws_' + name)[0]
+ elif name in {'txt', 'txt_n'}:
+ val = self._getattr('ws_' + name,None)
+ else:
+ raise AttributeError('Attribute %s not supported' % name)
+ self.__dict__[name] = val
+ return val
+
+ def has_txts(self):
+ return self.txt is not None or self.txt_n is not None
+
+
def write_parser_helpers(writer):
if writer.is_generated("helper", "demarshaller"):
return
--
2.1.0
More information about the Spice-devel
mailing list