summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill McGugan <willmcgugan@gmail.com>2015-11-13 22:18:29 +0000
committerWill McGugan <willmcgugan@gmail.com>2015-11-13 22:18:29 +0000
commit39f673de2671acb8146b1975cbaa285d340ac9a0 (patch)
tree1b96a8eb3caec3fc48608f0ae39f4129324c389f
parent9d9440e5544abe9742e23e41697f1e0d45f6d86e (diff)
downloadpyfilesystem-git-39f673de2671acb8146b1975cbaa285d340ac9a0.tar.gz
added credentials to s3 opener
-rw-r--r--fs/opener.py17
-rw-r--r--fs/osfs/__init__.py4
-rw-r--r--fs/s3fs.py3
-rw-r--r--tox.ini16
4 files changed, 19 insertions, 21 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 446ef93..90f4360 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))
@@ -228,6 +228,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:
diff --git a/fs/s3fs.py b/fs/s3fs.py
index 1c8b321..4f51a50 100644
--- a/fs/s3fs.py
+++ b/fs/s3fs.py
@@ -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."""
diff --git a/tox.ini b/tox.ini
index 849eea8..b7d5505 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
[tox]
-envlist = py26,py27,py31,py32,py33,pypy
+envlist = py27,py34,py35,pypy
sitepackages = False
[testenv]
@@ -15,17 +15,7 @@ changedir=.tox
commands = nosetests fs.tests -v \
[]
-
-[testenv:py31]
-commands = nosetests fs.tests -v \
- []
-deps = distribute
- six
- dexml
- nose
- winpdb
-
-[testenv:py32]
+[testenv:py34]
commands = nosetests fs.tests -v \
[]
deps = distribute
@@ -34,7 +24,7 @@ deps = distribute
nose
winpdb
-[testenv:py33]
+[testenv:py35]
commands = nosetests fs.tests -v \
[]
deps = distribute