Commit 071448fb authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

serializer.DumpJson: Control indentation by parameter

If the simplejson module supports indentation, it's always used. There
are cases where we might not want to use it or enable it only for
debugging purposes, such as in RPC.

Reviewed-by: iustinp
parent 6048c986
......@@ -28,6 +28,7 @@ backend (currently json).
import simplejson
import re
# Check whether the simplejson module supports indentation
......@@ -38,14 +39,18 @@ except TypeError:
_RE_EOLSP = re.compile('[ \t]+$', re.MULTILINE)
def DumpJson(data):
def DumpJson(data, indent=True):
"""Serialize a given object.
- indent: Whether to indent output (depends on simplejson version)
if _JSON_INDENT is None:
if not indent or _JSON_INDENT is None:
txt = simplejson.dumps(data)
txt = simplejson.dumps(data, indent=_JSON_INDENT)
txt = _RE_EOLSP.sub("", txt)
if not txt.endswith('\n'):
txt += '\n'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment