##// 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 8 # stdlib
9 import io
9 10 import os
10 11 import sys
11 12 import tempfile
@@ -124,7 +125,7 b' def test_history():'
124 125 # Cross testing: check that magic %save can get previous session.
125 126 testfilename = os.path.realpath(os.path.join(tmpdir, "test.py"))
126 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 129 nt.assert_equal(testfile.read(),
129 130 u"# coding: utf-8\n" + u"\n".join(hist)+u"\n")
130 131
@@ -8,8 +8,6 b' import types'
8 8
9 9 from .encoding import DEFAULT_ENCODING
10 10
11 orig_open = open
12
13 11 def no_code(x, encoding=None):
14 12 return x
15 13
@@ -97,7 +95,6 b' if sys.version_info[0] >= 3:'
97 95 return all(isidentifier(a) for a in s.split("."))
98 96 return s.isidentifier()
99 97
100 open = orig_open
101 98 xrange = range
102 99 def iteritems(d): return iter(d.items())
103 100 def itervalues(d): return iter(d.values())
@@ -164,27 +161,6 b' else:'
164 161 return all(isidentifier(a) for a in s.split("."))
165 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 164 xrange = xrange
189 165 def iteritems(d): return d.iteritems()
190 166 def itervalues(d): return d.itervalues()
@@ -34,7 +34,7 b" if __name__ == '__main__':"
34 34 # This just prints a deprecation msg:
35 35 r'\.frontend$',
36 36 # Deprecated:
37 r'\.core\.magics\.deprecated'
37 r'\.core\.magics\.deprecated',
38 38 # We document this manually.
39 39 r'\.utils\.py3compat',
40 40 # These are exposed by nbformat.current
@@ -43,6 +43,8 b" if __name__ == '__main__':"
43 43 # These are exposed in display
44 44 r'\.core\.display',
45 45 r'\.lib\.display',
46 # This isn't actually a module
47 r'\.html\.fabfile',
46 48 ]
47 49
48 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