Changed show to return a string rather than print
diff --git a/tools/munger/scripts/action_gen.py b/tools/munger/scripts/action_gen.py
index 8746faf..490fa54 100644
--- a/tools/munger/scripts/action_gen.py
+++ b/tools/munger/scripts/action_gen.py
@@ -77,8 +77,9 @@
self.type = --ACTION_NAME--
self.len = self.__len__()
def show(self, prefix=''):
- print prefix + "action_--TYPE--"
- --PARENT_TYPE--.show(self, prefix)
+ outstr += prefix + "action_--TYPE--\\n"
+ outstr += --PARENT_TYPE--.show(self, prefix)
+ return outstr
"""
if __name__ == '__main__':
diff --git a/tools/munger/scripts/error_gen.py b/tools/munger/scripts/error_gen.py
index 7ee2d35..83850f5 100644
--- a/tools/munger/scripts/error_gen.py
+++ b/tools/munger/scripts/error_gen.py
@@ -59,11 +59,12 @@
return OFP_HEADER_BYTES + OFP_ERROR_MSG_BYTES + len(self.data)
def show(self, prefix=''):
- print prefix + "--TYPE--_error_msg"
- self.header.show(prefix + ' ')
- ofp_error_msg.show(self, prefix + ' ')
- print prefix + "data is of length " + str(len(self.data))
+ outstr = prefix + "--TYPE--_error_msg\\m"
+ outstr += self.header.show(prefix + ' ')
+ outstr += ofp_error_msg.show(self, prefix + ' ')
+ outstr += prefix + "data is of length " + str(len(self.data)) + '\\n'
##@todo Consider trying to parse the string
+ return outstr
def __eq__(self, other):
if type(self) != type(other): return False
diff --git a/tools/munger/scripts/message_gen.py b/tools/munger/scripts/message_gen.py
index a839e77..3bda4fd 100644
--- a/tools/munger/scripts/message_gen.py
+++ b/tools/munger/scripts/message_gen.py
@@ -162,9 +162,10 @@
pass
def show(self, prefix=''):
\"""
- Display the contents of the object in a readable manner
+ Generate a string (with multiple lines) describing the contents
+ of the object in a readable manner
- @param prefix Printed at the beginning of each line.
+ @param prefix Pre-pended at the beginning of each line.
\"""
pass
@@ -398,35 +399,37 @@
##@todo Convert this to __str__
def show(self, prefix=''):
\"""
- Display the contents of the object in a readable manner
+ Generate a string (with multiple lines) describing the contents
+ of the object in a readable manner
- @param prefix Printed at the beginning of each line.
+ @param prefix Pre-pended at the beginning of each line.
\"""
"""
- _p2("print prefix + '" + msg + " (" + msg_name + ")'")
+ _p2("outstr = prefix + '" + msg + " (" + msg_name + ")\\n'")
_p2("prefix += ' '")
- _p2("print prefix + 'ofp header'")
- _p2("self.header.show(prefix + ' ')")
+ _p2("outstr += prefix + 'ofp header\\n'")
+ _p2("outstr += self.header.show(prefix + ' ')")
if has_core_members:
- _p2(parent + ".show(self, prefix)")
+ _p2("outstr += " + parent + ".show(self, prefix)")
if has_list:
if list_type == None:
- _p2('print prefix + "Array ' + list_var + '"')
+ _p2('outstr += prefix + "Array ' + list_var + '\\n"')
_p2('for obj in self.' + list_var +':')
- _p3("obj.show(prefix + ' ')")
+ _p3("outstr += obj.show(prefix + ' ')")
else:
- _p2('print prefix + "List ' + list_var + '"')
- _p2('self.' + list_var + ".show(prefix + ' ')")
+ _p2('outstr += prefix + "List ' + list_var + '\\n"')
+ _p2('outstr += self.' + list_var + ".show(prefix + ' ')")
if has_string:
- _p2("print prefix + 'data is of length ' + str(len(self.data))")
+ _p2("outstr += prefix + 'data is of length ' + str(len(self.data)) + '\\n'")
_p2("##@todo Fix this circular reference")
_p2("# if len(self.data) > 0:")
_p3("# obj = of_message_parse(self.data)")
_p3("# if obj != None:")
- _p4("# obj.show(prefix)")
+ _p4("# outstr += obj.show(prefix)")
_p3("# else:")
- _p4('# print prefix + "Unable to parse data"')
+ _p4('# outstr += prefix + "Unable to parse data\\n"')
+ _p2('return outstr')
print """
def __eq__(self, other):
@@ -484,7 +487,7 @@
def __len__(self):
return 0
def show(self, prefix=''):
- print prefix + "ofp_desc_stats_request (empty)"
+ return prefix + "ofp_desc_stats_request (empty)\\n"
def __eq__(self, other):
return type(self) == type(other)
def __ne__(self, other):
@@ -505,7 +508,7 @@
def __len__(self):
return 0
def show(self, prefix=''):
- print prefix + "ofp_table_stats_request (empty)"
+ return prefix + "ofp_table_stats_request (empty)\\n"
def __eq__(self, other):
return type(self) == type(other)
def __ne__(self, other):
@@ -547,11 +550,12 @@
OFP_--TYPE_UPPER--_STATS_REQUEST_BYTES
def show(self, prefix=''):
- print prefix + "--TYPE--_stats_request"
- print prefix + "ofp header:"
- self.header.show(prefix + ' ')
- ofp_stats_request.show(self)
- ofp_--TYPE--_stats_request.show(self)
+ outstr = prefix + "--TYPE--_stats_request\\n"
+ outstr += prefix + "ofp header:\\n"
+ outstr += self.header.show(prefix + ' ')
+ outstr += ofp_stats_request.show(self)
+ outstr += ofp_--TYPE--_stats_request.show(self)
+ return outstr
def __eq__(self, other):
if type(self) != type(other): return False
@@ -612,13 +616,14 @@
return length
def show(self, prefix=''):
- print prefix + "--TYPE--_stats_reply"
- print prefix + "ofp header:"
- self.header.show(prefix + ' ')
- ofp_stats_reply.show(self)
- print prefix + "Stats array of length " + str(len(self.stats))
+ outstr = prefix + "--TYPE--_stats_reply\\n"
+ outstr += prefix + "ofp header:\\n"
+ outstr += self.header.show(prefix + ' ')
+ outstr += ofp_stats_reply.show(self)
+ outstr += prefix + "Stats array of length " + str(len(self.stats)) + '\\n'
for obj in self.stats:
- obj.show()
+ outstr += obj.show()
+ return outstr
def __eq__(self, other):
if type(self) != type(other): return False
@@ -683,9 +688,10 @@
return OFP_FLOW_STATS_BYTES + len(self.actions)
def show(self, prefix=''):
- print prefix + "flow_stats_entry"
- ofp_flow_stats.show(self, prefix + ' ')
- self.actions.show(prefix + ' ')
+ outstr = prefix + "flow_stats_entry\\n"
+ outstr += ofp_flow_stats.show(self, prefix + ' ')
+ outstr += self.actions.show(prefix + ' ')
+ return outstr
def __eq__(self, other):
if type(self) != type(other): return False