How to use the bpython.args.exec_code function in bpython

To help you get started, we’ve selected a few bpython examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bpython / bpython / bpython / curtsies.py View on Github external
import logging
        logging.basicConfig(filename='scroll.log', level=logging.DEBUG)

    interp = None
    paste = None
    if exec_args:
        assert options, "don't pass in exec_args without options"
        exit_value = 0
        if options.type:
            paste = curtsies.events.PasteEvent()
            sourcecode = open(exec_args[0]).read()
            paste.events.extend(sourcecode)
        else:
            try:
                interp = code.InteractiveInterpreter(locals=locals_)
                bpargs.exec_code(interp, exec_args)
            except SystemExit, e:
                exit_value = e.args
            if not options.interactive:
                raise SystemExit(exit_value)
    else:
        sys.path.insert(0, '') # expected for interactive sessions (vanilla python does it)

    mainloop(config, locals_, banner, interp, paste)
github bpython / bpython / bpython / urwid.py View on Github external
def start(main_loop, user_data):
        if exec_args:
            bpargs.exec_code(interpreter, exec_args)
            if not options.interactive:
                raise urwid.ExitMainLoop()
        if not exec_args:
            sys.path.insert(0, "")
            # this is CLIRepl.startup inlined.
            filename = os.environ.get("PYTHONSTARTUP")
            if filename and os.path.isfile(filename):
                with open(filename, "r") as f:
                    if py3:
                        interpreter.runsource(f.read(), filename, "exec")
                    else:
                        interpreter.runsource(
                            f.read(), filename, "exec", encode=False
                        )

        if banner is not None: