@@ -169,7 +169,11 @@ def __iter__(self):
169169 return iter (_BucketIterator (connection = self ))
170170
171171 def __contains__ (self , bucket_name ):
172- return self .lookup (bucket_name ) is not None
172+ try :
173+ self .get_bucket (bucket_name )
174+ return True
175+ except NotFound :
176+ return False
173177
174178 def build_api_url (self , path , query_params = None , api_base_url = None ,
175179 api_version = None , upload = False ):
@@ -357,10 +361,7 @@ def get_bucket(self, bucket_name):
357361 """Get a bucket by name.
358362
359363 If the bucket isn't found, this will raise a
360- :class:`gcloud.exceptions.NotFound`. If you would
361- rather get a bucket by name, and return ``None`` if the bucket
362- isn't found (like ``{}.get('...')``) then use
363- :func:`Connection.lookup`.
364+ :class:`gcloud.storage.exceptions.NotFound`.
364365
365366 For example::
366367
@@ -383,32 +384,6 @@ def get_bucket(self, bucket_name):
383384 response = self .api_request (method = 'GET' , path = bucket .path )
384385 return Bucket (properties = response , connection = self )
385386
386- def lookup (self , bucket_name ):
387- """Get a bucket by name, returning None if not found.
388-
389- You can use this if you would rather checking for a None value
390- than catching an exception::
391-
392- >>> from gcloud import storage
393- >>> connection = storage.get_connection(project)
394- >>> bucket = connection.get_bucket('doesnt-exist')
395- >>> print bucket
396- None
397- >>> bucket = connection.get_bucket('my-bucket')
398- >>> print bucket
399- <Bucket: my-bucket>
400-
401- :type bucket_name: string
402- :param bucket_name: The name of the bucket to get.
403-
404- :rtype: :class:`gcloud.storage.bucket.Bucket`
405- :returns: The bucket matching the name provided or None if not found.
406- """
407- try :
408- return self .get_bucket (bucket_name )
409- except NotFound :
410- return None
411-
412387 def create_bucket (self , bucket ):
413388 """Create a new bucket.
414389
0 commit comments