diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index cbcb16c..e12af7e 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -22,13 +22,11 @@ import __future__ import abc import atexit import codeop -import exceptions -import new import os import re -import string import sys import tempfile +import types from contextlib import nested from IPython.config.configurable import Configurable @@ -104,7 +102,7 @@ def softspace(file, newvalue): def no_op(*a, **kw): pass -class SpaceInInput(exceptions.Exception): pass +class SpaceInInput(Exception): pass class Bunch: pass @@ -521,7 +519,7 @@ class InteractiveShell(Configurable, Magic): def restore_sys_module_state(self): """Restore the state of the sys module.""" try: - for k, v in self._orig_sys_module_state.items(): + for k, v in self._orig_sys_module_state.iteritems(): setattr(sys, k, v) except AttributeError: pass @@ -559,7 +557,7 @@ class InteractiveShell(Configurable, Magic): # accepts it. Probably at least check that the hook takes the number # of args it's supposed to. - f = new.instancemethod(hook,self,self.__class__) + f = types.MethodType(hook,self) # check if the hook is for strdispatcher first if str_key is not None: @@ -1313,7 +1311,7 @@ class InteractiveShell(Configurable, Magic): # The return value must be return structured_traceback - This will be made into an instance method (via new.instancemethod) + This will be made into an instance method (via types.MethodType) of IPython itself, and it will be called if any of the exceptions listed in the exc_tuple are caught. If the handler is None, an internal basic one is used, which just prints basic info. @@ -1334,7 +1332,7 @@ class InteractiveShell(Configurable, Magic): if handler is None: handler = dummy_handler - self.CustomTB = new.instancemethod(handler,self,self.__class__) + self.CustomTB = types.MethodType(handler,self) self.custom_exceptions = exc_tuple def excepthook(self, etype, value, tb): @@ -1538,8 +1536,7 @@ class InteractiveShell(Configurable, Magic): # Remove some chars from the delimiters list. If we encounter # unicode chars, discard them. delims = readline.get_completer_delims().encode("ascii", "ignore") - delims = delims.translate(string._idmap, - self.readline_remove_delims) + delims = delims.translate(None, self.readline_remove_delims) delims = delims.replace(ESC_MAGIC, '') readline.set_completer_delims(delims) # otherwise we end up with a monster history after a while: @@ -1676,8 +1673,7 @@ class InteractiveShell(Configurable, Magic): The position argument (defaults to 0) is the index in the completers list where you want the completer to be inserted.""" - newcomp = new.instancemethod(completer,self.Completer, - self.Completer.__class__) + newcomp = types.MethodType(completer,self.Completer) self.Completer.matchers.insert(pos,newcomp) def set_readline_completer(self): @@ -1753,7 +1749,7 @@ class InteractiveShell(Configurable, Magic): """ import new - im = new.instancemethod(func,self, self.__class__) + im = types.MethodType(func,self) old = getattr(self, "magic_" + magicname, None) setattr(self, "magic_" + magicname, im) return old @@ -2112,8 +2108,7 @@ class InteractiveShell(Configurable, Magic): list.append(self, val) import new - self.input_hist.append = new.instancemethod(myapp, self.input_hist, - list) + self.input_hist.append = types.MethodType(myapp, self.input_hist) # End dbg # All user code execution must happen with our context managers active diff --git a/IPython/core/oinspect.py b/IPython/core/oinspect.py index 7dd59de..243e941 100644 --- a/IPython/core/oinspect.py +++ b/IPython/core/oinspect.py @@ -22,7 +22,6 @@ import StringIO import inspect import linecache import os -import string import sys import types from collections import namedtuple @@ -450,7 +449,7 @@ class Inspector: if not detail_level and len(ostr)>string_max: ostr = ostr[:shalf] + ' <...> ' + ostr[-shalf:] ostr = ("\n" + " " * len(str_head.expandtabs())).\ - join(map(string.strip,ostr.split("\n"))) + join(q.strip() for q in ostr.split("\n")) if ostr.find('\n') > -1: # Print multi-line strings starting at the next line. str_sep = '\n' @@ -675,7 +674,7 @@ class Inspector: if not detail_level and len(ostr)>string_max: ostr = ostr[:shalf] + ' <...> ' + ostr[-shalf:] ostr = ("\n" + " " * len(str_head.expandtabs())).\ - join(map(string.strip,ostr.split("\n"))) + join(q.strip() for q in ostr.split("\n")) if ostr.find('\n') > -1: # Print multi-line strings starting at the next line. str_sep = '\n' diff --git a/IPython/core/ultratb.py b/IPython/core/ultratb.py index cfb7b2b..3652313 100644 --- a/IPython/core/ultratb.py +++ b/IPython/core/ultratb.py @@ -77,7 +77,6 @@ import linecache import os import pydoc import re -import string import sys import time import tokenize @@ -719,7 +718,7 @@ class VerboseTB(TBTools): if self.long_header: # Header with the exception type, python version, and date - pyver = 'Python ' + string.split(sys.version)[0] + ': ' + sys.executable + pyver = 'Python ' + sys.version.split()[0] + ': ' + sys.executable date = time.ctime(time.time()) head = '%s%s%s\n%s%s%s\n%s' % (Colors.topline, '-'*75, ColorsNormal, diff --git a/IPython/external/Itpl.py b/IPython/external/Itpl.py index ea98172..671e9ab 100644 --- a/IPython/external/Itpl.py +++ b/IPython/external/Itpl.py @@ -75,7 +75,6 @@ each time the instance is evaluated with str(instance). For example: __author__ = 'Ka-Ping Yee ' __license__ = 'MIT' -import string import sys from tokenize import tokenprog diff --git a/IPython/external/pexpect.py b/IPython/external/pexpect.py index 260c1d8..b2c0fe8 100644 --- a/IPython/external/pexpect.py +++ b/IPython/external/pexpect.py @@ -66,7 +66,6 @@ $Id: pexpect.py 507 2007-12-27 02:40:52Z noah $ try: import os, sys, time import select - import string import re import struct import resource @@ -1778,8 +1777,7 @@ def which (filename): # Oddly enough this was the one line that made Pexpect # incompatible with Python 1.5.2. - #pathlist = p.split (os.pathsep) - pathlist = string.split (p, os.pathsep) + pathlist = p.split(os.pathsep) for path in pathlist: f = os.path.join(path, filename)