Skip to content
Snippets Groups Projects
Commit e91ffe49 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Make sure serialized data ends with EOL character

Also fix the regular expression to not remove newlines. The simplejson
module puts whitespace at line endings when using indentation. Remove
unnecessary import of ConfigParser module.

Reviewed-by: ultrotter
parent 0402302c
No related branches found
No related tags found
No related merge requests found
......@@ -26,7 +26,6 @@ backend (currently json).
"""
import simplejson
import ConfigParser
import re
# Check whether the simplejson module supports indentation
......@@ -36,7 +35,7 @@ try:
except TypeError:
_JSON_INDENT = None
_RE_EOLSP = re.compile('\s+$', re.MULTILINE)
_RE_EOLSP = re.compile('[ \t]+$', re.MULTILINE)
def DumpJson(data):
......@@ -47,9 +46,9 @@ def DumpJson(data):
txt = simplejson.dumps(data)
else:
txt = simplejson.dumps(data, indent=_JSON_INDENT)
txt = _RE_EOLSP.sub("", txt)
if not txt.endswith('\n'):
txt += '\n'
txt = _RE_EOLSP.sub("", txt)
return txt
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment