Commit e7b412f9 by willmcgugan

Fixed a circular reference issue

parent c56e8ae6
......@@ -79,4 +79,5 @@
* Removed obsolete module fs.objectree; use fs.path.PathMap instead.
* Added setcontents_async method to base
* Added `appdirfs` module to abstract per-user application directories
0.5:
......@@ -15,7 +15,7 @@ implementations of this interface such as:
"""
__version__ = "0.4.0rc"
__version__ = "0.4.1"
__author__ = "Will McGugan (will@willmcgugan.com)"
# No longer necessary - WM
......
......@@ -82,7 +82,7 @@ class Command(object):
self.verbosity_level = 0
self.terminal_colors = not sys.platform.startswith('win') and self.is_terminal()
if self.is_terminal():
w, h = getTerminalSize()
w, _h = getTerminalSize()
self.terminal_width = w
else:
self.terminal_width = 80
......
......@@ -19,7 +19,7 @@ For example, lets say we have two filesystems containing config files and resour
We can combine these filesystems in to a single filesystem with the following code::
from fs.mountfs import MountFS
combined_fs = MountFS
combined_fs = MountFS()
combined_fs.mountdir('config', config_fs)
combined_fs.mountdir('resources', resources_fs)
......
......@@ -67,6 +67,7 @@ __all__ = ['OpenerError',
'HTTPOpener']
from fs.path import pathsplit, join, iswildcard, normpath
from fs.filelike import FileWrapper
from os import getcwd
import os.path
import re
......@@ -117,6 +118,14 @@ def _split_url_path(url):
url = '%s://%s' % (scheme, netloc)
return url, path
class _FSClosingFile(FileWrapper):
"""A file like object that closes its parent FS when closed itself"""
def close(self):
fs = getattr(self, '_closefs', None)
ret = super(_FSClosingFile).close()
if fs is not None:
fs.close
return ret
class OpenerRegistry(object):
......@@ -254,24 +263,10 @@ class OpenerRegistry(object):
writeable = 'w' in mode or 'a' in mode or '+' in mode
fs, path = self.parse(fs_url, writeable=writeable)
file_object = fs.open(path, mode)
from fs.filelike import FileWrapper
file_object = FileWrapper(file_object, mode)
# If we just return the file, then fs goes out of scope and closes,
# which may make the file unusable. To get around this, we store a
# reference in the file object to the FS, and patch the file's
# close method to also close the FS.
close = file_object.close
close_fs = fs
def replace_close():
ret = close()
close_fs.close()
return ret
file_object.close = replace_close
return file_object
file_object = _FSClosingFile(file_object, mode)
file_object.fs = fs
return file_object
def getcontents(self, fs_url):
"""Gets the contents from a given FS url (if it references a file)
......
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