当前位置: 首页>>代码示例>>Python>>正文


Python repl.embed函数代码示例

本文整理汇总了Python中ptpython.repl.embed函数的典型用法代码示例。如果您正苦于以下问题:Python embed函数的具体用法?Python embed怎么用?Python embed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了embed函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process_input

 def process_input(self, character):
     self.window.window.clear()
     if character == 263 and self.buffer:     # Handle backspace
         self.buffer = self.buffer[:-1]
     elif character == 10 or character == 13: # Handle the return key
         inputs = self.buffer.split("\n")
         if "menu" in inputs:
             menu = self.window.get("menu")
             menu.hidden = False if menu.hidden else True
             menu.active = True if not menu.active else False
         # Yup... Can launch ptpython with the "python" command.
         elif "python" in inputs:
             try:
                 from ptpython.repl import embed
                 self.window.stop()
                 l = {"pane": self, "window": self.window}
                 embed(locals=l, vi_mode=True)
                 self.buffer = ""
                 self.window.start()
             except:
                 pass
         elif "exit" in inputs:
             self.window.stop()
         self.buffer = ""
     else:
         try: self.buffer += chr(character)   # Append input to buffer
         except: pass
     import random
     colours = palette(-1, random.choice(["yellow","red"]))
     self.change_content(1, self.buffer, ALIGN_LEFT, colours)
开发者ID:LukeB42,项目名称:Window,代码行数:30,代码来源:advent.py

示例2: run

def run():
    a = docopt.docopt(__doc__)

    vi_mode = bool(a['--vi'])
    no_colors = bool(a['--no-colors'])

    # Create globals/locals dict.
    globals_, locals_ = {}, {}

    # Log history
    if a['--history']:
        history_filename = os.path.expanduser(a['--history'])
    else:
        history_filename = os.path.expanduser('~/.ptpython_history')

    # Startup path
    startup_paths = []
    if 'PYTHONSTARTUP' in os.environ:
        startup_paths.append(os.environ['PYTHONSTARTUP'])

    # --interactive
    if a['--interactive']:
        startup_paths.append(a['--interactive'])

    # Add the current directory to `sys.path`.
    sys.path.append('.')

    # When a file has been given, run that, otherwise start the shell.
    if a['<file>']:
        sys.argv = [a['<file>']] + a['<arg>']
        six.exec_(compile(open(a['<file>'], "rb").read(), a['<file>'], 'exec'))
    else:
        # Run interactive shell.
        embed(globals_, locals_, vi_mode=vi_mode, history_filename=history_filename,
              no_colors=no_colors, startup_paths=startup_paths)
开发者ID:8l,项目名称:ptpython,代码行数:35,代码来源:run_ptpython.py

示例3: start

    def start(self) -> None:
        try:
            from ptpython.repl import embed, run_config
        except ImportError:
            raise ShellNotAvailableError("PtPython shell not available.")
        print(self.banner)

        config_dir = Path("~/.ptpython/").expanduser()

        # Startup path
        startup_paths = []
        if "PYTHONSTARTUP" in os.environ:
            startup_paths.append(os.environ["PYTHONSTARTUP"])

        # Apply config file
        def configure(repl):
            path = config_dir / "config.py"
            if path.exists():
                run_config(repl, str(path))

        embed(
            globals=self.context,
            history_filename=config_dir / "history",
            vi_mode=self.ptpy_vi_mode,
            startup_paths=startup_paths,
            configure=configure,
        )
        return None
开发者ID:sloria,项目名称:konch,代码行数:28,代码来源:konch.py

示例4: __call__

 def __call__(self):
     try:
         from ptpython.repl import embed
         embed(globals(), None)
     except ImportError:
         printo('Install ptpython for a better repl')
         import code
         code.interact(banner="Launching strandard python repl", readfunc=None, local=globals())
开发者ID:nlewo,项目名称:contrail-api-cli,代码行数:8,代码来源:commands.py

示例5: main

def main():
    with ExitStack() as e:
        r = Robot()
        e.enter_context(r)
        # s = Server()
        # e.enter_context(s)
    # ws = Websocket()
        embed(globals(), locals())
开发者ID:ksurct,项目名称:MercuryRoboticsEmbedded2016,代码行数:8,代码来源:interact.py

