I think default mode is text

This commit is contained in:
Maciej Fijalkowski 2020-08-04 12:26:43 +02:00
parent 5fcc8c65db
commit d8bcbb901e
2 changed files with 3 additions and 3 deletions

View File

@ -94,7 +94,7 @@ class FileUtil(ReallyEqualMixin, unittest.TestCase):
basedir = "util/FileUtil/test_write_atomically" basedir = "util/FileUtil/test_write_atomically"
fileutil.make_dirs(basedir) fileutil.make_dirs(basedir)
fn = os.path.join(basedir, "here") fn = os.path.join(basedir, "here")
fileutil.write_atomically(fn, b"one") fileutil.write_atomically(fn, b"one", "b")
self.failUnlessEqual(fileutil.read(fn), b"one") self.failUnlessEqual(fileutil.read(fn), b"one")
fileutil.write_atomically(fn, u"two", mode="") # non-binary fileutil.write_atomically(fn, u"two", mode="") # non-binary
self.failUnlessEqual(fileutil.read(fn), b"two") self.failUnlessEqual(fileutil.read(fn), b"two")

View File

@ -264,8 +264,8 @@ def move_into_place(source, dest):
def write_atomically(target, contents, mode="b"): def write_atomically(target, contents, mode="b"):
assert ( assert (
isinstance(contents, bytes) and ("b" in mode or mode == "") or isinstance(contents, bytes) and "b" in mode or
isinstance(contents, unicode) and "t" in mode), (type(contents), mode) isinstance(contents, unicode) and "t" in mode or mode == ""), (type(contents), mode)
with open(target+".tmp", "w"+mode) as f: with open(target+".tmp", "w"+mode) as f:
f.write(contents) f.write(contents)
move_into_place(target+".tmp", target) move_into_place(target+".tmp", target)