Port json.dumps usage from wmlparser2 to python wmlparser
This commit is contained in:
parent
6ae77316bf
commit
34a49740e3
1 changed files with 9 additions and 6 deletions
|
@ -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):
|
||||
"""
|
||||
|
|
Loading…
Add table
Reference in a new issue