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)
| 23 | # can be useful during development of code here. |
| 24 | |
| 25 | def 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 |
no test coverage detected