Use json.dumps as strify() when available

This commit is contained in:
Alexander van Gessel 2010-10-14 13:49:29 +01:00
parent ea48793ec1
commit 7919a8453d

View file

@ -448,15 +448,18 @@ class Parser:
# #
########################################################################
def strify(string):
"""
try:
strify = __import__("json").dumps
except ImportError:
def strify(string):
"""
Massage a string into what appears to be a JSON-compatible form.
This can be replaced with json.dumps() in python 2.6.
"""
s = repr(string)
front = s.index("'")
s = s.replace('"', '\\"')
return '"%s"' % s[front+1:len(s)-1]
s = repr(string)
front = s.index("'")
s = s.replace('"', '\\"')
return '"%s"' % s[front+1:len(s)-1]
def jsonify(tree, verbose=False, depth=0):
"""