# Path: pyxc/util.py
# def usingPython3():
#     return sys.version_info[0] == 3
# 
# def check_communicate(cmd, input='', **Popen_kwargs):
#     out, err, returncode = communicateWithReturncode(cmd, input=input, **Popen_kwargs)
#     if returncode != 0:
#         raise SubprocessError(out, err, returncode)
#     return (out, err)
# 
# def exceptionRepr(exc_info=None):
#     
#     if usingPython3():
#         from io import StringIO
#     else:
#         from StringIO import StringIO
#     
#     if not exc_info:
#         exc_info = sys.exc_info()
#     f = StringIO()
#     traceback.print_exception(exc_info[0], exc_info[1], exc_info[2], file=f)
#     return f.getvalue()
# 
# Path: pj/api_internal.py
# def codeToCode(py):
#     
#     t = Transformer(pj.transformations, pj.js_ast.JSStatements)
#     jsAst = t.transformCode(py)
#     js = '%s\n%s' % ('\n'.join(t.snippets), str(jsAst))
#     
#     names = set(topLevelNamesInBody(ast.parse(py).body))
#     if len(names) > 0:
#         js = 'var %s;\n\n%s' % (
#             ', '.join(names),
#             js)
#     
#     return js


import os, json, re, sys
from pyxc.util import usingPython3, check_communicate, exceptionRepr
from pj.api_internal import codeToCode
                print(locals()[k])
            sys.exit(1)


def runJs(js):
    
    rhinoPath = os.environ['RHINO_JAR']
    
    try:
        out, err = check_communicate([
                            '/usr/bin/env',
                            'java',
                            '-jar', rhinoPath,
                            '-e', js.encode('utf-8')])
    except Exception as e:
        raise Exception(e.msg + '\n--- js ---\n' + js)
    return out


def valueOfLastLine_py(py):
    try:
        k = '___result___'
        py = changeLastLine(py, lambda line: '%s = %s' % (k, line))
        l, g = {}, {}
        exec(py, g, l)
        return json.loads(json.dumps(l[k]))
    except Exception:
        raise Exception('Error when running Python code.\n--- py ---\n%s\n--- err ---\n%s' % (py, exceptionRepr()))



# Path: pyxc/util.py
# def usingPython3():
#     return sys.version_info[0] == 3
# 
# def check_communicate(cmd, input='', **Popen_kwargs):
#     out, err, returncode = communicateWithReturncode(cmd, input=input, **Popen_kwargs)
#     if returncode != 0:
#         raise SubprocessError(out, err, returncode)
#     return (out, err)
# 
# def exceptionRepr(exc_info=None):
#     
#     if usingPython3():
#         from io import StringIO
#     else:
#         from StringIO import StringIO
#     
#     if not exc_info:
#         exc_info = sys.exc_info()
#     f = StringIO()
#     traceback.print_exception(exc_info[0], exc_info[1], exc_info[2], file=f)
#     return f.getvalue()
# 
# Path: pj/api_internal.py
# def codeToCode(py):
#     
#     t = Transformer(pj.transformations, pj.js_ast.JSStatements)
#     jsAst = t.transformCode(py)
#     js = '%s\n%s' % ('\n'.join(t.snippets), str(jsAst))
#     
#     names = set(topLevelNamesInBody(ast.parse(py).body))
#     if len(names) > 0:
#         js = 'var %s;\n\n%s' % (
#             ', '.join(names),
#             js)
#     
#     return js


# Path: pj/tests/dual_eval.py
import os, json, re, sys
from pyxc.util import usingPython3, check_communicate, exceptionRepr
from pj.api_internal import codeToCode

                print(locals()[k])
            sys.exit(1)


def runJs(js):
    
    rhinoPath = os.environ['RHINO_JAR']
    
    try:
        out, err = check_communicate([
                            '/usr/bin/env',
                            'java',
                            '-jar', rhinoPath,
                            '-e', js.encode('utf-8')])
    except Exception as e:
        raise Exception(e.msg + '\n--- js ---\n' + js)
    return out


def valueOfLastLine_py(py):
    try:
        k = '___result___'
        py = changeLastLine(py, lambda line: '%s = %s' % (k, line))
        l, g = {}, {}
        exec(py, g, l)
        return json.loads(json.dumps(l[k]))
    except Exception:
        raise Exception('Error when running Python code.\n--- py ---\n%s\n--- err ---\n%s' % (py, exceptionRepr()))



def valueOfLastLine_js(js):