22
33:class:`gcloud.storage.bucket.Bucket` has a getting method that creates
44an ACL object under the hood, and you can interact with that using
5- :func:`gcloud.storage.bucket.Bucket.get_acl `::
5+ :func:`gcloud.storage.bucket.Bucket.acl `::
66
77 >>> from gcloud import storage
88 >>> connection = storage.get_connection(project, email, key_path)
99 >>> bucket = connection.get_bucket(bucket_name)
10- >>> acl = bucket.get_acl()
10+ >>> acl = bucket.acl
1111
1212Adding and removing permissions can be done with the following methods
1313(in increasing order of granularity):
@@ -172,12 +172,19 @@ class ACL(object):
172172 def __init__ (self ):
173173 self .entities = {}
174174
175+ def _ensure_loaded (self ):
176+ """Load if not already loaded."""
177+ if not self .loaded :
178+ self .reload ()
179+
175180 def reset (self ):
176181 """Remove all entities from the ACL, and clear the ``loaded`` flag."""
177182 self .entities .clear ()
178183 self .loaded = False
179184
180185 def __iter__ (self ):
186+ self ._ensure_loaded ()
187+
181188 for entity in self .entities .itervalues ():
182189 for role in entity .get_roles ():
183190 if role :
@@ -224,6 +231,7 @@ def has_entity(self, entity):
224231 :rtype: bool
225232 :returns: True of the entity exists in the ACL.
226233 """
234+ self ._ensure_loaded ()
227235 return str (entity ) in self .entities
228236
229237 def get_entity (self , entity , default = None ):
@@ -240,6 +248,7 @@ def get_entity(self, entity, default=None):
240248 :returns: The corresponding entity or the value provided
241249 to ``default``.
242250 """
251+ self ._ensure_loaded ()
243252 return self .entities .get (str (entity ), default )
244253
245254 def add_entity (self , entity ):
@@ -248,8 +257,8 @@ def add_entity(self, entity):
248257 :type entity: :class:`_ACLEntity`
249258 :param entity: The entity to add to this ACL.
250259 """
260+ self ._ensure_loaded ()
251261 self .entities [str (entity )] = entity
252- self .loaded = True
253262
254263 def entity (self , entity_type , identifier = None ):
255264 """Factory method for creating an Entity.
@@ -332,6 +341,7 @@ def get_entities(self):
332341 :rtype: list of :class:`_ACLEntity` objects
333342 :returns: A list of all Entity objects.
334343 """
344+ self ._ensure_loaded ()
335345 return self .entities .values ()
336346
337347 def reload (self ):
@@ -381,12 +391,10 @@ def reload(self):
381391
382392 url_path = '%s/%s' % (self .bucket .path , self ._URL_PATH_ELEM )
383393 found = self .bucket .connection .api_request (method = 'GET' , path = url_path )
394+ self .loaded = True
384395 for entry in found ['items' ]:
385396 self .add_entity (self .entity_from_dict (entry ))
386397
387- # Even if we fetch no entries, the ACL is still loaded.
388- self .loaded = True
389-
390398 return self
391399
392400 def save (self , acl = None ):
@@ -407,7 +415,7 @@ def save(self, acl=None):
407415
408416 >>> bucket1 = connection.get_bucket(bucket1_name)
409417 >>> bucket2 = connection.get_bucket(bucket2_name)
410- >>> bucket2.acl.save(bucket1.get_acl() )
418+ >>> bucket2.acl.save(bucket1.acl )
411419
412420 :type acl: :class:`gcloud.storage.acl.ACL`, or a compatible list.
413421 :param acl: The ACL object to save. If left blank, this will save
@@ -489,12 +497,10 @@ def reload(self):
489497
490498 url_path = '%s/acl' % self .key .path
491499 found = self .key .connection .api_request (method = 'GET' , path = url_path )
500+ self .loaded = True
492501 for entry in found ['items' ]:
493502 self .add_entity (self .entity_from_dict (entry ))
494503
495- # Even if we fetch no entries, the ACL is still loaded.
496- self .loaded = True
497-
498504 return self
499505
500506 def save (self , acl = None ):
0 commit comments