summaryrefslogtreecommitdiff
path: root/fs/base.py
diff options
context:
space:
mode:
authorwillmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f>2011-03-07 14:32:49 +0000
committerwillmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f>2011-03-07 14:32:49 +0000
commit49bd11eef10959269e872183337f9494bb81931c (patch)
treea5b964f5f104c83f7a6cac8c8e2a97aefb94b914 /fs/base.py
parent06f917380c8add2ebe38c2c988e3dd197d3fcb78 (diff)
downloadpyfilesystem-49bd11eef10959269e872183337f9494bb81931c.tar.gz
Made base FS a context manager that closes itself
git-svn-id: http://pyfilesystem.googlecode.com/svn/trunk@642 67cdc799-7952-0410-af00-57a81ceafa0f
Diffstat (limited to 'fs/base.py')
-rw-r--r--fs/base.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/fs/base.py b/fs/base.py
index 59e4d83..77888a1 100644
--- a/fs/base.py
+++ b/fs/base.py
@@ -160,8 +160,14 @@ class FS(object):
def __del__(self):
if not getattr(self, 'closed', True):
self.close()
+
+ def __enter__(self):
+ return self
+
+ def __exit__(self, type, value, traceback):
+ self.close()
- def cache_hint(self, enabled):
+ def cachehint(self, enabled):
"""Recommends the use of caching. Implementations are free to use or
ignore this value.
@@ -172,6 +178,8 @@ class FS(object):
"""
pass
+ # Depricating cache_hint in favour of no underscore version, for consistency
+ cache_hint = cachehint
def close(self):
"""Close the filesystem. This will perform any shutdown related
@@ -783,8 +791,8 @@ class FS(object):
"""
- if path in ('', '/'):
- return self
+ #if path in ('', '/'):
+ # return self
from fs.wrapfs.subfs import SubFS
if not self.exists(path):
raise ResourceNotFoundError(path)