19
19
import re
20
20
21
21
from google .cloud .storage ._media import _helpers
22
- from google .cloud .storage ._media import common
23
22
from google .cloud .storage .exceptions import InvalidResponse
23
+ from google .cloud .storage .retry import DEFAULT_RETRY
24
24
25
25
26
26
_CONTENT_RANGE_RE = re .compile (
@@ -45,14 +45,30 @@ class DownloadBase(object):
45
45
end (int): The last byte in a range to be downloaded.
46
46
headers (Optional[Mapping[str, str]]): Extra headers that should
47
47
be sent with the request, e.g. headers for encrypted data.
48
+ retry (Optional[google.api_core.retry.Retry]): How to retry the RPC.
49
+ A None value will disable retries. A google.api_core.retry.Retry
50
+ value will enable retries, and the object will configure backoff and
51
+ timeout options.
52
+
53
+ See the retry.py source code and docstrings in this package
54
+ (google.cloud.storage.retry) for information on retry types and how
55
+ to configure them.
48
56
49
57
Attributes:
50
58
media_url (str): The URL containing the media to be downloaded.
51
59
start (Optional[int]): The first byte in a range to be downloaded.
52
60
end (Optional[int]): The last byte in a range to be downloaded.
53
61
"""
54
62
55
- def __init__ (self , media_url , stream = None , start = None , end = None , headers = None ):
63
+ def __init__ (
64
+ self ,
65
+ media_url ,
66
+ stream = None ,
67
+ start = None ,
68
+ end = None ,
69
+ headers = None ,
70
+ retry = DEFAULT_RETRY ,
71
+ ):
56
72
self .media_url = media_url
57
73
self ._stream = stream
58
74
self .start = start
@@ -61,7 +77,7 @@ def __init__(self, media_url, stream=None, start=None, end=None, headers=None):
61
77
headers = {}
62
78
self ._headers = headers
63
79
self ._finished = False
64
- self ._retry_strategy = common . RetryStrategy ()
80
+ self ._retry_strategy = retry
65
81
66
82
@property
67
83
def finished (self ):
@@ -133,6 +149,15 @@ class Download(DownloadBase):
133
149
values are "md5", "crc32c", "auto" and None. The default is "auto",
134
150
which will try to detect if the C extension for crc32c is installed
135
151
and fall back to md5 otherwise.
152
+ retry (Optional[google.api_core.retry.Retry]): How to retry the
153
+ RPC. A None value will disable retries. A
154
+ google.api_core.retry.Retry value will enable retries, and the
155
+ object will configure backoff and timeout options.
156
+
157
+ See the retry.py source code and docstrings in this package
158
+ (google.cloud.storage.retry) for information on retry types and how
159
+ to configure them.
160
+
136
161
"""
137
162
138
163
def __init__ (
@@ -143,9 +168,10 @@ def __init__(
143
168
end = None ,
144
169
headers = None ,
145
170
checksum = "auto" ,
171
+ retry = DEFAULT_RETRY ,
146
172
):
147
173
super (Download , self ).__init__ (
148
- media_url , stream = stream , start = start , end = end , headers = headers
174
+ media_url , stream = stream , start = start , end = end , headers = headers , retry = retry
149
175
)
150
176
self .checksum = checksum
151
177
if self .checksum == "auto" :
@@ -242,6 +268,14 @@ class ChunkedDownload(DownloadBase):
242
268
headers (Optional[Mapping[str, str]]): Extra headers that should
243
269
be sent with each request, e.g. headers for data encryption
244
270
key headers.
271
+ retry (Optional[google.api_core.retry.Retry]): How to retry the
272
+ RPC. A None value will disable retries. A
273
+ google.api_core.retry.Retry value will enable retries, and the
274
+ object will configure backoff and timeout options.
275
+
276
+ See the retry.py source code and docstrings in this package
277
+ (google.cloud.storage.retry) for information on retry types and how
278
+ to configure them.
245
279
246
280
Attributes:
247
281
media_url (str): The URL containing the media to be downloaded.
@@ -253,13 +287,27 @@ class ChunkedDownload(DownloadBase):
253
287
ValueError: If ``start`` is negative.
254
288
"""
255
289
256
- def __init__ (self , media_url , chunk_size , stream , start = 0 , end = None , headers = None ):
290
+ def __init__ (
291
+ self ,
292
+ media_url ,
293
+ chunk_size ,
294
+ stream ,
295
+ start = 0 ,
296
+ end = None ,
297
+ headers = None ,
298
+ retry = DEFAULT_RETRY ,
299
+ ):
257
300
if start < 0 :
258
301
raise ValueError (
259
302
"On a chunked download the starting " "value cannot be negative."
260
303
)
261
304
super (ChunkedDownload , self ).__init__ (
262
- media_url , stream = stream , start = start , end = end , headers = headers
305
+ media_url ,
306
+ stream = stream ,
307
+ start = start ,
308
+ end = end ,
309
+ headers = headers ,
310
+ retry = retry ,
263
311
)
264
312
self .chunk_size = chunk_size
265
313
self ._bytes_downloaded = 0
0 commit comments