diff --git a/IPython/terminal/console/interactiveshell.py b/IPython/terminal/console/interactiveshell.py index bd135cf..70559e9 100644 --- a/IPython/terminal/console/interactiveshell.py +++ b/IPython/terminal/console/interactiveshell.py @@ -25,11 +25,6 @@ import base64 from Queue import Empty -try: - from contextlib import nested -except: - from IPython.utils.nested_context import nested - from IPython.core import page from IPython.utils.warn import warn, error from IPython.utils import io @@ -303,8 +298,8 @@ class ZMQTerminalInteractiveShell(TerminalInteractiveShell): raw = base64.decodestring(data[mime].encode('ascii')) imageformat = self._imagemime[mime] filename = 'tmp.{0}'.format(imageformat) - with nested(NamedFileInTemporaryDirectory(filename), - open(os.devnull, 'w')) as (f, devnull): + with NamedFileInTemporaryDirectory(filename) as f, \ + open(os.devnull, 'w') as devnull: f.write(raw) f.flush() fmt = dict(file=f.name, format=imageformat) diff --git a/IPython/terminal/embed.py b/IPython/terminal/embed.py index ed0becb..2a956b0 100644 --- a/IPython/terminal/embed.py +++ b/IPython/terminal/embed.py @@ -27,13 +27,6 @@ from __future__ import with_statement import sys import warnings -# We need to use nested to support python 2.6, once we move to >=2.7, we can -# use the with keyword's new builtin support for nested managers -try: - from contextlib import nested -except: - from IPython.utils.nested_context import nested - from IPython.core import ultratb, compilerop from IPython.core.magic import Magics, magics_class, line_magic from IPython.terminal.interactiveshell import TerminalInteractiveShell @@ -251,7 +244,7 @@ class InteractiveShellEmbed(TerminalInteractiveShell): # actually completes using the frame's locals/globals self.set_completer_frame() - with nested(self.builtin_trap, self.display_trap): + with self.builtin_trap, self.display_trap: self.interact(display_banner=display_banner) # now, purge out the local namespace of IPython's hidden variables. diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py index 32a6c17..3a7c93a 100644 --- a/IPython/terminal/interactiveshell.py +++ b/IPython/terminal/interactiveshell.py @@ -19,13 +19,6 @@ import bdb import os import sys -# We need to use nested to support python 2.6, once we move to >=2.7, we can -# use the with keyword's new builtin support for nested managers -try: - from contextlib import nested -except: - from IPython.utils.nested_context import nested - from IPython.core.error import TryNext, UsageError from IPython.core.usage import interactive_usage, default_banner from IPython.core.inputsplitter import IPythonInputSplitter @@ -429,7 +422,7 @@ class TerminalInteractiveShell(InteractiveShell): internally created default banner. """ - with nested(self.builtin_trap, self.display_trap): + with self.builtin_trap, self.display_trap: while 1: try: diff --git a/IPython/utils/nested_context.py b/IPython/utils/nested_context.py deleted file mode 100644 index 46cbafb..0000000 --- a/IPython/utils/nested_context.py +++ /dev/null @@ -1,50 +0,0 @@ -"""Backwards compatibility - we use contextlib.nested to support Python 2.6, -but it's removed in Python 3.2.""" - -# TODO : Remove this once we drop support for Python 2.6, and use -# "with a, b:" instead. - -import sys - -from contextlib import contextmanager - -@contextmanager -def nested(*managers): - """Combine multiple context managers into a single nested context manager. - - This function has been deprecated in favour of the multiple manager form - of the with statement. - - The one advantage of this function over the multiple manager form of the - with statement is that argument unpacking allows it to be - used with a variable number of context managers as follows:: - - with nested(*managers): - do_something() - - """ - exits = [] - vars = [] - exc = (None, None, None) - try: - for mgr in managers: - exit = mgr.__exit__ - enter = mgr.__enter__ - vars.append(enter()) - exits.append(exit) - yield vars - except: - exc = sys.exc_info() - finally: - while exits: - exit = exits.pop() - try: - if exit(*exc): - exc = (None, None, None) - except: - exc = sys.exc_info() - if exc != (None, None, None): - # Don't rely on sys.exc_info() still containing - # the right information. Another exception may - # have been raised and caught by an exit method - raise exc[0], exc[1], exc[2]