def function_context(): from org.python.core import Py from org.python.util import PythonInterpreter from org.python.core import PySystemState ps = PySystemState() pi = PythonInterpreter({}, ps) if not sharing: ps.shadow() ps.builtins = ps.builtins.copy() pi.exec(function.func_code)
def execution_context(): from org.python.core import Py from org.python.util import PythonInterpreter from org.python.core import PySystemState ps = PySystemState() pi = PythonInterpreter({}, ps) if locals is not None: pi.setLocals(locals) if inp is not None: pi.setIn(inp) if out is not None: pi.setOut(out) if err is not None: pi.setErr(err) try: if isinstance(source, types.FunctionType): # A function wrapping a compiled code block pi.exec(source.func_code) elif isinstance(source, java.io.InputStream): # A byte-oriented file-like input stream pi.execfile(source) elif isinstance(source, java.io.Reader): # A character-oriented file-like input stream code = pi.compile(source) pi.exec(code) else: # A str or unicode (see UnicodeSourceTest) pi.exec(source) except: print print '-'*60 traceback.print_exc(file=sys.stdout) print '-'*60
def function_context(): from org.python.core import Py from org.python.util import PythonInterpreter from org.python.core import PySystemState ps = PySystemState() pi = PythonInterpreter({}, ps) if locals: pi.setLocals(locals) pi.setOut(out) pi.setErr(err) try: pi.exec(function.func_code) except: print '-'*60 traceback.print_exc(file=sys.stdout) print '-'*60
# # Test for bug 1758838 # # execfile(<any file>) should not throw a NullPointerException # # The error only shows up in interactive interpretation (type "single" for the compilation). # But we cannot use InteractiveInterpreter here since it catches all Exceptions, # therefore we do the compilation 'by hand'. # from org.python.core import Py from org.python.core import PySystemState from org.python.util import PythonInterpreter PySystemState.initialize() interp = PythonInterpreter() code = Py.compile_command_flags("execfile('test401/to_be_executed.py')", "<input>", "single", None, 1) interp.exec(code)
from common import ScriptRunner from java.util import HashMap from org.python.core import PyDictionary from org.python.core import PySystemState from org.python.util import PythonInterpreter #set = ScriptRunner.methods.keySet() #for item in set: # print item # print ScriptRunner.methods.get(item) path = '/Users/miura/Desktop/test.py' #ScriptRunner.run(path, HashMap()) pystate = PySystemState() pystate.setClassLoader(IJ.getClassLoader()) pi = PythonInterpreter(PyDictionary(), pystate) pi.execfile(path);
from common import ScriptRunner from java.util import HashMap from org.python.core import PyDictionary from org.python.core import PySystemState from org.python.util import PythonInterpreter #set = ScriptRunner.methods.keySet() #for item in set: # print item # print ScriptRunner.methods.get(item) path = '/Users/miura/Desktop/test.py' #ScriptRunner.run(path, HashMap()) pystate = PySystemState() pystate.setClassLoader(IJ.getClassLoader()) pi = PythonInterpreter(PyDictionary(), pystate) pi.execfile(path)