+def _FormatList(buf, data, indent_level):
+ """Formats a list of data at a given indent level.
+
+ If the element of the list is:
+ - a string, it is simply formatted as is
+ - a tuple, it will be split into key, value and the all the
+ values in a list will be aligned all at the same start column
+ - a list, will be recursively formatted
+
+ @type buf: StringIO
+ @param buf: the buffer into which we write the output
+ @param data: the list to format
+ @type indent_level: int
+ @param indent_level: the indent level to format at
+
+ """
+ max_tlen = max([len(elem[0]) for elem in data
+ if isinstance(elem, tuple)] or [0])
+ for elem in data:
+ if isinstance(elem, basestring):
+ buf.write("%*s%s\n" % (2*indent_level, "", elem))
+ elif isinstance(elem, tuple):
+ key, value = elem
+ spacer = "%*s" % (max_tlen - len(key), "")
+ buf.write("%*s%s:%s %s\n" % (2*indent_level, "", key, spacer, value))
+ elif isinstance(elem, list):
+ _FormatList(buf, elem, indent_level+1)
+