projects
/
ganeti-local
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Move SSH option building into a function
[ganeti-local]
/
lib
/
serializer.py
diff --git
a/lib/serializer.py
b/lib/serializer.py
index
d00dbc5
..
05bc334
100644
(file)
--- a/
lib/serializer.py
+++ b/
lib/serializer.py
@@
-26,9
+26,9
@@
backend (currently json).
"""
import simplejson
"""
import simplejson
-import ConfigParser
import re
import re
+
# Check whether the simplejson module supports indentation
_JSON_INDENT = 2
try:
# Check whether the simplejson module supports indentation
_JSON_INDENT = 2
try:
@@
-36,25
+36,33
@@
try:
except TypeError:
_JSON_INDENT = None
except TypeError:
_JSON_INDENT = None
-_RE_EOLSP = re.compile('\s+$', re.MULTILINE)
+_RE_EOLSP = re.compile('[ \t]+$', re.MULTILINE)
-def Dump(data):
+def DumpJson(data, indent=True):
"""Serialize a given object.
"""Serialize a given object.
+ Args:
+ - 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)
else:
txt = simplejson.dumps(data, indent=_JSON_INDENT)
txt = simplejson.dumps(data)
else:
txt = simplejson.dumps(data, indent=_JSON_INDENT)
+
+ txt = _RE_EOLSP.sub("", txt)
if not txt.endswith('\n'):
txt += '\n'
if not txt.endswith('\n'):
txt += '\n'
- txt = _RE_EOLSP.sub("", txt)
return txt
return txt
-def Load(txt):
+def LoadJson(txt):
"""Unserialize data from a string.
"""
return simplejson.loads(txt)
"""Unserialize data from a string.
"""
return simplejson.loads(txt)
+
+
+Dump = DumpJson
+Load = LoadJson