Beispiel #1
0
 def printMessage(self,event):
     self.text = self.textField.getText()
     intrp = PythonInterpreter()
     self.interpreterOut = JythonOutputStream(self.outputText)
     try:
         intrp.setOut(self.interpreterOut)
         intrp.exec(self.text)
     except Exception, ex:
         print ex
         intrp.setErr(self.interpreterOut)
Beispiel #2
0
def run_script(script, names):
    """Run the script and return a weak list of the values named"""
    pi = PythonInterpreter()
    pi.exec(script)
    if isinstance(names, str):
        names = (names, )
    result = []
    for n in names:
        obj = pi.getLocals()[n]
        result.append(weakref.ref(obj))
    return result
Beispiel #3
0
    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 create_proxies():
            pi = PythonInterpreter()
            pi.exec("""
from java.lang import Comparable

class Dog(Comparable):
    def compareTo(self, o):
        return 0
    def bark(self):
        return 'woof woof'

Dog().bark()
""")
    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
    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
Beispiel #7
0
    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
Beispiel #8
0
# 
# 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)
Beispiel #9
0
# 
# 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)
Beispiel #10
0
def execScript(script):
    interpreter = PythonInterpreter()
    interpreter.exec(script)