From bf8b655b57f13d231c9f901be012972b6cd17039 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Wed, 6 May 2015 14:18:43 -0700 Subject: [PATCH] Making Blob.exists() work as Bucket.exists(). Also returning the _BucketIterator directly in storage.api.list_buckets() rather than wrapping it in iter(). --- gcloud/storage/api.py | 2 +- gcloud/storage/blob.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/gcloud/storage/api.py b/gcloud/storage/api.py index b25a5149ca87..b16ce1842e12 100644 --- a/gcloud/storage/api.py +++ b/gcloud/storage/api.py @@ -126,7 +126,7 @@ def list_buckets(project=None, max_results=None, page_token=None, prefix=None, # class has it as a reserved property. if page_token is not None: result.next_page_token = page_token - return iter(result) + return result def get_bucket(bucket_name, connection=None): diff --git a/gcloud/storage/blob.py b/gcloud/storage/blob.py index dd55525a6e25..c916bdd6acd5 100644 --- a/gcloud/storage/blob.py +++ b/gcloud/storage/blob.py @@ -226,9 +226,14 @@ def exists(self, connection=None): # We only need the status code (200 or not) so we seek to # minimize the returned payload. query_params = {'fields': 'name'} + # We intentionally pass `_target_object=None` since fields=name + # would limit the local properties. connection.api_request(method='GET', path=self.path, query_params=query_params, - _target_object=self) + _target_object=None) + # NOTE: This will not fail immediately in a batch. However, when + # Batch.finish() is called, the resulting `NotFound` will be + # raised. return True except NotFound: return False