MCPcopy Index your code
hub / github.com/python/cpython / run_multiline_interactive_console

Function run_multiline_interactive_console

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

Source from the content-addressed store, hash-verified

98
99
100def run_multiline_interactive_console(
101 console: code.InteractiveConsole,
102 *,
103 future_flags: int = 0,
104) -> None:
105 from .readline import _setup
106 _setup(console.locals)
107 if future_flags:
108 console.compile.compiler.flags |= future_flags
109
110 more_lines = functools.partial(_more_lines, console)
111 input_n = 0
112
113 _is_x_showrefcount_set = sys._xoptions.get("showrefcount")
114 _is_pydebug_build = hasattr(sys, "gettotalrefcount")
115 show_ref_count = _is_x_showrefcount_set and _is_pydebug_build
116
117 def maybe_run_command(statement: str) -> bool:
118 statement = statement.strip()
119 if statement in console.locals or statement not in REPL_COMMANDS:
120 return False
121
122 reader = _get_reader()
123 reader.history.pop() # skip internal commands in history
124 command = REPL_COMMANDS[statement]
125 if callable(command):
126 # Make sure that history does not change because of commands
127 with reader.suspend_history(), reader.suspend_colorization():
128 command()
129 return True
130 return False
131
132 while True:
133 try:
134 try:
135 sys.stdout.flush()
136 except Exception:
137 pass
138
139 ps1 = getattr(sys, "ps1", ">>> ")
140 ps2 = getattr(sys, "ps2", "... ")
141 try:
142 statement = multiline_input(more_lines, ps1, ps2)
143 except EOFError:
144 break
145
146 if maybe_run_command(statement):
147 continue
148
149 input_name = f"<python-input-{input_n}>"
150 more = console.push(_strip_final_indent(statement), filename=input_name, _symbol="single") # type: ignore[call-arg]
151 assert not more
152 try:
153 append_history_file()
154 except (FileNotFoundError, PermissionError, OSError) as e:
155 warnings.warn(f"failed to open the history file for writing: {e}")
156
157 input_n += 1

Callers 2

runMethod · 0.90
interactive_consoleFunction · 0.85

Calls 15

multiline_inputFunction · 0.85
maybe_run_commandFunction · 0.85
_strip_final_indentFunction · 0.85
partialMethod · 0.80
cmpltn_resetMethod · 0.80
do_cmdMethod · 0.80
get_unicodeMethod · 0.80
resetbufferMethod · 0.80
_setupFunction · 0.70
getMethod · 0.45
flushMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…