@@ -101,8 +101,11 @@ class Bucket(_PropertyMixin):
101101 """
102102 _iterator_class = _BlobIterator
103103
104- _MAX_OBJECTS_FOR_BUCKET_DELETE = 256
105- """Maximum number of existing objects allowed in Bucket.delete()."""
104+ _MAX_OBJECTS_FOR_ITERATION = 256
105+ """Maximum number of existing objects allowed in iteration.
106+
107+ This is used in Bucket.delete() and Bucket.make_public().
108+ """
106109
107110 def __init__ (self , name = None ):
108111 super (Bucket , self ).__init__ (name = name )
@@ -349,15 +352,15 @@ def delete(self, force=False, connection=None):
349352 connection = _require_connection (connection )
350353 if force :
351354 blobs = list (self .list_blobs (
352- max_results = self ._MAX_OBJECTS_FOR_BUCKET_DELETE + 1 ,
355+ max_results = self ._MAX_OBJECTS_FOR_ITERATION + 1 ,
353356 connection = connection ))
354- if len (blobs ) > self ._MAX_OBJECTS_FOR_BUCKET_DELETE :
357+ if len (blobs ) > self ._MAX_OBJECTS_FOR_ITERATION :
355358 message = (
356359 'Refusing to delete bucket with more than '
357360 '%d objects. If you actually want to delete '
358361 'this bucket, please delete the objects '
359362 'yourself before calling Bucket.delete().'
360- ) % (self ._MAX_OBJECTS_FOR_BUCKET_DELETE ,)
363+ ) % (self ._MAX_OBJECTS_FOR_ITERATION ,)
361364 raise ValueError (message )
362365
363366 # Ignore 404 errors on delete.
@@ -849,6 +852,10 @@ def disable_website(self):
849852 def make_public (self , recursive = False , future = False , connection = None ):
850853 """Make a bucket public.
851854
855+ If ``recursive=True`` and the bucket contains more than 256
856+ objects / blobs this will cowardly refuse to make the objects public.
857+ This is to prevent extremely long runtime of this method.
858+
852859 :type recursive: boolean
853860 :param recursive: If True, this will make all blobs inside the bucket
854861 public as well.
@@ -875,7 +882,19 @@ def make_public(self, recursive=False, future=False, connection=None):
875882 doa .save (connection = connection )
876883
877884 if recursive :
878- for blob in self .list_blobs (projection = 'full' ,
879- connection = connection ):
885+ blobs = list (self .list_blobs (
886+ projection = 'full' ,
887+ max_results = self ._MAX_OBJECTS_FOR_ITERATION + 1 ,
888+ connection = connection ))
889+ if len (blobs ) > self ._MAX_OBJECTS_FOR_ITERATION :
890+ message = (
891+ 'Refusing to make public recursively with more than '
892+ '%d objects. If you actually want to make every object '
893+ 'in this bucket public, please do it on the objects '
894+ 'yourself.'
895+ ) % (self ._MAX_OBJECTS_FOR_ITERATION ,)
896+ raise ValueError (message )
897+
898+ for blob in blobs :
880899 blob .acl .all ().grant_read ()
881900 blob .acl .save (connection = connection )
0 commit comments