##// END OF EJS Templates
Various Python 3 fixes in IPython.utils
Thomas Kluyver -
Show More
@@ -16,6 +16,9 b' import sys'
16 16 import types
17 17 from datetime import datetime
18 18
19 from IPython.utils import py3compat
20 next_attr_name = '__next__' if py3compat.PY3 else 'next'
21
19 22 #-----------------------------------------------------------------------------
20 23 # Globals and constants
21 24 #-----------------------------------------------------------------------------
@@ -134,7 +137,7 b' def json_clean(obj):'
134 137 return obj.decode(sys.getdefaultencoding(), 'replace')
135 138
136 139 if isinstance(obj, container_to_list) or (
137 hasattr(obj, '__iter__') and hasattr(obj, 'next')):
140 hasattr(obj, '__iter__') and hasattr(obj, next_attr_name)):
138 141 obj = list(obj)
139 142
140 143 if isinstance(obj, list):
@@ -66,7 +66,7 b' def find_cmd(cmd):'
66 66 except OSError:
67 67 raise FindCmdError('command could not be found: %s' % cmd)
68 68 # which returns empty if not found
69 if path == '':
69 if path == b'':
70 70 raise FindCmdError('command could not be found: %s' % cmd)
71 71 return os.path.abspath(path)
72 72
@@ -31,18 +31,25 b' from IPython.testing import decorators as dec'
31 31 from IPython.testing.decorators import skip_if_not_win32, skip_win32
32 32 from IPython.testing.tools import make_tempfile
33 33 from IPython.utils import path, io
34 from IPython.utils import py3compat
34 35
35 36 # Platform-dependent imports
36 37 try:
37 38 import _winreg as wreg
38 39 except ImportError:
39 40 #Fake _winreg module on none windows platforms
40 import new
41 sys.modules["_winreg"] = new.module("_winreg")
41 import types
42 wr_name = "winreg" if py3compat.PY3 else "_winreg"
43 sys.modules[wr_name] = types.ModuleType(wr_name)
42 44 import _winreg as wreg
43 45 #Add entries that needs to be stubbed by the testing code
44 46 (wreg.OpenKey, wreg.QueryValueEx,) = (None, None)
45 47
48 try:
49 reload
50 except NameError: # Python 3
51 from imp import reload
52
46 53 #-----------------------------------------------------------------------------
47 54 # Globals
48 55 #-----------------------------------------------------------------------------
@@ -37,7 +37,7 b' def test_find_cmd_python():'
37 37 def test_find_cmd_ls():
38 38 """Make sure we can find the full path to ls."""
39 39 path = find_cmd('ls')
40 nt.assert_true(path.endswith('ls'))
40 nt.assert_true(path.endswith(b'ls'))
41 41
42 42
43 43 def has_pywin32():
@@ -587,10 +587,10 b' class EvalFormatter(Formatter):'
587 587 --------
588 588
589 589 In [1]: f = EvalFormatter()
590 In [2]: f.format('{n/4}', n=8)
590 In [2]: f.format('{n//4}', n=8)
591 591 Out[2]: '2'
592 592
593 In [3]: f.format('{range(3)}')
593 In [3]: f.format('{list(range(3))}')
594 594 Out[3]: '[0, 1, 2]'
595 595
596 596 In [4]: f.format('{3*2}')
@@ -882,7 +882,9 b' class CInt(Int):'
882 882 except:
883 883 self.error(obj, value)
884 884
885 if not py3compat.PY3:
885 if py3compat.PY3:
886 Long, CLong = Int, CInt
887 else:
886 888 class Long(TraitType):
887 889 """A long integer trait."""
888 890
General Comments 0
You need to be logged in to leave comments. Login now