From e91ffe49c804266a4181ae80abc12f7cf4b74b14 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Wed, 18 Jun 2008 12:29:03 +0000
Subject: [PATCH] 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
---
 lib/serializer.py | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/lib/serializer.py b/lib/serializer.py
index 7345c79e7..c5a8b0d39 100644
--- a/lib/serializer.py
+++ b/lib/serializer.py
@@ -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
 
 
-- 
GitLab