@@ -86,7 +86,11 @@ def __iter__(self):
8686 return iter (_BucketIterator (connection = self ))
8787
8888 def __contains__ (self , bucket_name ):
89- return self .lookup (bucket_name ) is not None
89+ try :
90+ self .get_bucket (bucket_name )
91+ return True
92+ except NotFound :
93+ return False
9094
9195 def build_api_url (self , path , query_params = None , api_base_url = None ,
9296 api_version = None , upload = False ):
@@ -274,10 +278,7 @@ def get_bucket(self, bucket_name):
274278 """Get a bucket by name.
275279
276280 If the bucket isn't found, this will raise a
277- :class:`gcloud.exceptions.NotFound`. If you would
278- rather get a bucket by name, and return ``None`` if the bucket
279- isn't found (like ``{}.get('...')``) then use
280- :func:`Connection.lookup`.
281+ :class:`gcloud.storage.exceptions.NotFound`.
281282
282283 For example::
283284
@@ -300,32 +301,6 @@ def get_bucket(self, bucket_name):
300301 response = self .api_request (method = 'GET' , path = bucket .path )
301302 return Bucket (properties = response , connection = self )
302303
303- def lookup (self , bucket_name ):
304- """Get a bucket by name, returning None if not found.
305-
306- You can use this if you would rather checking for a None value
307- than catching an exception::
308-
309- >>> from gcloud import storage
310- >>> connection = storage.get_connection(project)
311- >>> bucket = connection.get_bucket('doesnt-exist')
312- >>> print bucket
313- None
314- >>> bucket = connection.get_bucket('my-bucket')
315- >>> print bucket
316- <Bucket: my-bucket>
317-
318- :type bucket_name: string
319- :param bucket_name: The name of the bucket to get.
320-
321- :rtype: :class:`gcloud.storage.bucket.Bucket`
322- :returns: The bucket matching the name provided or None if not found.
323- """
324- try :
325- return self .get_bucket (bucket_name )
326- except NotFound :
327- return None
328-
329304 def create_bucket (self , bucket_name ):
330305 """Create a new bucket.
331306
0 commit comments