From 885528cdf3e161f991deb210af969bb32739c305 Mon Sep 17 00:00:00 2001 From: Matt Harrison Date: Mon, 19 Sep 2016 09:13:58 -0600 Subject: [PATCH 1/2] Support alternate datetime format for S3 files --- fs/s3fs.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/s3fs.py b/fs/s3fs.py index c2fb4ec..c416117 100644 --- a/fs/s3fs.py +++ b/fs/s3fs.py @@ -585,7 +585,10 @@ def _get_key_info(self,key,name=None): info['etag'] = etag.strip('"').strip("'") if hasattr(key,"last_modified"): # TODO: does S3 use any other formats? - fmt = "%a, %d %b %Y %H:%M:%S %Z" + if '-' in key.last_modified: + fmt = "%Y-%m-%dT%H:%M:%S.%fZ" + else: + fmt = "%a, %d %b %Y %H:%M:%S %Z" try: mtime = datetime.datetime.strptime(key.last_modified,fmt) info['modified_time'] = mtime From e77785f590a0e31d10265bc34e2f68aeea38dc30 Mon Sep 17 00:00:00 2001 From: Matt Harrison Date: Mon, 19 Sep 2016 21:46:19 -0600 Subject: [PATCH 2/2] Support Py3 --- fs/s3fs.py | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/fs/s3fs.py b/fs/s3fs.py index c416117..053f0ea 100644 --- a/fs/s3fs.py +++ b/fs/s3fs.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals """ fs.s3fs ======= @@ -113,8 +114,6 @@ def __init__(self, bucket, prefix="", aws_access_key=None, aws_secret_key=None, prefix = prefix[1:] if not prefix.endswith(separator) and prefix != "": prefix = prefix + separator - if isinstance(prefix,unicode): - prefix = prefix.encode("utf8") self._prefix = prefix self._tlocal = thread_local() super(S3FS, self).__init__(thread_synchronize=thread_synchronize) @@ -180,8 +179,6 @@ def _s3path(self,path): s3path = self._prefix + path if s3path and s3path[-1] == self._separator: s3path = s3path[:-1] - if isinstance(s3path,unicode): - s3path = s3path.encode("utf8") return s3path def _uns3path(self,s3path,roots3path=None): @@ -399,8 +396,6 @@ def _iter_keys(self,path): # Skip over the entry for the directory itself, if it exists name = self._uns3path(k.name,s3path) if name != "": - if not isinstance(name,unicode): - name = name.decode("utf8") if name.endswith(self._separator): name = name[:-1] yield (name,k) @@ -580,8 +575,6 @@ def _get_key_info(self,key,name=None): info['size'] = int(key.size) etag = getattr(key,"etag",None) if etag is not None: - if isinstance(etag,unicode): - etag = etag.encode("utf8") info['etag'] = etag.strip('"').strip("'") if hasattr(key,"last_modified"): # TODO: does S3 use any other formats? @@ -667,8 +660,6 @@ def walkfiles(self, for k in self._s3bukt.list(prefix=prefix): name = relpath(self._uns3path(k.name,prefix)) if name != "": - if not isinstance(name,unicode): - name = name.decode("utf8") if not k.name.endswith(self._separator): if wildcard is not None: if callable(wildcard): @@ -695,8 +686,6 @@ def walkinfo(self, for k in self._s3bukt.list(prefix=prefix): name = relpath(self._uns3path(k.name,prefix)) if name != "": - if not isinstance(name,unicode): - name = name.decode("utf8") if wildcard is not None: if callable(wildcard): if not wildcard(basename(name)): @@ -722,8 +711,6 @@ def walkfilesinfo(self, for k in self._s3bukt.list(prefix=prefix): name = relpath(self._uns3path(k.name,prefix)) if name != "": - if not isinstance(name,unicode): - name = name.decode("utf8") if not k.name.endswith(self._separator): if wildcard is not None: if callable(wildcard):