##// END OF EJS Templates
add strip_encoding_cookie transformer...
MinRK -
Show More
@@ -75,6 +75,7 b' from IPython.utils.py3compat import cast_unicode'
75 from IPython.core.inputtransformer import (leading_indent,
75 from IPython.core.inputtransformer import (leading_indent,
76 classic_prompt,
76 classic_prompt,
77 ipy_prompt,
77 ipy_prompt,
78 strip_encoding_cookie,
78 cellmagic,
79 cellmagic,
79 assemble_logical_lines,
80 assemble_logical_lines,
80 help_end,
81 help_end,
@@ -488,6 +489,7 b' class IPythonInputSplitter(InputSplitter):'
488 self.physical_line_transforms = [leading_indent(),
489 self.physical_line_transforms = [leading_indent(),
489 classic_prompt(),
490 classic_prompt(),
490 ipy_prompt(),
491 ipy_prompt(),
492 strip_encoding_cookie(),
491 ]
493 ]
492
494
493 self.assemble_logical_lines = assemble_logical_lines()
495 self.assemble_logical_lines = assemble_logical_lines()
@@ -5,6 +5,7 b' from StringIO import StringIO'
5
5
6 from IPython.core.splitinput import LineInfo
6 from IPython.core.splitinput import LineInfo
7 from IPython.utils import tokenize2
7 from IPython.utils import tokenize2
8 from IPython.utils.openpy import cookie_comment_re
8 from IPython.utils.tokenize2 import generate_tokens, untokenize, TokenError
9 from IPython.utils.tokenize2 import generate_tokens, untokenize, TokenError
9
10
10 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
@@ -422,6 +423,30 b' def leading_indent():'
422 line = (yield line)
423 line = (yield line)
423
424
424
425
426 @CoroutineInputTransformer.wrap
427 def strip_encoding_cookie():
428 """Remove encoding comment if found in first two lines
429
430 If the first or second line has the `# coding: utf-8` comment,
431 it will be removed.
432 """
433 line = ''
434 while True:
435 line = (yield line)
436 # check comment on first two lines
437 for i in range(2):
438 if line is None:
439 break
440 if cookie_comment_re.match(line):
441 line = (yield "")
442 else:
443 line = (yield line)
444
445 # no-op on the rest of the cell
446 while line is not None:
447 line = (yield line)
448
449
425 assign_system_re = re.compile(r'(?P<lhs>(\s*)([\w\.]+)((\s*,\s*[\w\.]+)*))'
450 assign_system_re = re.compile(r'(?P<lhs>(\s*)([\w\.]+)((\s*,\s*[\w\.]+)*))'
426 r'\s*=\s*!\s*(?P<cmd>.*)')
451 r'\s*=\s*!\s*(?P<cmd>.*)')
427 assign_system_template = '%s = get_ipython().getoutput(%r)'
452 assign_system_template = '%s = get_ipython().getoutput(%r)'
General Comments 0
You need to be logged in to leave comments. Login now