示例6: do_interact

 def do_interact(self, args):
     """
     Interact: start interpreter.
     (Override the 'pdb' implementation. We call ptpython instead.)
     """
     print('')
     ns = self.curframe.f_globals.copy()
     ns.update(self.curframe_locals)
     embed(globals=ns)
开发者ID:jonathanslenders,项目名称:ptpdb,代码行数:9,代码来源:__init__.py

示例7: shell

def shell(env):
    '''Start a new interactive python session'''
    namespace = {'env': env}
    try:
        from ptpython.repl import embed
        hf = str(Path('~/.ptpython_history').expanduser())
        embed(namespace, history_filename=hf)
    except ImportError:
        from code import interact
        interact('', local=namespace)
开发者ID:TimofonicJunkRoom,项目名称:mailur,代码行数:10,代码来源:manage.py

示例8: __call__

 def __call__(self):
     try:
         from ptpython.repl import embed
         embed(globals(), None)
     except ImportError:
         try:
             from IPython import embed
             embed()
         except ImportError:
             import code
             code.interact(banner="Launching standard python repl", readfunc=None, local=globals())
开发者ID:adrian,项目名称:contrail-api-cli,代码行数:11,代码来源:command.py

示例9: run

def run():
    a = docopt.docopt(__doc__)

    vi_mode = bool(a['--vi'])
    config_dir = os.path.expanduser(a['--config-dir'] or '~/.ptpython/')

    # Create config directory.
    if not os.path.isdir(config_dir):
        os.mkdir(config_dir)

    # Startup path
    startup_paths = []
    if 'PYTHONSTARTUP' in os.environ:
        startup_paths.append(os.environ['PYTHONSTARTUP'])

    # --interactive
    if a['--interactive']:
        startup_paths.append(a['--interactive'])

    # Add the current directory to `sys.path`.
    if sys.path[0] != '':
        sys.path.insert(0, '')

    # When a file has been given, run that, otherwise start the shell.
    if a['<file>']:
        sys.argv = [a['<file>']] + a['<arg>']
        six.exec_(compile(open(a['<file>'], "rb").read(), a['<file>'], 'exec'))

    # Run interactive shell.
    else:
        enable_deprecation_warnings()

        # Apply config file
        def configure(repl):
            path = os.path.join(config_dir, 'conf.cfg')
            if os.path.exists(path):
                load_config(repl, path)
            path = os.path.join(config_dir, 'config.py')
            if os.path.exists(path):
                run_config(repl, path)

        # Save user settings in config file when repl is done
        def done(repl):
            path = os.path.join(config_dir, 'conf.cfg')
            # Create the file if it doesn't exist
            repl.settings.save_config(path)

        embed(vi_mode=vi_mode,
              history_filename=os.path.join(config_dir, 'history'),
              configure=configure,
              done=done,
              startup_paths=startup_paths,
              title='Python REPL (ptpython)')
开发者ID:danirus,项目名称:ptpython,代码行数:53,代码来源:run_ptpython.py

示例10: _embed_ptpython

def _embed_ptpython():
    """Embed a ptpython vanilla prompt."""
    try:
        from ptpython.repl import embed
    except ImportError:
        return False

    from inspect import currentframe
    caller = currentframe().f_back.f_back
    print(_embed_banner.format(filename=caller.f_code.co_filename,
                               line=caller.f_lineno))
    embed(caller.f_globals, caller.f_locals)
    return True
开发者ID:brenns10,项目名称:smbio,代码行数:13,代码来源:repl.py

示例11: postOptions

 def postOptions(self):
     historyFile = os.path.expanduser(self['history-file'])
     if not embed:
         interp = code.InteractiveConsole(self.namespace(), '<axiom browser>')
         if readline is not None and os.path.exists(historyFile):
             readline.read_history_file(historyFile)
         try:
             interp.interact("%s.  Autocommit is off." % (str(axiom.version),))
         finally:
             if readline is not None:
                 readline.write_history_file(historyFile)
     else:
         embed(self.namespace(), None, None, False, historyFile, '<axiom browser>')
开发者ID:perkinslr,项目名称:axiom-py3,代码行数:13,代码来源:axiom_plugins.py

示例12: create_shell

