--- python_modules/dissector.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/python_modules/dissector.py b/python_modules/dissector.py index d623576..827f7f0 100644 --- a/python_modules/dissector.py +++ b/python_modules/dissector.py @@ -25,6 +25,45 @@ 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_name')[0] + if val is None: + 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