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