Show More
@@ -3045,11 +3045,11 b' Defaulting color scheme to \'NoColor\'"""' | |||||
3045 |
|
3045 | |||
3046 | dir_s = self.shell.dir_stack |
|
3046 | dir_s = self.shell.dir_stack | |
3047 | tgt = os.path.expanduser(unquote_filename(parameter_s)) |
|
3047 | tgt = os.path.expanduser(unquote_filename(parameter_s)) | |
3048 | cwd = os.getcwdu().replace(self.home_dir,'~') |
|
3048 | cwd = os.getcwdu().replace(self.shell.home_dir,'~') | |
3049 | if tgt: |
|
3049 | if tgt: | |
3050 | self.magic_cd(parameter_s) |
|
3050 | self.magic_cd(parameter_s) | |
3051 | dir_s.insert(0,cwd) |
|
3051 | dir_s.insert(0,cwd) | |
3052 |
return self.magic |
|
3052 | return self.shell.magic('dirs') | |
3053 |
|
3053 | |||
3054 | def magic_popd(self, parameter_s=''): |
|
3054 | def magic_popd(self, parameter_s=''): | |
3055 | """Change to directory popped off the top of the stack. |
|
3055 | """Change to directory popped off the top of the stack. | |
@@ -3417,7 +3417,7 b' Defaulting color scheme to \'NoColor\'"""' | |||||
3417 | ptformatter.pprint = False |
|
3417 | ptformatter.pprint = False | |
3418 | disp_formatter.plain_text_only = True |
|
3418 | disp_formatter.plain_text_only = True | |
3419 |
|
3419 | |||
3420 |
shell.magic |
|
3420 | shell.magic('xmode Plain') | |
3421 | else: |
|
3421 | else: | |
3422 | # turn off |
|
3422 | # turn off | |
3423 | pm.in_template, pm.in2_template, pm.out_template = dstore.prompt_templates |
|
3423 | pm.in_template, pm.in2_template, pm.out_template = dstore.prompt_templates | |
@@ -3432,7 +3432,7 b' Defaulting color scheme to \'NoColor\'"""' | |||||
3432 | ptformatter.pprint = dstore.rc_pprint |
|
3432 | ptformatter.pprint = dstore.rc_pprint | |
3433 | disp_formatter.plain_text_only = dstore.rc_plain_text_only |
|
3433 | disp_formatter.plain_text_only = dstore.rc_plain_text_only | |
3434 |
|
3434 | |||
3435 |
shell.magic |
|
3435 | shell.magic('xmode ' + dstore.xmode) | |
3436 |
|
3436 | |||
3437 | # Store new mode and inform |
|
3437 | # Store new mode and inform | |
3438 | dstore.mode = bool(1-int(mode)) |
|
3438 | dstore.mode = bool(1-int(mode)) | |
@@ -3487,7 +3487,8 b' Defaulting color scheme to \'NoColor\'"""' | |||||
3487 | """ |
|
3487 | """ | |
3488 | opts, args = self.parse_options(parameter_s, 'n:') |
|
3488 | opts, args = self.parse_options(parameter_s, 'n:') | |
3489 | try: |
|
3489 | try: | |
3490 |
filename = self.extension_manager.install_extension(args, |
|
3490 | filename = self.shell.extension_manager.install_extension(args, | |
|
3491 | opts.get('n')) | |||
3491 | except ValueError as e: |
|
3492 | except ValueError as e: | |
3492 | print e |
|
3493 | print e | |
3493 | return |
|
3494 | return | |
@@ -3499,15 +3500,15 b' Defaulting color scheme to \'NoColor\'"""' | |||||
3499 |
|
3500 | |||
3500 | def magic_load_ext(self, module_str): |
|
3501 | def magic_load_ext(self, module_str): | |
3501 | """Load an IPython extension by its module name.""" |
|
3502 | """Load an IPython extension by its module name.""" | |
3502 | return self.extension_manager.load_extension(module_str) |
|
3503 | return self.shell.extension_manager.load_extension(module_str) | |
3503 |
|
3504 | |||
3504 | def magic_unload_ext(self, module_str): |
|
3505 | def magic_unload_ext(self, module_str): | |
3505 | """Unload an IPython extension by its module name.""" |
|
3506 | """Unload an IPython extension by its module name.""" | |
3506 | self.extension_manager.unload_extension(module_str) |
|
3507 | self.shell.extension_manager.unload_extension(module_str) | |
3507 |
|
3508 | |||
3508 | def magic_reload_ext(self, module_str): |
|
3509 | def magic_reload_ext(self, module_str): | |
3509 | """Reload an IPython extension by its module name.""" |
|
3510 | """Reload an IPython extension by its module name.""" | |
3510 | self.extension_manager.reload_extension(module_str) |
|
3511 | self.shell.extension_manager.reload_extension(module_str) | |
3511 |
|
3512 | |||
3512 | def magic_install_profiles(self, s): |
|
3513 | def magic_install_profiles(self, s): | |
3513 | """%install_profiles has been deprecated.""" |
|
3514 | """%install_profiles has been deprecated.""" | |
@@ -3681,9 +3682,10 b' Defaulting color scheme to \'NoColor\'"""' | |||||
3681 | if args.export: |
|
3682 | if args.export: | |
3682 | fname, name, format = current.parse_filename(args.filename) |
|
3683 | fname, name, format = current.parse_filename(args.filename) | |
3683 | cells = [] |
|
3684 | cells = [] | |
3684 | hist = list(self.history_manager.get_range()) |
|
3685 | hist = list(self.shell.history_manager.get_range()) | |
3685 | for session, prompt_number, input in hist[:-1]: |
|
3686 | for session, prompt_number, input in hist[:-1]: | |
3686 |
cells.append(current.new_code_cell(prompt_number=prompt_number, |
|
3687 | cells.append(current.new_code_cell(prompt_number=prompt_number, | |
|
3688 | input=input)) | |||
3687 | worksheet = current.new_worksheet(cells=cells) |
|
3689 | worksheet = current.new_worksheet(cells=cells) | |
3688 | nb = current.new_notebook(name=name,worksheets=[worksheet]) |
|
3690 | nb = current.new_notebook(name=name,worksheets=[worksheet]) | |
3689 | with io.open(fname, 'w', encoding='utf-8') as f: |
|
3691 | with io.open(fname, 'w', encoding='utf-8') as f: |
@@ -343,7 +343,7 b' class TestSafeExecfileNonAsciiPath(unittest.TestCase):' | |||||
343 | def test_1(self): |
|
343 | def test_1(self): | |
344 | """Test safe_execfile with non-ascii path |
|
344 | """Test safe_execfile with non-ascii path | |
345 | """ |
|
345 | """ | |
346 |
_ip |
|
346 | _ip.safe_execfile(self.fname, {}, raise_exceptions=True) | |
347 |
|
347 | |||
348 |
|
348 | |||
349 | class TestSystemRaw(unittest.TestCase): |
|
349 | class TestSystemRaw(unittest.TestCase): | |
@@ -351,7 +351,7 b' class TestSystemRaw(unittest.TestCase):' | |||||
351 | """Test system_raw with non-ascii cmd |
|
351 | """Test system_raw with non-ascii cmd | |
352 | """ |
|
352 | """ | |
353 | cmd = ur'''python -c "'Γ₯Àâ'" ''' |
|
353 | cmd = ur'''python -c "'Γ₯Àâ'" ''' | |
354 |
_ip |
|
354 | _ip.system_raw(cmd) | |
355 |
|
355 | |||
356 |
|
356 | |||
357 | def test__IPYTHON__(): |
|
357 | def test__IPYTHON__(): |
@@ -51,7 +51,7 b' def test_magic_parse_options():' | |||||
51 | """Test that we don't mangle paths when parsing magic options.""" |
|
51 | """Test that we don't mangle paths when parsing magic options.""" | |
52 | ip = get_ipython() |
|
52 | ip = get_ipython() | |
53 | path = 'c:\\x' |
|
53 | path = 'c:\\x' | |
54 | opts = ip.parse_options('-f %s' % path,'f:')[0] |
|
54 | opts = ip._magic.parse_options('-f %s' % path,'f:')[0] | |
55 | # argv splitting is os-dependent |
|
55 | # argv splitting is os-dependent | |
56 | if os.name == 'posix': |
|
56 | if os.name == 'posix': | |
57 | expected = 'c:x' |
|
57 | expected = 'c:x' | |
@@ -284,8 +284,8 b' def test_parse_options():' | |||||
284 | """Tests for basic options parsing in magics.""" |
|
284 | """Tests for basic options parsing in magics.""" | |
285 | # These are only the most minimal of tests, more should be added later. At |
|
285 | # These are only the most minimal of tests, more should be added later. At | |
286 | # the very least we check that basic text/unicode calls work OK. |
|
286 | # the very least we check that basic text/unicode calls work OK. | |
287 | nt.assert_equal(_ip.parse_options('foo', '')[1], 'foo') |
|
287 | nt.assert_equal(_ip._magic.parse_options('foo', '')[1], 'foo') | |
288 | nt.assert_equal(_ip.parse_options(u'foo', '')[1], u'foo') |
|
288 | nt.assert_equal(_ip._magic.parse_options(u'foo', '')[1], u'foo') | |
289 |
|
289 | |||
290 |
|
290 | |||
291 | def test_dirops(): |
|
291 | def test_dirops(): | |
@@ -326,7 +326,7 b' def test_reset_hard():' | |||||
326 | _ip.run_cell("a") |
|
326 | _ip.run_cell("a") | |
327 |
|
327 | |||
328 | nt.assert_equal(monitor, []) |
|
328 | nt.assert_equal(monitor, []) | |
329 |
_ip.magic |
|
329 | _ip.magic("reset -f") | |
330 | nt.assert_equal(monitor, [1]) |
|
330 | nt.assert_equal(monitor, [1]) | |
331 |
|
331 | |||
332 | class TestXdel(tt.TempFileMixin): |
|
332 | class TestXdel(tt.TempFileMixin): | |
@@ -388,7 +388,7 b' def test_whos():' | |||||
388 | def doctest_precision(): |
|
388 | def doctest_precision(): | |
389 | """doctest for %precision |
|
389 | """doctest for %precision | |
390 |
|
390 | |||
391 |
In [1]: f = get_ipython(). |
|
391 | In [1]: f = get_ipython().display_formatter.formatters['text/plain'] | |
392 |
|
392 | |||
393 | In [2]: %precision 5 |
|
393 | In [2]: %precision 5 | |
394 | Out[2]: {u}'%.5f' |
|
394 | Out[2]: {u}'%.5f' | |
@@ -422,7 +422,7 b' def test_timeit_arguments():' | |||||
422 | "Test valid timeit arguments, should not cause SyntaxError (GH #1269)" |
|
422 | "Test valid timeit arguments, should not cause SyntaxError (GH #1269)" | |
423 | _ip.magic("timeit ('#')") |
|
423 | _ip.magic("timeit ('#')") | |
424 |
|
424 | |||
425 | @dec.skipif(_ip.magic_prun == _ip.profile_missing_notice) |
|
425 | @dec.skipif(_ip._magic.magic_prun == _ip._magic.profile_missing_notice) | |
426 | def test_prun_quotes(): |
|
426 | def test_prun_quotes(): | |
427 | "Test that prun does not clobber string escapes (GH #1302)" |
|
427 | "Test that prun does not clobber string escapes (GH #1302)" | |
428 | _ip.magic("prun -q x = '\t'") |
|
428 | _ip.magic("prun -q x = '\t'") |
@@ -79,7 +79,7 b' def test_issue_114():' | |||||
79 | msp = ip.prefilter_manager.multi_line_specials |
|
79 | msp = ip.prefilter_manager.multi_line_specials | |
80 | ip.prefilter_manager.multi_line_specials = False |
|
80 | ip.prefilter_manager.multi_line_specials = False | |
81 | try: |
|
81 | try: | |
82 | for mgk in ip.lsmagic(): |
|
82 | for mgk in ip._magic.lsmagic(): | |
83 | raw = template % mgk |
|
83 | raw = template % mgk | |
84 | yield nt.assert_equals(ip.prefilter(raw), raw) |
|
84 | yield nt.assert_equals(ip.prefilter(raw), raw) | |
85 | finally: |
|
85 | finally: |
@@ -120,6 +120,133 b" def rerun_pasted(shell, name='pasted_block'):" | |||||
120 | shell.run_cell(b) |
|
120 | shell.run_cell(b) | |
121 |
|
121 | |||
122 |
|
122 | |||
|
123 | #------------------------------------------------------------------------ | |||
|
124 | # Terminal-specific magics | |||
|
125 | #------------------------------------------------------------------------ | |||
|
126 | ||||
|
127 | def magic_autoindent(self, parameter_s = ''): | |||
|
128 | """Toggle autoindent on/off (if available).""" | |||
|
129 | ||||
|
130 | self.shell.set_autoindent() | |||
|
131 | print "Automatic indentation is:",['OFF','ON'][self.shell.autoindent] | |||
|
132 | ||||
|
133 | @skip_doctest | |||
|
134 | def magic_cpaste(self, parameter_s=''): | |||
|
135 | """Paste & execute a pre-formatted code block from clipboard. | |||
|
136 | ||||
|
137 | You must terminate the block with '--' (two minus-signs) or Ctrl-D | |||
|
138 | alone on the line. You can also provide your own sentinel with '%paste | |||
|
139 | -s %%' ('%%' is the new sentinel for this operation) | |||
|
140 | ||||
|
141 | The block is dedented prior to execution to enable execution of method | |||
|
142 | definitions. '>' and '+' characters at the beginning of a line are | |||
|
143 | ignored, to allow pasting directly from e-mails, diff files and | |||
|
144 | doctests (the '...' continuation prompt is also stripped). The | |||
|
145 | executed block is also assigned to variable named 'pasted_block' for | |||
|
146 | later editing with '%edit pasted_block'. | |||
|
147 | ||||
|
148 | You can also pass a variable name as an argument, e.g. '%cpaste foo'. | |||
|
149 | This assigns the pasted block to variable 'foo' as string, without | |||
|
150 | dedenting or executing it (preceding >>> and + is still stripped) | |||
|
151 | ||||
|
152 | '%cpaste -r' re-executes the block previously entered by cpaste. | |||
|
153 | ||||
|
154 | Do not be alarmed by garbled output on Windows (it's a readline bug). | |||
|
155 | Just press enter and type -- (and press enter again) and the block | |||
|
156 | will be what was just pasted. | |||
|
157 | ||||
|
158 | IPython statements (magics, shell escapes) are not supported (yet). | |||
|
159 | ||||
|
160 | See also | |||
|
161 | -------- | |||
|
162 | paste: automatically pull code from clipboard. | |||
|
163 | ||||
|
164 | Examples | |||
|
165 | -------- | |||
|
166 | :: | |||
|
167 | ||||
|
168 | In [8]: %cpaste | |||
|
169 | Pasting code; enter '--' alone on the line to stop. | |||
|
170 | :>>> a = ["world!", "Hello"] | |||
|
171 | :>>> print " ".join(sorted(a)) | |||
|
172 | :-- | |||
|
173 | Hello world! | |||
|
174 | """ | |||
|
175 | ||||
|
176 | opts, name = self.parse_options(parameter_s, 'rs:', mode='string') | |||
|
177 | if 'r' in opts: | |||
|
178 | rerun_pasted(self.shell) | |||
|
179 | return | |||
|
180 | ||||
|
181 | sentinel = opts.get('s', '--') | |||
|
182 | block = strip_email_quotes(get_pasted_lines(sentinel)) | |||
|
183 | store_or_execute(self.shell, block, name) | |||
|
184 | ||||
|
185 | ||||
|
186 | def magic_paste(self, parameter_s=''): | |||
|
187 | """Paste & execute a pre-formatted code block from clipboard. | |||
|
188 | ||||
|
189 | The text is pulled directly from the clipboard without user | |||
|
190 | intervention and printed back on the screen before execution (unless | |||
|
191 | the -q flag is given to force quiet mode). | |||
|
192 | ||||
|
193 | The block is dedented prior to execution to enable execution of method | |||
|
194 | definitions. '>' and '+' characters at the beginning of a line are | |||
|
195 | ignored, to allow pasting directly from e-mails, diff files and | |||
|
196 | doctests (the '...' continuation prompt is also stripped). The | |||
|
197 | executed block is also assigned to variable named 'pasted_block' for | |||
|
198 | later editing with '%edit pasted_block'. | |||
|
199 | ||||
|
200 | You can also pass a variable name as an argument, e.g. '%paste foo'. | |||
|
201 | This assigns the pasted block to variable 'foo' as string, without | |||
|
202 | dedenting or executing it (preceding >>> and + is still stripped) | |||
|
203 | ||||
|
204 | Options | |||
|
205 | ------- | |||
|
206 | ||||
|
207 | -r: re-executes the block previously entered by cpaste. | |||
|
208 | ||||
|
209 | -q: quiet mode: do not echo the pasted text back to the terminal. | |||
|
210 | ||||
|
211 | IPython statements (magics, shell escapes) are not supported (yet). | |||
|
212 | ||||
|
213 | See also | |||
|
214 | -------- | |||
|
215 | cpaste: manually paste code into terminal until you mark its end. | |||
|
216 | """ | |||
|
217 | opts, name = self.parse_options(parameter_s, 'rq', mode='string') | |||
|
218 | if 'r' in opts: | |||
|
219 | rerun_pasted(self.shell) | |||
|
220 | return | |||
|
221 | try: | |||
|
222 | text = self.shell.hooks.clipboard_get() | |||
|
223 | block = strip_email_quotes(text.splitlines()) | |||
|
224 | except TryNext as clipboard_exc: | |||
|
225 | message = getattr(clipboard_exc, 'args') | |||
|
226 | if message: | |||
|
227 | error(message[0]) | |||
|
228 | else: | |||
|
229 | error('Could not get text from the clipboard.') | |||
|
230 | return | |||
|
231 | ||||
|
232 | # By default, echo back to terminal unless quiet mode is requested | |||
|
233 | if 'q' not in opts: | |||
|
234 | write = self.shell.write | |||
|
235 | write(self.shell.pycolorize(block)) | |||
|
236 | if not block.endswith('\n'): | |||
|
237 | write('\n') | |||
|
238 | write("## -- End pasted text --\n") | |||
|
239 | ||||
|
240 | store_or_execute(self.shell, block, name) | |||
|
241 | ||||
|
242 | ||||
|
243 | # Class-level: add a '%cls' magic only on Windows | |||
|
244 | if sys.platform == 'win32': | |||
|
245 | def magic_cls(self, s): | |||
|
246 | """Clear screen. | |||
|
247 | """ | |||
|
248 | os.system("cls") | |||
|
249 | ||||
123 | #----------------------------------------------------------------------------- |
|
250 | #----------------------------------------------------------------------------- | |
124 | # Main class |
|
251 | # Main class | |
125 | #----------------------------------------------------------------------------- |
|
252 | #----------------------------------------------------------------------------- | |
@@ -531,134 +658,21 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
531 | else: |
|
658 | else: | |
532 | self.ask_exit() |
|
659 | self.ask_exit() | |
533 |
|
660 | |||
534 | #------------------------------------------------------------------------ |
|
661 | #------------------------------------------------------------------------- | |
535 | # Magic overrides |
|
662 | # Things related to magics | |
536 | #------------------------------------------------------------------------ |
|
663 | #------------------------------------------------------------------------- | |
537 | # Once the base class stops inheriting from magic, this code needs to be |
|
|||
538 | # moved into a separate machinery as well. For now, at least isolate here |
|
|||
539 | # the magics which this class needs to implement differently from the base |
|
|||
540 | # class, or that are unique to it. |
|
|||
541 |
|
||||
542 | def magic_autoindent(self, parameter_s = ''): |
|
|||
543 | """Toggle autoindent on/off (if available).""" |
|
|||
544 |
|
||||
545 | self.shell.set_autoindent() |
|
|||
546 | print "Automatic indentation is:",['OFF','ON'][self.shell.autoindent] |
|
|||
547 |
|
||||
548 | @skip_doctest |
|
|||
549 | def magic_cpaste(self, parameter_s=''): |
|
|||
550 | """Paste & execute a pre-formatted code block from clipboard. |
|
|||
551 |
|
||||
552 | You must terminate the block with '--' (two minus-signs) or Ctrl-D |
|
|||
553 | alone on the line. You can also provide your own sentinel with '%paste |
|
|||
554 | -s %%' ('%%' is the new sentinel for this operation) |
|
|||
555 |
|
||||
556 | The block is dedented prior to execution to enable execution of method |
|
|||
557 | definitions. '>' and '+' characters at the beginning of a line are |
|
|||
558 | ignored, to allow pasting directly from e-mails, diff files and |
|
|||
559 | doctests (the '...' continuation prompt is also stripped). The |
|
|||
560 | executed block is also assigned to variable named 'pasted_block' for |
|
|||
561 | later editing with '%edit pasted_block'. |
|
|||
562 |
|
||||
563 | You can also pass a variable name as an argument, e.g. '%cpaste foo'. |
|
|||
564 | This assigns the pasted block to variable 'foo' as string, without |
|
|||
565 | dedenting or executing it (preceding >>> and + is still stripped) |
|
|||
566 |
|
||||
567 | '%cpaste -r' re-executes the block previously entered by cpaste. |
|
|||
568 |
|
||||
569 | Do not be alarmed by garbled output on Windows (it's a readline bug). |
|
|||
570 | Just press enter and type -- (and press enter again) and the block |
|
|||
571 | will be what was just pasted. |
|
|||
572 |
|
||||
573 | IPython statements (magics, shell escapes) are not supported (yet). |
|
|||
574 |
|
||||
575 | See also |
|
|||
576 | -------- |
|
|||
577 | paste: automatically pull code from clipboard. |
|
|||
578 |
|
||||
579 | Examples |
|
|||
580 | -------- |
|
|||
581 | :: |
|
|||
582 |
|
||||
583 | In [8]: %cpaste |
|
|||
584 | Pasting code; enter '--' alone on the line to stop. |
|
|||
585 | :>>> a = ["world!", "Hello"] |
|
|||
586 | :>>> print " ".join(sorted(a)) |
|
|||
587 | :-- |
|
|||
588 | Hello world! |
|
|||
589 | """ |
|
|||
590 |
|
||||
591 | opts, name = self.parse_options(parameter_s, 'rs:', mode='string') |
|
|||
592 | if 'r' in opts: |
|
|||
593 | rerun_pasted(self.shell) |
|
|||
594 | return |
|
|||
595 |
|
||||
596 | sentinel = opts.get('s', '--') |
|
|||
597 | block = strip_email_quotes(get_pasted_lines(sentinel)) |
|
|||
598 | store_or_execute(self.shell, block, name) |
|
|||
599 |
|
||||
600 | def magic_paste(self, parameter_s=''): |
|
|||
601 | """Paste & execute a pre-formatted code block from clipboard. |
|
|||
602 |
|
||||
603 | The text is pulled directly from the clipboard without user |
|
|||
604 | intervention and printed back on the screen before execution (unless |
|
|||
605 | the -q flag is given to force quiet mode). |
|
|||
606 |
|
||||
607 | The block is dedented prior to execution to enable execution of method |
|
|||
608 | definitions. '>' and '+' characters at the beginning of a line are |
|
|||
609 | ignored, to allow pasting directly from e-mails, diff files and |
|
|||
610 | doctests (the '...' continuation prompt is also stripped). The |
|
|||
611 | executed block is also assigned to variable named 'pasted_block' for |
|
|||
612 | later editing with '%edit pasted_block'. |
|
|||
613 |
|
||||
614 | You can also pass a variable name as an argument, e.g. '%paste foo'. |
|
|||
615 | This assigns the pasted block to variable 'foo' as string, without |
|
|||
616 | dedenting or executing it (preceding >>> and + is still stripped) |
|
|||
617 |
|
||||
618 | Options |
|
|||
619 | ------- |
|
|||
620 |
|
||||
621 | -r: re-executes the block previously entered by cpaste. |
|
|||
622 |
|
||||
623 | -q: quiet mode: do not echo the pasted text back to the terminal. |
|
|||
624 |
|
||||
625 | IPython statements (magics, shell escapes) are not supported (yet). |
|
|||
626 |
|
664 | |||
627 | See also |
|
665 | def init_magics(self): | |
628 | -------- |
|
666 | super(TerminalInteractiveShell, self).init_magics() | |
629 | cpaste: manually paste code into terminal until you mark its end. |
|
667 | self.define_magic('autoindent', magic_autoindent) | |
630 | """ |
|
668 | self.define_magic('cpaste', magic_cpaste) | |
631 | opts, name = self.parse_options(parameter_s, 'rq', mode='string') |
|
669 | self.define_magic('paste', magic_paste) | |
632 | if 'r' in opts: |
|
|||
633 | rerun_pasted(self.shell) |
|
|||
634 | return |
|
|||
635 | try: |
|
670 | try: | |
636 | text = self.shell.hooks.clipboard_get() |
|
671 | magic_cls | |
637 | block = strip_email_quotes(text.splitlines()) |
|
672 | except NameError: | |
638 | except TryNext as clipboard_exc: |
|
673 | pass | |
639 | message = getattr(clipboard_exc, 'args') |
|
674 | else: | |
640 | if message: |
|
675 | self.define_magic('cls', magic_cls) | |
641 | error(message[0]) |
|
|||
642 | else: |
|
|||
643 | error('Could not get text from the clipboard.') |
|
|||
644 | return |
|
|||
645 |
|
||||
646 | # By default, echo back to terminal unless quiet mode is requested |
|
|||
647 | if 'q' not in opts: |
|
|||
648 | write = self.shell.write |
|
|||
649 | write(self.shell.pycolorize(block)) |
|
|||
650 | if not block.endswith('\n'): |
|
|||
651 | write('\n') |
|
|||
652 | write("## -- End pasted text --\n") |
|
|||
653 |
|
||||
654 | store_or_execute(self.shell, block, name) |
|
|||
655 |
|
||||
656 | # Class-level: add a '%cls' magic only on Windows |
|
|||
657 | if sys.platform == 'win32': |
|
|||
658 | def magic_cls(self, s): |
|
|||
659 | """Clear screen. |
|
|||
660 | """ |
|
|||
661 | os.system("cls") |
|
|||
662 |
|
676 | |||
663 | def showindentationerror(self): |
|
677 | def showindentationerror(self): | |
664 | super(TerminalInteractiveShell, self).showindentationerror() |
|
678 | super(TerminalInteractiveShell, self).showindentationerror() |
@@ -815,7 +815,7 b' class DirectView(View):' | |||||
815 | else: |
|
815 | else: | |
816 | pmagic = ip.plugin_manager.get_plugin('parallelmagic') |
|
816 | pmagic = ip.plugin_manager.get_plugin('parallelmagic') | |
817 | if pmagic is None: |
|
817 | if pmagic is None: | |
818 |
ip.magic |
|
818 | ip.magic('load_ext parallelmagic') | |
819 | pmagic = ip.plugin_manager.get_plugin('parallelmagic') |
|
819 | pmagic = ip.plugin_manager.get_plugin('parallelmagic') | |
820 |
|
820 | |||
821 | pmagic.active_view = self |
|
821 | pmagic.active_view = self |
@@ -374,21 +374,21 b' class TestView(ClusterTestCase, ParametricTestCase):' | |||||
374 | v.activate() |
|
374 | v.activate() | |
375 | v.block=True |
|
375 | v.block=True | |
376 |
|
376 | |||
377 |
ip.magic |
|
377 | ip.magic('px a=5') | |
378 | self.assertEquals(v['a'], 5) |
|
378 | self.assertEquals(v['a'], 5) | |
379 |
ip.magic |
|
379 | ip.magic('px a=10') | |
380 | self.assertEquals(v['a'], 10) |
|
380 | self.assertEquals(v['a'], 10) | |
381 | sio = StringIO() |
|
381 | sio = StringIO() | |
382 | savestdout = sys.stdout |
|
382 | savestdout = sys.stdout | |
383 | sys.stdout = sio |
|
383 | sys.stdout = sio | |
384 | # just 'print a' worst ~99% of the time, but this ensures that |
|
384 | # just 'print a' worst ~99% of the time, but this ensures that | |
385 | # the stdout message has arrived when the result is finished: |
|
385 | # the stdout message has arrived when the result is finished: | |
386 |
ip.magic |
|
386 | ip.magic('px import sys,time;print (a); sys.stdout.flush();time.sleep(0.2)') | |
387 | sys.stdout = savestdout |
|
387 | sys.stdout = savestdout | |
388 | buf = sio.getvalue() |
|
388 | buf = sio.getvalue() | |
389 | self.assertTrue('[stdout:' in buf, buf) |
|
389 | self.assertTrue('[stdout:' in buf, buf) | |
390 | self.assertTrue(buf.rstrip().endswith('10')) |
|
390 | self.assertTrue(buf.rstrip().endswith('10')) | |
391 |
self.assertRaisesRemote(ZeroDivisionError, ip.magic |
|
391 | self.assertRaisesRemote(ZeroDivisionError, ip.magic, 'px 1/0') | |
392 |
|
392 | |||
393 | def test_magic_px_nonblocking(self): |
|
393 | def test_magic_px_nonblocking(self): | |
394 | ip = get_ipython() |
|
394 | ip = get_ipython() | |
@@ -396,18 +396,18 b' class TestView(ClusterTestCase, ParametricTestCase):' | |||||
396 | v.activate() |
|
396 | v.activate() | |
397 | v.block=False |
|
397 | v.block=False | |
398 |
|
398 | |||
399 |
ip.magic |
|
399 | ip.magic('px a=5') | |
400 | self.assertEquals(v['a'], 5) |
|
400 | self.assertEquals(v['a'], 5) | |
401 |
ip.magic |
|
401 | ip.magic('px a=10') | |
402 | self.assertEquals(v['a'], 10) |
|
402 | self.assertEquals(v['a'], 10) | |
403 | sio = StringIO() |
|
403 | sio = StringIO() | |
404 | savestdout = sys.stdout |
|
404 | savestdout = sys.stdout | |
405 | sys.stdout = sio |
|
405 | sys.stdout = sio | |
406 |
ip.magic |
|
406 | ip.magic('px print a') | |
407 | sys.stdout = savestdout |
|
407 | sys.stdout = savestdout | |
408 | buf = sio.getvalue() |
|
408 | buf = sio.getvalue() | |
409 | self.assertFalse('[stdout:%i]'%v.targets in buf) |
|
409 | self.assertFalse('[stdout:%i]'%v.targets in buf) | |
410 |
ip.magic |
|
410 | ip.magic('px 1/0') | |
411 | ar = v.get_result(-1) |
|
411 | ar = v.get_result(-1) | |
412 | self.assertRaisesRemote(ZeroDivisionError, ar.get) |
|
412 | self.assertRaisesRemote(ZeroDivisionError, ar.get) | |
413 |
|
413 | |||
@@ -420,12 +420,12 b' class TestView(ClusterTestCase, ParametricTestCase):' | |||||
420 | sio = StringIO() |
|
420 | sio = StringIO() | |
421 | savestdout = sys.stdout |
|
421 | savestdout = sys.stdout | |
422 | sys.stdout = sio |
|
422 | sys.stdout = sio | |
423 |
ip.magic |
|
423 | ip.magic('autopx') | |
424 | ip.run_cell('\n'.join(('a=5','b=10','c=0'))) |
|
424 | ip.run_cell('\n'.join(('a=5','b=10','c=0'))) | |
425 | ip.run_cell('b*=2') |
|
425 | ip.run_cell('b*=2') | |
426 | ip.run_cell('print (b)') |
|
426 | ip.run_cell('print (b)') | |
427 | ip.run_cell("b/c") |
|
427 | ip.run_cell("b/c") | |
428 |
ip.magic |
|
428 | ip.magic('autopx') | |
429 | sys.stdout = savestdout |
|
429 | sys.stdout = savestdout | |
430 | output = sio.getvalue().strip() |
|
430 | output = sio.getvalue().strip() | |
431 | self.assertTrue(output.startswith('%autopx enabled')) |
|
431 | self.assertTrue(output.startswith('%autopx enabled')) | |
@@ -445,13 +445,13 b' class TestView(ClusterTestCase, ParametricTestCase):' | |||||
445 | sio = StringIO() |
|
445 | sio = StringIO() | |
446 | savestdout = sys.stdout |
|
446 | savestdout = sys.stdout | |
447 | sys.stdout = sio |
|
447 | sys.stdout = sio | |
448 |
ip.magic |
|
448 | ip.magic('autopx') | |
449 | ip.run_cell('\n'.join(('a=5','b=10','c=0'))) |
|
449 | ip.run_cell('\n'.join(('a=5','b=10','c=0'))) | |
450 | ip.run_cell('print (b)') |
|
450 | ip.run_cell('print (b)') | |
451 | ip.run_cell('import time; time.sleep(0.1)') |
|
451 | ip.run_cell('import time; time.sleep(0.1)') | |
452 | ip.run_cell("b/c") |
|
452 | ip.run_cell("b/c") | |
453 | ip.run_cell('b*=2') |
|
453 | ip.run_cell('b*=2') | |
454 |
ip.magic |
|
454 | ip.magic('autopx') | |
455 | sys.stdout = savestdout |
|
455 | sys.stdout = savestdout | |
456 | output = sio.getvalue().strip() |
|
456 | output = sio.getvalue().strip() | |
457 | self.assertTrue(output.startswith('%autopx enabled')) |
|
457 | self.assertTrue(output.startswith('%autopx enabled')) | |
@@ -472,10 +472,10 b' class TestView(ClusterTestCase, ParametricTestCase):' | |||||
472 | v['a'] = 111 |
|
472 | v['a'] = 111 | |
473 | ra = v['a'] |
|
473 | ra = v['a'] | |
474 |
|
474 | |||
475 |
ar = ip.magic |
|
475 | ar = ip.magic('result') | |
476 | self.assertEquals(ar.msg_ids, [v.history[-1]]) |
|
476 | self.assertEquals(ar.msg_ids, [v.history[-1]]) | |
477 | self.assertEquals(ar.get(), 111) |
|
477 | self.assertEquals(ar.get(), 111) | |
478 |
ar = ip.magic |
|
478 | ar = ip.magic('result -2') | |
479 | self.assertEquals(ar.msg_ids, [v.history[-2]]) |
|
479 | self.assertEquals(ar.msg_ids, [v.history[-2]]) | |
480 |
|
480 | |||
481 | def test_unicode_execute(self): |
|
481 | def test_unicode_execute(self): |
General Comments 0
You need to be logged in to leave comments.
Login now