| 215 | return res |
| 216 | |
| 217 | def eval_rhino(self, script): |
| 218 | script = "print(eval(unescape('%s')))" % urllib.quote(script) |
| 219 | if len(script) <= 1800: |
| 220 | script_file = None |
| 221 | p = subprocess.Popen(["java", "-cp", path, "org.mozilla.javascript.tools.shell.Main", "-e", script], |
| 222 | stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=-1) |
| 223 | else: |
| 224 | fd, script_file = tempfile.mkstemp(prefix='script_file_', suffix='.js', dir="tmp") |
| 225 | os.write(fd, script) |
| 226 | os.close(fd) |
| 227 | p = subprocess.Popen(["java", "-cp", path, "org.mozilla.javascript.tools.shell.Main", "-f", script_file], |
| 228 | stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=-1) |
| 229 | out, err = p.communicate() |
| 230 | if script_file and os.path.exists(script_file): |
| 231 | os.unlink(script_file) |
| 232 | res = out.strip() |
| 233 | return res.decode("utf8").encode("ISO-8859-1") |
| 234 | |
| 235 | def error(self): |
| 236 | return _("No js engine detected, please install either js2py, Spidermonkey, ossp-js, pyv8, nodejs or rhino") |