MCPcopy Create free account
hub / github.com/ipython/ipython / mini_interactive_loop

Function mini_interactive_loop

IPython/core/tests/test_inputsplitter.py:25–47  ·  view source on GitHub ↗

Minimal example of the logic of an interactive interpreter loop. This serves as an example, and it is used by the test system with a fake raw_input that simulates interactive input.

(input_func)

Source from the content-addressed store, hash-verified

23# can be useful during development of code here.
24
25def mini_interactive_loop(input_func):
26 """Minimal example of the logic of an interactive interpreter loop.
27
28 This serves as an example, and it is used by the test system with a fake
29 raw_input that simulates interactive input."""
30
31 from IPython.core.inputsplitter import InputSplitter
32
33 isp = InputSplitter()
34 # In practice, this input loop would be wrapped in an outside loop to read
35 # input indefinitely, until some exit/quit command was issued. Here we
36 # only illustrate the basic inner loop.
37 while isp.push_accepts_more():
38 indent = ' '*isp.get_indent_spaces()
39 prompt = '>>> ' + indent
40 line = indent + input_func(prompt)
41 isp.push(line)
42
43 # Here we just return input so we can use it in a test suite, but a real
44 # interpreter would instead send it for execution somewhere.
45 src = isp.source_reset()
46 #print 'Input source was:\n', src # dbg
47 return src
48
49#-----------------------------------------------------------------------------
50# Test utilities, just for local use

Callers 1

check_nsMethod · 0.85

Calls 5

push_accepts_moreMethod · 0.95
get_indent_spacesMethod · 0.95
pushMethod · 0.95
source_resetMethod · 0.95
InputSplitterClass · 0.90

Tested by

no test coverage detected