Skip to content

Commit

Permalink
Merge branch 'cleanup-old-code' of http://github.com/takowl/ipython i…
Browse files Browse the repository at this point in the history
…nto takowl-cleanup-old-code

Various cleanups of old and deprecated modules, this helps keep the
code tidier for the py3k branch and future migration.

Closes ipythongh-180 (pull request).
  • Loading branch information
fperez committed Oct 22, 2010
2 parents e6c4eee + 808eea8 commit 59ccc83
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 24 deletions.
25 changes: 10 additions & 15 deletions IPython/core/interactiveshell.py
Expand Up @@ -22,13 +22,11 @@
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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -521,7 +519,7 @@ def save_sys_module_state(self):
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
Expand Down Expand Up @@ -559,7 +557,7 @@ def set_hook(self,name,hook, priority = 50, str_key = None, re_key = None):
# 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:
Expand Down Expand Up @@ -1313,7 +1311,7 @@ def my_handler(self, etype, value, tb, tb_offset=None)
# 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.
Expand All @@ -1334,7 +1332,7 @@ def dummy_handler(self,etype,value,tb):

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):
Expand Down Expand Up @@ -1538,8 +1536,7 @@ def init_readline(self):
# 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:
Expand Down Expand Up @@ -1676,8 +1673,7 @@ def set_custom_completer(self, completer, pos=0):
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):
Expand Down Expand Up @@ -1753,7 +1749,7 @@ def foo_impl(self,parameter_s=''):
"""

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
Expand Down Expand Up @@ -2112,8 +2108,7 @@ def myapp(self, val): # dbg
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
Expand Down
5 changes: 2 additions & 3 deletions IPython/core/oinspect.py
Expand Up @@ -22,7 +22,6 @@
import inspect
import linecache
import os
import string
import sys
import types
from collections import namedtuple
Expand Down Expand Up @@ -450,7 +449,7 @@ def pinfo(self,obj,oname='',formatter=None,info=None,detail_level=0):
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'
Expand Down Expand Up @@ -675,7 +674,7 @@ def info(self, obj, oname='', formatter=None, info=None, detail_level=0):
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'
Expand Down
3 changes: 1 addition & 2 deletions IPython/core/ultratb.py
Expand Up @@ -77,7 +77,6 @@
import os
import pydoc
import re
import string
import sys
import time
import tokenize
Expand Down Expand Up @@ -719,7 +718,7 @@ def nullrepr(value, repr=text_repr): return ''

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,
Expand Down
1 change: 0 additions & 1 deletion IPython/external/Itpl.py
Expand Up @@ -75,7 +75,6 @@
__author__ = 'Ka-Ping Yee <ping@lfw.org>'
__license__ = 'MIT'

import string
import sys
from tokenize import tokenprog

Expand Down
4 changes: 1 addition & 3 deletions IPython/external/pexpect.py
Expand Up @@ -66,7 +66,6 @@
try:
import os, sys, time
import select
import string
import re
import struct
import resource
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 59ccc83

Please sign in to comment.