Hi all,
On 04/26/2014 08:50 AM, Tolga Dalman wrote:
> With Python 2.7, we have the opportunity to cleanup some very old Python
> conditional stuff. This way we should be able to replace cjson by the
> Python standard library JSON implementation. What do you think ?
attached you can find a patch for the existing Python scripts could look like.
It is completely untested, however, it can be seen that the change itself is
really non-disruptive.
Comments ?
Best regards
Tolga Dalman
Index: ChangeLog
===================================================================
--- ChangeLog (revision 19409)
+++ ChangeLog (working copy)
@@ -1,3 +1,14 @@
+2014-05-11 Tolga Dalman
+ * python/dialog/dialog_check.py: use standard library class json instead of
+ cjson (Python 2.6 or higher).
+ * python/dialog/npc_dialog.py: likewise.
+ * python/tod/filter.py: likewise.
+ * python/tod/push.py: likewise.
+ * python/tod/replace.py: likewise.
+ * python/tod/replace_in_map.py: likewise.
+ * python/tod/sleep.py: likewise.
+ * python/README: require Python 2.7 or higher.
+
2014-03-30 14:25 partmedia
* world/world_105_115: Add default entry coordinate for emergency
Index: python/README
===================================================================
--- python/README (revision 19409)
+++ python/README (working copy)
@@ -13,4 +13,4 @@
Script additions should be placed in a subdirectory, either existing, or when it makes sense, a new one.
Shared classes used for import should be placed in the root directory
-All Python scripts added to this map repository should be tested with and valid for Python 2.3
+All Python scripts require Python 2.7 or higher.
Index: python/dialog/dialog_check.py
===================================================================
--- python/dialog/dialog_check.py (revision 19409)
+++ python/dialog/dialog_check.py (working copy)
@@ -8,7 +8,7 @@
# for i in $(grep -h name.*msg ../../ -r | cut -d " " -f 2 | sort | uniq); do echo $i && python dialog_check.py "../../"$i; done
# from maps/python/dialog
-import cjson
+import json
import sys
import os
import re
@@ -80,7 +80,7 @@
errors +=1
else:
try:
- params = cjson.decode(f.read())
+ params = json.decode(f.read())
except:
print "ERROR: Failed to parse file, ", msgfile, "not a valid json file"
errors +=1
Index: python/dialog/npc_dialog.py
===================================================================
--- python/dialog/npc_dialog.py (revision 19409)
+++ python/dialog/npc_dialog.py (working copy)
@@ -43,7 +43,7 @@
import Crossfire
import os
from CFDialog import DialogRule, Dialog, IncludeRule
-import cjson
+import json
import random
location = "defaultdialognamespace"
@@ -67,7 +67,7 @@
raise
else:
Crossfire.Log(Crossfire.LogDebug, "Loading NPC dialog %s" % filepath)
- params = cjson.decode(f.read())
+ params = json.decode(f.read())
f.close()
if "location" in params:
location = params["location"]
Index: python/tod/filter.py
===================================================================
--- python/tod/filter.py (revision 19409)
+++ python/tod/filter.py (working copy)
@@ -37,8 +37,8 @@
import Crossfire
import string
from CFTimeOfDay import TimeOfDay
-import cjson
-parameters = cjson.decode(Crossfire.WhatIsEvent().Message)
+import json
+parameters = json.decode(Crossfire.WhatIsEvent().Message)
inverse = "inverse" in parameters and parameters["inverse"] == True
Crossfire.SetReturnValue(not inverse)
if not "match" in parameters:
Index: python/tod/push.py
===================================================================
--- python/tod/push.py (revision 19409)
+++ python/tod/push.py (working copy)
@@ -52,9 +52,9 @@
import Crossfire
import string
from CFTimeOfDay import TimeOfDay
-import cjson
+import json
event = Crossfire.WhatIsEvent()
-parameters = cjson.decode(event.Message)
+parameters = json.decode(event.Message)
alreadymatched = (event.Value!=0)
connected = int(parameters["connected"])
inverse = "inverse" in parameters and parameters["inverse"] == True
Index: python/tod/replace.py
===================================================================
--- python/tod/replace.py (revision 19409)
+++ python/tod/replace.py (working copy)
@@ -43,9 +43,9 @@
import Crossfire
import string
from CFTimeOfDay import TimeOfDay
-import cjson
+import json
event = Crossfire.WhatIsEvent()
-parameters = cjson.decode(event.Message)
+parameters = json.decode(event.Message)
alreadymatched = (event.Value!=0)
inverse = "inverse" in parameters and parameters["inverse"] == True
match = False
Index: python/tod/replace_in_map.py
===================================================================
--- python/tod/replace_in_map.py (revision 19409)
+++ python/tod/replace_in_map.py (working copy)
@@ -2,13 +2,13 @@
import random
from CFMapTransformer import CFMapTransformer
from CFTimeOfDay import TimeOfDay
-import cjson
+import json
import string
event = Crossfire.WhatIsEvent()
alreadymatched = (event.Value!=0)
-parameters = cjson.decode(event.Message)
+parameters = json.decode(event.Message)
current = TimeOfDay()
#current.log()
inverse = "inverse" in parameters and parameters["inverse"] == True
Index: python/tod/sleep.py
===================================================================
--- python/tod/sleep.py (revision 19409)
+++ python/tod/sleep.py (working copy)
@@ -45,9 +45,9 @@
import Crossfire
import string
from CFTimeOfDay import TimeOfDay
-import cjson
+import json
event = Crossfire.WhatIsEvent()
-parameters = cjson.decode(event.Message)
+parameters = json.decode(event.Message)
alreadymatched = (event.Value!=0)
inverse = "inverse" in parameters and parameters["inverse"] == True
match = False
_______________________________________________
crossfire mailing list
[email protected]
http://mailman.metalforge.org/mailman/listinfo/crossfire