Show More
@@ -3370,7 +3370,8 b' Defaulting color scheme to \'NoColor\'"""' | |||||
3370 | """Allows you to paste & execute a pre-formatted code block from clipboard. |
|
3370 | """Allows you to paste & execute a pre-formatted code block from clipboard. | |
3371 |
|
3371 | |||
3372 | The text is pulled directly from the clipboard without user |
|
3372 | The text is pulled directly from the clipboard without user | |
3373 | intervention. |
|
3373 | intervention and printed back on the screen before execution (unless | |
|
3374 | the -q flag is given to force quiet mode). | |||
3374 |
|
3375 | |||
3375 | The block is dedented prior to execution to enable execution of method |
|
3376 | The block is dedented prior to execution to enable execution of method | |
3376 | definitions. '>' and '+' characters at the beginning of a line are |
|
3377 | definitions. '>' and '+' characters at the beginning of a line are | |
@@ -3382,8 +3383,13 b' Defaulting color scheme to \'NoColor\'"""' | |||||
3382 | You can also pass a variable name as an argument, e.g. '%paste foo'. |
|
3383 | You can also pass a variable name as an argument, e.g. '%paste foo'. | |
3383 | This assigns the pasted block to variable 'foo' as string, without |
|
3384 | This assigns the pasted block to variable 'foo' as string, without | |
3384 | dedenting or executing it (preceding >>> and + is still stripped) |
|
3385 | dedenting or executing it (preceding >>> and + is still stripped) | |
|
3386 | ||||
|
3387 | Options | |||
|
3388 | ------- | |||
3385 |
|
3389 | |||
3386 |
|
|
3390 | -r: re-executes the block previously entered by cpaste. | |
|
3391 | ||||
|
3392 | -q: quiet mode: do not echo the pasted text back to the terminal. | |||
3387 |
|
3393 | |||
3388 | IPython statements (magics, shell escapes) are not supported (yet). |
|
3394 | IPython statements (magics, shell escapes) are not supported (yet). | |
3389 |
|
3395 | |||
@@ -3391,7 +3397,7 b' Defaulting color scheme to \'NoColor\'"""' | |||||
3391 | -------- |
|
3397 | -------- | |
3392 | cpaste: manually paste code into terminal until you mark its end. |
|
3398 | cpaste: manually paste code into terminal until you mark its end. | |
3393 | """ |
|
3399 | """ | |
3394 |
opts,args = self.parse_options(parameter_s,'r |
|
3400 | opts,args = self.parse_options(parameter_s,'rq',mode='string') | |
3395 | par = args.strip() |
|
3401 | par = args.strip() | |
3396 | if opts.has_key('r'): |
|
3402 | if opts.has_key('r'): | |
3397 | self._rerun_pasted() |
|
3403 | self._rerun_pasted() | |
@@ -3399,6 +3405,15 b' Defaulting color scheme to \'NoColor\'"""' | |||||
3399 |
|
3405 | |||
3400 | text = self.shell.hooks.clipboard_get() |
|
3406 | text = self.shell.hooks.clipboard_get() | |
3401 | block = self._strip_pasted_lines_for_code(text.splitlines()) |
|
3407 | block = self._strip_pasted_lines_for_code(text.splitlines()) | |
|
3408 | ||||
|
3409 | # By default, echo back to terminal unless quiet mode is requested | |||
|
3410 | if not opts.has_key('q'): | |||
|
3411 | write = self.shell.write | |||
|
3412 | write(block) | |||
|
3413 | if not block.endswith('\n'): | |||
|
3414 | write('\n') | |||
|
3415 | write("## -- End pasted text --\n") | |||
|
3416 | ||||
3402 | self._execute_block(block, par) |
|
3417 | self._execute_block(block, par) | |
3403 |
|
3418 | |||
3404 | def magic_quickref(self,arg): |
|
3419 | def magic_quickref(self,arg): |
@@ -7,6 +7,7 b' import os' | |||||
7 | import sys |
|
7 | import sys | |
8 | import tempfile |
|
8 | import tempfile | |
9 | import types |
|
9 | import types | |
|
10 | from cStringIO import StringIO | |||
10 |
|
11 | |||
11 | import nose.tools as nt |
|
12 | import nose.tools as nt | |
12 |
|
13 | |||
@@ -261,9 +262,10 b' class TestMagicRun(object):' | |||||
261 | # Multiple tests for clipboard pasting |
|
262 | # Multiple tests for clipboard pasting | |
262 | def test_paste(): |
|
263 | def test_paste(): | |
263 |
|
264 | |||
264 | def paste(txt): |
|
265 | def paste(txt, flags='-q'): | |
|
266 | """Paste input text, by default in quiet mode""" | |||
265 | hooks.clipboard_get = lambda : txt |
|
267 | hooks.clipboard_get = lambda : txt | |
266 | _ip.magic('paste') |
|
268 | _ip.magic('paste '+flags) | |
267 |
|
269 | |||
268 | # Inject fake clipboard hook but save original so we can restore it later |
|
270 | # Inject fake clipboard hook but save original so we can restore it later | |
269 | hooks = _ip.IP.hooks |
|
271 | hooks = _ip.IP.hooks | |
@@ -294,9 +296,31 b' def test_paste():' | |||||
294 | """) |
|
296 | """) | |
295 | yield (nt.assert_equal, user_ns['x'], [1,2,3]) |
|
297 | yield (nt.assert_equal, user_ns['x'], [1,2,3]) | |
296 | yield (nt.assert_equal, user_ns['y'], [1,4,9]) |
|
298 | yield (nt.assert_equal, user_ns['y'], [1,4,9]) | |
297 | except: |
|
|||
298 | pass |
|
|||
299 |
|
299 | |||
300 | # This should be in a finally clause, instead of the bare except above. |
|
300 | # Now, test that paste -r works | |
301 | # Restore original hook |
|
301 | user_ns.pop('x', None) | |
302 | hooks.clipboard_get = original_clip |
|
302 | yield (nt.assert_false, 'x' in user_ns) | |
|
303 | _ip.magic('paste -r') | |||
|
304 | yield (nt.assert_equal, user_ns['x'], [1,2,3]) | |||
|
305 | ||||
|
306 | # Also test paste echoing, by temporarily faking the writer | |||
|
307 | w = StringIO() | |||
|
308 | writer = _ip.IP.write | |||
|
309 | _ip.IP.write = w.write | |||
|
310 | code = """ | |||
|
311 | a = 100 | |||
|
312 | b = 200""" | |||
|
313 | try: | |||
|
314 | paste(code,'') | |||
|
315 | out = w.getvalue() | |||
|
316 | finally: | |||
|
317 | _ip.IP.write = writer | |||
|
318 | yield (nt.assert_equal, user_ns['a'], 100) | |||
|
319 | yield (nt.assert_equal, user_ns['b'], 200) | |||
|
320 | yield (nt.assert_equal, out, code+"\n## -- End pasted text --\n") | |||
|
321 | ||||
|
322 | finally: | |||
|
323 | # This should be in a finally clause, instead of the bare except above. | |||
|
324 | # Restore original hook | |||
|
325 | hooks.clipboard_get = original_clip | |||
|
326 |
@@ -12,6 +12,29 b'' | |||||
12 | What's new |
|
12 | What's new | |
13 | ========== |
|
13 | ========== | |
14 |
|
14 | |||
|
15 | Development | |||
|
16 | =========== | |||
|
17 | ||||
|
18 | New features | |||
|
19 | ------------ | |||
|
20 | ||||
|
21 | Bug fixes | |||
|
22 | --------- | |||
|
23 | ||||
|
24 | Backwards incompatible changes | |||
|
25 | ------------------------------ | |||
|
26 | ||||
|
27 | * New top-level sub-packages have been created: :mod:`IPython.core`, | |||
|
28 | :mod:`IPython.lib`, :mod:`IPython.utils`, :mod:`IPython.deathrow`, | |||
|
29 | :mod:`IPython.quarantine`. All existing top-level modules have been | |||
|
30 | moved to appropriate sub-packages. All internal import statements | |||
|
31 | have been updated and tests have been added. The build system (setup.py | |||
|
32 | and friends) have been updated. | |||
|
33 | * Compatability modules have been created for :mod:`IPython.Shell`, | |||
|
34 | :mod:`IPython.ipapi` and :mod:`IPython.iplib` that display warnings | |||
|
35 | and then load the actual implementation from :mod:`IPython.core`. | |||
|
36 | * :mod:`Extensions` has been moved to :mod:`extensions`. | |||
|
37 | ||||
15 | Release 0.10 |
|
38 | Release 0.10 | |
16 | ============ |
|
39 | ============ | |
17 |
|
40 |
@@ -1,6 +1,6 b'' | |||||
1 | ============================= |
|
1 | ============================= | |
2 | IPython module reorganization |
|
2 | IPython module reorganization | |
3 |
============================= |
|
3 | ============================= | |
4 |
|
4 | |||
5 | Currently, IPython has many top-level modules that serve many different |
|
5 | Currently, IPython has many top-level modules that serve many different | |
6 | purposes. The lack of organization make it very difficult for developers to |
|
6 | purposes. The lack of organization make it very difficult for developers to |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now