@@ -110,11 +110,15 @@ def put(self,
110
110
data : bytes ,
111
111
content_type : str | None = None ,
112
112
tagging : Tagging | None = None ,
113
+ * ,
114
+ exists_okay : bool = True ,
113
115
** kwargs ):
114
116
self ._s3 .put_object (Bucket = self .bucket_name ,
115
117
Key = object_key ,
116
118
Body = data ,
117
- ** self ._object_creation_kwargs (content_type = content_type , tagging = tagging ),
119
+ ** self ._object_creation_kwargs (content_type = content_type ,
120
+ tagging = tagging ,
121
+ exists_okay = exists_okay ),
118
122
** kwargs )
119
123
120
124
def list (self , prefix : str ) -> OrderedSet [str ]:
@@ -155,15 +159,19 @@ def upload_multipart_part(self,
155
159
156
160
def complete_multipart_upload (self ,
157
161
upload : MultipartUpload ,
158
- etags : Sequence [str ]) -> None :
162
+ etags : Sequence [str ],
163
+ * ,
164
+ exists_okay : bool = True ,
165
+ ) -> None :
159
166
parts = [
160
167
{
161
168
'PartNumber' : index + 1 ,
162
169
'ETag' : etag
163
170
}
164
171
for index , etag in enumerate (etags )
165
172
]
166
- upload .complete (MultipartUpload = {'Parts' : parts })
173
+ upload .complete (MultipartUpload = {'Parts' : parts },
174
+ ** self ._object_creation_kwargs (exists_okay = exists_okay ))
167
175
168
176
def upload (self ,
169
177
file_path : str ,
@@ -181,12 +189,16 @@ def upload(self,
181
189
182
190
def _object_creation_kwargs (self , * ,
183
191
content_type : str | None = None ,
184
- tagging : Tagging | None = None ):
192
+ tagging : Tagging | None = None ,
193
+ exists_okay : bool = True
194
+ ) -> Mapping [str , str ]:
185
195
kwargs = {}
186
196
if content_type is not None :
187
197
kwargs ['ContentType' ] = content_type
188
198
if tagging is not None :
189
199
kwargs ['Tagging' ] = urlencode (tagging )
200
+ if exists_okay is False :
201
+ kwargs ['IfNoneMatch' ] = '*'
190
202
return kwargs
191
203
192
204
def get_presigned_url (self , key : str , file_name : str | None = None ) -> str :
0 commit comments