Skip to content

Commit 3caedef

Browse files
committed
Finish coverage and add docstrings
1 parent 20afb8e commit 3caedef

File tree

5 files changed

+347
-1
lines changed

5 files changed

+347
-1
lines changed

google/cloud/storage/blob.py

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,28 @@ def download_to_file(
11001100
emitted. Supported values are "md5", "crc32c" and None. The default
11011101
is "md5".
11021102
1103+
:type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
1104+
:param retry: (Optional) How to retry the RPC. A None value will disable
1105+
retries. A google.api_core.retry.Retry value will enable retries,
1106+
and the object will define retriable response codes and errors and
1107+
configure backoff and timeout options.
1108+
1109+
A google.cloud.storage.retry.ConditionalRetryPolicy value wraps a
1110+
Retry object and activates it only if certain conditions are met.
1111+
This class exists to provide safe defaults for RPC calls that are
1112+
not technically safe to retry normally (due to potential data
1113+
duplication or other side-effects) but become safe to retry if a
1114+
condition such as if_metageneration_match is set.
1115+
1116+
See the retry.py source code and docstrings in this package
1117+
(google.cloud.storage.retry) for information on retry types and how
1118+
to configure them.
1119+
1120+
Media operations (downloads and uploads) do not support non-default
1121+
predicates in a Retry object. The default will always be used. Other
1122+
configuration changes for Retry objects such as delays and deadlines
1123+
are respected.
1124+
11031125
:raises: :class:`google.cloud.exceptions.NotFound`
11041126
"""
11051127
client = self._require_client(client)
@@ -1198,6 +1220,28 @@ def download_to_filename(
11981220
emitted. Supported values are "md5", "crc32c" and None. The default
11991221
is "md5".
12001222
1223+
:type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
1224+
:param retry: (Optional) How to retry the RPC. A None value will disable
1225+
retries. A google.api_core.retry.Retry value will enable retries,
1226+
and the object will define retriable response codes and errors and
1227+
configure backoff and timeout options.
1228+
1229+
A google.cloud.storage.retry.ConditionalRetryPolicy value wraps a
1230+
Retry object and activates it only if certain conditions are met.
1231+
This class exists to provide safe defaults for RPC calls that are
1232+
not technically safe to retry normally (due to potential data
1233+
duplication or other side-effects) but become safe to retry if a
1234+
condition such as if_metageneration_match is set.
1235+
1236+
See the retry.py source code and docstrings in this package
1237+
(google.cloud.storage.retry) for information on retry types and how
1238+
to configure them.
1239+
1240+
Media operations (downloads and uploads) do not support non-default
1241+
predicates in a Retry object. The default will always be used. Other
1242+
configuration changes for Retry objects such as delays and deadlines
1243+
are respected.
1244+
12011245
:raises: :class:`google.cloud.exceptions.NotFound`
12021246
"""
12031247
client = self._require_client(client)
@@ -1305,6 +1349,28 @@ def download_as_bytes(
13051349
emitted. Supported values are "md5", "crc32c" and None. The default
13061350
is "md5".
13071351
1352+
:type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
1353+
:param retry: (Optional) How to retry the RPC. A None value will disable
1354+
retries. A google.api_core.retry.Retry value will enable retries,
1355+
and the object will define retriable response codes and errors and
1356+
configure backoff and timeout options.
1357+
1358+
A google.cloud.storage.retry.ConditionalRetryPolicy value wraps a
1359+
Retry object and activates it only if certain conditions are met.
1360+
This class exists to provide safe defaults for RPC calls that are
1361+
not technically safe to retry normally (due to potential data
1362+
duplication or other side-effects) but become safe to retry if a
1363+
condition such as if_metageneration_match is set.
1364+
1365+
See the retry.py source code and docstrings in this package
1366+
(google.cloud.storage.retry) for information on retry types and how
1367+
to configure them.
1368+
1369+
Media operations (downloads and uploads) do not support non-default
1370+
predicates in a Retry object. The default will always be used. Other
1371+
configuration changes for Retry objects such as delays and deadlines
1372+
are respected.
1373+
13081374
:rtype: bytes
13091375
:returns: The data stored in this blob.
13101376
@@ -1394,6 +1460,28 @@ def download_as_string(
13941460
Can also be passed as a tuple (connect_timeout, read_timeout).
13951461
See :meth:`requests.Session.request` documentation for details.
13961462
1463+
:type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
1464+
:param retry: (Optional) How to retry the RPC. A None value will disable
1465+
retries. A google.api_core.retry.Retry value will enable retries,
1466+
and the object will define retriable response codes and errors and
1467+
configure backoff and timeout options.
1468+
1469+
A google.cloud.storage.retry.ConditionalRetryPolicy value wraps a
1470+
Retry object and activates it only if certain conditions are met.
1471+
This class exists to provide safe defaults for RPC calls that are
1472+
not technically safe to retry normally (due to potential data
1473+
duplication or other side-effects) but become safe to retry if a
1474+
condition such as if_metageneration_match is set.
1475+
1476+
See the retry.py source code and docstrings in this package
1477+
(google.cloud.storage.retry) for information on retry types and how
1478+
to configure them.
1479+
1480+
Media operations (downloads and uploads) do not support non-default
1481+
predicates in a Retry object. The default will always be used. Other
1482+
configuration changes for Retry objects such as delays and deadlines
1483+
are respected.
1484+
13971485
:rtype: bytes
13981486
:returns: The data stored in this blob.
13991487
@@ -1488,6 +1576,28 @@ def download_as_text(
14881576
Can also be passed as a tuple (connect_timeout, read_timeout).
14891577
See :meth:`requests.Session.request` documentation for details.
14901578
1579+
:type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
1580+
:param retry: (Optional) How to retry the RPC. A None value will disable
1581+
retries. A google.api_core.retry.Retry value will enable retries,
1582+
and the object will define retriable response codes and errors and
1583+
configure backoff and timeout options.
1584+
1585+
A google.cloud.storage.retry.ConditionalRetryPolicy value wraps a
1586+
Retry object and activates it only if certain conditions are met.
1587+
This class exists to provide safe defaults for RPC calls that are
1588+
not technically safe to retry normally (due to potential data
1589+
duplication or other side-effects) but become safe to retry if a
1590+
condition such as if_metageneration_match is set.
1591+
1592+
See the retry.py source code and docstrings in this package
1593+
(google.cloud.storage.retry) for information on retry types and how
1594+
to configure them.
1595+
1596+
Media operations (downloads and uploads) do not support non-default
1597+
predicates in a Retry object. The default will always be used. Other
1598+
configuration changes for Retry objects such as delays and deadlines
1599+
are respected.
1600+
14911601
:rtype: text
14921602
:returns: The data stored in this blob, decoded to text.
14931603
"""
@@ -1693,6 +1803,21 @@ def _do_multipart_upload(
16931803
manually-set checksum value. Supported values are "md5",
16941804
"crc32c" and None. The default is None.
16951805
1806+
:type retry: google.api_core.retry.Retry
1807+
:param retry: (Optional) How to retry the RPC. A None value will disable
1808+
retries. A google.api_core.retry.Retry value will enable retries,
1809+
and the object will configure backoff and timeout options. Custom
1810+
predicates (customizable error codes) are not supported for media
1811+
operations such as this one.
1812+
1813+
This private method does not accept ConditionalRetryPolicy values
1814+
because the information necessary to evaluate the policy is instead
1815+
evaluated in client.download_blob_to_file().
1816+
1817+
See the retry.py source code and docstrings in this package
1818+
(google.cloud.storage.retry) for information on retry types and how
1819+
to configure them.
1820+
16961821
:rtype: :class:`~requests.Response`
16971822
:returns: The "200 OK" response object returned after the multipart
16981823
upload request.
@@ -1874,6 +1999,21 @@ def _initiate_resumable_upload(
18741999
delete the uploaded object automatically. Supported values
18752000
are "md5", "crc32c" and None. The default is None.
18762001
2002+
:type retry: google.api_core.retry.Retry
2003+
:param retry: (Optional) How to retry the RPC. A None value will disable
2004+
retries. A google.api_core.retry.Retry value will enable retries,
2005+
and the object will configure backoff and timeout options. Custom
2006+
predicates (customizable error codes) are not supported for media
2007+
operations such as this one.
2008+
2009+
This private method does not accept ConditionalRetryPolicy values
2010+
because the information necessary to evaluate the policy is instead
2011+
evaluated in client.download_blob_to_file().
2012+
2013+
See the retry.py source code and docstrings in this package
2014+
(google.cloud.storage.retry) for information on retry types and how
2015+
to configure them.
2016+
18772017
:rtype: tuple
18782018
:returns:
18792019
Pair of
@@ -2052,6 +2192,21 @@ def _do_resumable_upload(
20522192
delete the uploaded object automatically. Supported values
20532193
are "md5", "crc32c" and None. The default is None.
20542194
2195+
:type retry: google.api_core.retry.Retry
2196+
:param retry: (Optional) How to retry the RPC. A None value will disable
2197+
retries. A google.api_core.retry.Retry value will enable retries,
2198+
and the object will configure backoff and timeout options. Custom
2199+
predicates (customizable error codes) are not supported for media
2200+
operations such as this one.
2201+
2202+
This private method does not accept ConditionalRetryPolicy values
2203+
because the information necessary to evaluate the policy is instead
2204+
evaluated in client.download_blob_to_file().
2205+
2206+
See the retry.py source code and docstrings in this package
2207+
(google.cloud.storage.retry) for information on retry types and how
2208+
to configure them.
2209+
20552210
:rtype: :class:`~requests.Response`
20562211
:returns: The "200 OK" response object returned after the final chunk
20572212
is uploaded.
@@ -2184,6 +2339,28 @@ def _do_upload(
21842339
attempting to delete the corrupted file. Supported values are
21852340
"md5", "crc32c" and None. The default is None.
21862341
2342+
:type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
2343+
:param retry: (Optional) How to retry the RPC. A None value will disable
2344+
retries. A google.api_core.retry.Retry value will enable retries,
2345+
and the object will define retriable response codes and errors and
2346+
configure backoff and timeout options.
2347+
2348+
A google.cloud.storage.retry.ConditionalRetryPolicy value wraps a
2349+
Retry object and activates it only if certain conditions are met.
2350+
This class exists to provide safe defaults for RPC calls that are
2351+
not technically safe to retry normally (due to potential data
2352+
duplication or other side-effects) but become safe to retry if a
2353+
condition such as if_metageneration_match is set.
2354+
2355+
See the retry.py source code and docstrings in this package
2356+
(google.cloud.storage.retry) for information on retry types and how
2357+
to configure them.
2358+
2359+
Media operations (downloads and uploads) do not support non-default
2360+
predicates in a Retry object. The default will always be used. Other
2361+
configuration changes for Retry objects such as delays and deadlines
2362+
are respected.
2363+
21872364
:rtype: dict
21882365
:returns: The parsed JSON from the "200 OK" response. This will be the
21892366
**only** response in the multipart case and it will be the
@@ -2370,6 +2547,28 @@ def upload_from_file(
23702547
attempting to delete the corrupted file. Supported values are
23712548
"md5", "crc32c" and None. The default is None.
23722549
2550+
:type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
2551+
:param retry: (Optional) How to retry the RPC. A None value will disable
2552+
retries. A google.api_core.retry.Retry value will enable retries,
2553+
and the object will define retriable response codes and errors and
2554+
configure backoff and timeout options.
2555+
2556+
A google.cloud.storage.retry.ConditionalRetryPolicy value wraps a
2557+
Retry object and activates it only if certain conditions are met.
2558+
This class exists to provide safe defaults for RPC calls that are
2559+
not technically safe to retry normally (due to potential data
2560+
duplication or other side-effects) but become safe to retry if a
2561+
condition such as if_metageneration_match is set.
2562+
2563+
See the retry.py source code and docstrings in this package
2564+
(google.cloud.storage.retry) for information on retry types and how
2565+
to configure them.
2566+
2567+
Media operations (downloads and uploads) do not support non-default
2568+
predicates in a Retry object. The default will always be used. Other
2569+
configuration changes for Retry objects such as delays and deadlines
2570+
are respected.
2571+
23732572
:raises: :class:`~google.cloud.exceptions.GoogleCloudError`
23742573
if the upload response returns an error status.
23752574
@@ -2513,6 +2712,28 @@ def upload_from_filename(
25132712
google.resumable_media.common.DataCorruption on a mismatch and
25142713
attempting to delete the corrupted file. Supported values are
25152714
"md5", "crc32c" and None. The default is None.
2715+
2716+
:type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
2717+
:param retry: (Optional) How to retry the RPC. A None value will disable
2718+
retries. A google.api_core.retry.Retry value will enable retries,
2719+
and the object will define retriable response codes and errors and
2720+
configure backoff and timeout options.
2721+
2722+
A google.cloud.storage.retry.ConditionalRetryPolicy value wraps a
2723+
Retry object and activates it only if certain conditions are met.
2724+
This class exists to provide safe defaults for RPC calls that are
2725+
not technically safe to retry normally (due to potential data
2726+
duplication or other side-effects) but become safe to retry if a
2727+
condition such as if_metageneration_match is set.
2728+
2729+
See the retry.py source code and docstrings in this package
2730+
(google.cloud.storage.retry) for information on retry types and how
2731+
to configure them.
2732+
2733+
Media operations (downloads and uploads) do not support non-default
2734+
predicates in a Retry object. The default will always be used. Other
2735+
configuration changes for Retry objects such as delays and deadlines
2736+
are respected.
25162737
"""
25172738
content_type = self._get_content_type(content_type, filename=filename)
25182739

@@ -2635,6 +2856,28 @@ def upload_from_string(
26352856
google.resumable_media.common.DataCorruption on a mismatch and
26362857
attempting to delete the corrupted file. Supported values are
26372858
"md5", "crc32c" and None. The default is None.
2859+
2860+
:type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
2861+
:param retry: (Optional) How to retry the RPC. A None value will disable
2862+
retries. A google.api_core.retry.Retry value will enable retries,
2863+
and the object will define retriable response codes and errors and
2864+
configure backoff and timeout options.
2865+
2866+
A google.cloud.storage.retry.ConditionalRetryPolicy value wraps a
2867+
Retry object and activates it only if certain conditions are met.
2868+
This class exists to provide safe defaults for RPC calls that are
2869+
not technically safe to retry normally (due to potential data
2870+
duplication or other side-effects) but become safe to retry if a
2871+
condition such as if_metageneration_match is set.
2872+
2873+
See the retry.py source code and docstrings in this package
2874+
(google.cloud.storage.retry) for information on retry types and how
2875+
to configure them.
2876+
2877+
Media operations (downloads and uploads) do not support non-default
2878+
predicates in a Retry object. The default will always be used. Other
2879+
configuration changes for Retry objects such as delays and deadlines
2880+
are respected.
26382881
"""
26392882
data = _to_bytes(data, encoding="utf-8")
26402883
string_buffer = BytesIO(data)

google/cloud/storage/client.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,27 @@ def download_blob_to_file(
679679
downloads where chunk_size is set) an INFO-level log will be
680680
emitted. Supported values are "md5", "crc32c" and None. The default
681681
is "md5".
682+
retry (google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy)
683+
(Optional) How to retry the RPC. A None value will disable
684+
retries. A google.api_core.retry.Retry value will enable retries,
685+
and the object will define retriable response codes and errors and
686+
configure backoff and timeout options.
687+
688+
A google.cloud.storage.retry.ConditionalRetryPolicy value wraps a
689+
Retry object and activates it only if certain conditions are met.
690+
This class exists to provide safe defaults for RPC calls that are
691+
not technically safe to retry normally (due to potential data
692+
duplication or other side-effects) but become safe to retry if a
693+
condition such as if_metageneration_match is set.
694+
695+
See the retry.py source code and docstrings in this package
696+
(google.cloud.storage.retry) for information on retry types and how
697+
to configure them.
698+
699+
Media operations (downloads and uploads) do not support non-default
700+
predicates in a Retry object. The default will always be used. Other
701+
configuration changes for Retry objects such as delays and deadlines
702+
are respected.
682703
683704
Examples:
684705
Download a blob using a blob resource.

0 commit comments

Comments
 (0)