A class for wrapping an existing FS object with additional functionality.
This module provides the class WrapFS, a base class for objects that wrap another FS object and provide some transformation of its contents. It could be very useful for implementing e.g. transparent encryption or compression services.
For a simple example of how this class could be used, see the ‘HideDotFilesFS’ class in the module fs.wrapfs.hidedotfilesfs. This wrapper implements the standard unix shell functionality of hiding dot-files in directory listings.
FS that wraps another FS, providing translation etc.
This class allows simple transforms to be applied to the names and/or contents of files in an FS. It could be used to implement e.g. compression or encryption in a relatively painless manner.
The following methods can be overridden to control how files are accessed in the underlying FS object:
- _file_wrap(file, mode): called for each file that is opened from
the underlying FS; may return a modified file-like object.
_encode(path): encode a path for access in the underlying FS
_decode(path): decode a path from the underlying FS
If the required path translation proceeds one component at a time, it may be simpler to override the _encode_name() and _decode_name() methods.
Re-write paths in errors raised by wrapped FS objects.
Apply the given decorator to all FS methods on the given class.
This function can be used in two ways. When called with two arguments it applies the given function ‘decorator’ to each FS method of the given class. When called with just a single argument, it creates and returns a class decorator which will do the same thing when applied. So you can use it like this:
Or on more recent Python versions, like this:
@wrap_fs_methods(mydecorator) class MyFSClass(FS): ...