mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-20 13:33:09 +00:00
I think default mode is text
This commit is contained in:
parent
5fcc8c65db
commit
d8bcbb901e
@ -94,7 +94,7 @@ class FileUtil(ReallyEqualMixin, unittest.TestCase):
|
||||
basedir = "util/FileUtil/test_write_atomically"
|
||||
fileutil.make_dirs(basedir)
|
||||
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")
|
||||
fileutil.write_atomically(fn, u"two", mode="") # non-binary
|
||||
self.failUnlessEqual(fileutil.read(fn), b"two")
|
||||
|
@ -264,8 +264,8 @@ def move_into_place(source, dest):
|
||||
|
||||
def write_atomically(target, contents, mode="b"):
|
||||
assert (
|
||||
isinstance(contents, bytes) and ("b" in mode or mode == "") or
|
||||
isinstance(contents, unicode) and "t" in mode), (type(contents), mode)
|
||||
isinstance(contents, bytes) and "b" in mode or
|
||||
isinstance(contents, unicode) and "t" in mode or mode == ""), (type(contents), mode)
|
||||
with open(target+".tmp", "w"+mode) as f:
|
||||
f.write(contents)
|
||||
move_into_place(target+".tmp", target)
|
||||
|
Loading…
Reference in New Issue
Block a user