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). ...@@ -26,7 +26,6 @@ backend (currently json).
""" """
import simplejson import simplejson
import ConfigParser
import re import re
# Check whether the simplejson module supports indentation # Check whether the simplejson module supports indentation
...@@ -36,7 +35,7 @@ try: ...@@ -36,7 +35,7 @@ try:
except TypeError: except TypeError:
_JSON_INDENT = None _JSON_INDENT = None
_RE_EOLSP = re.compile('\s+$', re.MULTILINE) _RE_EOLSP = re.compile('[ \t]+$', re.MULTILINE)
def DumpJson(data): def DumpJson(data):
...@@ -47,9 +46,9 @@ def DumpJson(data): ...@@ -47,9 +46,9 @@ def DumpJson(data):
txt = simplejson.dumps(data) txt = simplejson.dumps(data)
else: else:
txt = simplejson.dumps(data, indent=_JSON_INDENT) txt = simplejson.dumps(data, indent=_JSON_INDENT)
txt = _RE_EOLSP.sub("", txt)
if not txt.endswith('\n'): if not txt.endswith('\n'):
txt += '\n' txt += '\n'
txt = _RE_EOLSP.sub("", txt)
return 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