79
79
when sending metadata for ACLs to the API.
80
80
"""
81
81
82
+ from google .cloud .storage .constants import _DEFAULT_TIMEOUT
83
+
82
84
83
85
class _ACLEntity (object ):
84
86
"""Class representing a set of roles for an entity.
@@ -206,10 +208,18 @@ class ACL(object):
206
208
def __init__ (self ):
207
209
self .entities = {}
208
210
209
- def _ensure_loaded (self ):
210
- """Load if not already loaded."""
211
+ def _ensure_loaded (self , timeout = _DEFAULT_TIMEOUT ):
212
+ """Load if not already loaded.
213
+
214
+ :type timeout: float or tuple
215
+ :param timeout: (optional) The amount of time, in seconds, to wait
216
+ for the server response.
217
+
218
+ Can also be passed as a tuple (connect_timeout, read_timeout).
219
+ See :meth:`requests.Session.request` documentation for details.
220
+ """
211
221
if not self .loaded :
212
- self .reload ()
222
+ self .reload (timeout = timeout )
213
223
214
224
@classmethod
215
225
def validate_predefined (cls , predefined ):
@@ -415,7 +425,7 @@ def _require_client(self, client):
415
425
client = self .client
416
426
return client
417
427
418
- def reload (self , client = None ):
428
+ def reload (self , client = None , timeout = _DEFAULT_TIMEOUT ):
419
429
"""Reload the ACL data from Cloud Storage.
420
430
421
431
If :attr:`user_project` is set, bills the API request to that project.
@@ -424,6 +434,12 @@ def reload(self, client=None):
424
434
``NoneType``
425
435
:param client: Optional. The client to use. If not passed, falls back
426
436
to the ``client`` stored on the ACL's parent.
437
+ :type timeout: float or tuple
438
+ :param timeout: (optional) The amount of time, in seconds, to wait
439
+ for the server response.
440
+
441
+ Can also be passed as a tuple (connect_timeout, read_timeout).
442
+ See :meth:`requests.Session.request` documentation for details.
427
443
"""
428
444
path = self .reload_path
429
445
client = self ._require_client (client )
@@ -435,13 +451,13 @@ def reload(self, client=None):
435
451
self .entities .clear ()
436
452
437
453
found = client ._connection .api_request (
438
- method = "GET" , path = path , query_params = query_params
454
+ method = "GET" , path = path , query_params = query_params , timeout = timeout
439
455
)
440
456
self .loaded = True
441
457
for entry in found .get ("items" , ()):
442
458
self .add_entity (self .entity_from_dict (entry ))
443
459
444
- def _save (self , acl , predefined , client ):
460
+ def _save (self , acl , predefined , client , timeout = _DEFAULT_TIMEOUT ):
445
461
"""Helper for :meth:`save` and :meth:`save_predefined`.
446
462
447
463
:type acl: :class:`google.cloud.storage.acl.ACL`, or a compatible list.
@@ -457,6 +473,12 @@ def _save(self, acl, predefined, client):
457
473
``NoneType``
458
474
:param client: Optional. The client to use. If not passed, falls back
459
475
to the ``client`` stored on the ACL's parent.
476
+ :type timeout: float or tuple
477
+ :param timeout: (optional) The amount of time, in seconds, to wait
478
+ for the server response.
479
+
480
+ Can also be passed as a tuple (connect_timeout, read_timeout).
481
+ See :meth:`requests.Session.request` documentation for details.
460
482
"""
461
483
query_params = {"projection" : "full" }
462
484
if predefined is not None :
@@ -474,13 +496,14 @@ def _save(self, acl, predefined, client):
474
496
path = path ,
475
497
data = {self ._URL_PATH_ELEM : list (acl )},
476
498
query_params = query_params ,
499
+ timeout = timeout ,
477
500
)
478
501
self .entities .clear ()
479
502
for entry in result .get (self ._URL_PATH_ELEM , ()):
480
503
self .add_entity (self .entity_from_dict (entry ))
481
504
self .loaded = True
482
505
483
- def save (self , acl = None , client = None ):
506
+ def save (self , acl = None , client = None , timeout = _DEFAULT_TIMEOUT ):
484
507
"""Save this ACL for the current bucket.
485
508
486
509
If :attr:`user_project` is set, bills the API request to that project.
@@ -493,6 +516,12 @@ def save(self, acl=None, client=None):
493
516
``NoneType``
494
517
:param client: Optional. The client to use. If not passed, falls back
495
518
to the ``client`` stored on the ACL's parent.
519
+ :type timeout: float or tuple
520
+ :param timeout: (optional) The amount of time, in seconds, to wait
521
+ for the server response.
522
+
523
+ Can also be passed as a tuple (connect_timeout, read_timeout).
524
+ See :meth:`requests.Session.request` documentation for details.
496
525
"""
497
526
if acl is None :
498
527
acl = self
@@ -501,9 +530,9 @@ def save(self, acl=None, client=None):
501
530
save_to_backend = True
502
531
503
532
if save_to_backend :
504
- self ._save (acl , None , client )
533
+ self ._save (acl , None , client , timeout = timeout )
505
534
506
- def save_predefined (self , predefined , client = None ):
535
+ def save_predefined (self , predefined , client = None , timeout = _DEFAULT_TIMEOUT ):
507
536
"""Save this ACL for the current bucket using a predefined ACL.
508
537
509
538
If :attr:`user_project` is set, bills the API request to that project.
@@ -519,11 +548,17 @@ def save_predefined(self, predefined, client=None):
519
548
``NoneType``
520
549
:param client: Optional. The client to use. If not passed, falls back
521
550
to the ``client`` stored on the ACL's parent.
551
+ :type timeout: float or tuple
552
+ :param timeout: (optional) The amount of time, in seconds, to wait
553
+ for the server response.
554
+
555
+ Can also be passed as a tuple (connect_timeout, read_timeout).
556
+ See :meth:`requests.Session.request` documentation for details.
522
557
"""
523
558
predefined = self .validate_predefined (predefined )
524
- self ._save (None , predefined , client )
559
+ self ._save (None , predefined , client , timeout = timeout )
525
560
526
- def clear (self , client = None ):
561
+ def clear (self , client = None , timeout = _DEFAULT_TIMEOUT ):
527
562
"""Remove all ACL entries.
528
563
529
564
If :attr:`user_project` is set, bills the API request to that project.
@@ -537,8 +572,14 @@ def clear(self, client=None):
537
572
``NoneType``
538
573
:param client: Optional. The client to use. If not passed, falls back
539
574
to the ``client`` stored on the ACL's parent.
575
+ :type timeout: float or tuple
576
+ :param timeout: (optional) The amount of time, in seconds, to wait
577
+ for the server response.
578
+
579
+ Can also be passed as a tuple (connect_timeout, read_timeout).
580
+ See :meth:`requests.Session.request` documentation for details.
540
581
"""
541
- self .save ([], client = client )
582
+ self .save ([], client = client , timeout = timeout )
542
583
543
584
544
585
class BucketACL (ACL ):
0 commit comments