59
59
from google .cloud ._helpers import _rfc3339_nanos_to_datetime
60
60
from google .cloud ._helpers import _to_bytes
61
61
from google .cloud .exceptions import NotFound
62
+ from google .cloud .storage ._helpers import _add_etag_match_headers
62
63
from google .cloud .storage ._helpers import _add_generation_match_parameters
63
64
from google .cloud .storage ._helpers import _PropertyMixin
64
65
from google .cloud .storage ._helpers import _scalar_property
@@ -634,6 +635,8 @@ def generate_signed_url(
634
635
def exists (
635
636
self ,
636
637
client = None ,
638
+ if_etag_match = None ,
639
+ if_etag_not_match = None ,
637
640
if_generation_match = None ,
638
641
if_generation_not_match = None ,
639
642
if_metageneration_match = None ,
@@ -651,6 +654,14 @@ def exists(
651
654
(Optional) The client to use. If not passed, falls back to the
652
655
``client`` stored on the blob's bucket.
653
656
657
+ :type if_etag_match: Union[str, Set[str]]
658
+ :param if_etag_match:
659
+ (Optional) See :ref:`using-if-etag-match`
660
+
661
+ :type if_etag_not_match: Union[str, Set[str]]
662
+ :param if_etag_not_match:
663
+ (Optional) See :ref:`using-if-etag-not-match`
664
+
654
665
:type if_generation_match: long
655
666
:param if_generation_match:
656
667
(Optional) See :ref:`using-if-generation-match`
@@ -692,12 +703,19 @@ def exists(
692
703
if_metageneration_match = if_metageneration_match ,
693
704
if_metageneration_not_match = if_metageneration_not_match ,
694
705
)
706
+
707
+ headers = {}
708
+ _add_etag_match_headers (
709
+ headers , if_etag_match = if_etag_match , if_etag_not_match = if_etag_not_match
710
+ )
711
+
695
712
try :
696
713
# We intentionally pass `_target_object=None` since fields=name
697
714
# would limit the local properties.
698
715
client ._get_resource (
699
716
self .path ,
700
717
query_params = query_params ,
718
+ headers = headers ,
701
719
timeout = timeout ,
702
720
retry = retry ,
703
721
_target_object = None ,
@@ -1002,6 +1020,8 @@ def download_to_file(
1002
1020
start = None ,
1003
1021
end = None ,
1004
1022
raw_download = False ,
1023
+ if_etag_match = None ,
1024
+ if_etag_not_match = None ,
1005
1025
if_generation_match = None ,
1006
1026
if_generation_not_match = None ,
1007
1027
if_metageneration_match = None ,
@@ -1057,6 +1077,14 @@ def download_to_file(
1057
1077
:param raw_download:
1058
1078
(Optional) If true, download the object without any expansion.
1059
1079
1080
+ :type if_etag_match: Union[str, Set[str]]
1081
+ :param if_etag_match:
1082
+ (Optional) See :ref:`using-if-etag-match`
1083
+
1084
+ :type if_etag_not_match: Union[str, Set[str]]
1085
+ :param if_etag_not_match:
1086
+ (Optional) See :ref:`using-if-etag-not-match`
1087
+
1060
1088
:type if_generation_match: long
1061
1089
:param if_generation_match:
1062
1090
(Optional) See :ref:`using-if-generation-match`
@@ -1121,6 +1149,8 @@ def download_to_file(
1121
1149
start = start ,
1122
1150
end = end ,
1123
1151
raw_download = raw_download ,
1152
+ if_etag_match = if_etag_match ,
1153
+ if_etag_not_match = if_etag_not_match ,
1124
1154
if_generation_match = if_generation_match ,
1125
1155
if_generation_not_match = if_generation_not_match ,
1126
1156
if_metageneration_match = if_metageneration_match ,
@@ -1137,6 +1167,8 @@ def download_to_filename(
1137
1167
start = None ,
1138
1168
end = None ,
1139
1169
raw_download = False ,
1170
+ if_etag_match = None ,
1171
+ if_etag_not_match = None ,
1140
1172
if_generation_match = None ,
1141
1173
if_generation_not_match = None ,
1142
1174
if_metageneration_match = None ,
@@ -1168,6 +1200,14 @@ def download_to_filename(
1168
1200
:param raw_download:
1169
1201
(Optional) If true, download the object without any expansion.
1170
1202
1203
+ :type if_etag_match: Union[str, Set[str]]
1204
+ :param if_etag_match:
1205
+ (Optional) See :ref:`using-if-etag-match`
1206
+
1207
+ :type if_etag_not_match: Union[str, Set[str]]
1208
+ :param if_etag_not_match:
1209
+ (Optional) See :ref:`using-if-etag-not-match`
1210
+
1171
1211
:type if_generation_match: long
1172
1212
:param if_generation_match:
1173
1213
(Optional) See :ref:`using-if-generation-match`
@@ -1233,6 +1273,8 @@ def download_to_filename(
1233
1273
start = start ,
1234
1274
end = end ,
1235
1275
raw_download = raw_download ,
1276
+ if_etag_match = if_etag_match ,
1277
+ if_etag_not_match = if_etag_not_match ,
1236
1278
if_generation_match = if_generation_match ,
1237
1279
if_generation_not_match = if_generation_not_match ,
1238
1280
if_metageneration_match = if_metageneration_match ,
@@ -1260,6 +1302,8 @@ def download_as_bytes(
1260
1302
start = None ,
1261
1303
end = None ,
1262
1304
raw_download = False ,
1305
+ if_etag_match = None ,
1306
+ if_etag_not_match = None ,
1263
1307
if_generation_match = None ,
1264
1308
if_generation_not_match = None ,
1265
1309
if_metageneration_match = None ,
@@ -1288,6 +1332,14 @@ def download_as_bytes(
1288
1332
:param raw_download:
1289
1333
(Optional) If true, download the object without any expansion.
1290
1334
1335
+ :type if_etag_match: Union[str, Set[str]]
1336
+ :param if_etag_match:
1337
+ (Optional) See :ref:`using-if-etag-match`
1338
+
1339
+ :type if_etag_not_match: Union[str, Set[str]]
1340
+ :param if_etag_not_match:
1341
+ (Optional) See :ref:`using-if-etag-not-match`
1342
+
1291
1343
:type if_generation_match: long
1292
1344
:param if_generation_match:
1293
1345
(Optional) See :ref:`using-if-generation-match`
@@ -1355,6 +1407,8 @@ def download_as_bytes(
1355
1407
start = start ,
1356
1408
end = end ,
1357
1409
raw_download = raw_download ,
1410
+ if_etag_match = if_etag_match ,
1411
+ if_etag_not_match = if_etag_not_match ,
1358
1412
if_generation_match = if_generation_match ,
1359
1413
if_generation_not_match = if_generation_not_match ,
1360
1414
if_metageneration_match = if_metageneration_match ,
@@ -1371,6 +1425,8 @@ def download_as_string(
1371
1425
start = None ,
1372
1426
end = None ,
1373
1427
raw_download = False ,
1428
+ if_etag_match = None ,
1429
+ if_etag_not_match = None ,
1374
1430
if_generation_match = None ,
1375
1431
if_generation_not_match = None ,
1376
1432
if_metageneration_match = None ,
@@ -1401,6 +1457,14 @@ def download_as_string(
1401
1457
:param raw_download:
1402
1458
(Optional) If true, download the object without any expansion.
1403
1459
1460
+ :type if_etag_match: Union[str, Set[str]]
1461
+ :param if_etag_match:
1462
+ (Optional) See :ref:`using-if-etag-match`
1463
+
1464
+ :type if_etag_not_match: Union[str, Set[str]]
1465
+ :param if_etag_not_match:
1466
+ (Optional) See :ref:`using-if-etag-not-match`
1467
+
1404
1468
:type if_generation_match: long
1405
1469
:param if_generation_match:
1406
1470
(Optional) See :ref:`using-if-generation-match`
@@ -1460,6 +1524,8 @@ def download_as_string(
1460
1524
start = start ,
1461
1525
end = end ,
1462
1526
raw_download = raw_download ,
1527
+ if_etag_match = if_etag_match ,
1528
+ if_etag_not_match = if_etag_not_match ,
1463
1529
if_generation_match = if_generation_match ,
1464
1530
if_generation_not_match = if_generation_not_match ,
1465
1531
if_metageneration_match = if_metageneration_match ,
@@ -1475,6 +1541,8 @@ def download_as_text(
1475
1541
end = None ,
1476
1542
raw_download = False ,
1477
1543
encoding = None ,
1544
+ if_etag_match = None ,
1545
+ if_etag_not_match = None ,
1478
1546
if_generation_match = None ,
1479
1547
if_generation_not_match = None ,
1480
1548
if_metageneration_match = None ,
@@ -1507,6 +1575,14 @@ def download_as_text(
1507
1575
downloaded bytes. Defaults to the ``charset`` param of
1508
1576
attr:`content_type`, or else to "utf-8".
1509
1577
1578
+ :type if_etag_match: Union[str, Set[str]]
1579
+ :param if_etag_match:
1580
+ (Optional) See :ref:`using-if-etag-match`
1581
+
1582
+ :type if_etag_not_match: Union[str, Set[str]]
1583
+ :param if_etag_not_match:
1584
+ (Optional) See :ref:`using-if-etag-not-match`
1585
+
1510
1586
:type if_generation_match: long
1511
1587
:param if_generation_match:
1512
1588
(Optional) See :ref:`using-if-generation-match`
@@ -1558,6 +1634,8 @@ def download_as_text(
1558
1634
start = start ,
1559
1635
end = end ,
1560
1636
raw_download = raw_download ,
1637
+ if_etag_match = if_etag_match ,
1638
+ if_etag_not_match = if_etag_not_match ,
1561
1639
if_generation_match = if_generation_match ,
1562
1640
if_generation_not_match = if_generation_not_match ,
1563
1641
if_metageneration_match = if_metageneration_match ,
0 commit comments