##// END OF EJS Templates
don't use text mode in mkstemp...
Min RK -
Show More
@@ -267,7 +267,7 b" def atomic_writing(path, text=True, encoding='utf-8', **kwargs):"
267 267 path = os.path.join(os.path.dirname(path), os.readlink(path))
268 268
269 269 dirname, basename = os.path.split(path)
270 handle, tmp_path = tempfile.mkstemp(prefix=basename, dir=dirname, text=text)
270 handle, tmp_path = tempfile.mkstemp(prefix=basename, dir=dirname)
271 271 if text:
272 272 fileobj = io.open(handle, 'w', encoding=encoding, **kwargs)
273 273 else:
@@ -175,4 +175,41 b' def test_atomic_writing():'
175 175 f.write(u'written from symlink')
176 176
177 177 with stdlib_io.open(f1, 'r') as f:
178 nt.assert_equal(f.read(), u'written from symlink') No newline at end of file
178 nt.assert_equal(f.read(), u'written from symlink')
179
180 def test_atomic_writing_newlines():
181 with TemporaryDirectory() as td:
182 path = os.path.join(td, 'testfile')
183
184 lf = u'a\nb\nc\n'
185 plat = lf.replace(u'\n', os.linesep)
186 crlf = lf.replace(u'\n', u'\r\n')
187
188 # test default
189 with stdlib_io.open(path, 'w') as f:
190 f.write(lf)
191 with stdlib_io.open(path, 'r', newline='') as f:
192 read = f.read()
193 nt.assert_equal(read, plat)
194
195 # test newline=LF
196 with stdlib_io.open(path, 'w', newline='\n') as f:
197 f.write(lf)
198 with stdlib_io.open(path, 'r', newline='') as f:
199 read = f.read()
200 nt.assert_equal(read, lf)
201
202 # test newline=CRLF
203 with atomic_writing(path, newline='\r\n') as f:
204 f.write(lf)
205 with stdlib_io.open(path, 'r', newline='') as f:
206 read = f.read()
207 nt.assert_equal(read, crlf)
208
209 # test newline=no convert
210 text = u'crlf\r\ncr\rlf\n'
211 with atomic_writing(path, newline='') as f:
212 f.write(text)
213 with stdlib_io.open(path, 'r', newline='') as f:
214 read = f.read()
215 nt.assert_equal(read, text)
General Comments 0
You need to be logged in to leave comments. Login now