def create_shell(ipython, ptpython, manage_dict=None, extra_vars=None):
    """Creates the shell"""
    manage_dict = manage_dict or MANAGE_DICT
    _vars = globals()
    _vars.update(locals())
    auto_imported = import_objects(manage_dict)
    if extra_vars:
        auto_imported.update(extra_vars)
    _vars.update(auto_imported)
    msgs = []
    if manage_dict['shell']['banner']['enabled']:
        msgs.append(
            manage_dict['shell']['banner']['message'].format(**manage_dict)
        )
    if auto_imported and manage_dict['shell']['auto_import']['display']:
        auto_imported_names = [
            key for key in auto_imported.keys()
            if key not in ['__builtins__', 'builtins']
        ]
        msgs.append('\tAuto imported: {0}\n'.format(auto_imported_names))

    banner_msg = u'\n'.join(msgs)

    if manage_dict['shell']['readline_enabled']:
        readline.set_completer(rlcompleter.Completer(_vars).complete)
        readline.parse_and_bind('tab: complete')

    exec_init(manage_dict, _vars)
    exec_init_script(manage_dict, _vars)

    if ptpython:
        try:
            from ptpython.repl import embed
            embed({}, _vars)
        except ImportError:
            click.echo("ptpython is not installed!")
        return

    try:
        if ipython is True:
            from IPython import start_ipython
            from traitlets.config import Config
            c = Config()
            c.TerminalInteractiveShell.banner2 = banner_msg
            start_ipython(argv=[], user_ns=_vars, config=c)
        else:
            raise ImportError
    except ImportError:
        shell = code.InteractiveConsole(_vars)
        shell.interact(banner=banner_msg)
开发者ID:raj347,项目名称:manage,代码行数:50,代码来源:cli.py

示例13: run

def run():
    a = docopt.docopt(__doc__)

    vi_mode = bool(a['--vi'])
    config_dir = os.path.expanduser(a['--config-dir'] or '~/.ptpython/')

    # Create config directory.
    if not os.path.isdir(config_dir):
        os.mkdir(config_dir)

    # Startup path
    startup_paths = []
    if 'PYTHONSTARTUP' in os.environ:
        startup_paths.append(os.environ['PYTHONSTARTUP'])

    # --interactive
    if a['--interactive']:
        startup_paths.append(a['--interactive'])
        sys.argv = [a['--interactive']] + a['<arg>']

    # Add the current directory to `sys.path`.
    if sys.path[0] != '':
        sys.path.insert(0, '')

    # When a file has been given, run that, otherwise start the shell.
    if a['<arg>'] and not a['--interactive']:
        sys.argv = a['<arg>']
        path = a['<arg>'][0]
        with open(path, 'rb') as f:
            code = compile(f.read(), path, 'exec')
            six.exec_(code)

    # Run interactive shell.
    else:
        enable_deprecation_warnings()

        # Apply config file
        def configure(repl):
            path = os.path.join(config_dir, 'config.py')
            if os.path.exists(path):
                run_config(repl, path)

        import __main__
        embed(vi_mode=vi_mode,
              history_filename=os.path.join(config_dir, 'history'),
              configure=configure,
              locals=__main__.__dict__,
              globals=__main__.__dict__,
              startup_paths=startup_paths,
              title='Python REPL (ptpython)')
开发者ID:jonathanslenders,项目名称:ptpython,代码行数:50,代码来源:run_ptpython.py

示例14: run_interactive_shell

        def run_interactive_shell():

            def configure(repl):
                """Apply config file"""
                path = os.path.join(args['config_dir'], 'config.py')
                if os.path.exists(path):
                    repl.run_config(repl, path)

            from ptpython import repl
            repl.enable_deprecation_warnings()
            repl.embed(
                vi_mode=args.get('--vi', True),
                history_filename=os.path.join(args['config_dir'], 'history'),
                configure=configure,
                startup_paths=args.get('startup_paths', []),
                title=u'Pym REPL (pym)')
开发者ID:jalanb,项目名称:pym,代码行数:16,代码来源:reply.py

示例15: start_shell

 def start_shell(self):
     try:
         from ptpython.repl import embed
     except ImportError:
         log.error("Unable to start a shell: the ptpython module must be installed!")
         return
     yield from embed(globals(), locals(), return_asyncio_coroutine=True, patch_stdout=True, history_filename=".gns3_shell_history")
开发者ID:AJNOURI,项目名称:gns3-server,代码行数:7,代码来源:web_server.py


注:本文中的ptpython.repl.embed函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。