##// END OF EJS Templates
Merge pull request #6184 from takluyver/rm-py3compat-open...
Min RK -
r17304:ecdfa090 merge
parent child Browse files
Show More
@@ -0,0 +1,2 b''
1 * ``IPython.utils.py3compat.open`` was removed: :func:`io.open` provides all
2 the same functionality.
@@ -6,6 +6,7 b''
6 #-----------------------------------------------------------------------------
6 #-----------------------------------------------------------------------------
7
7
8 # stdlib
8 # stdlib
9 import io
9 import os
10 import os
10 import sys
11 import sys
11 import tempfile
12 import tempfile
@@ -124,7 +125,7 b' def test_history():'
124 # Cross testing: check that magic %save can get previous session.
125 # Cross testing: check that magic %save can get previous session.
125 testfilename = os.path.realpath(os.path.join(tmpdir, "test.py"))
126 testfilename = os.path.realpath(os.path.join(tmpdir, "test.py"))
126 ip.magic("save " + testfilename + " ~1/1-3")
127 ip.magic("save " + testfilename + " ~1/1-3")
127 with py3compat.open(testfilename, encoding='utf-8') as testfile:
128 with io.open(testfilename, encoding='utf-8') as testfile:
128 nt.assert_equal(testfile.read(),
129 nt.assert_equal(testfile.read(),
129 u"# coding: utf-8\n" + u"\n".join(hist)+u"\n")
130 u"# coding: utf-8\n" + u"\n".join(hist)+u"\n")
130
131
@@ -8,8 +8,6 b' import types'
8
8
9 from .encoding import DEFAULT_ENCODING
9 from .encoding import DEFAULT_ENCODING
10
10
11 orig_open = open
12
13 def no_code(x, encoding=None):
11 def no_code(x, encoding=None):
14 return x
12 return x
15
13
@@ -96,8 +94,7 b' if sys.version_info[0] >= 3:'
96 if dotted:
94 if dotted:
97 return all(isidentifier(a) for a in s.split("."))
95 return all(isidentifier(a) for a in s.split("."))
98 return s.isidentifier()
96 return s.isidentifier()
99
97
100 open = orig_open
101 xrange = range
98 xrange = range
102 def iteritems(d): return iter(d.items())
99 def iteritems(d): return iter(d.items())
103 def itervalues(d): return iter(d.values())
100 def itervalues(d): return iter(d.values())
@@ -164,27 +161,6 b' else:'
164 return all(isidentifier(a) for a in s.split("."))
161 return all(isidentifier(a) for a in s.split("."))
165 return bool(_name_re.match(s))
162 return bool(_name_re.match(s))
166
163
167 class open(object):
168 """Wrapper providing key part of Python 3 open() interface."""
169 def __init__(self, fname, mode="r", encoding="utf-8"):
170 self.f = orig_open(fname, mode)
171 self.enc = encoding
172
173 def write(self, s):
174 return self.f.write(s.encode(self.enc))
175
176 def read(self, size=-1):
177 return self.f.read(size).decode(self.enc)
178
179 def close(self):
180 return self.f.close()
181
182 def __enter__(self):
183 return self
184
185 def __exit__(self, etype, value, traceback):
186 self.f.close()
187
188 xrange = xrange
164 xrange = xrange
189 def iteritems(d): return d.iteritems()
165 def iteritems(d): return d.iteritems()
190 def itervalues(d): return d.itervalues()
166 def itervalues(d): return d.itervalues()
@@ -34,7 +34,7 b" if __name__ == '__main__':"
34 # This just prints a deprecation msg:
34 # This just prints a deprecation msg:
35 r'\.frontend$',
35 r'\.frontend$',
36 # Deprecated:
36 # Deprecated:
37 r'\.core\.magics\.deprecated'
37 r'\.core\.magics\.deprecated',
38 # We document this manually.
38 # We document this manually.
39 r'\.utils\.py3compat',
39 r'\.utils\.py3compat',
40 # These are exposed by nbformat.current
40 # These are exposed by nbformat.current
@@ -43,6 +43,8 b" if __name__ == '__main__':"
43 # These are exposed in display
43 # These are exposed in display
44 r'\.core\.display',
44 r'\.core\.display',
45 r'\.lib\.display',
45 r'\.lib\.display',
46 # This isn't actually a module
47 r'\.html\.fabfile',
46 ]
48 ]
47
49
48 # These modules import functions and classes from other places to expose
50 # These modules import functions and classes from other places to expose
General Comments 0
You need to be logged in to leave comments. Login now