Author: ai0867
Date: Thu Oct 14 14:49:29 2010
New Revision: 47043

URL: http://svn.gna.org/viewcvs/wesnoth?rev=47043&view=rev
Log:
Use json.dumps as strify() when available

Modified:
    trunk/data/tools/wesnoth/wmlparser2.py

Modified: trunk/data/tools/wesnoth/wmlparser2.py
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/wesnoth/wmlparser2.py?rev=47043&r1=47042&r2=47043&view=diff
==============================================================================
--- trunk/data/tools/wesnoth/wmlparser2.py (original)
+++ trunk/data/tools/wesnoth/wmlparser2.py Thu Oct 14 14:49:29 2010
@@ -448,15 +448,18 @@
 #                                                                      #
 ########################################################################
 
-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):
     """


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to