[PATCH v4 24/41] dissector: Introduce a class to handle wireshark attributes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]