Show More
@@ -348,22 +348,31 b' def cellmagic(end_on_blank_line=False):' | |||
|
348 | 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 | 352 | """Remove matching input prompts from a block of input.""" |
|
353 | 353 | line = '' |
|
354 | 354 | while True: |
|
355 | 355 | line = (yield line) |
|
356 | 356 | |
|
357 | # First line of cell | |
|
357 | 358 | if line is None: |
|
358 | 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 | 376 | else: |
|
368 | 377 | # Prompts not in input - wait for reset |
|
369 | 378 | while line is not None: |
@@ -372,16 +381,14 b' def _strip_prompts(prompt1_re, prompt2_re):' | |||
|
372 | 381 | @CoroutineInputTransformer.wrap |
|
373 | 382 | def classic_prompt(): |
|
374 | 383 | """Strip the >>>/... prompts of the Python interactive shell.""" |
|
375 |
prompt |
|
|
376 | prompt2_re = re.compile(r'^(>>> |^\.\.\. )') | |
|
377 | return _strip_prompts(prompt1_re, prompt2_re) | |
|
384 | prompt_re = re.compile(r'^(>>> |^\.\.\. )') | |
|
385 | return _strip_prompts(prompt_re) | |
|
378 | 386 | |
|
379 | 387 | @CoroutineInputTransformer.wrap |
|
380 | 388 | def ipy_prompt(): |
|
381 | 389 | """Strip IPython's In [1]:/...: prompts.""" |
|
382 |
prompt |
|
|
383 | prompt2_re = re.compile(r'^(In \[\d+\]: |^\ \ \ \.\.\.+: )') | |
|
384 | return _strip_prompts(prompt1_re, prompt2_re) | |
|
390 | prompt_re = re.compile(r'^(In \[\d+\]: |^\ \ \ \.\.\.+: )') | |
|
391 | return _strip_prompts(prompt_re) | |
|
385 | 392 | |
|
386 | 393 | |
|
387 | 394 | @CoroutineInputTransformer.wrap |
@@ -173,7 +173,12 b' syntax_ml = \\' | |||
|
173 | 173 | ('... 123"""','123"""'), |
|
174 | 174 | ], |
|
175 | 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 | 191 | (' ...: 123"""','123"""'), |
|
187 | 192 | ], |
|
188 | 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