Show More
@@ -3369,7 +3369,8 b' Defaulting color scheme to \'NoColor\'"""' | |||||
3369 | """Allows you to paste & execute a pre-formatted code block from clipboard. |
|
3369 | """Allows you to paste & execute a pre-formatted code block from clipboard. | |
3370 |
|
3370 | |||
3371 | The text is pulled directly from the clipboard without user |
|
3371 | The text is pulled directly from the clipboard without user | |
3372 | intervention. |
|
3372 | intervention and printed back on the screen before execution (unless | |
|
3373 | the -q flag is given to force quiet mode). | |||
3373 |
|
3374 | |||
3374 | The block is dedented prior to execution to enable execution of method |
|
3375 | The block is dedented prior to execution to enable execution of method | |
3375 | definitions. '>' and '+' characters at the beginning of a line are |
|
3376 | definitions. '>' and '+' characters at the beginning of a line are | |
@@ -3387,7 +3388,7 b' Defaulting color scheme to \'NoColor\'"""' | |||||
3387 |
|
3388 | |||
3388 | -r: re-executes the block previously entered by cpaste. |
|
3389 | -r: re-executes the block previously entered by cpaste. | |
3389 |
|
3390 | |||
3390 | -e: echo the pasted text back to the terminal. |
|
3391 | -q: quiet mode: do not echo the pasted text back to the terminal. | |
3391 |
|
3392 | |||
3392 | IPython statements (magics, shell escapes) are not supported (yet). |
|
3393 | IPython statements (magics, shell escapes) are not supported (yet). | |
3393 |
|
3394 | |||
@@ -3395,7 +3396,7 b' Defaulting color scheme to \'NoColor\'"""' | |||||
3395 | -------- |
|
3396 | -------- | |
3396 | cpaste: manually paste code into terminal until you mark its end. |
|
3397 | cpaste: manually paste code into terminal until you mark its end. | |
3397 | """ |
|
3398 | """ | |
3398 |
opts,args = self.parse_options(parameter_s,'r |
|
3399 | opts,args = self.parse_options(parameter_s,'rq',mode='string') | |
3399 | par = args.strip() |
|
3400 | par = args.strip() | |
3400 | if opts.has_key('r'): |
|
3401 | if opts.has_key('r'): | |
3401 | self._rerun_pasted() |
|
3402 | self._rerun_pasted() | |
@@ -3404,8 +3405,8 b' Defaulting color scheme to \'NoColor\'"""' | |||||
3404 | text = self.shell.hooks.clipboard_get() |
|
3405 | text = self.shell.hooks.clipboard_get() | |
3405 | block = self._strip_pasted_lines_for_code(text.splitlines()) |
|
3406 | block = self._strip_pasted_lines_for_code(text.splitlines()) | |
3406 |
|
3407 | |||
3407 | if opts.has_key('e'): |
|
3408 | # By default, echo back to terminal unless quiet mode is requested | |
3408 | # Echo back to terminal. |
|
3409 | if not opts.has_key('q'): | |
3409 | write = self.shell.write |
|
3410 | write = self.shell.write | |
3410 | write(block) |
|
3411 | write(block) | |
3411 | if not block.endswith('\n'): |
|
3412 | if not block.endswith('\n'): |
@@ -262,7 +262,8 b' class TestMagicRun(object):' | |||||
262 | # Multiple tests for clipboard pasting |
|
262 | # Multiple tests for clipboard pasting | |
263 | def test_paste(): |
|
263 | def test_paste(): | |
264 |
|
264 | |||
265 | def paste(txt, flags=''): |
|
265 | def paste(txt, flags='-q'): | |
|
266 | """Paste input text, by default in quiet mode""" | |||
266 | hooks.clipboard_get = lambda : txt |
|
267 | hooks.clipboard_get = lambda : txt | |
267 | _ip.magic('paste '+flags) |
|
268 | _ip.magic('paste '+flags) | |
268 |
|
269 | |||
@@ -302,7 +303,7 b' def test_paste():' | |||||
302 | _ip.magic('paste -r') |
|
303 | _ip.magic('paste -r') | |
303 | yield (nt.assert_equal, user_ns['x'], [1,2,3]) |
|
304 | yield (nt.assert_equal, user_ns['x'], [1,2,3]) | |
304 |
|
305 | |||
305 |
# Also test paste |
|
306 | # Also test paste echoing, by temporarily faking the writer | |
306 | w = StringIO() |
|
307 | w = StringIO() | |
307 | writer = _ip.IP.write |
|
308 | writer = _ip.IP.write | |
308 | _ip.IP.write = w.write |
|
309 | _ip.IP.write = w.write | |
@@ -310,7 +311,7 b' def test_paste():' | |||||
310 | a = 100 |
|
311 | a = 100 | |
311 | b = 200""" |
|
312 | b = 200""" | |
312 | try: |
|
313 | try: | |
313 |
paste(code,' |
|
314 | paste(code,'') | |
314 | out = w.getvalue() |
|
315 | out = w.getvalue() | |
315 | finally: |
|
316 | finally: | |
316 | _ip.IP.write = writer |
|
317 | _ip.IP.write = writer |
General Comments 0
You need to be logged in to leave comments.
Login now