aboutsummaryrefslogtreecommitdiffstats
path: root/tools/python/xen/xend/PrettyPrint.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/python/xen/xend/PrettyPrint.py')
-rw-r--r--tools/python/xen/xend/PrettyPrint.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/tools/python/xen/xend/PrettyPrint.py b/tools/python/xen/xend/PrettyPrint.py
index 5fcc6e6d08..a57a3c6b52 100644
--- a/tools/python/xen/xend/PrettyPrint.py
+++ b/tools/python/xen/xend/PrettyPrint.py
@@ -285,15 +285,18 @@ def prettyprint(sxpr, out=sys.stdout, width=80):
sxp.show(sxpr, out=out)
print >> out
-def prettyprintstring(sxp):
- class tmpstr:
- def __init__(self):
- self.str = ""
- def write(self, str):
- self.str = self.str + str
- tmp = tmpstr()
- prettyprint(sxp, out=tmp)
- return tmp.str
+def prettyprintstring(sxpr, width=80):
+ """Prettyprint an SXP form to a string.
+
+ sxpr s-expression
+ width maximum output width
+ """
+ io = StringIO.StringIO()
+ prettyprint(sxpr, out=io, width=width)
+ io.seek(0)
+ val = io.getvalue()
+ io.close()
+ return val
def main():
pin = sxp.Parser()