From d341394495cadf18d60cbb5cc43e74d6e771ba46 2009-08-14 17:55:24 From: Brian Granger Date: 2009-08-14 17:55:24 Subject: [PATCH] Merging upstream changes. --- diff --git a/.hgignore b/.hgignore deleted file mode 100644 index ecc75a2..0000000 --- a/.hgignore +++ /dev/null @@ -1,18 +0,0 @@ -syntax: glob - -*~ -*.tmp -*.pyc -*.bak -*.tgz -*.org -*.rej -.svn/ -.bzr/ -.settings/ -.project -*.diff -IPython_crash_report.txt - -syntax: regexp -.*\#.*\#$ diff --git a/IPython/core/magic.py b/IPython/core/magic.py index 843954a..e6187e8 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -3370,7 +3370,8 @@ Defaulting color scheme to 'NoColor'""" """Allows you to paste & execute a pre-formatted code block from clipboard. The text is pulled directly from the clipboard without user - intervention. + intervention and printed back on the screen before execution (unless + the -q flag is given to force quiet mode). The block is dedented prior to execution to enable execution of method definitions. '>' and '+' characters at the beginning of a line are @@ -3382,8 +3383,13 @@ Defaulting color scheme to 'NoColor'""" You can also pass a variable name as an argument, e.g. '%paste foo'. This assigns the pasted block to variable 'foo' as string, without dedenting or executing it (preceding >>> and + is still stripped) + + Options + ------- - '%paste -r' re-executes the block previously entered by cpaste. + -r: re-executes the block previously entered by cpaste. + + -q: quiet mode: do not echo the pasted text back to the terminal. IPython statements (magics, shell escapes) are not supported (yet). @@ -3391,7 +3397,7 @@ Defaulting color scheme to 'NoColor'""" -------- cpaste: manually paste code into terminal until you mark its end. """ - opts,args = self.parse_options(parameter_s,'r:',mode='string') + opts,args = self.parse_options(parameter_s,'rq',mode='string') par = args.strip() if opts.has_key('r'): self._rerun_pasted() @@ -3399,6 +3405,15 @@ Defaulting color scheme to 'NoColor'""" text = self.shell.hooks.clipboard_get() block = self._strip_pasted_lines_for_code(text.splitlines()) + + # By default, echo back to terminal unless quiet mode is requested + if not opts.has_key('q'): + write = self.shell.write + write(block) + if not block.endswith('\n'): + write('\n') + write("## -- End pasted text --\n") + self._execute_block(block, par) def magic_quickref(self,arg): diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index 8644e4c..87da106 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -7,6 +7,7 @@ import os import sys import tempfile import types +from cStringIO import StringIO import nose.tools as nt @@ -261,9 +262,10 @@ class TestMagicRun(object): # Multiple tests for clipboard pasting def test_paste(): - def paste(txt): + def paste(txt, flags='-q'): + """Paste input text, by default in quiet mode""" hooks.clipboard_get = lambda : txt - _ip.magic('paste') + _ip.magic('paste '+flags) # Inject fake clipboard hook but save original so we can restore it later hooks = _ip.IP.hooks @@ -294,9 +296,31 @@ def test_paste(): """) yield (nt.assert_equal, user_ns['x'], [1,2,3]) yield (nt.assert_equal, user_ns['y'], [1,4,9]) - except: - pass - # This should be in a finally clause, instead of the bare except above. - # Restore original hook - hooks.clipboard_get = original_clip + # Now, test that paste -r works + user_ns.pop('x', None) + yield (nt.assert_false, 'x' in user_ns) + _ip.magic('paste -r') + yield (nt.assert_equal, user_ns['x'], [1,2,3]) + + # Also test paste echoing, by temporarily faking the writer + w = StringIO() + writer = _ip.IP.write + _ip.IP.write = w.write + code = """ + a = 100 + b = 200""" + try: + paste(code,'') + out = w.getvalue() + finally: + _ip.IP.write = writer + yield (nt.assert_equal, user_ns['a'], 100) + yield (nt.assert_equal, user_ns['b'], 200) + yield (nt.assert_equal, out, code+"\n## -- End pasted text --\n") + + finally: + # This should be in a finally clause, instead of the bare except above. + # Restore original hook + hooks.clipboard_get = original_clip + diff --git a/docs/source/changes.txt b/docs/source/changes.txt index 7f050a6..08da62c 100644 --- a/docs/source/changes.txt +++ b/docs/source/changes.txt @@ -12,6 +12,29 @@ What's new ========== +Development +=========== + +New features +------------ + +Bug fixes +--------- + +Backwards incompatible changes +------------------------------ + +* New top-level sub-packages have been created: :mod:`IPython.core`, + :mod:`IPython.lib`, :mod:`IPython.utils`, :mod:`IPython.deathrow`, + :mod:`IPython.quarantine`. All existing top-level modules have been + moved to appropriate sub-packages. All internal import statements + have been updated and tests have been added. The build system (setup.py + and friends) have been updated. +* Compatability modules have been created for :mod:`IPython.Shell`, + :mod:`IPython.ipapi` and :mod:`IPython.iplib` that display warnings + and then load the actual implementation from :mod:`IPython.core`. +* :mod:`Extensions` has been moved to :mod:`extensions`. + Release 0.10 ============ diff --git a/docs/source/development/reorg.txt b/docs/source/development/reorg.txt index 1233c52..298710b 100644 --- a/docs/source/development/reorg.txt +++ b/docs/source/development/reorg.txt @@ -1,6 +1,6 @@ ============================= IPython module reorganization -=============================' +============================= Currently, IPython has many top-level modules that serve many different purposes. The lack of organization make it very difficult for developers to