Show More
@@ -94,7 +94,7 b' def cell_magic(lines):' | |||
|
94 | 94 | if re.match(r'%%\w+\?', lines[0]): |
|
95 | 95 | # This case will be handled by help_end |
|
96 | 96 | return lines |
|
97 |
magic_name, _, first_line = lines[0][2: |
|
|
97 | magic_name, _, first_line = lines[0][2:].rstrip().partition(' ') | |
|
98 | 98 | body = ''.join(lines[1:]) |
|
99 | 99 | return ['get_ipython().run_cell_magic(%r, %r, %r)\n' |
|
100 | 100 | % (magic_name, first_line, body)] |
@@ -153,8 +153,8 b' def assemble_continued_line(lines, start: Tuple[int, int], end_line: int):' | |||
|
153 | 153 | multiple lines. |
|
154 | 154 | """ |
|
155 | 155 | parts = [lines[start[0]][start[1]:]] + lines[start[0]+1:end_line+1] |
|
156 |
return ' '.join([p[:- |
|
|
157 |
+ [parts[-1] |
|
|
156 | return ' '.join([p.rstrip()[:-1] for p in parts[:-1]] # Strip backslash+newline | |
|
157 | + [parts[-1].rstrip()]) # Strip newline from last line | |
|
158 | 158 | |
|
159 | 159 | class TokenTransformBase: |
|
160 | 160 | """Base class for transformations which examine tokens. |
@@ -31,6 +31,16 b' for a in range(5):' | |||
|
31 | 31 | get_ipython().run_line_magic('ls', '') |
|
32 | 32 | """.splitlines(keepends=True)) |
|
33 | 33 | |
|
34 | CRLF_MAGIC = ([ | |
|
35 | "a = f()\n", | |
|
36 | "%ls\r\n", | |
|
37 | "g()\n" | |
|
38 | ], (2, 0), [ | |
|
39 | "a = f()\n", | |
|
40 | "get_ipython().run_line_magic('ls', '')\n", | |
|
41 | "g()\n" | |
|
42 | ]) | |
|
43 | ||
|
34 | 44 | MULTILINE_MAGIC_ASSIGN = ("""\ |
|
35 | 45 | a = f() |
|
36 | 46 | b = %foo \\ |
@@ -190,6 +200,7 b' def test_find_magic_escape():' | |||
|
190 | 200 | def test_transform_magic_escape(): |
|
191 | 201 | check_transform(ipt2.EscapedCommand, MULTILINE_MAGIC) |
|
192 | 202 | check_transform(ipt2.EscapedCommand, INDENTED_MAGIC) |
|
203 | check_transform(ipt2.EscapedCommand, CRLF_MAGIC) | |
|
193 | 204 | |
|
194 | 205 | def test_find_autocalls(): |
|
195 | 206 | for case in [AUTOCALL_QUOTE, AUTOCALL_QUOTE2, AUTOCALL_PAREN]: |
@@ -114,3 +114,13 b' def test_leading_empty_lines():' | |||
|
114 | 114 | nt.assert_equal( |
|
115 | 115 | ipt2.leading_empty_lines(sample.splitlines(keepends=True)), |
|
116 | 116 | expected.splitlines(keepends=True)) |
|
117 | ||
|
118 | CRLF_MAGIC = ([ | |
|
119 | "%%ls\r\n" | |
|
120 | ], [ | |
|
121 | "get_ipython().run_cell_magic('ls', '', '')\n" | |
|
122 | ]) | |
|
123 | ||
|
124 | def test_crlf_magic(): | |
|
125 | for sample, expected in [CRLF_MAGIC]: | |
|
126 | nt.assert_equal(ipt2.cell_magic(sample), expected) No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now