Revision 071448fb

b/lib/serializer.py
28 28
import simplejson
29 29
import re
30 30

  
31

  
31 32
# Check whether the simplejson module supports indentation
32 33
_JSON_INDENT = 2
33 34
try:
......
38 39
_RE_EOLSP = re.compile('[ \t]+$', re.MULTILINE)
39 40

  
40 41

  
41
def DumpJson(data):
42
def DumpJson(data, indent=True):
42 43
  """Serialize a given object.
43 44

  
45
  Args:
46
  - indent: Whether to indent output (depends on simplejson version)
47

  
44 48
  """
45
  if _JSON_INDENT is None:
49
  if not indent or _JSON_INDENT is None:
46 50
    txt = simplejson.dumps(data)
47 51
  else:
48 52
    txt = simplejson.dumps(data, indent=_JSON_INDENT)
53

  
49 54
  txt = _RE_EOLSP.sub("", txt)
50 55
  if not txt.endswith('\n'):
51 56
    txt += '\n'

Also available in: Unified diff