##// END OF EJS Templates
only strip continuation prompts if regular prompts seen first...
MinRK -
Show More
@@ -359,8 +359,17 b' def cellmagic(end_on_blank_line=False):'
359 line = tpl % (magic_name, first, u'\n'.join(body))
359 line = tpl % (magic_name, first, u'\n'.join(body))
360
360
361
361
362 def _strip_prompts(prompt_re):
362 def _strip_prompts(prompt_re, continuation_re=None):
363 """Remove matching input prompts from a block of input."""
363 """Remove matching input prompts from a block of input.
364
365 prompt_re is stripped only once, on either the first or second line.
366 If prompt_re is found on one of the first two lines,
367 continuation_re is stripped from lines thereafter.
368
369 If continuation_re is unspecified, prompt_re will be used for both.
370 """
371 if continuation_re is None:
372 continuation_re = prompt_re
364 line = ''
373 line = ''
365 while True:
374 while True:
366 line = (yield line)
375 line = (yield line)
@@ -375,14 +384,19 b' def _strip_prompts(prompt_re):'
375 # first prompt, so we might not see it in the first line.
384 # first prompt, so we might not see it in the first line.
376 if line is None:
385 if line is None:
377 continue
386 continue
378 out, n2 = prompt_re.subn('', line, count=1)
387 # check for first prompt if not found on first line, continuation otherwise
388 if n1:
389 pat = continuation_re
390 else:
391 pat = prompt_re
392 out, n2 = pat.subn('', line, count=1)
379 line = (yield out)
393 line = (yield out)
380
394
381 if n1 or n2:
395 if n1 or n2:
382 # Found the input prompt in the first two lines - check for it in
396 # Found the input prompt in the first two lines - check for it in
383 # the rest of the cell as well.
397 # the rest of the cell as well.
384 while line is not None:
398 while line is not None:
385 line = (yield prompt_re.sub('', line, count=1))
399 line = (yield continuation_re.sub('', line, count=1))
386
400
387 else:
401 else:
388 # Prompts not in input - wait for reset
402 # Prompts not in input - wait for reset
@@ -393,16 +407,18 b' def _strip_prompts(prompt_re):'
393 def classic_prompt():
407 def classic_prompt():
394 """Strip the >>>/... prompts of the Python interactive shell."""
408 """Strip the >>>/... prompts of the Python interactive shell."""
395 # FIXME: non-capturing version (?:...) usable?
409 # FIXME: non-capturing version (?:...) usable?
396 prompt_re = re.compile(r'^(>>> ?|\.\.\. ?)')
410 prompt_re = re.compile(r'^(>>> ?)')
397 return _strip_prompts(prompt_re)
411 continuation_re = re.compile(r'^(>>> ?|\.\.\. ?)')
412 return _strip_prompts(prompt_re, continuation_re)
398
413
399 @CoroutineInputTransformer.wrap
414 @CoroutineInputTransformer.wrap
400 def ipy_prompt():
415 def ipy_prompt():
401 """Strip IPython's In [1]:/...: prompts."""
416 """Strip IPython's In [1]:/...: prompts."""
402 # FIXME: non-capturing version (?:...) usable?
417 # FIXME: non-capturing version (?:...) usable?
403 # FIXME: r'^(In \[\d+\]: | {3}\.{3,}: )' clearer?
418 # FIXME: r'^(In \[\d+\]: | {3}\.{3,}: )' clearer?
404 prompt_re = re.compile(r'^(In \[\d+\]: |\ \ \ \.\.\.+: )')
419 prompt_re = re.compile(r'^(In \[\d+\]: )')
405 return _strip_prompts(prompt_re)
420 continuation_re = re.compile(r'^(In \[\d+\]: |\ \ \ \.\.\.+: )')
421 return _strip_prompts(prompt_re, continuation_re)
406
422
407
423
408 @CoroutineInputTransformer.wrap
424 @CoroutineInputTransformer.wrap
@@ -179,13 +179,18 b' syntax_ml = \\'
179 ('... 123"""','123"""'),
179 ('... 123"""','123"""'),
180 ],
180 ],
181 [('a="""','a="""'),
181 [('a="""','a="""'),
182 ('... 123','123'),
182 ('... 123','... 123'),
183 ('... 456"""','456"""'),
183 ('... 456"""','... 456"""'),
184 ],
184 ],
185 [('a="""','a="""'),
185 [('a="""','a="""'),
186 ('123','123'),
186 ('123','123'),
187 ('... 456"""','... 456"""'),
187 ('... 456"""','... 456"""'),
188 ],
188 ],
189 [('....__class__','....__class__'),
190 ],
191 [('a=5', 'a=5'),
192 ('...', '...'),
193 ],
189 [('>>> def f(x):', 'def f(x):'),
194 [('>>> def f(x):', 'def f(x):'),
190 ('...', ''),
195 ('...', ''),
191 ('... return x', ' return x'),
196 ('... return x', ' return x'),
@@ -201,8 +206,8 b' syntax_ml = \\'
201 (' ...: 123"""','123"""'),
206 (' ...: 123"""','123"""'),
202 ],
207 ],
203 [('a="""','a="""'),
208 [('a="""','a="""'),
204 (' ...: 123','123'),
209 (' ...: 123',' ...: 123'),
205 (' ...: 456"""','456"""'),
210 (' ...: 456"""',' ...: 456"""'),
206 ],
211 ],
207 [('a="""','a="""'),
212 [('a="""','a="""'),
208 ('123','123'),
213 ('123','123'),
General Comments 0
You need to be logged in to leave comments. Login now