7979when sending metadata for ACLs to the API.
8080"""
8181
82+ from google .cloud .storage .constants import _DEFAULT_TIMEOUT
83+
8284
8385class _ACLEntity (object ):
8486 """Class representing a set of roles for an entity.
@@ -206,10 +208,18 @@ class ACL(object):
206208 def __init__ (self ):
207209 self .entities = {}
208210
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+ """
211221 if not self .loaded :
212- self .reload ()
222+ self .reload (timeout = timeout )
213223
214224 @classmethod
215225 def validate_predefined (cls , predefined ):
@@ -415,7 +425,7 @@ def _require_client(self, client):
415425 client = self .client
416426 return client
417427
418- def reload (self , client = None ):
428+ def reload (self , client = None , timeout = _DEFAULT_TIMEOUT ):
419429 """Reload the ACL data from Cloud Storage.
420430
421431 If :attr:`user_project` is set, bills the API request to that project.
@@ -424,6 +434,12 @@ def reload(self, client=None):
424434 ``NoneType``
425435 :param client: Optional. The client to use. If not passed, falls back
426436 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.
427443 """
428444 path = self .reload_path
429445 client = self ._require_client (client )
@@ -435,13 +451,13 @@ def reload(self, client=None):
435451 self .entities .clear ()
436452
437453 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
439455 )
440456 self .loaded = True
441457 for entry in found .get ("items" , ()):
442458 self .add_entity (self .entity_from_dict (entry ))
443459
444- def _save (self , acl , predefined , client ):
460+ def _save (self , acl , predefined , client , timeout = _DEFAULT_TIMEOUT ):
445461 """Helper for :meth:`save` and :meth:`save_predefined`.
446462
447463 :type acl: :class:`google.cloud.storage.acl.ACL`, or a compatible list.
@@ -457,6 +473,12 @@ def _save(self, acl, predefined, client):
457473 ``NoneType``
458474 :param client: Optional. The client to use. If not passed, falls back
459475 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.
460482 """
461483 query_params = {"projection" : "full" }
462484 if predefined is not None :
@@ -474,13 +496,14 @@ def _save(self, acl, predefined, client):
474496 path = path ,
475497 data = {self ._URL_PATH_ELEM : list (acl )},
476498 query_params = query_params ,
499+ timeout = timeout ,
477500 )
478501 self .entities .clear ()
479502 for entry in result .get (self ._URL_PATH_ELEM , ()):
480503 self .add_entity (self .entity_from_dict (entry ))
481504 self .loaded = True
482505
483- def save (self , acl = None , client = None ):
506+ def save (self , acl = None , client = None , timeout = _DEFAULT_TIMEOUT ):
484507 """Save this ACL for the current bucket.
485508
486509 If :attr:`user_project` is set, bills the API request to that project.
@@ -493,6 +516,12 @@ def save(self, acl=None, client=None):
493516 ``NoneType``
494517 :param client: Optional. The client to use. If not passed, falls back
495518 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.
496525 """
497526 if acl is None :
498527 acl = self
@@ -501,9 +530,9 @@ def save(self, acl=None, client=None):
501530 save_to_backend = True
502531
503532 if save_to_backend :
504- self ._save (acl , None , client )
533+ self ._save (acl , None , client , timeout = timeout )
505534
506- def save_predefined (self , predefined , client = None ):
535+ def save_predefined (self , predefined , client = None , timeout = _DEFAULT_TIMEOUT ):
507536 """Save this ACL for the current bucket using a predefined ACL.
508537
509538 If :attr:`user_project` is set, bills the API request to that project.
@@ -519,11 +548,17 @@ def save_predefined(self, predefined, client=None):
519548 ``NoneType``
520549 :param client: Optional. The client to use. If not passed, falls back
521550 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.
522557 """
523558 predefined = self .validate_predefined (predefined )
524- self ._save (None , predefined , client )
559+ self ._save (None , predefined , client , timeout = timeout )
525560
526- def clear (self , client = None ):
561+ def clear (self , client = None , timeout = _DEFAULT_TIMEOUT ):
527562 """Remove all ACL entries.
528563
529564 If :attr:`user_project` is set, bills the API request to that project.
@@ -537,8 +572,14 @@ def clear(self, client=None):
537572 ``NoneType``
538573 :param client: Optional. The client to use. If not passed, falls back
539574 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.
540581 """
541- self .save ([], client = client )
582+ self .save ([], client = client , timeout = timeout )
542583
543584
544585class BucketACL (ACL ):
0 commit comments