Skip to content

Commit fd73bcf

Browse files
committed
Merge pull request #877 from tseaver/storage-remove_bucket___iter___and___contains__
Remove 'Bucket.__iter__' and 'Bucket.__contains__'.
2 parents a888f64 + 3a3edb4 commit fd73bcf

File tree

2 files changed

+2
-81
lines changed

2 files changed

+2
-81
lines changed

gcloud/storage/bucket.py

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""Create / interact with gcloud storage buckets.
16-
17-
If you want to check whether a blob exists, you can use the ``in`` operator
18-
in Python::
19-
20-
>>> print 'kitten.jpg' in bucket
21-
True
22-
>>> print 'does-not-exist' in bucket
23-
False
24-
25-
If you want to get all the blobs in the bucket, you can use
26-
:func:`list_blobs <gcloud.storage.bucket.Bucket.list_blobs>`::
27-
28-
>>> blobs = bucket.list_blobs()
29-
30-
You can also use the bucket as an iterator::
31-
32-
>>> for blob in bucket:
33-
... print blob
34-
"""
15+
"""Create / interact with gcloud storage buckets."""
3516

3617
import datetime
3718
import copy
@@ -56,7 +37,7 @@ class _BlobIterator(Iterator):
5637
"""An iterator listing blobs in a bucket
5738
5839
You shouldn't have to use this directly, but instead should use the
59-
helper methods on :class:`gcloud.storage.blob.Bucket` objects.
40+
:class:`gcloud.storage.blob.Bucket.list_blobs` method.
6041
6142
:type bucket: :class:`gcloud.storage.bucket.Bucket`
6243
:param bucket: The bucket from which to list blobs.
@@ -115,13 +96,6 @@ def __init__(self, name=None):
11596
def __repr__(self):
11697
return '<Bucket: %s>' % self.name
11798

118-
def __iter__(self):
119-
return iter(self.list_blobs())
120-
121-
def __contains__(self, blob_name):
122-
blob = Blob(blob_name, bucket=self)
123-
return blob.exists()
124-
12599
def exists(self, connection=None):
126100
"""Determines whether or not this bucket exists.
127101

gcloud/storage/test_bucket.py

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -106,59 +106,6 @@ def test_ctor_explicit(self):
106106
self.assertFalse(bucket._default_object_acl.loaded)
107107
self.assertTrue(bucket._default_object_acl.bucket is bucket)
108108

109-
def test___iter___empty(self):
110-
from gcloud.storage._testing import _monkey_defaults
111-
NAME = 'name'
112-
connection = _Connection({'items': []})
113-
bucket = self._makeOne(NAME)
114-
with _monkey_defaults(connection=connection):
115-
blobs = list(bucket)
116-
self.assertEqual(blobs, [])
117-
kw, = connection._requested
118-
self.assertEqual(kw['method'], 'GET')
119-
self.assertEqual(kw['path'], '/b/%s/o' % NAME)
120-
self.assertEqual(kw['query_params'], {'projection': 'noAcl'})
121-
122-
def test___iter___non_empty(self):
123-
from gcloud.storage._testing import _monkey_defaults
124-
NAME = 'name'
125-
BLOB_NAME = 'blob-name'
126-
connection = _Connection({'items': [{'name': BLOB_NAME}]})
127-
bucket = self._makeOne(NAME)
128-
with _monkey_defaults(connection=connection):
129-
blobs = list(bucket)
130-
blob, = blobs
131-
self.assertTrue(blob.bucket is bucket)
132-
self.assertEqual(blob.name, BLOB_NAME)
133-
kw, = connection._requested
134-
self.assertEqual(kw['method'], 'GET')
135-
self.assertEqual(kw['path'], '/b/%s/o' % NAME)
136-
self.assertEqual(kw['query_params'], {'projection': 'noAcl'})
137-
138-
def test___contains___miss(self):
139-
from gcloud.storage._testing import _monkey_defaults
140-
NAME = 'name'
141-
NONESUCH = 'nonesuch'
142-
connection = _Connection()
143-
bucket = self._makeOne(NAME)
144-
with _monkey_defaults(connection=connection):
145-
self.assertFalse(NONESUCH in bucket)
146-
kw, = connection._requested
147-
self.assertEqual(kw['method'], 'GET')
148-
self.assertEqual(kw['path'], '/b/%s/o/%s' % (NAME, NONESUCH))
149-
150-
def test___contains___hit(self):
151-
from gcloud.storage._testing import _monkey_defaults
152-
NAME = 'name'
153-
BLOB_NAME = 'blob-name'
154-
connection = _Connection({'name': BLOB_NAME})
155-
bucket = self._makeOne(NAME)
156-
with _monkey_defaults(connection=connection):
157-
self.assertTrue(BLOB_NAME in bucket)
158-
kw, = connection._requested
159-
self.assertEqual(kw['method'], 'GET')
160-
self.assertEqual(kw['path'], '/b/%s/o/%s' % (NAME, BLOB_NAME))
161-
162109
def test_exists_miss(self):
163110
from gcloud.exceptions import NotFound
164111

0 commit comments

Comments
 (0)