@@ -169,11 +169,11 @@ def remove_by_prefix(self, prefix):
169
169
170
170
171
171
class GenericBlobStorage :
172
- def __init__ (self , bucket , * , prefix = None ):
172
+ def __init__ (self , bucket , * , prefix : str | None = None ):
173
173
self .bucket = bucket
174
174
self .prefix = prefix
175
175
176
- def _get_path (self , path ) :
176
+ def _get_path (self , path : str ) -> str :
177
177
# If we have a prefix, then prepend it to our path. This will let us
178
178
# store items inside of a sub directory without exposing that to end
179
179
# users.
@@ -184,7 +184,7 @@ def _get_path(self, path):
184
184
185
185
186
186
class GenericB2BlobStorage (GenericBlobStorage ):
187
- def get (self , path ):
187
+ def get (self , path : str ):
188
188
path = self ._get_path (path )
189
189
try :
190
190
file_obj = io .BytesIO ()
@@ -195,14 +195,14 @@ def get(self, path):
195
195
except b2sdk .v2 .exception .FileNotPresent :
196
196
raise FileNotFoundError (f"No such key: { path !r} " ) from None
197
197
198
- def get_metadata (self , path ):
198
+ def get_metadata (self , path : str ):
199
199
path = self ._get_path (path )
200
200
try :
201
201
return self .bucket .get_file_info_by_name (path ).file_info
202
202
except b2sdk .v2 .exception .FileNotPresent :
203
203
raise FileNotFoundError (f"No such key: { path !r} " ) from None
204
204
205
- def get_checksum (self , path ):
205
+ def get_checksum (self , path : str ):
206
206
path = self ._get_path (path )
207
207
try :
208
208
return self .bucket .get_file_info_by_id (
@@ -211,7 +211,7 @@ def get_checksum(self, path):
211
211
except b2sdk .v2 .exception .FileNotPresent :
212
212
raise FileNotFoundError (f"No such key: { path !r} " ) from None
213
213
214
- def store (self , path , file_path , * , meta = None ):
214
+ def store (self , path : str , file_path , * , meta = None ):
215
215
path = self ._get_path (path )
216
216
self .bucket .upload_local_file (
217
217
local_file = file_path ,
@@ -231,7 +231,7 @@ def create_service(cls, context, request):
231
231
232
232
233
233
class GenericS3BlobStorage (GenericBlobStorage ):
234
- def get (self , path ):
234
+ def get (self , path : str ):
235
235
# Note: this is not actually used to serve files, instead our CDN is
236
236
# configured to connect directly to our storage bucket. See:
237
237
# https://github.com/python/pypi-infra/blob/master/terraform/file-hosting/vcl/main.vcl
@@ -242,15 +242,15 @@ def get(self, path):
242
242
raise
243
243
raise FileNotFoundError (f"No such key: { path !r} " ) from None
244
244
245
- def get_metadata (self , path ):
245
+ def get_metadata (self , path : str ):
246
246
try :
247
247
return self .bucket .Object (self ._get_path (path )).metadata
248
248
except botocore .exceptions .ClientError as exc :
249
249
if exc .response ["Error" ]["Code" ] != "NoSuchKey" :
250
250
raise
251
251
raise FileNotFoundError (f"No such key: { path !r} " ) from None
252
252
253
- def get_checksum (self , path ):
253
+ def get_checksum (self , path : str ):
254
254
try :
255
255
return (
256
256
self .bucket .Object (self ._get_path (path )).e_tag .rstrip ('"' ).lstrip ('"' )
@@ -261,7 +261,7 @@ def get_checksum(self, path):
261
261
raise
262
262
raise FileNotFoundError (f"No such key: { path !r} " ) from None
263
263
264
- def store (self , path , file_path , * , meta = None ):
264
+ def store (self , path : str , file_path , * , meta = None ):
265
265
extra_args = {}
266
266
if meta is not None :
267
267
extra_args ["Metadata" ] = meta
@@ -327,24 +327,24 @@ def remove_by_prefix(self, prefix):
327
327
328
328
329
329
class GenericGCSBlobStorage (GenericBlobStorage ):
330
- def get (self , path ):
330
+ def get (self , path : str ):
331
331
# Note: this is not actually used in to serve files, instead our CDN is
332
332
# configured to connect directly to our storage bucket. See:
333
333
# https://github.com/python/pypi-infra/blob/master/terraform/file-hosting/vcl/main.vcl
334
334
raise NotImplementedError
335
335
336
- def get_metadata (self , path ):
336
+ def get_metadata (self , path : str ):
337
337
raise NotImplementedError
338
338
339
- def get_checksum (self , path ):
339
+ def get_checksum (self , path : str ):
340
340
raise NotImplementedError
341
341
342
342
@google .api_core .retry .Retry (
343
343
predicate = google .api_core .retry .if_exception_type (
344
344
google .api_core .exceptions .ServiceUnavailable
345
345
)
346
346
)
347
- def store (self , path , file_path , * , meta = None ):
347
+ def store (self , path : str , file_path , * , meta = None ):
348
348
path = self ._get_path (path )
349
349
blob = self .bucket .blob (path )
350
350
if meta is not None :
0 commit comments