MCPcopy Index your code
hub / github.com/RustPython/RustPython / run_multiline_interactive_console

Function run_multiline_interactive_console

Lib/_pyrepl/simple_interact.py:105–167  ·  view source on GitHub ↗
(
    console: code.InteractiveConsole,
    *,
    future_flags: int = 0,
)

Source from the content-addressed store, hash-verified

103
104
105def run_multiline_interactive_console(
106 console: code.InteractiveConsole,
107 *,
108 future_flags: int = 0,
109) -> None:
110 from .readline import _setup
111 _setup(console.locals)
112 if future_flags:
113 console.compile.compiler.flags |= future_flags
114
115 more_lines = functools.partial(_more_lines, console)
116 input_n = 0
117
118 def maybe_run_command(statement: str) -> bool:
119 statement = statement.strip()
120 if statement in console.locals or statement not in REPL_COMMANDS:
121 return False
122
123 reader = _get_reader()
124 reader.history.pop() # skip internal commands in history
125 command = REPL_COMMANDS[statement]
126 if callable(command):
127 # Make sure that history does not change because of commands
128 with reader.suspend_history():
129 command()
130 return True
131 return False
132
133 while 1:
134 try:
135 try:
136 sys.stdout.flush()
137 except Exception:
138 pass
139
140 ps1 = getattr(sys, "ps1", ">>> ")
141 ps2 = getattr(sys, "ps2", "... ")
142 try:
143 statement = multiline_input(more_lines, ps1, ps2)
144 except EOFError:
145 break
146
147 if maybe_run_command(statement):
148 continue
149
150 input_name = f"<python-input-{input_n}>"
151 linecache._register_code(input_name, statement, "<stdin>") # type: ignore[attr-defined]
152 more = console.push(_strip_final_indent(statement), filename=input_name, _symbol="single") # type: ignore[call-arg]
153 assert not more
154 input_n += 1
155 except KeyboardInterrupt:
156 r = _get_reader()
157 if r.input_trans is r.isearch_trans:
158 r.do_cmd(("isearch-end", [""]))
159 r.pos = len(r.get_unicode())
160 r.dirty = True
161 r.refresh()
162 r.in_bracketed_paste = False

Callers 2

runMethod · 0.90
interactive_consoleFunction · 0.85

Calls 13

getattrFunction · 0.85
maybe_run_commandFunction · 0.85
_strip_final_indentFunction · 0.85
lenFunction · 0.85
partialMethod · 0.80
do_cmdMethod · 0.80
get_unicodeMethod · 0.80
resetbufferMethod · 0.80
_setupFunction · 0.70
flushMethod · 0.45
pushMethod · 0.45
refreshMethod · 0.45

Tested by

no test coverage detected