diff options
-rw-r--r-- | module/common/JsEngine.py | 31 | ||||
-rw-r--r-- | module/common/json_layer.py | 11 |
2 files changed, 13 insertions, 29 deletions
diff --git a/module/common/JsEngine.py b/module/common/JsEngine.py index 5612b12a3..d48cbfcec 100644 --- a/module/common/JsEngine.py +++ b/module/common/JsEngine.py @@ -19,14 +19,10 @@ from imp import find_module from os.path import join, exists +from urllib import quote -ENGINE = "" -try: - find_module("spidermonkey") - ENGINE = "spidermonkey" -except: - pass +ENGINE = "" if not ENGINE: try: @@ -73,6 +69,10 @@ if not ENGINE: except: pass + + + + class JsEngine(): def __init__(self): self.engine = ENGINE @@ -83,11 +83,7 @@ class JsEngine(): def eval(self, script): if not self.init: - if ENGINE == "spidermonkey": - import spidermonkey - global spidermonkey - - elif ENGINE == "pyv8": + if ENGINE == "pyv8": import PyV8 global PyV8 @@ -95,8 +91,6 @@ class JsEngine(): if not ENGINE: raise Exception("No JS Engine") - elif ENGINE == "spidermonkey": - return self.eval_spidermonkey(script) elif ENGINE == "pyv8": return self.eval_pyv8(script) elif ENGINE == "js": @@ -105,25 +99,20 @@ class JsEngine(): return self.eval_rhino(script) - def eval_spidermonkey(self, script): - rt = spidermonkey.Runtime() - cx = rt.new_context() - return cx.execute(script) - def eval_pyv8(self, script): rt = PyV8.JSContext() rt.enter() return rt.eval(script) def eval_js(self, script): - script = "print(eval('%s'))" % script.replace("'", '"') + script = "print(eval(unescape('%s')))" % quote(script) p = subprocess.Popen(["js", "-e", script], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=-1) out, err = p.communicate() res = out.strip() return res def eval_rhino(self, script): - script = "print(eval('%s'))" % script.replace("'", '"') + script = "print(eval(unescape('%s')))" % quote(script) p = subprocess.Popen(["java", "-cp", path, "org.mozilla.javascript.tools.shell.Main", "-e", script], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=-1) out, err = p.communicate() res = out.strip() @@ -135,12 +124,10 @@ class JsEngine(): if __name__ == "__main__": js = JsEngine() import subprocess - import spidermonkey #import PyV8 test = '"a"+"b"' print js.eval_js(test) - print js.eval_spidermonkey(test) print js.eval_rhino(test) print js.eval_pyv8(test)
\ No newline at end of file diff --git a/module/common/json_layer.py b/module/common/json_layer.py index 7b1c80bb5..4d57a9f38 100644 --- a/module/common/json_layer.py +++ b/module/common/json_layer.py @@ -7,10 +7,7 @@ try: # since python 2.6 import json from json import loads as json_loads from json import dumps as json_dumps -except ImportError: - try: - import module.lib.simplejson as json - from module.lib.simplejson import loads as json_loads - from module.lib.simplejson import dumps as json_dumps - except: - print "Could not import simplejson" +except ImportError: #use system simplejson if available + import simplejson as json + from simplejson import loads as json_loads + from simplejson import dumps as json_dumps |