From fbe1238c34ef238a0a50166d6b2ec19a7ee94435 Mon Sep 17 00:00:00 2001 From: "willmcgugan@gmail.com" Date: Mon, 9 Sep 2013 21:47:01 +0000 Subject: Changed signature for 'createfile' everywhere, fixes #133 git-svn-id: http://pyfilesystem.googlecode.com/svn/trunk@875 67cdc799-7952-0410-af00-57a81ceafa0f --- fs/remote.py | 4 ++-- fs/tests/__init__.py | 16 ++++++++++++++-- fs/watch.py | 4 ++-- fs/wrapfs/__init__.py | 4 ++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/fs/remote.py b/fs/remote.py index eb41cdb..1ac502b 100644 --- a/fs/remote.py +++ b/fs/remote.py @@ -679,8 +679,8 @@ class CacheFSMixin(FS): self.__cache[path] = CachedInfo.new_file_stub() return res - def createfile(self, path): - super(CacheFSMixin,self).createfile(path) + def createfile(self, path, wipe=False): + super(CacheFSMixin,self).createfile(path, wipe=wipe) with self.__cache_lock: self.__cache.clear(path) self.__cache[path] = CachedInfo.new_file_stub() diff --git a/fs/tests/__init__.py b/fs/tests/__init__.py index 9fd3cda..42f396f 100644 --- a/fs/tests/__init__.py +++ b/fs/tests/__init__.py @@ -136,6 +136,18 @@ class FSTestCases(object): self.assertEquals(f.read(), b("test file overwrite")) f.close() + def test_createfile(self): + """Test createfile""" + test = b('now with content') + self.fs.createfile("test.txt") + self.assert_(self.fs.exists("test.txt")) + self.assertEqual(self.fs.getcontents("test.txt", "rb"), b('')) + self.fs.setcontents("test.txt", test) + self.fs.createfile("test.txt") + self.assertEqual(self.fs.getcontents("test.txt", "rb"), test) + self.fs.createfile("test.txt", wipe=True) + self.assertEqual(self.fs.getcontents("test.txt", "rb"), b('')) + def test_setcontents(self): # setcontents() should accept both a string... self.fs.setcontents("hello", b("world")) @@ -152,7 +164,7 @@ class FSTestCases(object): b("to you, good sir!")), chunk_size=2) self.assertEquals(self.fs.getcontents( "hello", "rb"), b("to you, good sir!")) - self.fs.setcontents("hello", "", "wb") + self.fs.setcontents("hello", b"") self.assertEquals(self.fs.getcontents("hello", "rb"), "") def test_setcontents_async(self): @@ -888,7 +900,7 @@ class FSTestCases(object): def test_zero_read(self): """Test read(0) returns empty string""" - self.fs.setcontents('foo.txt', b('Hello, World'), 'wb') + self.fs.setcontents('foo.txt', b('Hello, World') ) with self.fs.open('foo.txt', 'rb') as f: self.assert_(len(f.read(0)) == 0) with self.fs.open('foo.txt', 'rt') as f: diff --git a/fs/watch.py b/fs/watch.py index 04d9803..55e7462 100644 --- a/fs/watch.py +++ b/fs/watch.py @@ -323,9 +323,9 @@ class WatchableFS(WatchableFSMixin,WrapFS): self.notify_watchers(MODIFIED, path, True) return ret - def createfile(self, path): + def createfile(self, path, wipe=False): existed = self.wrapped_fs.isfile(path) - ret = super(WatchableFS, self).createfile(path) + ret = super(WatchableFS, self).createfile(path, wipe=False) if not existed: self.notify_watchers(CREATED,path) self.notify_watchers(ACCESSED,path) diff --git a/fs/wrapfs/__init__.py b/fs/wrapfs/__init__.py index b8b9bea..d50cee8 100644 --- a/fs/wrapfs/__init__.py +++ b/fs/wrapfs/__init__.py @@ -167,8 +167,8 @@ class WrapFS(FS): return super(WrapFS, self).setcontents(path, data, encoding=encoding, errors=errors, chunk_size=chunk_size) @rewrite_errors - def createfile(self, path): - return self.wrapped_fs.createfile(self._encode(path)) + def createfile(self, path, wipe=False): + return self.wrapped_fs.createfile(self._encode(path), wipe=wipe) @rewrite_errors def exists(self, path): -- cgit v1.2.1