|
22 | 22 | import abc |
23 | 23 | import atexit |
24 | 24 | import codeop |
25 | | -import exceptions |
26 | | -import new |
27 | 25 | import os |
28 | 26 | import re |
29 | 27 | import string |
30 | 28 | import sys |
31 | 29 | import tempfile |
| 30 | +import types |
32 | 31 | from contextlib import nested |
33 | 32 |
|
34 | 33 | from IPython.config.configurable import Configurable |
@@ -102,7 +101,7 @@ def softspace(file, newvalue): |
102 | 101 |
|
103 | 102 | def no_op(*a, **kw): pass |
104 | 103 |
|
105 | | -class SpaceInInput(exceptions.Exception): pass |
| 104 | +class SpaceInInput(Exception): pass |
106 | 105 |
|
107 | 106 | class Bunch: pass |
108 | 107 |
|
@@ -512,7 +511,7 @@ def save_sys_module_state(self): |
512 | 511 | def restore_sys_module_state(self): |
513 | 512 | """Restore the state of the sys module.""" |
514 | 513 | try: |
515 | | - for k, v in self._orig_sys_module_state.items(): |
| 514 | + for k, v in self._orig_sys_module_state.iteritems(): |
516 | 515 | setattr(sys, k, v) |
517 | 516 | except AttributeError: |
518 | 517 | pass |
@@ -550,7 +549,7 @@ def set_hook(self,name,hook, priority = 50, str_key = None, re_key = None): |
550 | 549 | # accepts it. Probably at least check that the hook takes the number |
551 | 550 | # of args it's supposed to. |
552 | 551 |
|
553 | | - f = new.instancemethod(hook,self,self.__class__) |
| 552 | + f = types.MethodType(hook, self) |
554 | 553 |
|
555 | 554 | # check if the hook is for strdispatcher first |
556 | 555 | if str_key is not None: |
@@ -1249,7 +1248,7 @@ def init_history(self): |
1249 | 1248 | def init_shadow_hist(self): |
1250 | 1249 | try: |
1251 | 1250 | self.db = pickleshare.PickleShareDB(self.ipython_dir + "/db") |
1252 | | - except exceptions.UnicodeDecodeError: |
| 1251 | + except UnicodeDecodeError: |
1253 | 1252 | print "Your ipython_dir can't be decoded to unicode!" |
1254 | 1253 | print "Please set HOME environment variable to something that" |
1255 | 1254 | print r"only has ASCII characters, e.g. c:\home" |
@@ -1414,7 +1413,7 @@ def dummy_handler(self,etype,value,tb): |
1414 | 1413 |
|
1415 | 1414 | if handler is None: handler = dummy_handler |
1416 | 1415 |
|
1417 | | - self.CustomTB = new.instancemethod(handler,self,self.__class__) |
| 1416 | + self.CustomTB = types.MethodType(handler, self) |
1418 | 1417 | self.custom_exceptions = exc_tuple |
1419 | 1418 |
|
1420 | 1419 | def excepthook(self, etype, value, tb): |
@@ -1756,8 +1755,7 @@ def set_custom_completer(self, completer, pos=0): |
1756 | 1755 | The position argument (defaults to 0) is the index in the completers |
1757 | 1756 | list where you want the completer to be inserted.""" |
1758 | 1757 |
|
1759 | | - newcomp = new.instancemethod(completer,self.Completer, |
1760 | | - self.Completer.__class__) |
| 1758 | + newcomp = types.MethodType(completer, self.Completer) |
1761 | 1759 | self.Completer.matchers.insert(pos,newcomp) |
1762 | 1760 |
|
1763 | 1761 | def set_readline_completer(self): |
@@ -1828,12 +1826,11 @@ def foo_impl(self,parameter_s=''): |
1828 | 1826 | print 'Magic function. Passed parameter is between < >:' |
1829 | 1827 | print '<%s>' % parameter_s |
1830 | 1828 | print 'The self object is:',self |
1831 | | - |
| 1829 | + newcomp = types.MethodType(completer, self.Completer) |
1832 | 1830 | self.define_magic('foo',foo_impl) |
1833 | 1831 | """ |
1834 | 1832 |
|
1835 | | - import new |
1836 | | - im = new.instancemethod(func,self, self.__class__) |
| 1833 | + im = types.MethodType(func, self) |
1837 | 1834 | old = getattr(self, "magic_" + magicname, None) |
1838 | 1835 | setattr(self, "magic_" + magicname, im) |
1839 | 1836 | return old |
|
0 commit comments