2323 False
2424
2525If you want to get all the blobs in the bucket, you can use
26- :func:`get_all_blobs <gcloud.storage.bucket.Bucket.get_all_blobs >`::
26+ :func:`list_blobs <gcloud.storage.bucket.Bucket.list_blobs >`::
2727
28- >>> blobs = bucket.get_all_blobs ()
28+ >>> blobs = bucket.list_blobs ()
2929
3030You can also use the bucket as an iterator::
3131
@@ -104,7 +104,7 @@ def __repr__(self):
104104 return '<Bucket: %s>' % self .name
105105
106106 def __iter__ (self ):
107- return iter (self ._iterator_class ( bucket = self ))
107+ return iter (self .list_blobs ( ))
108108
109109 def __contains__ (self , blob_name ):
110110 blob = Blob (blob_name , bucket = self )
@@ -223,56 +223,68 @@ def get_blob(self, blob_name):
223223 except NotFound :
224224 return None
225225
226- def get_all_blobs (self ):
227- """List all the blobs in this bucket.
228-
229- This will **not** retrieve all the data for all the blobs, it
230- will only retrieve the blob paths.
231-
232- This is equivalent to::
233-
234- blobs = [blob for blob in bucket]
226+ def list_blobs (self , max_results = None , page_token = None , prefix = None ,
227+ delimiter = None , versions = None ,
228+ projection = 'noAcl' , fields = None ):
229+ """Return an iterator used to find blobs in the bucket.
235230
236- :rtype: list of :class:`gcloud.storage.blob.Blob`
237- :returns: A list of all the Blob objects in this bucket.
238- """
239- return list (self )
231+ :type max_results: integer or ``NoneType``
232+ :param max_results: maximum number of blobs to return.
240233
241- def iterator ( self , prefix = None , delimiter = None , max_results = None ,
242- versions = None ):
243- """Return an iterator used to find blobs in the bucket .
234+ :type page_token: string
235+ :param page_token: opaque marker for the next "page" of blobs. If not
236+ passed, will return the first page of blobs .
244237
245- :type prefix: string or None
238+ :type prefix: string or ``NoneType``
246239 :param prefix: optional prefix used to filter blobs.
247240
248- :type delimiter: string or None
241+ :type delimiter: string or ``NoneType``
249242 :param delimiter: optional delimter, used with ``prefix`` to
250243 emulate hierarchy.
251244
252- :type max_results: integer or None
253- :param max_results: maximum number of blobs to return.
254-
255- :type versions: boolean or None
245+ :type versions: boolean or ``NoneType``
256246 :param versions: whether object versions should be returned as
257247 separate blobs.
258248
259- :rtype: :class:`_BlobIterator`
249+ :type projection: string or ``NoneType``
250+ :param projection: If used, must be 'full' or 'noAcl'. Defaults to
251+ 'noAcl'. Specifies the set of properties to return.
252+
253+ :type fields: string or ``NoneType``
254+ :param fields: Selector specifying which fields to include in a
255+ partial response. Must be a list of fields. For example
256+ to get a partial response with just the next page token
257+ and the language of each blob returned:
258+ 'items/contentLanguage,nextPageToken'
259+
260+ :rtype: :class:`_BlobIterator`.
261+ :returns: An iterator of blobs.
260262 """
261263 extra_params = {}
262264
265+ if max_results is not None :
266+ extra_params ['maxResults' ] = max_results
267+
263268 if prefix is not None :
264269 extra_params ['prefix' ] = prefix
265270
266271 if delimiter is not None :
267272 extra_params ['delimiter' ] = delimiter
268273
269- if max_results is not None :
270- extra_params ['maxResults' ] = max_results
271-
272274 if versions is not None :
273275 extra_params ['versions' ] = versions
274276
275- return self ._iterator_class (self , extra_params = extra_params )
277+ extra_params ['projection' ] = projection
278+
279+ if fields is not None :
280+ extra_params ['fields' ] = fields
281+
282+ result = self ._iterator_class (self , extra_params = extra_params )
283+ # Page token must be handled specially since the base `Iterator`
284+ # class has it as a reserved property.
285+ if page_token is not None :
286+ result .next_page_token = page_token
287+ return result
276288
277289 def delete (self , force = False ):
278290 """Delete this bucket.
@@ -297,7 +309,7 @@ def delete(self, force=False):
297309 contains more than 256 objects / blobs.
298310 """
299311 if force :
300- blobs = list (self .iterator (
312+ blobs = list (self .list_blobs (
301313 max_results = self ._MAX_OBJECTS_FOR_BUCKET_DELETE + 1 ))
302314 if len (blobs ) > self ._MAX_OBJECTS_FOR_BUCKET_DELETE :
303315 message = (
@@ -325,7 +337,7 @@ def delete_blob(self, blob_name):
325337 >>> from gcloud import storage
326338 >>> connection = storage.get_connection()
327339 >>> bucket = storage.get_bucket('my-bucket', connection=connection)
328- >>> print bucket.get_all_blobs ()
340+ >>> print bucket.list_blobs ()
329341 [<Blob: my-bucket, my-file.txt>]
330342 >>> bucket.delete_blob('my-file.txt')
331343 >>> try:
@@ -408,7 +420,7 @@ def upload_file(self, filename, blob_name=None):
408420 >>> connection = storage.get_connection()
409421 >>> bucket = storage.get_bucket('my-bucket', connection=connection)
410422 >>> bucket.upload_file('~/my-file.txt', 'remote-text-file.txt')
411- >>> print bucket.get_all_blobs ()
423+ >>> print bucket.list_blobs ()
412424 [<Blob: my-bucket, remote-text-file.txt>]
413425
414426 If you don't provide a blob name, we will try to upload the file
@@ -418,7 +430,7 @@ def upload_file(self, filename, blob_name=None):
418430 >>> connection = storage.get_connection()
419431 >>> bucket = storage.get_bucket('my-bucket', connection=connection)
420432 >>> bucket.upload_file('~/my-file.txt')
421- >>> print bucket.get_all_blobs ()
433+ >>> print bucket.list_blobs ()
422434 [<Blob: my-bucket, my-file.txt>]
423435
424436 :type filename: string
@@ -450,7 +462,7 @@ def upload_file_object(self, file_obj, blob_name=None):
450462 >>> connection = storage.get_connection()
451463 >>> bucket = storage.get_bucket('my-bucket', connection=connection)
452464 >>> bucket.upload_file(open('~/my-file.txt'), 'remote-text-file.txt')
453- >>> print bucket.get_all_blobs ()
465+ >>> print bucket.list_blobs ()
454466 [<Blob: my-bucket, remote-text-file.txt>]
455467
456468 If you don't provide a blob name, we will try to upload the file
@@ -460,7 +472,7 @@ def upload_file_object(self, file_obj, blob_name=None):
460472 >>> connection = storage.get_connection()
461473 >>> bucket = storage.get_bucket('my-bucket', connection=connection)
462474 >>> bucket.upload_file(open('~/my-file.txt'))
463- >>> print bucket.get_all_blobs ()
475+ >>> print bucket.list_blobs ()
464476 [<Blob: my-bucket, my-file.txt>]
465477
466478 :type file_obj: file
0 commit comments