Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / tools / swarming_client / utils / tools.py
index 98dd999..c7537d8 100644 (file)
@@ -4,6 +4,7 @@
 
 """Various utility functions and classes not specific to any single area."""
 
+import cStringIO
 import json
 import logging
 import logging.handlers
@@ -143,6 +144,16 @@ def write_json(filepath_or_handle, data, dense):
       json.dump(data, f, **kwargs)
 
 
+def format_json(data, dense):
+  """Returns a string with json encoded data.
+
+  If dense is True, the json is packed. Otherwise, it is human readable.
+  """
+  buf = cStringIO.StringIO()
+  write_json(buf, data, dense)
+  return buf.getvalue()
+
+
 def report_error(error):
   """Prints a error to stderr, wrapping it into header and footer.