Пример #1
0
def run_files(args, verbose=0, inspect=False):
    sys.argv = args
    filename = args[0]
    args = args[1:]

    import java.io.File as File
    abspath = File(filename).getAbsolutePath()
    path = str(abspath[0:abspath.rindex(File.separator)])
    sys.path.insert(0, path)

    program=open(filename).read()
    from pysoc import compiler
    src = compiler.compile(program)

    from impSocialite import addMod, loadMod, setSocialiteVars
    sys.modules.pop("__main__", None)

    class FakeConsole:
        def __init__(self):
            self.locals = None

    console = FakeConsole()
    adapter = PythonInterpAdapter(console)
    import socialite.functions.PyInterp as PyInterp
    PyInterp.set(adapter)

    mod = addMod("__main__")
    setSocialiteVars(mod.__dict__)
    console.locals = mod.__dict__
    try:
        import java.lang.System as Sys
        mod = loadMod("__main__", src, filename)
        #exec src in locals
    except SystemExit:
        sys.exit(0)
    except:
        # adapted from code.py::InteractiveInterpreter::showtraceback
        import traceback
        try:
            tp, value, tb = sys.exc_info()
            sys.last_type = tp
            sys.last_value = value
            sys.last_traceback = tb
            tblist = traceback.extract_tb(tb)
            del tblist[:1]
            list = traceback.format_list(tblist)
            if list:
                list.insert(0, "Traceback (most recent call last):\n")
            list[len(list):] = traceback.format_exception_only(tp, value)
        finally:
            tblist = tb = None
        map(sys.stderr.write, list)
        sys.exit(1)
 
    if inspect:
        console = SociaLiteConsole(verbose=verbose)
        console.initLocals(mod.__dict__)
        console.interact("")
Пример #2
0
def run_files(args, verbose=0, inspect=False):
    sys.argv = args
    filename = args[0]
    args = args[1:]

    import java.io.File as File
    abspath = File(filename).getAbsolutePath()
    path = str(abspath[0:abspath.rindex(File.separator)])
    sys.path.insert(0, path)

    program = open(filename).read()
    from pysoc import compiler
    src = compiler.compile(program)

    from impSocialite import addMod, loadMod, setSocialiteVars
    sys.modules.pop("__main__", None)

    class FakeConsole:
        def __init__(self):
            self.locals = None

    console = FakeConsole()
    adapter = PythonInterpAdapter(console)
    import socialite.functions.PyInterp as PyInterp
    PyInterp.set(adapter)

    mod = addMod("__main__")
    setSocialiteVars(mod.__dict__)
    console.locals = mod.__dict__
    try:
        import java.lang.System as Sys
        mod = loadMod("__main__", src, filename)
        #exec src in locals
    except SystemExit:
        sys.exit(0)
    except:
        # adapted from code.py::InteractiveInterpreter::showtraceback
        import traceback
        try:
            tp, value, tb = sys.exc_info()
            sys.last_type = tp
            sys.last_value = value
            sys.last_traceback = tb
            tblist = traceback.extract_tb(tb)
            del tblist[:1]
            list = traceback.format_list(tblist)
            if list:
                list.insert(0, "Traceback (most recent call last):\n")
            list[len(list):] = traceback.format_exception_only(tp, value)
        finally:
            tblist = tb = None
        map(sys.stderr.write, list)
        sys.exit(1)

    if inspect:
        console = SociaLiteConsole(verbose=verbose)
        console.initLocals(mod.__dict__)
        console.interact("")
Пример #3
0
    def __init__(self, cpu=None, verbose=False):
        InteractiveConsole.__init__(self)
        self.filename="<stdin>"

        self.inQuery = False # True if the shell is in SociaLite query
        self.compiler = None

        self.declBegin = None
        self.declEnd = None

        self.locals={}

        from impSocialite import setSocialiteVars
        setSocialiteVars(self.locals)
        self.locals["__name__"] = "__main__"

        self.adapter = PythonInterpAdapter(self)
        import socialite.functions.PyInterp as PyInterp
        PyInterp.set(self.adapter)
Пример #4
0
    def __init__(self, cpu=None, verbose=False):
        InteractiveConsole.__init__(self)
        self.filename = "<stdin>"

        self.inQuery = False  # True if the shell is in SociaLite query
        self.compiler = None

        self.declBegin = None
        self.declEnd = None

        self.locals = {}

        from impSocialite import setSocialiteVars
        setSocialiteVars(self.locals)
        self.locals["__name__"] = "__main__"

        self.adapter = PythonInterpAdapter(self)
        import socialite.functions.PyInterp as PyInterp
        PyInterp.set(self.adapter)
Пример #5
0
    def __init__(self, cpu=None, verbose=False):
        InteractiveConsole.__init__(self)
        self.filename="<stdin>"

        self.inQuery = False # True if the shell is in SociaLite query
        self.compiler = compiler

        self.declBegin = p.stringStart+p.Literal("`")
        self.declBegin.ignore(p.pythonStyleComment)
        self.declBegin.ignore(p.quotedString)

        self.declEnd = p.Literal("`") + p.stringEnd
        self.declEnd.ignore(p.pythonStyleComment)
        self.declEnd.ignore(p.quotedString)

        self.locals={}

        from impSocialite import setSocialiteVars
        setSocialiteVars(self.locals)
        self.locals["__name__"] = "__main__"

        self.adapter = PythonInterpAdapter(self)
        import socialite.functions.PyInterp as PyInterp
        PyInterp.set(self.adapter)