Show More
@@ -486,17 +486,19 b' class IPythonInputSplitter(InputSplitter):' | |||
|
486 | 486 | if physical_line_transforms is not None: |
|
487 | 487 | self.physical_line_transforms = physical_line_transforms |
|
488 | 488 | else: |
|
489 |
self.physical_line_transforms = [ |
|
|
489 | self.physical_line_transforms = [ | |
|
490 | leading_indent(), | |
|
490 | 491 | classic_prompt(), |
|
491 | 492 | ipy_prompt(), |
|
492 | 493 | strip_encoding_cookie(), |
|
494 | cellmagic(end_on_blank_line=line_input_checker), | |
|
493 | 495 | ] |
|
494 | 496 | |
|
495 | 497 | self.assemble_logical_lines = assemble_logical_lines() |
|
496 | 498 | if logical_line_transforms is not None: |
|
497 | 499 | self.logical_line_transforms = logical_line_transforms |
|
498 | 500 | else: |
|
499 |
self.logical_line_transforms = [ |
|
|
501 | self.logical_line_transforms = [ | |
|
500 | 502 | help_end(), |
|
501 | 503 | escaped_commands(), |
|
502 | 504 | assign_from_magic(), |
@@ -227,6 +227,8 b' def _tr_help(line_info):' | |||
|
227 | 227 | def _tr_magic(line_info): |
|
228 | 228 | "Translate lines escaped with: %" |
|
229 | 229 | tpl = '%sget_ipython().magic(%r)' |
|
230 | if line_info.line.startswith(ESC_MAGIC2): | |
|
231 | return line_info.line | |
|
230 | 232 | cmd = ' '.join([line_info.ifun, line_info.the_rest]).strip() |
|
231 | 233 | return tpl % (line_info.pre, cmd) |
|
232 | 234 | |
@@ -272,7 +274,8 b' _help_end_re = re.compile(r"""(%{0,2}' | |||
|
272 | 274 | [a-zA-Z_*][\w*]* # Variable name |
|
273 | 275 | (\.[a-zA-Z_*][\w*]*)* # .etc.etc |
|
274 | 276 | ) |
|
275 |
(\?\??)$ # ? or ?? |
|
|
277 | (\?\??)$ # ? or ?? | |
|
278 | """, | |
|
276 | 279 | re.VERBOSE) |
|
277 | 280 | |
|
278 | 281 | def has_comment(src): |
@@ -328,7 +331,14 b' def cellmagic(end_on_blank_line=False):' | |||
|
328 | 331 | line = '' |
|
329 | 332 | while True: |
|
330 | 333 | line = (yield line) |
|
331 | if (not line) or (not line.startswith(ESC_MAGIC2)): | |
|
334 | # consume leading empty lines | |
|
335 | while not line: | |
|
336 | line = (yield line) | |
|
337 | ||
|
338 | if not line.startswith(ESC_MAGIC2): | |
|
339 | # This isn't a cell magic, idle waiting for reset then start over | |
|
340 | while line is not None: | |
|
341 | line = (yield line) | |
|
332 | 342 | continue |
|
333 | 343 | |
|
334 | 344 | if cellmagic_help_re.match(line): |
@@ -1672,7 +1672,13 b' class InteractiveShell(SingletonConfigurable):' | |||
|
1672 | 1672 | |
|
1673 | 1673 | return etype, value, tb |
|
1674 | 1674 | |
|
1675 | ||
|
1675 | def show_usage_error(self, exc): | |
|
1676 | """Show a short message for UsageErrors | |
|
1677 | ||
|
1678 | These are special exceptions that shouldn't show a traceback. | |
|
1679 | """ | |
|
1680 | self.write_err("UsageError: %s" % exc) | |
|
1681 | ||
|
1676 | 1682 | def showtraceback(self,exc_tuple = None,filename=None,tb_offset=None, |
|
1677 | 1683 | exception_only=False): |
|
1678 | 1684 | """Display the exception that just occurred. |
@@ -1698,7 +1704,7 b' class InteractiveShell(SingletonConfigurable):' | |||
|
1698 | 1704 | # line, there may be SyntaxError cases with imported code. |
|
1699 | 1705 | self.showsyntaxerror(filename) |
|
1700 | 1706 | elif etype is UsageError: |
|
1701 |
self. |
|
|
1707 | self.show_usage_error(value) | |
|
1702 | 1708 | else: |
|
1703 | 1709 | if exception_only: |
|
1704 | 1710 | stb = ['An exception has occurred, use %tb to see ' |
@@ -446,6 +446,24 b' class IPythonInputTestCase(InputSplitterTestCase):' | |||
|
446 | 446 | out = isp.transform_cell(raw) |
|
447 | 447 | # Match ignoring trailing whitespace |
|
448 | 448 | self.assertEqual(out.rstrip(), out_t.rstrip()) |
|
449 | ||
|
450 | def test_cellmagic_preempt(self): | |
|
451 | isp = self.isp | |
|
452 | for raw, name, line, cell in [ | |
|
453 | ("%%cellm a\nIn[1]:", u'cellm', u'a', u'In[1]:'), | |
|
454 | ("%%cellm \nline\n>>>hi", u'cellm', u'', u'line\n>>>hi'), | |
|
455 | (">>>%%cellm \nline\n>>>hi", u'cellm', u'', u'line\nhi'), | |
|
456 | ("%%cellm \n>>>hi", u'cellm', u'', u'hi'), | |
|
457 | ("%%cellm \nline1\nline2", u'cellm', u'', u'line1\nline2'), | |
|
458 | ("%%cellm \nline1\\\\\nline2", u'cellm', u'', u'line1\\\\\nline2'), | |
|
459 | ]: | |
|
460 | expected = "get_ipython().run_cell_magic(%r, %r, %r)" % ( | |
|
461 | name, line, cell | |
|
462 | ) | |
|
463 | out = isp.transform_cell(raw) | |
|
464 | self.assertEqual(out.rstrip(), expected.rstrip()) | |
|
465 | ||
|
466 | ||
|
449 | 467 | |
|
450 | 468 | #----------------------------------------------------------------------------- |
|
451 | 469 | # Main - use as a script, mostly for developer experiments |
General Comments 0
You need to be logged in to leave comments.
Login now