99import boto3
1010from botocore .exceptions import ClientError
1111
12+ import six
1213from six import text_type
1314
1415from fs import ResourceType
@@ -70,17 +71,27 @@ def __init__(self, f, filename, mode, on_close=None):
7071 self ._on_close = on_close
7172
7273 def close (self ):
73- if not self . _f . closed :
74- if self ._on_close ( self . _f ) :
75- self ._f . close ( )
74+ print ( "Close" )
75+ if self ._on_close is not None :
76+ self ._on_close ( self . _f )
7677
7778 def __getattr__ (self , key ):
7879 return getattr (self ._f , key )
7980
8081
81-
82+ @ six . python_2_unicode_compatible
8283class S3FS (FS ):
8384
85+ _meta = {
86+ 'case_insensitive' : False ,
87+ 'invalid_path_chars' : '\0 ' ,
88+ 'network' : True ,
89+ 'read_only' : False ,
90+ 'thread_safe' : True ,
91+ 'unicode_paths' : True ,
92+ 'virtual' : False ,
93+ }
94+
8495 def __init__ (self ,
8596 bucket_name ,
8697 aws_access_key_id = None ,
@@ -221,7 +232,7 @@ def listdir(self, path):
221232 _directory .append (name )
222233
223234 if not _directory :
224- if not self .getinfo (path ).is_dir :
235+ if not self .getinfo (_path ).is_dir :
225236 raise errors .DirectoryExpected (path )
226237
227238 return _directory
@@ -257,7 +268,19 @@ def on_close(proxy_file):
257268 self .client .upload_fileobj (proxy_file , self ._bucket_name , _key )
258269 return True
259270
271+ if _mode .exclusive :
272+ try :
273+ self .getinfo (path )
274+ except errors .ResourceNotFound :
275+ pass
276+ else :
277+ raise errors .FileExists (path )
278+
260279 proxy_file = S3File .factory (path , _mode , on_close = on_close )
280+ if _mode .appending :
281+ self .client .download_fileobj (self ._bucket_name , _key , proxy_file )
282+ proxy_file .seek (0 , os .SEEK_END )
283+
261284 return proxy_file
262285
263286 info = self .getinfo (path )
@@ -271,10 +294,8 @@ def on_close(proxy_file):
271294 return True
272295
273296 proxy_file = S3File .factory (path , _mode , on_close = on_close )
274-
275297 self .client .download_fileobj (self ._bucket_name , _key , proxy_file )
276- if not _mode .appending :
277- proxy_file .seek (0 , os .SEEK_SET )
298+ proxy_file .seek (0 , os .SEEK_SET )
278299
279300 return proxy_file
280301
@@ -323,4 +344,4 @@ def removedir(self, path):
323344 )
324345
325346 def setinfo (self , path , info ):
326- getinfo (path )
347+ self . getinfo (path )
0 commit comments