Yield pasted lines until the user enters the given sentinel value.
(sentinel, l_input=py3compat.input, quiet=False)
| 15 | from IPython.utils import py3compat |
| 16 | |
| 17 | def get_pasted_lines(sentinel, l_input=py3compat.input, quiet=False): |
| 18 | """ Yield pasted lines until the user enters the given sentinel value. |
| 19 | """ |
| 20 | if not quiet: |
| 21 | print("Pasting code; enter '%s' alone on the line to stop or use Ctrl-D." \ |
| 22 | % sentinel) |
| 23 | prompt = ":" |
| 24 | else: |
| 25 | prompt = "" |
| 26 | while True: |
| 27 | try: |
| 28 | l = l_input(prompt) |
| 29 | if l == sentinel: |
| 30 | return |
| 31 | else: |
| 32 | yield l |
| 33 | except EOFError: |
| 34 | print('<EOF>') |
| 35 | return |
| 36 | |
| 37 | |
| 38 | @magics_class |