21
21
22
22
class s3 (object ):
23
23
24
- def __init__ (self , session = None ):
24
+ def __init__ (self , session = None , requester_pays = False ):
25
+ self .requester_pays = requester_pays
25
26
if session is None :
26
27
self .s3 = boto3 .client ('s3' )
27
28
else :
@@ -104,15 +105,15 @@ def upload_json(self, data, url, extra={}, **kwargs):
104
105
finally :
105
106
rmtree (tmpdir )
106
107
107
- def get_object (self , bucket , key , requester_pays = False ):
108
+ def get_object (self , bucket , key ):
108
109
""" Get an S3 object """
109
- if requester_pays :
110
+ if self . requester_pays :
110
111
response = self .s3 .get_object (Bucket = bucket , Key = key , RequestPayer = 'requester' )
111
112
else :
112
113
response = self .s3 .get_object (Bucket = bucket , Key = key )
113
114
return response
114
115
115
- def download (self , uri , path = '' , ** kwargs ):
116
+ def download (self , uri , path = '' ):
116
117
"""
117
118
Download object from S3
118
119
:param uri: URI of object to download
@@ -124,24 +125,24 @@ def download(self, uri, path='', **kwargs):
124
125
if path != '' :
125
126
makedirs (path , exist_ok = True )
126
127
127
- response = self .get_object (s3_uri ['bucket' ], s3_uri ['key' ], ** kwargs )
128
+ response = self .get_object (s3_uri ['bucket' ], s3_uri ['key' ])
128
129
129
130
with open (fout , 'wb' ) as f :
130
131
f .write (response ['Body' ].read ())
131
132
return fout
132
133
133
- def read (self , url , ** kwargs ):
134
+ def read (self , url ):
134
135
""" Read object from s3 """
135
136
parts = self .urlparse (url )
136
- response = self .get_object (parts ['bucket' ], parts ['key' ], ** kwargs )
137
+ response = self .get_object (parts ['bucket' ], parts ['key' ])
137
138
body = response ['Body' ].read ()
138
139
if op .splitext (parts ['key' ])[1 ] == '.gz' :
139
140
body = GzipFile (None , 'rb' , fileobj = BytesIO (body )).read ()
140
141
return body .decode ('utf-8' )
141
142
142
- def read_json (self , url , ** kwargs ):
143
+ def read_json (self , url ):
143
144
""" Download object from S3 as JSON """
144
- return json .loads (self .read (url , ** kwargs ))
145
+ return json .loads (self .read (url ))
145
146
146
147
def delete (self , url ):
147
148
""" Remove object from S3 """
0 commit comments