From 6ba8a04b9146e29c6d6e30e579927bccf51002f5 Mon Sep 17 00:00:00 2001 From: "Mark W. Eichin" Date: Tue, 7 Apr 2009 07:27:44 +0000 Subject: allow a class to override the display of individual fields; since this is at the class level, it can look at other fields (ie. z_num_hdr_fields) for lengths or other parameters that modify the display. implemented for z_hdr_fields, z_other_fields. probably useful for selecting z_sender_sockaddr values too. --- lib/zephyr_tests.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'lib/zephyr_tests.py') diff --git a/lib/zephyr_tests.py b/lib/zephyr_tests.py index 8f9ca50..06817ca 100755 --- a/lib/zephyr_tests.py +++ b/lib/zephyr_tests.py @@ -28,7 +28,10 @@ def ctypes_pprint(cstruct, indent=""): for field_name, field_ctype in cstruct._fields_: field_value = getattr(cstruct, field_name) print indent + field_name, - if hasattr(field_value, "pprint"): + pprint_name = "pprint_%s" % field_name + if hasattr(cstruct, pprint_name): + print getattr(cstruct, pprint_name)(indent + " ") + elif hasattr(field_value, "pprint"): print field_value.pprint() elif hasattr(field_value, "_fields_"): print @@ -240,6 +243,17 @@ class ZNotice_t(Structure): ("z_hdr_fields", POINTER(c_char_p)), # } ZNotice_t; ] + def pprint_z_other_fields(self, indent): + fields = ["%s%d: %s" % (indent, n, self.z_other_fields[n]) + for n in range(Z_MAXOTHERFIELDS)] + return "\n" + "\n".join(fields) + def pprint_z_hdr_fields(self, indent): + if not self.z_hdr_fields: + return "NULL" + fields = ["%s%d: %s" % (indent, n, self.z_hdr_fields[n]) + for n in range(self.z_num_hdr_fields)] + return "\n" + "\n".join(fields) + class libZephyr(object): -- cgit v1.2.3