Port json.dumps usage from wmlparser2 to python wmlparser

This commit is contained in:
Alexander van Gessel 2010-10-14 17:44:59 +01:00
parent 6ae77316bf
commit 34a49740e3

View file

@ -815,15 +815,18 @@ class Parser:
data.insert(subdata)
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):
"""