Author: ai0867
Date: Fri Mar 18 00:08:57 2011
New Revision: 48929
URL: http://svn.gna.org/viewcvs/wesnoth?rev=48929&view=rev
Log:
Remove a hacky json.dumps approximation. The json module is part of mainline
python since 2.6, which is included in debian stable.
Modified:
trunk/data/tools/wesnoth/wmlparser.py
trunk/data/tools/wesnoth/wmlparser2.py
Modified: trunk/data/tools/wesnoth/wmlparser.py
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/wesnoth/wmlparser.py?rev=48929&r1=48928&r2=48929&view=diff
==============================================================================
--- trunk/data/tools/wesnoth/wmlparser.py (original)
+++ trunk/data/tools/wesnoth/wmlparser.py Fri Mar 18 00:08:57 2011
@@ -815,19 +815,7 @@
data.insert(subdata)
-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]
-
+import json
def jsonify(tree, verbose=False, depth=0):
"""
Convert a DataSub into JSON
@@ -849,7 +837,7 @@
if child.get_type() == "DataSub":
jsonify(child, verbose, depth + 1)
else:
- print strify(child.get_value()),
+ print json.dumps(child.get_value()),
if verbose:
sys.stdout.write(sdepth1)
sys.stdout.write("}")
Modified: trunk/data/tools/wesnoth/wmlparser2.py
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/wesnoth/wmlparser2.py?rev=48929&r1=48928&r2=48929&view=diff
==============================================================================
--- trunk/data/tools/wesnoth/wmlparser2.py (original)
+++ trunk/data/tools/wesnoth/wmlparser2.py Fri Mar 18 00:08:57 2011
@@ -448,26 +448,7 @@
return self.root.get_text_val(name, default, translation)
-########################################################################
-# #
-# EVERYTHING BELOW IS ONLY TESTING STUFF AND CAN BE SAFELY IGNORED OR #
-# REMOVED. #
-# #
-########################################################################
-
-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]
-
+import json
def jsonify(tree, verbose=False, depth=0):
"""
Convert a DataSub into JSON
@@ -511,7 +492,7 @@
if verbose:
sys.stdout.write(sdepth2)
print '"%s":' % child.name,
- print strify(child.get_text()),
+ print json.dumps(child.get_text()),
if verbose:
sys.stdout.write(sdepth1)
sys.stdout.write("}")
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits