diff options
Diffstat (limited to 'fs')
-rw-r--r-- | fs/opener.py | 17 | ||||
-rw-r--r-- | fs/osfs/__init__.py | 4 | ||||
-rw-r--r-- | fs/s3fs.py | 3 |
3 files changed, 16 insertions, 8 deletions
diff --git a/fs/opener.py b/fs/opener.py index 8500eac..8abde0c 100644 --- a/fs/opener.py +++ b/fs/opener.py @@ -551,9 +551,9 @@ example: class TempOpener(Opener): names = ['temp'] - desc = """Creates a temporary filesystem, that is erased on exit. + desc = """Creates a temporary filesystem that is erased on exit. Probably only useful for mounting or serving. -NB: If you user fscp or fsmv to copy/move files here, you are effectively deleting them! +NB: If you use fscp or fsmv to copy/move files here, you are effectively deleting them! example: * temp://""" @@ -565,20 +565,24 @@ example: fs = LazyFS((TempFS,(),{"identifier":fs_name_params})) return fs, fs_path + class S3Opener(Opener): names = ['s3'] desc = """Opens a filesystem stored on Amazon S3 storage The environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY should be set""" + @classmethod def get_fs(cls, registry, fs_name, fs_name_params, fs_path, writeable, create_dir): from fs.s3fs import S3FS - bucket = fs_path - path ='' - if '/' in fs_path: + username, password, bucket = _parse_credentials(fs_path) + path = '' + if '/' in bucket: bucket, path = fs_path.split('/', 1) - fs = S3FS(bucket) + fs = S3FS(bucket, + aws_access_key=username or None, + aws_secret_key=password or None) if path: dirpath, resourcepath = pathsplit(path) @@ -588,6 +592,7 @@ class S3Opener(Opener): return fs, path + class TahoeOpener(Opener): names = ['tahoe'] desc = """Opens a Tahoe-LAFS filesystem diff --git a/fs/osfs/__init__.py b/fs/osfs/__init__.py index 0e4039c..9226b08 100644 --- a/fs/osfs/__init__.py +++ b/fs/osfs/__init__.py @@ -115,7 +115,7 @@ class OSFS(OSFSXAttrMixin, OSFSWatchMixin, FS): """ super(OSFS, self).__init__(thread_synchronize=thread_synchronize) - self.encoding = encoding or sys.getfilesystemencoding() + self.encoding = encoding or sys.getfilesystemencoding() or 'utf-8' self.dir_mode = dir_mode self.use_long_paths = use_long_paths root_path = os.path.expanduser(os.path.expandvars(root_path)) @@ -230,6 +230,8 @@ class OSFS(OSFSXAttrMixin, OSFSWatchMixin, FS): def open(self, path, mode='r', buffering=-1, encoding=None, errors=None, newline=None, line_buffering=False, **kwargs): mode = ''.join(c for c in mode if c in 'rwabt+') sys_path = self.getsyspath(path) + if not encoding and 'b' not in mode: + encoding = encoding or 'utf-8' try: return io.open(sys_path, mode=mode, buffering=buffering, encoding=encoding, errors=errors, newline=newline) except EnvironmentError, e: @@ -487,7 +487,8 @@ class S3FS(FS): msg = "Parent directory does not exist: %(path)s" raise ParentDirectoryMissingError(path, msg=msg) # Create an empty file representing the directory - self._sync_set_contents(s3pathD,"") + if s3pathD not in ('/', ''): + self._sync_set_contents(s3pathD,"") def remove(self,path): """Remove the file at the given path.""" |