本文整理汇总了Python中IPython.terminal.embed.InteractiveShellEmbed.prompts方法的典型用法代码示例。如果您正苦于以下问题:Python InteractiveShellEmbed.prompts方法的具体用法?Python InteractiveShellEmbed.prompts怎么用?Python InteractiveShellEmbed.prompts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPython.terminal.embed.InteractiveShellEmbed
的用法示例。
在下文中一共展示了InteractiveShellEmbed.prompts方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start_shell
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import prompts [as 别名]
def start_shell(controller=None):
"""Load Kytos interactive shell."""
kytos_ascii = r"""
_ _
| | | |
| | ___ _| |_ ___ ___
| |/ / | | | __/ _ \/ __|
| <| |_| | || (_) \__ \
|_|\_\__, |\__\___/|___/
__/ |
|___/
"""
banner1 = f"""\033[95m{kytos_ascii}\033[0m
Welcome to Kytos SDN Platform!
We are making a huge effort to make sure that this console will work fine
but for now it's still experimental.
Kytos website.: https://kytos.io/
Documentation.: https://docs.kytos.io/
OF Address....:"""
exit_msg = "Stopping Kytos daemon... Bye, see you!"
if controller:
address = controller.server.server_address[0]
port = controller.server.server_address[1]
banner1 += f" tcp://{address}:{port}\n"
api_port = controller.api_server.port
banner1 += f" WEB UI........: http://{address}:{api_port}/\n"
banner1 += f" Kytos Version.: {__version__}"
banner1 += "\n"
cfg = Config()
cfg.TerminalInteractiveShell.autocall = 2
cfg.TerminalInteractiveShell.show_rewritten_input = False
cfg.TerminalInteractiveShell.confirm_exit = False
# Avoiding sqlite3.ProgrammingError when trying to save command history
# on Kytos shutdown
cfg.HistoryAccessor.enabled = False
ipshell = InteractiveShellEmbed(config=cfg,
banner1=banner1,
exit_msg=exit_msg)
ipshell.prompts = KytosPrompt(ipshell)
ipshell()
示例2: interface_shell_embed
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import prompts [as 别名]
def interface_shell_embed(interface):
"""
Returns an IPython shell which uses a Sage interface on the
backend to perform the evaluations. It uses
:class:`InterfaceShellTransformer` to transform the input into the
appropriate ``interface.eval(...)`` input.
INPUT:
- ``interface`` -- A Sage ``PExpect`` interface instance.
EXAMPLES::
sage: from sage.repl.interpreter import interface_shell_embed
sage: shell = interface_shell_embed(gap)
sage: shell.run_cell('List( [1..10], IsPrime )')
[ false, true, true, false, true, false, true, false, false, false ]
<repr(<IPython.core.interactiveshell.ExecutionResult at 0x...>) failed:
AttributeError: type object 'ExecutionResult' has no attribute '__qualname__'>
Note that the repr error is https://github.com/ipython/ipython/issues/9756
"""
cfg = sage_ipython_config.copy()
ipshell = InteractiveShellEmbed(config=cfg,
banner1='\n --> Switching to %s <--\n\n'%interface,
exit_msg='\n --> Exiting back to Sage <--\n')
ipshell.interface = interface
ipshell.prompts = InterfacePrompts(interface.name())
while ipshell.prefilter_manager.transformers:
ipshell.prefilter_manager.transformers.pop()
while ipshell.prefilter_manager.checkers:
ipshell.prefilter_manager.checkers.pop()
ipshell.ex('import sage.misc.all')
InterfaceShellTransformer(shell=ipshell,
prefilter_manager=ipshell.prefilter_manager,
config=cfg)
return ipshell
示例3: interface_shell_embed
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import prompts [as 别名]
def interface_shell_embed(interface):
"""
Returns an IPython shell which uses a Sage interface on the
backend to perform the evaluations. It uses
:class:`InterfaceShellTransformer` to transform the input into the
appropriate ``interface.eval(...)`` input.
INPUT:
- ``interface`` -- A Sage ``PExpect`` interface instance.
EXAMPLES::
sage: from sage.repl.interpreter import interface_shell_embed
sage: shell = interface_shell_embed(gap)
sage: shell.run_cell('List( [1..10], IsPrime )')
[ false, true, true, false, true, false, true, false, false, false ]
<ExecutionResult object at ..., execution_count=None error_before_exec=None error_in_exec=None result=[ false, true, true, false, true, false, true, false, false, false ]>
"""
cfg = sage_ipython_config.copy()
ipshell = InteractiveShellEmbed(config=cfg,
banner1='\n --> Switching to %s <--\n\n'%interface,
exit_msg='\n --> Exiting back to Sage <--\n')
ipshell.interface = interface
ipshell.prompts = InterfacePrompts(interface.name())
while ipshell.prefilter_manager.transformers:
ipshell.prefilter_manager.transformers.pop()
while ipshell.prefilter_manager.checkers:
ipshell.prefilter_manager.checkers.pop()
ipshell.ex('import sage.misc.all')
InterfaceShellTransformer(shell=ipshell,
prefilter_manager=ipshell.prefilter_manager,
config=cfg)
return ipshell
示例4: interact
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import prompts [as 别名]
def interact(argv=sys.argv): # pragma: no cover
conf = Conf().load()
banner = "\033[1mSnimpy\033[0m ({0}) -- {1}.\n".format(
snimpy.__version__, snimpy.__doc__)
banner += " load -> load an additional MIB\n"
banner += " M -> manager object"
local = {"conf": conf,
"M": manager.Manager,
"load": manager.load,
"timedelta": timedelta,
"snmp": manager.snmp
}
if len(argv) <= 1:
manager.Manager._complete = True
for ms in conf.mibs:
manager.load(ms)
globals().update(local)
if len(argv) > 1:
argv = argv[1:]
exec(compile(open(argv[0]).read(), argv[0], 'exec')) in local
return
try:
try:
try:
# ipython >= 1.0
from IPython.terminal.embed import \
InteractiveShellEmbed
except ImportError:
# ipython >= 0.11
from IPython.frontend.terminal.embed import \
InteractiveShellEmbed
import IPython
if IPython.version_info < (4,):
from IPython.config.loader import Config
else:
from traitlets.config.loader import Config
cfg = Config()
try:
# >= 5
from IPython.terminal.prompts import Prompts, Token
class SnimpyPrompt(Prompts):
def in_prompt_tokens(self, cli=None):
return [
(Token.Prompt, "Snimpy["),
(Token.PromptNum, str(self.shell.execution_count)),
(Token.Prompt, ']> '),
]
def out_prompt_tokens(self):
return [
(Token.OutPrompt, "Snimpy["),
(Token.OutPromptNum,
str(self.shell.execution_count)),
(Token.OutPrompt, ']: '),
]
except ImportError:
SnimpyPrompt = None
try:
# >= 0.12
cfg.PromptManager.in_template = "Snimpy [\\#]> "
cfg.PromptManager.out_template = "Snimpy [\\#]: "
except ImportError:
# 0.11
cfg.InteractiveShellEmbed.prompt_in1 = "Snimpy [\\#]> "
cfg.InteractiveShellEmbed.prompt_out = "Snimpy [\\#]: "
if conf.ipythonprofile:
cfg.InteractiveShellEmbed.profile = conf.ipythonprofile
shell = InteractiveShellEmbed(
config=cfg,
banner1=banner,
user_ns=local)
# Not interested by traceback in this module
shell.InteractiveTB.tb_offset += 1
if SnimpyPrompt is not None:
shell.prompts = SnimpyPrompt(shell)
except ImportError:
# ipython < 0.11
from IPython.Shell import IPShellEmbed
argv = ["-prompt_in1", "Snimpy [\\#]> ",
"-prompt_out", "Snimpy [\\#]: "]
if conf.ipythonprofile:
argv += ["-profile", conf.ipythonprofile]
shell = IPShellEmbed(argv=argv,
banner=banner, user_ns=local)
# Not interested by traceback in this module
shell.IP.InteractiveTB.tb_offset += 1
except ImportError:
shell = None
if shell and conf.ipython:
shell()
else:
#.........这里部分代码省略.........