Show More
@@ -348,22 +348,31 b' def cellmagic(end_on_blank_line=False):' | |||||
348 | line = tpl % (magic_name, first, u'\n'.join(body)) |
|
348 | line = tpl % (magic_name, first, u'\n'.join(body)) | |
349 |
|
349 | |||
350 |
|
350 | |||
351 |
def _strip_prompts(prompt |
|
351 | def _strip_prompts(prompt_re): | |
352 | """Remove matching input prompts from a block of input.""" |
|
352 | """Remove matching input prompts from a block of input.""" | |
353 | line = '' |
|
353 | line = '' | |
354 | while True: |
|
354 | while True: | |
355 | line = (yield line) |
|
355 | line = (yield line) | |
356 |
|
356 | |||
|
357 | # First line of cell | |||
357 | if line is None: |
|
358 | if line is None: | |
358 | continue |
|
359 | continue | |
|
360 | out, n1 = prompt_re.subn('', line, count=1) | |||
|
361 | line = (yield out) | |||
|
362 | ||||
|
363 | # Second line of cell, because people often copy from just after the | |||
|
364 | # first prompt, so we might not see it in the first line. | |||
|
365 | if line is None: | |||
|
366 | continue | |||
|
367 | out, n2 = prompt_re.subn('', line, count=1) | |||
|
368 | line = (yield out) | |||
|
369 | ||||
|
370 | if n1 or n2: | |||
|
371 | # Found the input prompt in the first two lines - check for it in | |||
|
372 | # the rest of the cell as well. | |||
|
373 | while line is not None: | |||
|
374 | line = (yield prompt_re.sub('', line, count=1)) | |||
359 |
|
375 | |||
360 | m = prompt1_re.match(line) |
|
|||
361 | if m: |
|
|||
362 | while m: |
|
|||
363 | line = (yield line[len(m.group(0)):]) |
|
|||
364 | if line is None: |
|
|||
365 | break |
|
|||
366 | m = prompt2_re.match(line) |
|
|||
367 | else: |
|
376 | else: | |
368 | # Prompts not in input - wait for reset |
|
377 | # Prompts not in input - wait for reset | |
369 | while line is not None: |
|
378 | while line is not None: | |
@@ -372,16 +381,14 b' def _strip_prompts(prompt1_re, prompt2_re):' | |||||
372 | @CoroutineInputTransformer.wrap |
|
381 | @CoroutineInputTransformer.wrap | |
373 | def classic_prompt(): |
|
382 | def classic_prompt(): | |
374 | """Strip the >>>/... prompts of the Python interactive shell.""" |
|
383 | """Strip the >>>/... prompts of the Python interactive shell.""" | |
375 |
prompt |
|
384 | prompt_re = re.compile(r'^(>>> |^\.\.\. )') | |
376 | prompt2_re = re.compile(r'^(>>> |^\.\.\. )') |
|
385 | return _strip_prompts(prompt_re) | |
377 | return _strip_prompts(prompt1_re, prompt2_re) |
|
|||
378 |
|
386 | |||
379 | @CoroutineInputTransformer.wrap |
|
387 | @CoroutineInputTransformer.wrap | |
380 | def ipy_prompt(): |
|
388 | def ipy_prompt(): | |
381 | """Strip IPython's In [1]:/...: prompts.""" |
|
389 | """Strip IPython's In [1]:/...: prompts.""" | |
382 |
prompt |
|
390 | prompt_re = re.compile(r'^(In \[\d+\]: |^\ \ \ \.\.\.+: )') | |
383 | prompt2_re = re.compile(r'^(In \[\d+\]: |^\ \ \ \.\.\.+: )') |
|
391 | return _strip_prompts(prompt_re) | |
384 | return _strip_prompts(prompt1_re, prompt2_re) |
|
|||
385 |
|
392 | |||
386 |
|
393 | |||
387 | @CoroutineInputTransformer.wrap |
|
394 | @CoroutineInputTransformer.wrap |
@@ -173,7 +173,12 b' syntax_ml = \\' | |||||
173 | ('... 123"""','123"""'), |
|
173 | ('... 123"""','123"""'), | |
174 | ], |
|
174 | ], | |
175 | [('a="""','a="""'), |
|
175 | [('a="""','a="""'), | |
176 |
('... 123 |
|
176 | ('... 123','123'), | |
|
177 | ('... 456"""','456"""'), | |||
|
178 | ], | |||
|
179 | [('a="""','a="""'), | |||
|
180 | ('123','123'), | |||
|
181 | ('... 456"""','... 456"""'), | |||
177 | ], |
|
182 | ], | |
178 | ], |
|
183 | ], | |
179 |
|
184 | |||
@@ -186,7 +191,12 b' syntax_ml = \\' | |||||
186 | (' ...: 123"""','123"""'), |
|
191 | (' ...: 123"""','123"""'), | |
187 | ], |
|
192 | ], | |
188 | [('a="""','a="""'), |
|
193 | [('a="""','a="""'), | |
189 |
(' ...: 123 |
|
194 | (' ...: 123','123'), | |
|
195 | (' ...: 456"""','456"""'), | |||
|
196 | ], | |||
|
197 | [('a="""','a="""'), | |||
|
198 | ('123','123'), | |||
|
199 | (' ...: 456"""',' ...: 456"""'), | |||
190 | ], |
|
200 | ], | |
191 | ], |
|
201 | ], | |
192 |
|
202 |
General Comments 0
You need to be logged in to leave comments.
Login now