projects
/
ganeti-local
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add utils.IsNormAbsPath function
[ganeti-local]
/
lib
/
serializer.py
diff --git
a/lib/serializer.py
b/lib/serializer.py
index
c5a8b0d
..
fcde992
100644
(file)
--- a/
lib/serializer.py
+++ b/
lib/serializer.py
@@
-28,6
+28,7
@@
backend (currently json).
import simplejson
import re
import simplejson
import re
+
# Check whether the simplejson module supports indentation
_JSON_INDENT = 2
try:
# Check whether the simplejson module supports indentation
_JSON_INDENT = 2
try:
@@
-38,14
+39,20
@@
except TypeError:
_RE_EOLSP = re.compile('[ \t]+$', re.MULTILINE)
_RE_EOLSP = re.compile('[ \t]+$', re.MULTILINE)
-def DumpJson(data):
+def DumpJson(data, indent=True):
"""Serialize a given object.
"""Serialize a given object.
+ @param data: the data to serialize
+ @param indent: whether to indent output (depends on simplejson version)
+
+ @return: the string representation of data
+
"""
"""
- 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'
txt = _RE_EOLSP.sub("", txt)
if not txt.endswith('\n'):
txt += '\n'
@@
-55,6
+62,10
@@
def DumpJson(data):
def LoadJson(txt):
"""Unserialize data from a string.
def LoadJson(txt):
"""Unserialize data from a string.
+ @param txt: the json-encoded form
+
+ @return: the original data
+
"""
return simplejson.loads(txt)
"""
return simplejson.loads(txt)