Commit ca009f83 by willmcgugan

Made base FS a context manager that closes itself

parent 2b6f9424
...@@ -161,7 +161,13 @@ class FS(object): ...@@ -161,7 +161,13 @@ class FS(object):
if not getattr(self, 'closed', True): if not getattr(self, 'closed', True):
self.close() self.close()
def cache_hint(self, enabled): def __enter__(self):
return self
def __exit__(self, type, value, traceback):
self.close()
def cachehint(self, enabled):
"""Recommends the use of caching. Implementations are free to use or """Recommends the use of caching. Implementations are free to use or
ignore this value. ignore this value.
...@@ -172,6 +178,8 @@ class FS(object): ...@@ -172,6 +178,8 @@ class FS(object):
""" """
pass pass
# Depricating cache_hint in favour of no underscore version, for consistency
cache_hint = cachehint
def close(self): def close(self):
"""Close the filesystem. This will perform any shutdown related """Close the filesystem. This will perform any shutdown related
...@@ -783,8 +791,8 @@ class FS(object): ...@@ -783,8 +791,8 @@ class FS(object):
""" """
if path in ('', '/'): #if path in ('', '/'):
return self # return self
from fs.wrapfs.subfs import SubFS from fs.wrapfs.subfs import SubFS
if not self.exists(path): if not self.exists(path):
raise ResourceNotFoundError(path) raise ResourceNotFoundError(path)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment